]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Various little cleanups, many of them from a clang static analysis
authorSteve Underwood <steveu@coppice.org>
Fri, 2 May 2014 15:32:33 +0000 (23:32 +0800)
committerSteve Underwood <steveu@coppice.org>
Fri, 2 May 2014 15:32:33 +0000 (23:32 +0800)
75 files changed:
libs/spandsp/src/alloc.c
libs/spandsp/src/at_interpreter.c
libs/spandsp/src/bell_r2_mf.c
libs/spandsp/src/dtmf.c
libs/spandsp/src/echo.c
libs/spandsp/src/fax.c
libs/spandsp/src/fax_modems.c
libs/spandsp/src/filter_tools.c
libs/spandsp/src/fsk.c
libs/spandsp/src/g722.c
libs/spandsp/src/g726.c
libs/spandsp/src/gsm0610_decode.c
libs/spandsp/src/gsm0610_encode.c
libs/spandsp/src/gsm0610_local.h
libs/spandsp/src/gsm0610_long_term.c
libs/spandsp/src/gsm0610_lpc.c
libs/spandsp/src/gsm0610_preprocess.c
libs/spandsp/src/gsm0610_rpe.c
libs/spandsp/src/gsm0610_short_term.c
libs/spandsp/src/ima_adpcm.c
libs/spandsp/src/image_translate.c
libs/spandsp/src/logging.c
libs/spandsp/src/lpc10_decode.c
libs/spandsp/src/lpc10_voicing.c
libs/spandsp/src/make_at_dictionary.c
libs/spandsp/src/make_cielab_luts.c
libs/spandsp/src/make_math_fixed_tables.c
libs/spandsp/src/make_modem_filter.c
libs/spandsp/src/make_t43_gray_code_tables.c
libs/spandsp/src/mmx_sse_decs.h
libs/spandsp/src/noise.c
libs/spandsp/src/sig_tone.c
libs/spandsp/src/spandsp/ademco_contactid.h
libs/spandsp/src/spandsp/bit_operations.h
libs/spandsp/src/spandsp/fax_modems.h
libs/spandsp/src/spandsp/logging.h
libs/spandsp/src/spandsp/private/fax_modems.h
libs/spandsp/src/spandsp/private/g722.h
libs/spandsp/src/spandsp/private/t31.h
libs/spandsp/src/spandsp/private/timezone.h
libs/spandsp/src/spandsp/saturated.h
libs/spandsp/src/spandsp/telephony.h
libs/spandsp/src/spandsp/v17rx.h
libs/spandsp/src/spandsp/v22bis.h
libs/spandsp/src/t31.c
libs/spandsp/src/t38_core.c
libs/spandsp/src/t38_gateway.c
libs/spandsp/src/t38_terminal.c
libs/spandsp/src/t43.c
libs/spandsp/src/t4_t6_encode.c
libs/spandsp/src/time_scale.c
libs/spandsp/src/timezone.c
libs/spandsp/src/v17rx.c
libs/spandsp/src/v17tx.c
libs/spandsp/src/v18.c
libs/spandsp/src/v22bis_rx.c
libs/spandsp/src/v22bis_tx.c
libs/spandsp/src/v27ter_rx.c
libs/spandsp/src/v27ter_tx.c
libs/spandsp/src/v29rx.c
libs/spandsp/src/v29tx.c
libs/spandsp/src/v42.c
libs/spandsp/tests/bell_mf_rx_tests.c
libs/spandsp/tests/dtmf_rx_tests.c
libs/spandsp/tests/echo_tests.c
libs/spandsp/tests/fax_tester.c
libs/spandsp/tests/fax_tests.sh
libs/spandsp/tests/g722_tests.c
libs/spandsp/tests/r2_mf_rx_tests.c
libs/spandsp/tests/saturated_tests.c
libs/spandsp/tests/super_tone_rx_tests.c
libs/spandsp/tests/t42_tests.c
libs/spandsp/tests/t43_tests.c
libs/spandsp/tests/udptl.c
libs/spandsp/tests/v8_tests.c

index b8cb6810c8f88ed1b2b9419517b075889de7f52d..3785293ea2276d70041226da312ec63e6177c44d 100644 (file)
@@ -41,7 +41,7 @@
 #define __ISO_C_VISIBLE 2011
 #endif
 #include <stdlib.h>
-#if defined(HAVE_MALLOC_H) && !defined(__OpenBSD__) && !defined(__DragonFly__)
+#if defined(HAVE_MALLOC_H)  &&  !defined(__OpenBSD__)  &&  !defined(__DragonFly__)
 #include <malloc.h>
 #endif
 #include <inttypes.h>
index c009a19a5240de615f4f7cf954d0e1f3cde40492..9bebde62724e4e371efcc4788d5aa0c332587434 100644 (file)
@@ -463,7 +463,6 @@ static int parse_hex_num(const char **s, int max_value)
 
     /* The spec. says a hex value is always 2 digits, and the alpha digits are
        upper case. */
-    i = 0;
     if (isdigit((int) **s))
         i = **s - '0';
     else if (**s >= 'A'  &&  **s <= 'F')
@@ -912,7 +911,6 @@ static const char *at_cmd_dummy(at_state_t *s, const char *t)
 static const char *at_cmd_A(at_state_t *s, const char *t)
 {
     /* V.250 6.3.5 - Answer (abortable) */
-    t += 1;
     if (!answer_call(s))
         return NULL;
     return (const char *) -1;
@@ -921,7 +919,6 @@ static const char *at_cmd_A(at_state_t *s, const char *t)
 
 static const char *at_cmd_D(at_state_t *s, const char *t)
 {
-    int ok;
     char *u;
     char num[100 + 1];
     char ch;
@@ -932,7 +929,6 @@ static const char *at_cmd_D(at_state_t *s, const char *t)
     s->silent_dial = false;
     s->command_dial = false;
     t += 1;
-    ok = false;
     /* There are a numbers of options in a dial command string.
        Many are completely irrelevant in this application. */
     u = num;
@@ -1024,7 +1020,7 @@ static const char *at_cmd_D(at_state_t *s, const char *t)
         }
     }
     *u = '\0';
-    if ((ok = at_modem_control(s, AT_MODEM_CONTROL_CALL, num)) < 0)
+    if (at_modem_control(s, AT_MODEM_CONTROL_CALL, num) < 0)
         return NULL;
     /* Dialing should now be in progress. No AT response should be
        issued at this point. */
index 8f74b7a86a16e4d16a895baae7729bb55d2e3a53..b8e507026e2d61f1d767f97ffb8ca13eb5e27ba3 100644 (file)
@@ -479,7 +479,6 @@ SPAN_DECLARE(int) bell_mf_rx(bell_mf_rx_state_t *s, const int16_t amp[], int sam
     int limit;
     uint8_t hit;
 
-    hit = 0;
     for (sample = 0;  sample < samples;  sample = limit)
     {
         if ((samples - sample) >= (BELL_MF_SAMPLES_PER_BLOCK - s->current_sample))
@@ -700,8 +699,6 @@ SPAN_DECLARE(int) r2_mf_rx(r2_mf_rx_state_t *s, const int16_t amp[], int samples
     int hit_digit;
     int limit;
 
-    hit = 0;
-    hit_digit = 0;
     for (sample = 0;  sample < samples;  sample = limit)
     {
         if ((samples - sample) >= (R2_MF_SAMPLES_PER_BLOCK - s->current_sample))
index 39c475a5541408219205d7f53b9b2a916136fafb..1f4e012dd314d436290957508d4eb3ebee65fd42 100644 (file)
@@ -131,7 +131,6 @@ SPAN_DECLARE(int) dtmf_rx(dtmf_rx_state_t *s, const int16_t amp[], int samples)
     int limit;
     uint8_t hit;
 
-    hit = 0;
     for (sample = 0;  sample < samples;  sample = limit)
     {
         /* The block length is optimised to meet the DTMF specs. */
index 5d6a1cadd285dfc9fc2193c741c396815a04934c..70c1730bc7190eb7d9b4725c87df6be1ab5b4b85 100644 (file)
@@ -392,7 +392,7 @@ static __inline__ int16_t echo_can_hpf(int32_t coeff[2], int16_t amp)
     coeff[1] = z;
     z = coeff[0] >> 15;
 
-    return saturate(z);
+    return saturate16(z);
 }
 /*- End of function --------------------------------------------------------*/
 
@@ -498,7 +498,7 @@ printf("Rotate to %d at %d\n", ec->tap_set, sample_no);
                 /* ... and we are not in the dwell time from previous speech. */
                 if ((ec->adaption_mode & ECHO_CAN_USE_ADAPTION)  &&   ec->narrowband_score == 0)
                 {
-                    //nsuppr = saturate((clean_rx << 16)/ec->tx_power[1]);
+                    //nsuppr = saturate16((clean_rx << 16)/ec->tx_power[1]);
                     //nsuppr = clean_rx/ec->tx_power[1];
                     /* If a sudden surge in signal level (e.g. the onset of a tone
                        burst) cause an abnormally high instantaneous to average
index c43abd02435fc339e0226edfa59513a471bf928f..998af14177f5c15aedbc74d774cf16e39e1881a8 100644 (file)
@@ -171,8 +171,10 @@ SPAN_DECLARE_NONSTD(int) fax_rx(fax_state_t *s, int16_t *amp, int len)
 #endif
     for (i = 0;  i < len;  i++)
         amp[i] = dc_restore(&s->modems.dc_restore, amp[i]);
+    /*endfor*/
     if (s->modems.rx_handler)
         s->modems.rx_handler(s->modems.rx_user_data, amp, len);
+    /*endif*/
     t30_timer_update(&s->t30, len);
     return 0;
 }
@@ -198,6 +200,7 @@ SPAN_DECLARE_NONSTD(int) fax_rx_fillin(fax_state_t *s, int len)
         vec_zeroi16(amp, len);
         write(s->modems.audio_rx_log, amp, len*sizeof(int16_t));
     }
+    /*endif*/
 #endif
     /* Call the fillin function of the current modem (if there is one). */
     s->modems.rx_fillin_handler(s->modems.rx_fillin_user_data, len);
@@ -254,6 +257,7 @@ static void fax_set_rx_type(void *user_data, int type, int bit_rate, int short_t
     span_log(&s->logging, SPAN_LOG_FLOW, "Set rx type %d\n", type);
     if (t->current_rx_type == type)
         return;
+    /*endif*/
     t->current_rx_type = type;
     t->rx_bit_rate = bit_rate;
     hdlc_rx_init(&t->hdlc_rx, false, true, HDLC_FRAMING_OK_THRESHOLD, fax_modems_hdlc_accept, t);
@@ -279,6 +283,7 @@ static void fax_set_rx_type(void *user_data, int type, int bit_rate, int short_t
         fax_modems_set_rx_handler(t, (span_rx_handler_t) &span_dummy_rx, s, (span_rx_fillin_handler_t) &span_dummy_rx_fillin, s);
         break;
     }
+    /*endswitch*/
 }
 /*- End of function --------------------------------------------------------*/
 
@@ -293,7 +298,7 @@ static void fax_set_tx_type(void *user_data, int type, int bit_rate, int short_t
     span_log(&s->logging, SPAN_LOG_FLOW, "Set tx type %d\n", type);
     if (t->current_tx_type == type)
         return;
-
+    /*endif*/
     switch (type)
     {
     case T30_MODEM_PAUSE:
@@ -359,6 +364,7 @@ static void fax_set_tx_type(void *user_data, int type, int bit_rate, int short_t
         t->transmit = false;
         break;
     }
+    /*endswitch*/
     t->tx_bit_rate = bit_rate;
     t->current_tx_type = type;
 }
@@ -398,12 +404,16 @@ SPAN_DECLARE(int) fax_restart(fax_state_t *s, int calling_party)
     v8_parms.modulations = V8_MOD_V21;
     if (s->t30.supported_modems & T30_SUPPORT_V27TER)
         v8_parms.modulations |= V8_MOD_V27TER;
+    /*endif*/
     if (s->t30.supported_modems & T30_SUPPORT_V29)
         v8_parms.modulations |= V8_MOD_V29;
+    /*endif*/
     if (s->t30.supported_modems & T30_SUPPORT_V17)
         v8_parms.modulations |= V8_MOD_V17;
+    /*endif*/
     if (s->t30.supported_modems & T30_SUPPORT_V34HDX)
         v8_parms.modulations |= V8_MOD_V34HDX;
+    /*endif*/
     v8_parms.protocol = V8_PROTOCOL_NONE;
     v8_parms.pcm_modem_availability = 0;
     v8_parms.pstn_access = 0;
@@ -453,7 +463,9 @@ SPAN_DECLARE(fax_state_t *) fax_init(fax_state_t *s, int calling_party)
     {
         if ((s = (fax_state_t *) span_alloc(sizeof(*s))) == NULL)
             return NULL;
+        /*endif*/
     }
+    /*endif*/
     memset(s, 0, sizeof(*s));
     span_log_init(&s->logging, SPAN_LOG_NONE, NULL);
     span_log_set_protocol(&s->logging, "FAX");
@@ -479,12 +491,16 @@ SPAN_DECLARE(fax_state_t *) fax_init(fax_state_t *s, int calling_party)
     v8_parms.modulations = V8_MOD_V21;
     if (s->t30.supported_modems & T30_SUPPORT_V27TER)
         v8_parms.modulations |= V8_MOD_V27TER;
+    /*endif*/
     if (s->t30.supported_modems & T30_SUPPORT_V29)
         v8_parms.modulations |= V8_MOD_V29;
+    /*endif*/
     if (s->t30.supported_modems & T30_SUPPORT_V17)
         v8_parms.modulations |= V8_MOD_V17;
+    /*endif*/
     if (s->t30.supported_modems & T30_SUPPORT_V34HDX)
         v8_parms.modulations |= V8_MOD_V34HDX;
+    /*endif*/
     v8_parms.protocol = V8_PROTOCOL_NONE;
     v8_parms.pcm_modem_availability = 0;
     v8_parms.pstn_access = 0;
index b32fba7adac7c16771bb0b1a4c25a96ea772863f..a09b0c950642504233a2a3c32f5cecb2d049e005 100644 (file)
@@ -157,6 +157,8 @@ SPAN_DECLARE_NONSTD(void) fax_modems_hdlc_accept(void *user_data, const uint8_t
     fax_modems_state_t *s;
 
     s = (fax_modems_state_t *) user_data;
+    /* If this is a good frame report - i.e. not a status report, or a bad frame - we can
+       say the current signal source is valid. */
     if (len >= 0  &&  ok)
         s->rx_frame_received = true;
     if (s->hdlc_accept)
index ff625bb13d726fdfe747d895fe6e41cd5fc96074..4411226074d5877cfd86a4246138f3a8ffaccd93 100644 (file)
@@ -195,6 +195,11 @@ void compute_hilbert_transform(double coeffs[], int len)
             coeffs[h + i] = -x;
             coeffs[h - i] = x;
         }
+        else
+        {
+            coeffs[h + i] =
+            coeffs[h - i] = 0.0;
+        }
     }
 }
 /*- End of function --------------------------------------------------------*/
index 29b32c65ea49487a02bed81f145f3a9015c13f79..07c242bfc498df65e1e354da2c44d41d645d9ebc 100644 (file)
@@ -175,7 +175,9 @@ SPAN_DECLARE(fsk_tx_state_t *) fsk_tx_init(fsk_tx_state_t *s,
     {
         if ((s = (fsk_tx_state_t *) span_alloc(sizeof(*s))) == NULL)
             return NULL;
+        /*endif*/
     }
+    /*endif*/
     memset(s, 0, sizeof(*s));
 
     s->get_bit = get_bit;
@@ -205,6 +207,7 @@ SPAN_DECLARE_NONSTD(int) fsk_tx(fsk_tx_state_t *s, int16_t amp[], int len)
 
     if (s->shutdown)
         return 0;
+    /*endif*/
     /* Make the transitions between 0 and 1 phase coherent, but instantaneous
        jumps. There is currently no interpolation for bauds that end mid-sample.
        Mainstream users will not care. Some specialist users might have a problem
@@ -218,15 +221,20 @@ SPAN_DECLARE_NONSTD(int) fsk_tx(fsk_tx_state_t *s, int16_t amp[], int len)
             {
                 if (s->status_handler)
                     s->status_handler(s->status_user_data, SIG_STATUS_END_OF_DATA);
+                /*endif*/
                 if (s->status_handler)
                     s->status_handler(s->status_user_data, SIG_STATUS_SHUTDOWN_COMPLETE);
+                /*endif*/
                 s->shutdown = true;
                 break;
             }
+            /*endif*/
             s->current_phase_rate = s->phase_rates[bit & 1];
         }
-        amp[sample] = dds_mod(&(s->phase_acc), s->current_phase_rate, s->scaling, 0);
+        /*endif*/
+        amp[sample] = dds_mod(&s->phase_acc, s->current_phase_rate, s->scaling, 0);
     }
+    /*endfor*/
     return sample;
 }
 /*- End of function --------------------------------------------------------*/
@@ -304,6 +312,7 @@ SPAN_DECLARE(int) fsk_rx_restart(fsk_rx_state_t *s, const fsk_spec_t *spec, int
        buffer. */
     if (s->correlation_span > FSK_MAX_WINDOW_LEN)
         s->correlation_span = FSK_MAX_WINDOW_LEN;
+    /*endif*/
 
     /* We need to scale, to avoid overflow in the correlation. */
     s->scaling_shift = 0;
@@ -313,6 +322,7 @@ SPAN_DECLARE(int) fsk_rx_restart(fsk_rx_state_t *s, const fsk_spec_t *spec, int
         s->scaling_shift++;
         chop >>= 1;
     }
+    /*endwhile*/
 
     /* Initialise the baud/bit rate tracking. */
     s->baud_phase = 0;
@@ -321,7 +331,7 @@ SPAN_DECLARE(int) fsk_rx_restart(fsk_rx_state_t *s, const fsk_spec_t *spec, int
     s->last_bit = 0;
 
     /* Initialise a power detector, so sense when a signal is present. */
-    power_meter_init(&(s->power), 4);
+    power_meter_init(&s->power, 4);
     s->signal_present = 0;
     return 0;
 }
@@ -337,7 +347,9 @@ SPAN_DECLARE(fsk_rx_state_t *) fsk_rx_init(fsk_rx_state_t *s,
     {
         if ((s = (fsk_rx_state_t *) span_alloc(sizeof(*s))) == NULL)
             return NULL;
+        /*endif*/
     }
+    /*endif*/
     memset(s, 0, sizeof(*s));
 
     s->put_bit = put_bit;
@@ -366,6 +378,7 @@ static void report_status_change(fsk_rx_state_t *s, int status)
         s->status_handler(s->status_user_data, status);
     else if (s->put_bit)
         s->put_bit(s->put_bit_user_data, status);
+    /*endif*/
 }
 /*- End of function --------------------------------------------------------*/
 
@@ -382,7 +395,6 @@ SPAN_DECLARE_NONSTD(int) fsk_rx(fsk_rx_state_t *s, const int16_t *amp, int len)
     complexi_t ph;
 
     buf_ptr = s->buf_ptr;
-
     for (i = 0;  i < len;  i++)
     {
         /* The *totally* asynchronous character to character behaviour of these
@@ -393,7 +405,7 @@ SPAN_DECLARE_NONSTD(int) fsk_rx(fsk_rx_state_t *s, const int16_t *amp, int len)
             s->dot[j].re -= s->window[j][buf_ptr].re;
             s->dot[j].im -= s->window[j][buf_ptr].im;
 
-            ph = dds_complexi(&(s->phase_acc[j]), s->phase_rate[j]);
+            ph = dds_complexi(&s->phase_acc[j], s->phase_rate[j]);
             s->window[j][buf_ptr].re = (ph.re*amp[i]) >> s->scaling_shift;
             s->window[j][buf_ptr].im = (ph.im*amp[i]) >> s->scaling_shift;
 
@@ -405,13 +417,14 @@ SPAN_DECLARE_NONSTD(int) fsk_rx(fsk_rx_state_t *s, const int16_t *amp, int len)
             dot = s->dot[j].im >> 15;
             sum[j] += dot*dot;
         }
+        /*endfor*/
         /* If there isn't much signal, don't demodulate - it will only produce
            useless junk results. */
         /* There should be no DC in the signal, but sometimes there is.
            We need to measure the power with the DC blocked, but not using
            a slow to respond DC blocker. Use the most elementary HPF. */
         x = amp[i] >> 1;
-        power = power_meter_update(&(s->power), x - s->last_sample);
+        power = power_meter_update(&s->power, x - s->last_sample);
         s->last_sample = x;
         if (s->signal_present)
         {
@@ -426,7 +439,9 @@ SPAN_DECLARE_NONSTD(int) fsk_rx(fsk_rx_state_t *s, const int16_t *amp, int len)
                     s->baud_phase = 0;
                     continue;
                 }
+                /*endif*/
             }
+            /*endif*/
         }
         else
         {
@@ -436,11 +451,13 @@ SPAN_DECLARE_NONSTD(int) fsk_rx(fsk_rx_state_t *s, const int16_t *amp, int len)
                 s->baud_phase = 0;
                 continue;
             }
+            /*endif*/
             if (s->baud_phase < (s->correlation_span >> 1) - 30)
             {
                 s->baud_phase++;
                 continue;
             }
+            /*endif*/
             s->signal_present = 1;
             /* Initialise the baud/bit rate tracking. */
             s->baud_phase = 0;
@@ -449,6 +466,7 @@ SPAN_DECLARE_NONSTD(int) fsk_rx(fsk_rx_state_t *s, const int16_t *amp, int len)
             s->last_bit = 0;
             report_status_change(s, SIG_STATUS_CARRIER_UP);
         }
+        /*endif*/
         /* Non-coherent FSK demodulation by correlation with the target tones
            over a one baud interval. The slow V.xx specs. are too open ended
            to allow anything fancier to be used. The dot products are calculated
@@ -469,7 +487,9 @@ SPAN_DECLARE_NONSTD(int) fsk_rx(fsk_rx_state_t *s, const int16_t *amp, int len)
                     s->baud_phase += (s->baud_rate >> 3);
                 else
                     s->baud_phase -= (s->baud_rate >> 3);
+                /*endif*/
             }
+            /*endif*/
             if ((s->baud_phase += s->baud_rate) >= (SAMPLE_RATE*100))
             {
                 /* We should be in the middle of a baud now, so report the current
@@ -477,6 +497,7 @@ SPAN_DECLARE_NONSTD(int) fsk_rx(fsk_rx_state_t *s, const int16_t *amp, int len)
                 s->baud_phase -= (SAMPLE_RATE*100);
                 s->put_bit(s->put_bit_user_data, baudstate);
             }
+            /*endif*/
             break;
         case FSK_FRAME_MODE_ASYNC:
             /* Fully asynchronous mode */
@@ -492,6 +513,7 @@ SPAN_DECLARE_NONSTD(int) fsk_rx(fsk_rx_state_t *s, const int16_t *amp, int len)
                    the most accurate baud alignment we can do. */
                 s->baud_phase = SAMPLE_RATE*50;
             }
+            /*endif*/
             if ((s->baud_phase += s->baud_rate) >= (SAMPLE_RATE*100))
             {
                 /* We should be in the middle of a baud now, so report the current
@@ -499,6 +521,7 @@ SPAN_DECLARE_NONSTD(int) fsk_rx(fsk_rx_state_t *s, const int16_t *amp, int len)
                 s->baud_phase -= (SAMPLE_RATE*100);
                 s->put_bit(s->put_bit_user_data, baudstate);
             }
+            /*endif*/
             break;
         case FSK_FRAME_MODE_5N1_FRAMES:
         case FSK_FRAME_MODE_7N1_FRAMES:
@@ -517,6 +540,7 @@ SPAN_DECLARE_NONSTD(int) fsk_rx(fsk_rx_state_t *s, const int16_t *amp, int len)
                     s->frame_bits = 0;
                     s->last_bit = -1;
                 }
+                /*endif*/
             }
             else if (s->frame_state == -1)
             {
@@ -535,7 +559,9 @@ SPAN_DECLARE_NONSTD(int) fsk_rx(fsk_rx_state_t *s, const int16_t *amp, int len)
                         s->frame_state = 1;
                         s->last_bit = baudstate;
                     }
+                    /*endif*/
                 }
+                /*endif*/
             }
             else
             {
@@ -544,6 +570,7 @@ SPAN_DECLARE_NONSTD(int) fsk_rx(fsk_rx_state_t *s, const int16_t *amp, int len)
                 {
                     if (s->last_bit < 0)
                         s->last_bit = baudstate;
+                    /*endif*/
                     /* Look for the bit being consistent over the central 20% of the bit time. */
                     if (s->last_bit != baudstate)
                     {
@@ -563,6 +590,7 @@ SPAN_DECLARE_NONSTD(int) fsk_rx(fsk_rx_state_t *s, const int16_t *amp, int len)
                                     /* Drop the start bit, and pass the rest back */
                                     s->put_bit(s->put_bit_user_data, s->frame_bits >> 2);
                                 }
+                                /*endif*/
                                 s->frame_state = 0;
                             }
                             else
@@ -570,21 +598,29 @@ SPAN_DECLARE_NONSTD(int) fsk_rx(fsk_rx_state_t *s, const int16_t *amp, int len)
                                 s->frame_bits |= (baudstate << s->framing_mode);
                                 s->frame_bits >>= 1;
                             }
+                            /*endif*/
                             s->baud_phase -= (SAMPLE_RATE*100);
                         }
                         else
                         {
                             s->frame_state = 0;
                         }
+                        /*endif*/
                         s->last_bit = -1;
                     }
+                    /*endif*/
                 }
+                /*endif*/
             }
+            /*endif*/
             break;
         }
+        /*endswitch*/
         if (++buf_ptr >= s->correlation_span)
             buf_ptr = 0;
+        /*endif*/
     }
+    /*endfor*/
     s->buf_ptr = buf_ptr;
     return 0;
 }
@@ -592,10 +628,33 @@ SPAN_DECLARE_NONSTD(int) fsk_rx(fsk_rx_state_t *s, const int16_t *amp, int len)
 
 SPAN_DECLARE_NONSTD(int) fsk_rx_fillin(fsk_rx_state_t *s, int len)
 {
+    int buf_ptr;
+    int i;
+    int j;
+
     /* The valid choice here is probably to do nothing. We don't change state
       (i.e carrier on<->carrier off), and we'll just output less bits than we
       should. */
-    /* TODO: Advance the symbol phase the appropriate amount */
+    buf_ptr = s->buf_ptr;
+    for (i = 0;  i < len;  i++)
+    {
+        for (j = 0;  j < 2;  j++)
+        {
+            s->dot[j].re -= s->window[j][buf_ptr].re;
+            s->dot[j].im -= s->window[j][buf_ptr].im;
+
+            dds_advance(&s->phase_acc[j], s->phase_rate[j]);
+
+            s->window[j][buf_ptr].re = 0;
+            s->window[j][buf_ptr].im = 0;
+
+            s->dot[j].re += s->window[j][buf_ptr].re;
+            s->dot[j].im += s->window[j][buf_ptr].im;
+        }
+        /*endfor*/
+    }
+    /*endfor*/
+    s->buf_ptr = buf_ptr;
     return 0;
 }
 /*- End of function --------------------------------------------------------*/
index 2f11715c106394a345b63f723be20b253cd5fac6..aebe9a575e57d8737a3588ebc7947c514eff6b7e 100644 (file)
@@ -194,37 +194,37 @@ static void block4(g722_band_t *s, int16_t dx)
     int i;
 
     /* RECONS */
-    r = saturated_add16(s->s, dx);
+    r = sat_add16(s->s, dx);
     /* PARREC */
-    p = saturated_add16(s->sz, dx);
+    p = sat_add16(s->sz, dx);
 
     /* UPPOL2 */
-    wd1 = saturate((int32_t) s->a[0] << 2);
+    wd1 = saturate16((int32_t) s->a[0] << 2);
     wd32 = ((p ^ s->p[0]) & 0x8000)  ?  wd1  :  -wd1;
     if (wd32 > 32767)
         wd32 = 32767;
     wd3 = (int16_t) ((((p ^ s->p[1]) & 0x8000)  ?  -128  :  128)
                      + (wd32 >> 7)
-                     + (((int32_t) s->a[1]*(int32_t) 32512) >> 15));
+                     + (((int32_t) s->a[1]*32512) >> 15));
     if (abs(wd3) > 12288)
         wd3 = (wd3 < 0)  ?  -12288  :  12288;
     ap[1] = wd3;
 
     /* UPPOL1 */
     wd1 = ((p ^ s->p[0]) & 0x8000)  ?  -192  :  192;
-    wd2 = (int16_t) (((int32_t) s->a[0]*(int32_t) 32640) >> 15);
-    ap[0] = saturated_add16(wd1, wd2);
+    wd2 = (int16_t) (((int32_t) s->a[0]*32640) >> 15);
+    ap[0] = sat_add16(wd1, wd2);
 
-    wd3 = saturated_sub16(15360, ap[1]);
+    wd3 = sat_sub16(15360, ap[1]);
     if (abs(ap[0]) > wd3)
         ap[0] = (ap[0] < 0)  ?  -wd3  :  wd3;
 
     /* FILTEP */
-    wd1 = saturated_add16(r, r);
-    wd1 = (int16_t) (((int32_t) ap[0]*(int32_t) wd1) >> 15);
-    wd2 = saturated_add16(s->r, s->r);
-    wd2 = (int16_t) (((int32_t) ap[1]*(int32_t) wd2) >> 15);
-    sp = saturated_add16(wd1, wd2);
+    wd1 = sat_add16(r, r);
+    wd1 = (int16_t) (((int32_t) ap[0]*wd1) >> 15);
+    wd2 = sat_add16(s->r, s->r);
+    wd2 = (int16_t) (((int32_t) ap[1]*wd2) >> 15);
+    sp = sat_add16(wd1, wd2);
     s->r = r;
     s->a[1] = ap[1];
     s->a[0] = ap[0];
@@ -240,16 +240,16 @@ static void block4(g722_band_t *s, int16_t dx)
     for (i = 5;  i >= 0;  i--)
     {
         wd2 = ((s->d[i + 1] ^ dx) & 0x8000)  ?  -wd1  :  wd1;
-        wd3 = (int16_t) (((int32_t) s->b[i]*(int32_t) 32640) >> 15);
-        s->b[i] = saturated_add16(wd2, wd3);
-        wd3 = saturated_add16(s->d[i], s->d[i]);
-        sz += ((int32_t) s->b[i]*(int32_t) wd3) >> 15;
+        wd3 = (int16_t) (((int32_t) s->b[i]*32640) >> 15);
+        s->b[i] = sat_add16(wd2, wd3);
+        wd3 = sat_add16(s->d[i], s->d[i]);
+        sz += ((int32_t) s->b[i]*wd3) >> 15;
         s->d[i + 1] = s->d[i];
     }
-    s->sz = saturate(sz);
+    s->sz = saturate16(sz);
 
     /* PREDIC */
-    s->s = saturated_add16(sp, s->sz);
+    s->s = sat_add16(sp, s->sz);
 }
 /*- End of function --------------------------------------------------------*/
 
@@ -349,18 +349,18 @@ SPAN_DECLARE(int) g722_decode(g722_decode_state_t *s, int16_t amp[], const uint8
             break;
         }
         /* Block 5L, LOW BAND INVQBL */
-        wd2 = ((int32_t) s->band[0].det*(int32_t) wd2) >> 15;
+        wd2 = ((int32_t) s->band[0].det*wd2) >> 15;
         /* Block 5L, RECONS */
         /* Block 6L, LIMIT */
         rlow = saturate15(s->band[0].s + wd2);
 
         /* Block 2L, INVQAL */
         wd2 = qm4[wd1];
-        dlow = (int16_t) (((int32_t) s->band[0].det*(int32_t) wd2) >> 15);
+        dlow = (int16_t) (((int32_t) s->band[0].det*wd2) >> 15);
 
         /* Block 3L, LOGSCL */
         wd2 = rl42[wd1];
-        wd1 = ((int32_t) s->band[0].nb*(int32_t) 127) >> 7;
+        wd1 = ((int32_t) s->band[0].nb*127) >> 7;
         wd1 += wl[wd2];
         if (wd1 < 0)
             wd1 = 0;
@@ -380,14 +380,14 @@ SPAN_DECLARE(int) g722_decode(g722_decode_state_t *s, int16_t amp[], const uint8
         {
             /* Block 2H, INVQAH */
             wd2 = qm2[ihigh];
-            dhigh = (int16_t) (((int32_t) s->band[1].det*(int32_t) wd2) >> 15);
+            dhigh = (int16_t) (((int32_t) s->band[1].det*wd2) >> 15);
             /* Block 5H, RECONS */
             /* Block 6H, LIMIT */
             rhigh = saturate15(dhigh + s->band[1].s);
 
             /* Block 2H, INVQAH */
             wd2 = rh2[ihigh];
-            wd1 = ((int32_t) s->band[1].nb*(int32_t) 127) >> 7;
+            wd1 = ((int32_t) s->band[1].nb*127) >> 7;
             wd1 += wh[wd2];
             if (wd1 < 0)
                 wd1 = 0;
@@ -532,14 +532,14 @@ SPAN_DECLARE(int) g722_encode(g722_encode_state_t *s, uint8_t g722_data[], const
             }
         }
         /* Block 1L, SUBTRA */
-        el = saturated_sub16(xlow, s->band[0].s);
+        el = sat_sub16(xlow, s->band[0].s);
 
         /* Block 1L, QUANTL */
         wd = (el >= 0)  ?  el  :  ~el;
 
         for (i = 1;  i < 30;  i++)
         {
-            wd1 = ((int32_t) q6[i]*(int32_t) s->band[0].det) >> 12;
+            wd1 = ((int32_t) q6[i]*s->band[0].det) >> 12;
             if (wd < wd1)
                 break;
         }
@@ -548,11 +548,11 @@ SPAN_DECLARE(int) g722_encode(g722_encode_state_t *s, uint8_t g722_data[], const
         /* Block 2L, INVQAL */
         ril = ilow >> 2;
         wd2 = qm4[ril];
-        dlow = (int16_t) (((int32_t) s->band[0].det*(int32_t) wd2) >> 15);
+        dlow = (int16_t) (((int32_t) s->band[0].det*wd2) >> 15);
 
         /* Block 3L, LOGSCL */
         il4 = rl42[ril];
-        wd = ((int32_t) s->band[0].nb*(int32_t) 127) >> 7;
+        wd = ((int32_t) s->band[0].nb*127) >> 7;
         s->band[0].nb = (int16_t) (wd + wl[il4]);
         if (s->band[0].nb < 0)
             s->band[0].nb = 0;
@@ -575,7 +575,7 @@ SPAN_DECLARE(int) g722_encode(g722_encode_state_t *s, uint8_t g722_data[], const
         else
         {
             /* Block 1H, SUBTRA */
-            eh = saturated_sub16(xhigh, s->band[1].s);
+            eh = sat_sub16(xhigh, s->band[1].s);
 
             /* Block 1H, QUANTH */
             wd = (eh >= 0)  ?  eh  :  ~eh;
@@ -585,11 +585,11 @@ SPAN_DECLARE(int) g722_encode(g722_encode_state_t *s, uint8_t g722_data[], const
 
             /* Block 2H, INVQAH */
             wd2 = qm2[ihigh];
-            dhigh = (int16_t) (((int32_t) s->band[1].det*(int32_t) wd2) >> 15);
+            dhigh = (int16_t) (((int32_t) s->band[1].det*wd2) >> 15);
 
             /* Block 3H, LOGSCH */
             ih2 = rh2[ihigh];
-            wd = ((int32_t) s->band[1].nb*(int32_t) 127) >> 7;
+            wd = ((int32_t) s->band[1].nb*127) >> 7;
             s->band[1].nb = (int16_t) (wd + wh[ih2]);
             if (s->band[1].nb < 0)
                 s->band[1].nb = 0;
index 4f3bea3b6b4545afc96afac49f42d1ddb061c55e..3219465d11a75e32bcd88ed202b013d9b28c0390 100644 (file)
@@ -295,7 +295,7 @@ static int step_size(g726_state_t *s)
  */
 static int16_t quantize(int d,                  /* Raw difference signal sample */
                         int y,                  /* Step size multiplier */
-                        const int table[],     /* quantization table */
+                        const int table[],      /* quantization table */
                         int quantizer_states)   /* table size of int16_t integers */
 {
     int16_t dqm;    /* Magnitude of 'd' */
index d3e21f390f7e813826e1a7a57fa3e4dc9c20b8c4..81097d1a2149c6c3a38876fbf3858f8424016ba5 100644 (file)
@@ -65,9 +65,9 @@ static void postprocessing(gsm0610_state_t *s, int16_t amp[])
     {
         tmp = gsm_mult_r(msr, 28180);
         /* De-emphasis */
-        msr = saturated_add16(amp[k], tmp);
-        /* Truncation & upscaling */
-        amp[k] = (int16_t) (saturated_add16(msr, msr) & 0xFFF8);
+        msr = sat_add16(amp[k], tmp);
+        /* Truncation and upscaling */
+        amp[k] = (int16_t) (sat_add16(msr, msr) & 0xFFF8);
     }
     /*endfor*/
     s->msr = msr;
@@ -162,7 +162,6 @@ SPAN_DECLARE(int) gsm0610_unpack_wav49(gsm0610_frame_t *s, const uint8_t c[])
         s->xmaxc[i] = sr & 0x3F;
         sr >>= 6;
         s->xMc[i][0] = sr & 0x7;
-        sr >>= 3;
         sr = *c++;
         s->xMc[i][1] = sr & 0x7;
         sr >>= 3;
@@ -181,7 +180,6 @@ SPAN_DECLARE(int) gsm0610_unpack_wav49(gsm0610_frame_t *s, const uint8_t c[])
         s->xMc[i][7] = sr & 0x7;
         sr >>= 3;
         s->xMc[i][8] = sr & 0x7;
-        sr >>= 3;
         sr = *c++;
         s->xMc[i][9] = sr & 0x7;
         sr >>= 3;
@@ -199,7 +197,6 @@ SPAN_DECLARE(int) gsm0610_unpack_wav49(gsm0610_frame_t *s, const uint8_t c[])
     s->LARc[0] = sr & 0x3F;
     sr >>= 6;
     s->LARc[1] = sr & 0x3F;
-    sr >>= 6;
     sr = *c++;
     s->LARc[2] = sr & 0x1F;
     sr >>= 5;
@@ -214,7 +211,6 @@ SPAN_DECLARE(int) gsm0610_unpack_wav49(gsm0610_frame_t *s, const uint8_t c[])
     s->LARc[6] = sr & 0x7;
     sr >>= 3;
     s->LARc[7] = sr & 0x7;
-    sr >>= 3;
 
     for (i = 0;  i < 4;  i++)
     {
@@ -239,7 +235,6 @@ SPAN_DECLARE(int) gsm0610_unpack_wav49(gsm0610_frame_t *s, const uint8_t c[])
         s->xMc[i][3] = sr & 0x7;
         sr >>= 3;
         s->xMc[i][4] = sr & 0x7;
-        sr >>= 3;
         sr = *c++;
         s->xMc[i][5] = sr & 0x7;
         sr >>= 3;
@@ -258,7 +253,6 @@ SPAN_DECLARE(int) gsm0610_unpack_wav49(gsm0610_frame_t *s, const uint8_t c[])
         s->xMc[i][11] = sr & 0x7;
         sr >>= 3;
         s->xMc[i][12] = sr & 0x7;
-        sr >>= 3;
     }
     return 65;
 }
index eeac7d288130c0bf64f47248a2a765ac727fc8b0..c810fa2c69993118a3fe1600ddd06b2efa289262 100644 (file)
@@ -93,7 +93,7 @@ static void encode_a_frame(gsm0610_state_t *s, gsm0610_frame_t *f, const int16_t
         gsm0610_rpe_encoding(s, s->e + 5, &f->xmaxc[k], &f->Mc[k], f->xMc[k]);
 
         for (i = 0;  i < 40;  i++)
-            dp[i] = saturated_add16(s->e[5 + i], dpp[i]);
+            dp[i] = sat_add16(s->e[5 + i], dpp[i]);
         /*endfor*/
         dp += 40;
         dpp += 40;
index 84c4c20edca292d577cc0c899a29a30aa2a4fe2c..8aaac612e0659e2ac9ccf85680319f3e7c51d2a0 100644 (file)
@@ -53,7 +53,7 @@ static __inline__ int16_t gsm_add(int16_t a, int16_t b)
     int32_t sum;
 
     sum = (int32_t) a + (int32_t) b;
-    return  saturate(sum);
+    return  saturate16(sum);
 #endif
 }
 /*- End of function --------------------------------------------------------*/
@@ -98,7 +98,7 @@ static __inline__ int16_t gsm_sub(int16_t a, int16_t b)
     int32_t diff;
 
     diff = (int32_t) a - (int32_t) b;
-    return  saturate(diff);
+    return  saturate16(diff);
 }
 /*- End of function --------------------------------------------------------*/
 
index 32d4ab39b7189208012836ea35e25ec25891b601..2ec7aa78181bca346d3bb71478b3120082fcf61c 100644 (file)
@@ -269,7 +269,7 @@ static int16_t evaluate_ltp_parameters(int16_t d[40],
     for (k = 0;  k < 40;  k++)
     {
         temp = d[k];
-        temp = saturated_abs16(temp);
+        temp = sat_abs16(temp);
         if (temp > dmax)
             dmax = temp;
         /*endif*/
@@ -337,7 +337,7 @@ static int16_t evaluate_ltp_parameters(int16_t d[40],
        quantization of the LTP gain b to get the coded version bc. */
     for (bc = 0;  bc <= 2;  bc++)
     {
-        if (R <= saturated_mul16(S, gsm_DLB[bc]))
+        if (R <= sat_mul16(S, gsm_DLB[bc]))
             break;
         /*endif*/
     }
@@ -363,7 +363,7 @@ static void long_term_analysis_filtering(int16_t bc,
     for (k = 0;  k < 40;  k++)
     {
         dpp[k] = gsm_mult_r(gsm_QLB[bc], dp[k - Nc]);
-        e[k] = saturated_sub16(d[k], dpp[k]);
+        e[k] = sat_sub16(d[k], dpp[k]);
     }
     /*endfor*/
 }
@@ -421,7 +421,7 @@ void gsm0610_long_term_synthesis_filtering(gsm0610_state_t *s,
     for (k = 0;  k < 40;  k++)
     {
         drpp = gsm_mult_r(brp, drp[k - Nr]);
-        drp[k] = saturated_add16(erp[k], drpp);
+        drp[k] = sat_add16(erp[k], drpp);
     }
     /*endfor*/
 
index 8d32edab6bf81fc5b8ff10298be8ec85176009c9..70e06d4122d3cb88b074ca8b02a08c9600dc9b31 100644 (file)
@@ -290,11 +290,11 @@ static void autocorrelation(int16_t amp[GSM0610_FRAME_LEN], int32_t L_ACF[9])
     /* Dynamic scaling of the array  s[0..159] */
     /* Search for the maximum. */
 #if defined(__GNUC__)  &&  defined(SPANDSP_USE_MMX)
-    smax = saturate(vec_min_maxi16(amp, GSM0610_FRAME_LEN, NULL));
+    smax = saturate16(vec_min_maxi16(amp, GSM0610_FRAME_LEN, NULL));
 #else
     for (smax = 0, k = 0;  k < GSM0610_FRAME_LEN;  k++)
     {
-        temp = saturated_abs16(amp[k]);
+        temp = sat_abs16(amp[k]);
         if (temp > smax)
             smax = (int16_t) temp;
         /*endif*/
@@ -462,7 +462,7 @@ static void reflection_coefficients(int32_t L_ACF[9], int16_t r[8])
     for (n = 1;  n <= 8;  n++, r++)
     {
         temp = P[1];
-        temp = saturated_abs16(temp);
+        temp = sat_abs16(temp);
         if (P[0] < temp)
         {
             for (i = n;  i <= 8;  i++)
@@ -485,15 +485,15 @@ static void reflection_coefficients(int32_t L_ACF[9], int16_t r[8])
 
         /* Schur recursion */
         temp = gsm_mult_r(P[1], *r);
-        P[0] = saturated_add16(P[0], temp);
+        P[0] = sat_add16(P[0], temp);
 
         for (m = 1;  m <= 8 - n;  m++)
         {
             temp = gsm_mult_r(K[m], *r);
-            P[m] = saturated_add16(P[m + 1], temp);
+            P[m] = sat_add16(P[m + 1], temp);
 
             temp = gsm_mult_r(P[m + 1], *r);
-            K[m] = saturated_add16(K[m], temp);
+            K[m] = sat_add16(K[m], temp);
         }
         /*endfor*/
     }
@@ -517,7 +517,7 @@ static void transform_to_log_area_ratios(int16_t r[8])
     /* Computation of the LAR[0..7] from the r[0..7] */
     for (i = 1;  i <= 8;  i++, r++)
     {
-        temp = saturated_abs16(*r);
+        temp = sat_abs16(*r);
         assert(temp >= 0);
 
         if (temp < 22118)
@@ -559,8 +559,8 @@ static void quantization_and_coding(int16_t LAR[8])
 
 #undef STEP
 #define STEP(A,B,MAC,MIC)                                       \
-        temp = saturated_mul16(A, *LAR);                        \
-        temp = saturated_add16(temp, (B + 256));                \
+        temp = sat_mul16(A, *LAR);                              \
+        temp = sat_add16(temp, (B + 256));                      \
         temp >>= 9;                                             \
         *LAR  = (int16_t) ((temp > MAC)                         \
                          ?                                      \
index 92ca2e30b3f5ec0a5241496da5bec3b8cfca8d12..b4191b78c80b42e2c49ba293fdd98e1038ddf761 100644 (file)
@@ -121,7 +121,7 @@ void gsm0610_preprocess(gsm0610_state_t *s, const int16_t amp[GSM0610_FRAME_LEN]
          * L_temp = (++L_temp) >> 1;
          * L_z2 = L_z2 - L_temp;
          */
-        L_z2 = saturated_add32(L_z2, L_s2);
+        L_z2 = sat_add32(L_z2, L_s2);
 #else
         /* This does L_z2  = L_z2 * 0x7FD5/0x8000 + L_s2 */
         msp = (int16_t) (L_z2 >> 15);
@@ -129,16 +129,16 @@ void gsm0610_preprocess(gsm0610_state_t *s, const int16_t amp[GSM0610_FRAME_LEN]
 
         L_s2 += gsm_mult_r(lsp, 32735);
         L_temp = (int32_t) msp*32735;
-        L_z2 = saturated_add32(L_temp, L_s2);
+        L_z2 = sat_add32(L_temp, L_s2);
 #endif
 
         /* Compute sof[k] with rounding */
-        L_temp = saturated_add32(L_z2, 16384);
+        L_temp = sat_add32(L_z2, 16384);
 
         /* 4.2.3  Preemphasis */
         msp = gsm_mult_r(mp, -28180);
         mp = (int16_t) (L_temp >> 15);
-        so[k] = saturated_add16(mp, msp);
+        so[k] = sat_add16(mp, msp);
     }
     /*endfor*/
 
index 0a6cbb649cd2dcaa16d3f68a7a40cf9d0619c821..b21e43af14f67ec36eb3c8284b2d89bf3aa0928b 100644 (file)
@@ -196,8 +196,8 @@ static void weighting_filter(int16_t x[40],
 
         /* for (i = 0; i <= 10; i++)
          * {
-         *      temp   = saturated_mul16_32(wt[k + i], gsm_H[i]);
-         *      result = saturated_add32(result, temp);
+         *      temp   = sat_mul16_32(wt[k + i], gsm_H[i]);
+         *      result = sat_add32(result, temp);
          * }
          */
 
@@ -223,7 +223,7 @@ static void weighting_filter(int16_t x[40],
         /* 2 adds vs. >> 16 => 14, minus one shift to compensate for
            those we lost when replacing L_MULT by '*'. */
         result >>= 13;
-        x[k] = saturate(result);
+        x[k] = saturate16(result);
     }
     /*endfor*/
 #endif
@@ -242,7 +242,6 @@ static void rpe_grid_selection(int16_t x[40], int16_t xM[13], int16_t *Mc_out)
 
     /* The signal x[0..39] is used to select the RPE grid which is
        represented by Mc. */
-
     EM = 0;
     Mc = 0;
 
@@ -327,10 +326,7 @@ static void rpe_grid_selection(int16_t x[40], int16_t xM[13], int16_t *Mc_out)
     STEP(3, 12);
     L_result <<= 1;
     if (L_result > EM)
-    {
         Mc = 3;
-        EM = L_result;
-    }
     /*endif*/
 
     /* Down-sampling by a factor 3 to get the selected xM[0..12]
@@ -408,7 +404,7 @@ static void apcm_quantization(int16_t xM[13],
     for (i = 0;  i < 13;  i++)
     {
         temp = xM[i];
-        temp = saturated_abs16(temp);
+        temp = sat_abs16(temp);
         if (temp > xmax)
             xmax = temp;
         /*endif*/
@@ -436,7 +432,7 @@ static void apcm_quantization(int16_t xM[13],
     temp = (int16_t) (exp + 5);
 
     assert(temp <= 11  &&  temp >= 0);
-    xmaxc = saturated_add16((xmax >> temp), exp << 3);
+    xmaxc = sat_add16((xmax >> temp), exp << 3);
 
     /* Quantizing and coding of the xM[0..12] RPE sequence
        to get the xMc[0..12] */
@@ -463,7 +459,7 @@ static void apcm_quantization(int16_t xM[13],
         assert(temp1 >= 0  &&  temp1 < 16);
 
         temp = xM[i] << temp1;
-        temp = saturated_mul16(temp, temp2);
+        temp = sat_mul16(temp, temp2);
         temp >>= 12;
         xMc[i] = (int16_t) (temp + 4);      /* See note below */
     }
@@ -483,7 +479,7 @@ static void apcm_inverse_quantization(int16_t xMc[13],
                                       int16_t xMp[13])
 {
     /* Table 4.6   Normalized direct mantissa used to compute xM/xmax */
-    static const int16_t gsm_FAC[8] =
+    static const int16_t gsm_fac[8] =
     {
         18431, 20479, 22527, 24575, 26623, 28671, 30719, 32767
     };
@@ -501,9 +497,9 @@ static void apcm_inverse_quantization(int16_t xMc[13],
     assert(mant >= 0  &&  mant <= 7);
 #endif
 
-    temp1 = gsm_FAC[mant];                  /* See 4.2-15 for mant */
-    temp2 = saturated_sub16(6, exp);        /* See 4.2-15 for exp */
-    temp3 = gsm_asl(1, saturated_sub16(temp2, 1));
+    temp1 = gsm_fac[mant];                      /* See 4.2-15 for mant */
+    temp2 = sat_sub16(6, exp);                  /* See 4.2-15 for exp */
+    temp3 = gsm_asl(1, sat_sub16(temp2, 1));
 
     for (i = 0;  i < 13;  i++)
     {
@@ -514,7 +510,7 @@ static void apcm_inverse_quantization(int16_t xMc[13],
 
         temp <<= 12;                            /* 16 bit signed */
         temp = gsm_mult_r(temp1, temp);
-        temp = saturated_add16(temp, temp3);
+        temp = sat_add16(temp, temp3);
         xMp[i] = gsm_asr(temp, temp2);
     }
     /*endfor*/
index 1eb46a7e972f28b351ace3313c795f4f33388428..62130fdf28837f192c000ba31a5a4bc17c5c4537 100644 (file)
@@ -68,10 +68,10 @@ static void decode_log_area_ratios(int16_t LARc[8], int16_t *LARpp)
 
 #undef STEP
 #define STEP(B,MIC,INVA)                            \
-    temp1 = saturated_add16(*LARc++, MIC) << 10;    \
-    temp1 = saturated_sub16(temp1, B << 1);         \
+    temp1 = sat_add16(*LARc++, MIC) << 10;          \
+    temp1 = sat_sub16(temp1, B << 1);               \
     temp1 = gsm_mult_r(INVA, temp1);                \
-    *LARpp++ = saturated_add16(temp1, temp1);
+    *LARpp++ = sat_add16(temp1, temp1);
 
     STEP(    0,  -32,  13107);
     STEP(    0,  -32,  13107);
@@ -109,8 +109,8 @@ static void coefficients_0_12(int16_t *LARpp_j_1,
 
     for (i = 1;  i <= 8;  i++, LARp++, LARpp_j_1++, LARpp_j++)
     {
-        *LARp = saturated_add16(*LARpp_j_1 >> 2, *LARpp_j >> 2);
-        *LARp = saturated_add16(*LARp, *LARpp_j_1 >> 1);
+        *LARp = sat_add16(*LARpp_j_1 >> 2, *LARpp_j >> 2);
+        *LARp = sat_add16(*LARp, *LARpp_j_1 >> 1);
     }
     /*endfor*/
 }
@@ -123,7 +123,7 @@ static void coefficients_13_26(int16_t *LARpp_j_1,
     int i;
 
     for (i = 1;  i <= 8;  i++, LARpp_j_1++, LARpp_j++, LARp++)
-        *LARp = saturated_add16(*LARpp_j_1 >> 1, *LARpp_j >> 1);
+        *LARp = sat_add16(*LARpp_j_1 >> 1, *LARpp_j >> 1);
     /*endfor*/
 }
 /*- End of function --------------------------------------------------------*/
@@ -136,8 +136,8 @@ static void coefficients_27_39(int16_t *LARpp_j_1,
 
     for (i = 1;  i <= 8;  i++, LARpp_j_1++, LARpp_j++, LARp++)
     {
-        *LARp = saturated_add16(*LARpp_j_1 >> 2, *LARpp_j >> 2);
-        *LARp = saturated_add16(*LARp, *LARpp_j >> 1);
+        *LARp = sat_add16(*LARpp_j_1 >> 2, *LARpp_j >> 2);
+        *LARp = sat_add16(*LARp, *LARpp_j >> 1);
     }
     /*endfor*/
 }
@@ -181,7 +181,7 @@ static void larp_to_rp(int16_t LARp[8])
             else if (temp < 20070)
                 temp += 11059;
             else
-                temp = saturated_add16(temp >> 2, 26112);
+                temp = sat_add16(temp >> 2, 26112);
             /*endif*/
             *LARpx = -temp;
         }
@@ -192,7 +192,7 @@ static void larp_to_rp(int16_t LARp[8])
             else if (temp < 20070)
                 temp += 11059;
             else
-                temp = saturated_add16(temp >> 2, 26112);
+                temp = sat_add16(temp >> 2, 26112);
             /*endif*/
             *LARpx = temp;
         }
@@ -242,8 +242,8 @@ static void short_term_analysis_filtering(gsm0610_state_t *s,
             rpi = *rpx++;
             u_out = ui + (((rpi*di) + 0x4000) >> 15);
             di = di + (((rpi*ui) + 0x4000) >> 15);
-            u_out = saturate(u_out);
-            di = saturate(di);
+            u_out = saturate16(u_out);
+            di = saturate16(di);
         }
         /*endfor*/
         amp[i] = (int16_t) di;
@@ -278,7 +278,7 @@ static void short_term_synthesis_filtering(gsm0610_state_t *s,
                    :
                    (int16_t) (((int32_t) tmp1*(int32_t) tmp2 + 16384) >> 15) & 0xFFFF);
 
-            sri = saturated_sub16(sri, tmp2);
+            sri = sat_sub16(sri, tmp2);
 
             tmp1 = ((tmp1 == INT16_MIN  &&  sri == INT16_MIN)
                     ?
@@ -286,7 +286,7 @@ static void short_term_synthesis_filtering(gsm0610_state_t *s,
                     :
                     (int16_t) (((int32_t) tmp1*(int32_t) sri + 16384) >> 15) & 0xFFFF);
 
-            v[i + 1] = saturated_add16(v[i], tmp1);
+            v[i + 1] = sat_add16(v[i], tmp1);
         }
         /*endfor*/
         *sr++ =
index fbd59df62183594ced9d7bead1ccbdfa843cf061..c974424cb4ddd4b46e2d225a14c8b70b3a53fdc5 100644 (file)
@@ -194,7 +194,7 @@ static int16_t decode(ima_adpcm_state_t *s, uint8_t adpcm)
     int ss;
     int16_t linear;
 
-    /* e = (adpcm+0.5)*step/4 */
+    /* e = (adpcm + 0.5)*step/4 */
     ss = step_size[s->step_index];
     e = ss >> 3;
     if (adpcm & 0x01)
@@ -209,7 +209,7 @@ static int16_t decode(ima_adpcm_state_t *s, uint8_t adpcm)
     if (adpcm & 0x08)
         e = -e;
     /*endif*/
-    linear = saturate(s->last + e);
+    linear = saturate16(s->last + e);
     s->last = linear;
     s->step_index += step_adjustment[adpcm & 0x07];
     if (s->step_index < 0)
@@ -266,7 +266,7 @@ static uint8_t encode(ima_adpcm_state_t *s, int16_t linear)
     else
         diff = diff + initial_e - e;
     /*endif*/
-    s->last = saturate(diff + s->last);
+    s->last = saturate16(diff + s->last);
     s->step_index += step_adjustment[adpcm & 0x07];
     if (s->step_index < 0)
         s->step_index = 0;
index 217e560260ca74a10e644f413488f6f7b8048d0e..d337ee98a2156eccf49d88684b6ca5c5d976d90d 100644 (file)
@@ -461,7 +461,6 @@ static int image_resize_row(image_translate_state_t *s, uint8_t buf[])
     case T4_IMAGE_TYPE_GRAY_12BIT:
         row16[0] = (uint16_t *) s->raw_pixel_row[0];
         row16[1] = (uint16_t *) s->raw_pixel_row[1];
-        buf16 = (uint16_t *) buf;
         for (i = 0;  i < output_width;  i++)
         {
 #if defined(SPANDSP_USE_FIXED_POINT)
@@ -668,7 +667,6 @@ static int image_format_to_bytes_per_pixel(int image_format)
 {
     switch (image_format)
     {
-    default:
     case T4_IMAGE_TYPE_BILEVEL:
     case T4_IMAGE_TYPE_GRAY_8BIT:
         return 1;
@@ -685,6 +683,7 @@ static int image_format_to_bytes_per_pixel(int image_format)
     case T4_IMAGE_TYPE_4COLOUR_12BIT:
         return 8;
     }
+    return 1;
 }
 /*- End of function --------------------------------------------------------*/
 
index 09bc29b6c631c14e54b8b0b99b8966c010547350..808ee7e39232c450f049ff519bbab38130163d01 100644 (file)
@@ -143,7 +143,7 @@ SPAN_DECLARE(int) span_log(logging_state_t *s, int level, const char *format, ..
             /*endif*/
         }
         /*endif*/
-        len += vsnprintf(msg + len, 1024 - len, format, arg_ptr);
+        vsnprintf(msg + len, 1024 - len, format, arg_ptr);
         if (s->span_message)
             s->span_message(s->user_data, level, msg);
         else if (__span_message)
@@ -170,13 +170,19 @@ SPAN_DECLARE(int) span_log_buf(logging_state_t *s, int level, const char *tag, c
             msg_len += snprintf(msg + msg_len, 1024 - msg_len, "%s", tag);
         for (i = 0;  i < len  &&  msg_len < 800;  i++)
             msg_len += snprintf(msg + msg_len, 1024 - msg_len, " %02x", buf[i]);
-        msg_len += snprintf(msg + msg_len, 1024 - msg_len, "\n");
+        snprintf(msg + msg_len, 1024 - msg_len, "\n");
         return span_log(s, level, msg);
     }
     return 0;
 }
 /*- End of function --------------------------------------------------------*/
 
+SPAN_DECLARE(int) span_log_get_level(logging_state_t *s)
+{
+    return s->level;
+}
+/*- End of function --------------------------------------------------------*/
+
 SPAN_DECLARE(int) span_log_set_level(logging_state_t *s, int level)
 {
     s->level = level;
@@ -185,6 +191,12 @@ SPAN_DECLARE(int) span_log_set_level(logging_state_t *s, int level)
 }
 /*- End of function --------------------------------------------------------*/
 
+SPAN_DECLARE(const char *) span_log_get_tag(logging_state_t *s)
+{
+    return s->tag;
+}
+/*- End of function --------------------------------------------------------*/
+
 SPAN_DECLARE(int) span_log_set_tag(logging_state_t *s, const char *tag)
 {
     s->tag = tag;
@@ -193,6 +205,12 @@ SPAN_DECLARE(int) span_log_set_tag(logging_state_t *s, const char *tag)
 }
 /*- End of function --------------------------------------------------------*/
 
+SPAN_DECLARE(const char *) span_log_get_protocol(logging_state_t *s)
+{
+    return s->protocol;
+}
+/*- End of function --------------------------------------------------------*/
+
 SPAN_DECLARE(int) span_log_set_protocol(logging_state_t *s, const char *protocol)
 {
     s->protocol = protocol;
index 224213359136a53187aa4726c24f6140ae8b8d8c..e56b16ecf0643ea8a79c87a28edc15dabebc1894 100644 (file)
@@ -269,7 +269,6 @@ static int pitsyn(lpc10_decode_state_t *s,
     *ratio = *rms/(s->rmso + 8.0f);
     if (s->first_pitsyn)
     {
-        lsamp = 0;
         ivoice = voice[1];
         if (ivoice == 0)
             *pitch = LPC10_SAMPLES_PER_FRAME/4;
@@ -291,7 +290,6 @@ static int pitsyn(lpc10_decode_state_t *s,
     {
         vflag = 0;
         lsamp = LPC10_SAMPLES_PER_FRAME + s->jsamp;
-        slope = (*pitch - s->ipito)/(float) lsamp;
         *nout = 0;
         jused = 0;
         istart = 1;
@@ -335,7 +333,6 @@ static int pitsyn(lpc10_decode_state_t *s,
                     rci[i + (rci_dim1 << 1) + 1] = s->rco[i];
                     s->rco[i] = rc[i];
                 }
-                slope = 0.0f;
                 *nout = 2;
                 s->ipito = *pitch;
                 jused = nl;
@@ -360,9 +357,9 @@ static int pitsyn(lpc10_decode_state_t *s,
                     rc[i] = s->rco[i];
                 }
                 ivoice = 1;
-                slope = 0.0f;
                 vflag = 1;
             }
+            slope = 0.0f;
         }
         /* Here is the value of most variables that are used below, depending on */
         /* the values of IVOICO, VOICE(1), and VOICE(2).  VOICE(1) and VOICE(2) */
index fdb1b3f7c552afd085a9f74dea070ccbd0ff961b..e41f26a2694804102952b3c698b795a99a72c3b4 100644 (file)
@@ -357,7 +357,6 @@ void lpc10_voicing(lpc10_encode_state_t *s,
     /* a consistent value from one call to the next when HALF .EQ. 1. */
     /* The value of VSTATE is not used for any other purpose when this is */
     /* true. */
-    vstate = -1;
     if (half != 0)
     {
         /* Voicing decision smoothing rules (override of linear combination): */
index 3a881af992ec93609d6f8d36db28da5617f1b2f4..6259207368e5858994bf5b954af73277e696f170 100644 (file)
@@ -551,7 +551,8 @@ static void trie_add(trie_t *s, const char *u, size_t len)
         /* Is there a child node for this character? */
         if (t->child_list[index] == NULL)
         {
-            t->child_list[index] = trie_node_create();
+            if ((t->child_list[index] = trie_node_create()) == NULL)
+                exit(2);
             if (index < t->first)
                 t->first = index;
             if (index > t->last)
@@ -609,7 +610,12 @@ int main(int argc, char *argv[])
     trie_t *s;
     int i;
 
-    s = trie_create();
+    if ((s = trie_create()) == NULL)
+        exit(2);
+
+    printf("/* THIS FILE WAS AUTOMATICALLY GENERATED - ANY MODIFICATIONS MADE TO THIS");
+    printf("   FILE MAY BE OVERWRITTEN DURING FUTURE BUILDS OF THE SOFTWARE */\n");
+    printf("\n");
 
     for (i = 0;  wordlist[i];  i++)
         trie_add(s, wordlist[i], strlen(wordlist[i]));
index dc5172817dc4d4f50313c3a721c9fe06347933c9..b780355543d6c229170dc31bb8d9e470737527a2 100644 (file)
@@ -46,6 +46,10 @@ int main(int argc, char *argv[])
     uint8_t srgb;
     int i;
 
+    printf("/* THIS FILE WAS AUTOMATICALLY GENERATED - ANY MODIFICATIONS MADE TO THIS");
+    printf("   FILE MAY BE OVERWRITTEN DURING FUTURE BUILDS OF THE SOFTWARE */\n");
+    printf("\n");
+
     printf("static const float srgb_to_linear[256] =\n");
     printf("{\n");
     for (i = 0;  i < 256;  i++)
index 8e290b44cec96bb9ff80fc5cf65244ac9c6d958a..1f568286f72602d85433f950fce39e7356c6a021 100644 (file)
@@ -37,6 +37,10 @@ int main(int argc, char *argv[])
     double val;
     int ival;
 
+    printf("/* THIS FILE WAS AUTOMATICALLY GENERATED - ANY MODIFICATIONS MADE TO THIS");
+    printf("   FILE MAY BE OVERWRITTEN DURING FUTURE BUILDS OF THE SOFTWARE */\n");
+    printf("\n");
+
     printf("static const uint16_t fixed_reciprocal_table[129] =\n");
     printf("{\n");
     for (i = 0;  i < 129;  i++)
index bd9427e24f38a302584fd802c6dfb0807084af19..2579461db154b059d84013021f4bf56b9aea570c 100644 (file)
@@ -103,6 +103,9 @@ static void make_tx_filter(int coeff_sets,
 
     /* Churn out the data as a C source code header file, which can be directly included by the
        modem code. */
+    printf("/* THIS FILE WAS AUTOMATICALLY GENERATED - ANY MODIFICATIONS MADE TO THIS");
+    printf("   FILE MAY BE OVERWRITTEN DURING FUTURE BUILDS OF THE SOFTWARE */\n");
+    printf("\n");
     printf("#if defined(SPANDSP_USE_FIXED_POINT)\n");
     printf("#define TX_PULSESHAPER%s_SCALE(x)    ((int16_t) (%f*x + ((x >= 0.0)  ?  0.5  :  -0.5)))\n", tag, fixed_scaling);
     printf("#define TX_PULSESHAPER%s_GAIN        %ff\n", tag, fixed_gain);
index 90117c5d837cff59ac50eb801dcb10bed0aadab2..0016c988a08254ac088b62e2053d7043c40604bf 100644 (file)
@@ -39,6 +39,10 @@ int main(int argc, char *argv[])
     int new_gray;
     int restore;
 
+    printf("/* THIS FILE WAS AUTOMATICALLY GENERATED - ANY MODIFICATIONS MADE TO THIS");
+    printf("   FILE MAY BE OVERWRITTEN DURING FUTURE BUILDS OF THE SOFTWARE */\n");
+    printf("\n");
+
     printf("static const int16_t gray_code[4096] =\n{\n");
     for (i = 0;  i < 4096;  i++)
     {
index 4dff6fe26afdfa4b5751913fd9b8481516ee94a9..5ebd5f95c98195c0fa931207d386cc231e54dbef 100644 (file)
 #if defined(SPANDSP_USE_SSE5)
 #include <bmmintrin.h>
 #endif
+#if defined(SPANDSP_USE_AVX)
+#include <immintrin.h>
+#endif
+#if defined(SPANDSP_USE_AVX2)
+#include <x86intrin.h>
+#endif
 
 #endif
 
index 3ad164cf7f2347ceb458943d9418a981eada60be..1a8f58842e6780c50dd1182840967e84a31fd96c 100644 (file)
@@ -75,7 +75,7 @@ SPAN_DECLARE(int16_t) noise(noise_state_t *s)
            simple approx. leaves the signal about 0.35dB low. */
         val = s->state << 1;
     }
-    return saturate((val*s->rms) >> 10);
+    return saturate16((val*s->rms) >> 10);
 }
 /*- End of function --------------------------------------------------------*/
 
index 1b30d8e583cce8bb6f9d0dfc7e5f31b1f8a05ddf..20e16df3e4f8a40f08e42151a12432babe12a85d 100644 (file)
@@ -303,7 +303,7 @@ SPAN_DECLARE(int) sig_tone_tx(sig_tone_tx_state_t *s, int16_t amp[], int len)
                     for (j = i;  j < i + n;  j++)
                     {
                         tone = dds_mod(&(s->phase_acc[k]), s->phase_rate[k], s->tone_scaling[k][high_low], 0);
-                        amp[j] = saturated_add16(amp[j], tone);
+                        amp[j] = sat_add16(amp[j], tone);
                     }
                     /*endfor*/
                 }
index abae8e701b4a9395a572bb0e3f0877aaf0eeaccf..43d807fb9bb5050c8d9642b502af9fc029f20251 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * SpanDSP  a series of DSP components for telephony
+ * SpanDSP - a series of DSP components for telephony
  *
  * ademco_contactid.h  Ademco ContactID alarm protocol
  *
index 311408123e026dc203ab616a9d44d49c591f9319..c7f4093ab3f1d28d9cf61a6e77d023a8f63cac1f 100644 (file)
@@ -53,6 +53,13 @@ static __inline__ int top_bit(uint32_t bits)
              : [res] "=&r" (res)
              : [bits] "rm" (bits));
     return res;
+#elif defined(__GNUC__x)  &&  (defined(__ARM_ARCH_6__)  ||  defined(__ARM_ARCH_7A__))
+    int res;
+
+    __asm__("clz %[res], %[bits]"
+            : [res] "=r" (res)
+            : [bits] "r" (bits));
+    return res;
 #elif defined(__ppc__)  ||   defined(__powerpc__)
     int res;
 
index 6edfa967e7a214c96f36d3acea9d2af5d3e99798..a076c0332f53204f6444c62688ed9ba0695505f0 100644 (file)
@@ -46,7 +46,11 @@ enum
     FAX_MODEM_V21_RX,
     FAX_MODEM_V17_RX,
     FAX_MODEM_V27TER_RX,
-    FAX_MODEM_V29_RX
+    FAX_MODEM_V29_RX,
+#if defined(SPANDSP_SUPPORT_V34)
+    FAX_MODEM_V34_TX,
+    FAX_MODEM_V34_RX
+#endif
 };
 
 /*!
@@ -59,6 +63,7 @@ extern "C"
 {
 #endif
 
+/* TEMPORARY FUDGE */
 SPAN_DECLARE_NONSTD(void) fax_modems_hdlc_accept(void *user_data, const uint8_t *msg, int len, int ok);
 
 /*! Convert a FAX modem type to a short text description.
index 78db086ef0a41550a8f2361eecac1f7f155a09a7..cd0d73355c5bb90417803775adddca4515c8f03c 100644 (file)
@@ -104,10 +104,16 @@ SPAN_DECLARE(int) span_log(logging_state_t *s, int level, const char *format, ..
 */
 SPAN_DECLARE(int) span_log_buf(logging_state_t *s, int level, const char *tag, const uint8_t *buf, int len);
 
+SPAN_DECLARE(int) span_log_get_level(logging_state_t *s);
+
 SPAN_DECLARE(int) span_log_set_level(logging_state_t *s, int level);
 
+SPAN_DECLARE(const char *) span_log_get_tag(logging_state_t *s);
+
 SPAN_DECLARE(int) span_log_set_tag(logging_state_t *s, const char *tag);
 
+SPAN_DECLARE(const char *) span_log_get_protocol(logging_state_t *s);
+
 SPAN_DECLARE(int) span_log_set_protocol(logging_state_t *s, const char *protocol);
 
 SPAN_DECLARE(int) span_log_set_sample_rate(logging_state_t *s, int samples_per_second);
index 373a692994f9db3a108bd41e9177f10d2549267a..d11397793bf0b0c46ee1e657e77215f896ec67fa 100644 (file)
@@ -64,18 +64,22 @@ struct fax_modems_state_s
         /*! \brief A V.29 modem context used when receiving FAXes at 7200bps, 9600bps
                    12000bps or 14400bps */
         v17_rx_state_t v17_rx;
-        /*! \brief A V.29 modem context used when sending FAXes at 7200bps or
-                   9600bps */
-        v29_tx_state_t v29_tx;
-        /*! \brief A V.29 modem context used when receiving FAXes at 7200bps or
-                   9600bps */
-        v29_rx_state_t v29_rx;
         /*! \brief A V.27ter modem context used when sending FAXes at 2400bps or
                    4800bps */
         v27ter_tx_state_t v27ter_tx;
         /*! \brief A V.27ter modem context used when receiving FAXes at 2400bps or
                    4800bps */
         v27ter_rx_state_t v27ter_rx;
+        /*! \brief A V.29 modem context used when sending FAXes at 7200bps or
+                   9600bps */
+        v29_tx_state_t v29_tx;
+        /*! \brief A V.29 modem context used when receiving FAXes at 7200bps or
+                   9600bps */
+        v29_rx_state_t v29_rx;
+#if defined(SPANDSP_SUPPORT_V34)
+        /*! \brief A V.34 modem context used when sending or receiving Super-G3 FAXes */
+        v34_state_t v34;
+#endif
     } fast_modems;
     /*! \brief Used to insert timed silences. */
     silence_gen_state_t silence_gen;
index 81dfc68c300873a1eeb1162a535793983cf68cd2..a98a574ce61fe28fe2db4a5df55774bd35df7454 100644 (file)
@@ -47,12 +47,12 @@ typedef struct
  */
 struct g722_encode_state_s
 {
-    /*! True if the operating in the special ITU test mode, with the band split filters
+    /*! True if operating in the special ITU test mode, with the band split filters
              disabled. */
     bool itu_test_mode;
     /*! True if the G.722 data is packed */
     bool packed;
-    /*! True if encode from 8k samples/second */
+    /*! True if encoding from 8k samples/second */
     bool eight_k;
     /*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
     int bits_per_sample;
@@ -73,12 +73,12 @@ struct g722_encode_state_s
  */
 struct g722_decode_state_s
 {
-    /*! True if the operating in the special ITU test mode, with the band split filters
+    /*! True if operating in the special ITU test mode, with the band split filters
              disabled. */
     bool itu_test_mode;
     /*! True if the G.722 data is packed */
     bool packed;
-    /*! True if decode to 8k samples/second */
+    /*! True if decoding to 8k samples/second */
     bool eight_k;
     /*! 6 for 48000kbps, 7 for 56000kbps, or 8 for 64000kbps. */
     int bits_per_sample;
index 2bfed82d0bfb98de281aec1b2b5ddd47fb706ff6..373ca74fc7aeacdf04ffd9a4e0986895ac90e13e 100644 (file)
@@ -138,8 +138,8 @@ typedef struct
 
     t31_hdlc_state_t hdlc_from_t31;
 
-    /*! \brief True if we are using ECM mode. This is used to select HDLC faking, necessary
-               with clunky class 1 modems. */
+    /*! \brief True if we are using ECM mode. This is used to select HDLC faking, which is
+               necessary with clunky class 1 modems. */
     int ecm_mode;
 
     /*! \brief Counter for trailing non-ECM bytes, used to flush out the far end's modem. */
index b2397cf2d259841f94e65485ac520e955f0152e4..78519f0f7a6ebbd2971ed8e1125c12709a81ac12 100644 (file)
@@ -30,7 +30,7 @@
 
 #define TZ_MAX_LEAPS            50      /* Maximum number of leap second corrections */
 
-#define SPANDSP_TZNAME_MAX              255
+#define SPANDSP_TZNAME_MAX      255
 
 /* The TZ_MAX_TIMES value below is enough to handle a bit more than a
  * year's worth of solar time (corrected daily to the nearest second) or
index 41b8ba3db0819e9583967fbfe93fd55bec28708c..db9baf4f4bd596b298981d9c47e79b9ef454afbe 100644 (file)
@@ -42,32 +42,6 @@ extern "C"
 {
 #endif
 
-/* This is the same as saturate16(), but is here for historic reasons */
-static __inline__ int16_t saturate(int32_t amp)
-{
-#if defined(__GNUC__)  &&  (defined(__ARM_ARCH_6__)  ||  defined(__ARM_ARCH_7A__))
-    int16_t z;
-
-    __asm__ __volatile__(
-        " ssat %[z],#16,%[amp];\n"
-        : [z] "=r" (z)
-        : [amp] "r" (amp)
-    );
-    return z;
-#else
-    int16_t z;
-
-    /* Hopefully this is optimised for the common case - not clipping */
-    z = (int16_t) amp;
-    if (amp == z)
-        return z;
-    if (amp > INT16_MAX)
-        return INT16_MAX;
-    return INT16_MIN;
-#endif
-}
-/*- End of function --------------------------------------------------------*/
-
 static __inline__ int16_t saturate16(int32_t amp)
 {
 #if defined(__GNUC__)  &&  (defined(__ARM_ARCH_6__)  ||  defined(__ARM_ARCH_7A__))
@@ -229,152 +203,141 @@ static __inline__ double ffsaturate(double famp)
 }
 /*- End of function --------------------------------------------------------*/
 
-static __inline__ int16_t saturated_add16(int16_t a, int16_t b)
+static __inline__ int16_t sat_add16(int16_t x, int16_t y)
 {
 #if defined(__GNUC__)  &&  (defined(__i386__)  ||  defined(__x86_64__))
-    __asm__ __volatile__(
-        " addw %2,%0;\n"
-        " jno 0f;\n"
-        " movw $0x7fff,%0;\n"
-        " adcw $0,%0;\n"
-        "0:"
-        : "=r" (a)
-        : "0" (a), "ir" (b)
-        : "cc"
-    );
-    return a;
+    __asm__ __volatile__(" addw %[y],%[x];\n"
+                         " jno 0f;\n"
+                         " movw $0x7FFF,%[x];\n"
+                         " adcw $0,%[x];\n"
+                         "0:"
+                         : [x] "+r" (x)
+                         : [y] "ir" (y)
+                         : "cc");
+    return x;
 #elif defined(__GNUC__)  &&  (defined(__ARM_ARCH_6__)  ||  defined(__ARM_ARCH_7A__))
     int16_t z;
 
     __asm__ __volatile__(
-        " qadd16 %[z],%[a],%[b];\n"
+        " qadd16 %[z],%[c],%[y];\n"
         : [z] "=r" (z)
-        : [a] "r" (a), [b] "r" (b)
+        : [x] "r" (x), [y] "r" (y)
     );
     return z;
+//#elif defined(__GNUC__)  &&  defined(__ARM_ARCH_5T__)
 #else
-    return saturate((int32_t) a + (int32_t) b);
+    return saturate16((int32_t) x + y);
 #endif
 }
 /*- End of function --------------------------------------------------------*/
 
-static __inline__ int32_t saturated_add32(int32_t a, int32_t b)
+static __inline__ int32_t sat_add32(int32_t x, int32_t y)
 {
 #if defined(__GNUC__)  &&  (defined(__i386__)  ||  defined(__x86_64__))
-    __asm__ __volatile__(
-        " addl %2,%0;\n"
-        " jno 0f;\n"
-        " movl $0x7fffffff,%0;\n"
-        " adcl $0,%0;\n"
-        "0:"
-        : "=r" (a)
-        : "0" (a), "ir" (b)
-        : "cc"
-    );
-    return a;
+    __asm__ __volatile__(" addl %[y],%[x];\n"
+                         " jno 0f;\n"
+                         " movl $0x7FFFFFFF,%[x];\n"
+                         " adcl $0,%[x];\n"
+                         "0:"
+                         : [x] "+r" (x)
+                         : [y] "ir" (y)
+                         : "cc");
+    return x;
 #elif defined(__GNUC__)  &&  (defined(__ARM_ARCH_6__)  ||  defined(__ARM_ARCH_7A__))
     int32_t z;
 
-    __asm__ __volatile__(
-        " qadd %[z],%[a],%[b];\n"
-        : [z] "=r" (z)
-        : [a] "r" (a), [b] "r" (b)
-    );
+    __asm__ __volatile__(" qadd %[z],%[x],%[y];\n"
+                         : [z] "=r" (z)
+                         : [x] "r" (x), [y] "r" (y));
     return z;
+//#elif defined(__GNUC__)  &&  defined(__ARM_ARCH_5T__)
 #else
     int32_t z;
 
-    z = a + b;
-    if ((a ^ b) >= 0)
+    z = x + y;
+    if ((x ^ y) >= 0)
     {
-        if ((z ^ a) < 0)
-            z = (a < 0)  ?  INT32_MIN  :  INT32_MAX;
+        if ((z ^ x) < 0)
+            z = (x < 0)  ?  INT32_MIN  :  INT32_MAX;
     }
     return z;
 #endif
 }
 /*- End of function --------------------------------------------------------*/
 
-static __inline__ int16_t saturated_sub16(int16_t a, int16_t b)
+static __inline__ int16_t sat_sub16(int16_t x, int16_t y)
 {
 #if defined(__GNUC__)  &&  (defined(__i386__)  ||  defined(__x86_64__))
-    __asm__ __volatile__(
-        " subw %2,%0;\n"
-        " jno 0f;\n"
-        " movw $0x8000,%0;\n"
-        " sbbw $0,%0;\n"
-        "0:"
-        : "=r" (a)
-        : "0" (a), "ir" (b)
-        : "cc"
-    );
-    return a;
+    __asm__ __volatile__(" subw %[y],%[x];\n"
+                         " jno 0f;\n"
+                         " movw $0x8000,%[x];\n"
+                         " sbbw $0,%[x];\n"
+                         "0:"
+                         : [x] "+r" (x)
+                         : [y] "ir" (y)
+                         : "cc");
+    return x;
 #elif defined(__GNUC__)  &&  (defined(__ARM_ARCH_6__)  ||  defined(__ARM_ARCH_7A__))
     int16_t z;
 
-    __asm__ __volatile__(
-        " qsub16 %[z],%[a],%[b];\n"
-        : [z] "=r" (z)
-        : [a] "r" (a), [b] "r" (b)
-    );
+    __asm__ __volatile__(" qsub16 %[z],%[x],%[y];\n"
+                         : [z] "=r" (z)
+                         : [x] "r" (x), [y] "r" (y));
     return z;
+//#elif defined(__GNUC__)  &&  defined(__ARM_ARCH_5T__)
 #else
-    return saturate((int32_t) a - (int32_t) b);
+    return saturate16((int32_t) x - y);
 #endif
 }
 /*- End of function --------------------------------------------------------*/
 
-static __inline__ int32_t saturated_sub32(int32_t a, int32_t b)
+static __inline__ int32_t sat_sub32(int32_t x, int32_t y)
 {
 #if defined(__GNUC__)  &&  (defined(__i386__)  ||  defined(__x86_64__))
-    __asm__ __volatile__(
-        " subl %2,%0;\n"
-        " jno 0f;\n"
-        " movl $0x80000000,%0;\n"
-        " sbbl $0,%0;\n"
-        "0:"
-        : "=r" (a)
-        : "0" (a), "ir" (b)
-        : "cc"
-    );
-    return a;
+    __asm__ __volatile__(" subl %[y],%[x];\n"
+                         " jno 0f;\n"
+                         " movl $0x80000000,%[x];\n"
+                         " sbbl $0,%[x];\n"
+                         "0:"
+                         : [x] "+r" (x)
+                         : [y] "ir" (y)
+                         : "cc");
+    return x;
 #elif defined(__GNUC__)  &&  (defined(__ARM_ARCH_6__)  ||  defined(__ARM_ARCH_7A__))
     int32_t z;
 
-    __asm__ __volatile__(
-        " qsub %[z],%[a],%[b];\n"
-        : [z] "=r" (z)
-        : [a] "r" (a), [b] "r" (b)
-    );
+    __asm__ __volatile__(" qsub %[z],%[x],%[y];\n"
+                         : [z] "=r" (z)
+                         : [x] "r" (x), [y] "r" (y));
     return z;
+//#elif defined(__GNUC__)  &&  defined(__ARM_ARCH_5T__)
 #else
     int32_t z;
 
-    z = a - b;
-    if ((a ^ b) < 0)
+    z = x - y;
+    if ((x ^ y) < 0)
     {
-        if ((z ^ a) & INT32_MIN)
-            z = (a < 0L)  ?  INT32_MIN  :  INT32_MAX;
+        if ((z ^ x) < 0)
+            z = (x < 0L)  ?  INT32_MIN  :  INT32_MAX;
     }
     return z;
 #endif
 }
 /*- End of function --------------------------------------------------------*/
 
-static __inline__ int16_t saturated_mul16(int16_t a, int16_t b)
+static __inline__ int16_t sat_mul16(int16_t x, int16_t y)
 {
     int32_t z;
 
 #if defined(__GNUC__)  &&  (defined(__ARM_ARCH_6__)  ||  defined(__ARM_ARCH_7A__))
-    __asm__ __volatile__(
-        " smulbb %[z],%[a],%[b];\n"
-        " qadd %[z],%[z],%[z];\n"
-        : [z] "=r" (z)
-        : [a] "r" (a), [b] "r" (b)
-    );
+    __asm__ __volatile__(" smulbb %[z],%[c],%[y];\n"
+                         " qadd %[z],%[z],%[z];\n"
+                         : [z] "=r" (z)
+                         : [x] "r" (x), [y] "r" (y));
+    /* The qadd added one to the shift of 15 */
     return (int16_t) (z >> 16);
 #else
-    z = (int32_t) a*b;
+    z = (int32_t) x*y;
     if (z == 0x40000000)
         return INT16_MAX;
     /*endif*/
@@ -383,20 +346,18 @@ static __inline__ int16_t saturated_mul16(int16_t a, int16_t b)
 }
 /*- End of function --------------------------------------------------------*/
 
-static __inline__ int32_t saturated_mul16_32(int16_t a, int16_t b)
+static __inline__ int32_t sat_mul32_16(int16_t x, int16_t y)
 {
     int32_t z;
 
 #if defined(__GNUC__)  &&  (defined(__ARM_ARCH_6__)  ||  defined(__ARM_ARCH_7A__))
-    __asm__ __volatile__(
-        " smulbb %[z],%[a],%[b];\n"
-        " qadd %[z],%[z],%[z];\n"
-        : [z] "=r" (z)
-        : [a] "r" (a), [b] "r" (b)
-    );
+    __asm__ __volatile__(" smulbb %[z],%[x],%[y];\n"
+                         " qadd %[z],%[z],%[z];\n"
+                         : [z] "=r" (z)
+                         : [x] "r" (x), [y] "r" (y));
     return z;
 #else
-    z = (int32_t) a*b;
+    z = (int32_t) x*y;
     if (z == 0x40000000)
         return INT32_MAX;
     return z << 1;
@@ -404,45 +365,51 @@ static __inline__ int32_t saturated_mul16_32(int16_t a, int16_t b)
 }
 /*- End of function --------------------------------------------------------*/
 
-static __inline__ int32_t saturated_mac16_32(int32_t z, int16_t a, int16_t b)
+static __inline__ int32_t sat_mac32_16(int32_t z, int16_t x, int16_t y)
 {
 #if defined(__GNUC__)  &&  (defined(__ARM_ARCH_6__)  ||  defined(__ARM_ARCH_7A__))
     int32_t product;
 
-    __asm__ __volatile__(
-        " smulbb %[p],%[a],%[b];\n"
-        " qdadd %[z],%[z],%[p];\n"
-        : [z] "=r" (z)
-        : "[z]" (z), [a] "r" (a), [b] "r" (b), [p] "r"(product)
-    );
+    __asm__ __volatile__(" smulbb %[p],%[x],%[y];\n"
+                         " qdadd %[z],%[z],%[p];\n"
+                         : [z] "+r" (z)
+                         : [x] "r" (x), [y] "r" (y), [p] "r" (product));
     return z;
 #else
-    return saturated_add32(z, saturated_mul16_32(a, b));
+    return sat_add32(z, sat_mul32_16(x, y));
 #endif
 }
 /*- End of function --------------------------------------------------------*/
 
-static __inline__ int32_t saturated_msu16_32(int32_t z, int16_t a, int16_t b)
+static __inline__ int32_t sat_msu32_16(int32_t z, int16_t x, int16_t y)
 {
 #if defined(__GNUC__)  &&  (defined(__ARM_ARCH_6__)  ||  defined(__ARM_ARCH_7A__))
     int32_t product;
 
-    __asm__ __volatile__(
-        " smulbb %[p],%[a],%[b];\n"
-        " qdsub %[z],%[z],%[p];\n"
-        : [z] "=r" (z)
-        : "[z]" (z), [a] "r" (a), [b] "r" (b), [p] "r" (product)
-    );
+    __asm__ __volatile__(" smulbb %[p],%[x],%[y];\n"
+                         " qdsub %[z],%[z],%[p];\n"
+                         : [z] "+r" (z)
+                         : [x] "r" (x), [y] "r" (y), [p] "r" (product));
     return z;
 #else
-    return saturated_sub32(z, saturated_mul16_32(a, b));
+    return sat_sub32(z, sat_mul32_16(x, y));
 #endif
 }
 /*- End of function --------------------------------------------------------*/
 
-static __inline__ int16_t saturated_abs16(int16_t a)
+static __inline__ int16_t sat_abs16(int16_t x)
 {
-    return (a == INT16_MIN)  ?  INT16_MAX  :  (int16_t) abs(a);
+    if (x == INT16_MIN)
+        return INT16_MAX;
+    return (int16_t) abs(x);
+}
+/*- End of function --------------------------------------------------------*/
+
+static __inline__ int32_t sat_abs32(int32_t x)
+{
+    if (x == INT32_MIN)
+        return INT32_MAX;
+    return abs(x);
 }
 /*- End of function --------------------------------------------------------*/
 
index b32ecfa0f576ec9d8202787818b636c471fd0df1..58a8e29c6a5dd29555c66e08b5057c8090309e1f 100644 (file)
 #define SPAN_DECLARE_DATA               /**/
 #endif
 
+#define span_container_of(ptr, type, member) ({ \
+    const typeof(((type *) 0)->member) *__mptr = (ptr); \
+    (type *) ((char *) __mptr - offsetof(type, member));})
+
 #define SAMPLE_RATE                 8000
 
 /* This is based on A-law, but u-law is only 0.03dB different */
@@ -70,36 +74,57 @@ typedef int (*span_tx_handler_t)(void *s, int16_t amp[], int max_len);
 #define ms_to_samples(t)            ((t)*(SAMPLE_RATE/1000))
 #define us_to_samples(t)            ((t)/(1000000/SAMPLE_RATE))
 
-/* Fixed point constant macros */
-#define FP_Q_9_7(x) ((int16_t) (128.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_8_8(x) ((int16_t) (256.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_7_9(x) ((int16_t) (512.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_6_10(x) ((int16_t) (1024.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_5_11(x) ((int16_t) (2048.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_4_12(x) ((int16_t) (4096.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_3_13(x) ((int16_t) (8192.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_2_14(x) ((int16_t) (16384.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_1_15(x) ((int16_t) (32768.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-
-#define FP_Q_9_7_32(x) ((int32_t) (128.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_8_8_32(x) ((int32_t) (256.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_7_9_32(x) ((int32_t) (512.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_6_10_32(x) ((int32_t) (1024.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_5_11_32(x) ((int32_t) (2048.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_4_12_32(x) ((int32_t) (4096.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_3_13_32(x) ((int32_t) (8192.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_2_14_32(x) ((int32_t) (16384.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_1_15_32(x) ((int32_t) (32768.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+/* Fixed point constant macros for 16 bit values */
+#define FP_Q16_0(x) ((int16_t) (1.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q15_1(x) ((int16_t) (2.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q14_2(x) ((int16_t) (4.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q13_3(x) ((int16_t) (8.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q12_4(x) ((int16_t) (16.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q11_5(x) ((int16_t) (32.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q10_6(x) ((int16_t) (64.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q9_7(x) ((int16_t) (128.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q8_8(x) ((int16_t) (256.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q7_9(x) ((int16_t) (512.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q6_10(x) ((int16_t) (1024.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q5_11(x) ((int16_t) (2048.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q4_12(x) ((int16_t) (4096.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q3_13(x) ((int16_t) (8192.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q2_14(x) ((int16_t) (16384.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q1_15(x) ((int16_t) (32768.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
 
-#define FP_Q_9_23(x) ((int32_t) (65536.0*128.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_8_24(x) ((int32_t) (65536.0*256.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_7_25(x) ((int32_t) (65536.0*512.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_6_26(x) ((int32_t) (65536.0*1024.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_5_27(x) ((int32_t) (65536.0*2048.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_4_28(x) ((int32_t) (65536.0*4096.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_3_29(x) ((int32_t) (65536.0*8192.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_2_30(x) ((int32_t) (65536.0*16384.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
-#define FP_Q_1_31(x) ((int32_t) (65536.0*32768.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+/* Fixed point constant macros for 32 bit values */
+#define FP_Q32_0(x) ((int32_t) (1.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q31_1(x) ((int32_t) (2.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q30_2(x) ((int32_t) (4.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q29_3(x) ((int32_t) (8.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q28_4(x) ((int32_t) (16.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q27_5(x) ((int32_t) (32.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q26_6(x) ((int32_t) (64.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q25_7(x) ((int32_t) (128.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q24_8(x) ((int32_t) (256.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q23_9(x) ((int32_t) (512.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q22_10(x) ((int32_t) (1024.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q21_11(x) ((int32_t) (2048.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q20_12(x) ((int32_t) (4096.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q19_13(x) ((int32_t) (8192.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q18_14(x) ((int32_t) (16384.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q17_15(x) ((int32_t) (32768.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q16_16(x) ((int32_t) (65536.0*1.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q15_17(x) ((int32_t) (65536.0*2.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q14_18(x) ((int32_t) (65536.0*4.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q13_19(x) ((int32_t) (65536.0*8.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q12_20(x) ((int32_t) (65536.0*16.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q11_21(x) ((int32_t) (65536.0*32.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q10_22(x) ((int32_t) (65536.0*64.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q9_23(x) ((int32_t) (65536.0*128.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q8_24(x) ((int32_t) (65536.0*256.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q7_25(x) ((int32_t) (65536.0*512.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q6_26(x) ((int32_t) (65536.0*1024.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q5_27(x) ((int32_t) (65536.0*2048.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q4_28(x) ((int32_t) (65536.0*4096.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q3_29(x) ((int32_t) (65536.0*8192.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q2_30(x) ((int32_t) (65536.0*16384.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
+#define FP_Q1_31(x) ((int32_t) (65536.0*32768.0*x + ((x >= 0.0)  ?  0.5  :  -0.5)))
 
 #if defined(__cplusplus)
 /* C++ doesn't seem to have sane rounding functions/macros yet */
index d99674ddd591d7fb81e335730a4aaf98e30ac9f2..8aebe8526304d772611b003f2db29e39b3388e03 100644 (file)
@@ -239,7 +239,9 @@ SPAN_DECLARE(v17_rx_state_t *) v17_rx_init(v17_rx_state_t *s, int bit_rate, put_
     \brief Reinitialise an existing V.17 modem receive context.
     \param s The modem context.
     \param bit_rate The bit rate of the modem. Valid values are 7200, 9600, 12000 and 14400.
-    \param short_train True if a short training sequence is expected.
+    \param short_train 0 if a long training sequence is expected.
+                       1 if a short training sequence is expected.
+                       2 if the expected training sequence is automatically selected.
     \return 0 for OK, -1 for bad parameter */
 SPAN_DECLARE(int) v17_rx_restart(v17_rx_state_t *s, int bit_rate, int short_train);
 
index f20656919fa17552d1df4e053f2f4396ca283f9e..50b2fb44672e1ee876f893f77fb0ee61bb41027f 100644 (file)
@@ -172,8 +172,9 @@ SPAN_DECLARE(int) v22bis_get_current_bit_rate(v22bis_state_t *s);
     \param guard The guard tone option. 0 = none, 1 = 550Hz, 2 = 1800Hz.
     \param calling_party True if this is the calling modem.
     \param get_bit The callback routine used to get the data to be transmitted.
-    \param put_bit The callback routine used to get the data to be transmitted.
-    \param user_data An opaque pointer, passed in calls to the get and put routines.
+    \param get_bit_user_data An opaque pointer, passed in calls to the get_bit routine.
+    \param put_bit The callback routine used to put the data received.
+    \param put_bit_user_data An opaque pointer, passed in calls to the put_bit routine.
     \return A pointer to the modem context, or NULL if there was a problem. */
 SPAN_DECLARE(v22bis_state_t *) v22bis_init(v22bis_state_t *s,
                                            int bit_rate,
index d0c42bd84d4b08d643495af6f9366ea3196cfea8..47f26c9e49e04e236de67cadc12b822ec7663f00 100644 (file)
@@ -267,7 +267,6 @@ static int extra_bits_in_stuffed_frame(const uint8_t buf[], int len)
     int i;
     int j;
 
-    bitstream = 0;
     ones = 0;
     stuffed = 0;
     /* We should really append the CRC, and include the stuffed bits for that, to get
@@ -1100,7 +1099,6 @@ static int stream_hdlc(t31_state_t *s)
                     data_fields[0].field_len = i;
 
                     /* Now see about the next HDLC frame. This will tell us whether to send FCS_OK or FCS_OK_SIG_END */
-                    previous = fe->current_tx_data_type;
                     s->hdlc_tx.ptr = 0;
                     s->hdlc_tx.len = 0;
                     if (front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE) < 0)
@@ -2117,7 +2115,6 @@ static int restart_modem(t31_state_t *s, int new_modem)
         {
             s->t38_fe.next_tx_indicator = T38_IND_V21_PREAMBLE;
             s->t38_fe.current_tx_data_type = T38_DATA_V21;
-            use_hdlc = true;
             s->t38_fe.timed_step = T38_TIMED_STEP_HDLC_MODEM;
             set_octets_per_data_packet(s, 300);
         }
@@ -2449,13 +2446,11 @@ static int process_class1_cmd(void *user_data, int direction, int operation, int
     int new_transmit;
     int i;
     int len;
-    int immediate_response;
     t31_state_t *s;
     uint8_t msg[256];
 
     s = (t31_state_t *) user_data;
     new_transmit = direction;
-    immediate_response = true;
     switch (operation)
     {
     case 'S':
@@ -2489,7 +2484,6 @@ static int process_class1_cmd(void *user_data, int direction, int operation, int
             /*endif*/
         }
         /*endif*/
-        immediate_response = false;
         span_log(&s->logging, SPAN_LOG_FLOW, "Silence %dms\n", val*10);
         break;
     case 'H':
@@ -2506,10 +2500,7 @@ static int process_class1_cmd(void *user_data, int direction, int operation, int
         /*endswitch*/
         span_log(&s->logging, SPAN_LOG_FLOW, "HDLC\n");
         if (new_modem != s->modem)
-        {
             restart_modem(s, new_modem);
-            immediate_response = false;
-        }
         /*endif*/
         s->at_state.transmit = new_transmit;
         if (new_transmit)
@@ -2561,7 +2552,6 @@ static int process_class1_cmd(void *user_data, int direction, int operation, int
             while (msg[0] == AT_RESPONSE_CODE_CONNECT);
         }
         /*endif*/
-        immediate_response = false;
         break;
     default:
         switch (val)
@@ -2666,11 +2656,10 @@ static int process_class1_cmd(void *user_data, int direction, int operation, int
         }
         /*endif*/
         restart_modem(s, new_modem);
-        immediate_response = false;
         break;
     }
     /*endswitch*/
-    return immediate_response;
+    return false;
 }
 /*- End of function --------------------------------------------------------*/
 
index 0bbbd18fb62cd02cc91c3a945a4486b520e66d82..5fb57bbc8229d1b4c780f1ba08918b2283a0830a 100644 (file)
@@ -462,7 +462,6 @@ SPAN_DECLARE_NONSTD(int) t38_core_rx_ifp_stream(t38_core_state_t *s, const uint8
         /* Do a dummy run through the fields to check we have a complete and uncorrupted packet. */
         prev_ptr = ptr;
         other_half = false;
-        t30_field_type = 0;
         for (i = 0;  i < (int) count;  i++)
         {
             if (ptr >= pkt_len)
@@ -514,7 +513,7 @@ SPAN_DECLARE_NONSTD(int) t38_core_rx_ifp_stream(t38_core_state_t *s, const uint8
                 }
                 else
                 {
-                    t30_field_type = (buf[ptr++] >> 3) & 0x7;
+                    ptr++;
                 }
             }
             /* Decode field_data */
@@ -523,14 +522,8 @@ SPAN_DECLARE_NONSTD(int) t38_core_rx_ifp_stream(t38_core_state_t *s, const uint8
                 if ((ptr + 2) > pkt_len)
                     return ret;
                 numocts = ((buf[ptr] << 8) | buf[ptr + 1]) + 1;
-                msg = buf + ptr + 2;
                 ptr += numocts + 2;
             }
-            else
-            {
-                numocts = 0;
-                msg = NULL;
-            }
             if (ptr > pkt_len)
                 return ret;
         }
@@ -766,7 +759,6 @@ static int t38_encode_data(t38_core_state_t *s, uint8_t buf[], int data_type, co
     /* There seems no valid reason why a packet would ever be generated without a data field present */
     data_field_present = (fields > 0)  ?  0x80  :  0x00;
 
-    data_field_no = 0;
     /* Data field present */
     /* Data packet */
     /* Type of data */
index 402c7cded2e8c8238246497042f61850b749aabb..8535f2d59c00779c34272203d3ea636766ae561d 100644 (file)
@@ -1066,7 +1066,6 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type,
             if (len <= 0  ||  buf[0] != 0xFF)
                 s->core.hdlc_to_modem.buf[s->core.hdlc_to_modem.in].flags |= HDLC_FLAG_MISSING_DATA;
             /*endif*/
-            hdlc_buf = &s->core.hdlc_to_modem.buf[s->core.hdlc_to_modem.in];
         }
         /*endif*/
         if (len > 0)
@@ -1313,10 +1312,7 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type,
         xx->current_rx_field_class = T38_FIELD_CLASS_NON_ECM;
         hdlc_buf = &s->core.hdlc_to_modem.buf[s->core.hdlc_to_modem.in];
         if (hdlc_buf->contents != (data_type | FLAG_DATA))
-        {
             queue_missing_indicator(s, data_type);
-            hdlc_buf = &s->core.hdlc_to_modem.buf[s->core.hdlc_to_modem.in];
-        }
         /*endif*/
         if (len > 0)
             t38_non_ecm_buffer_inject(&s->core.non_ecm_to_modem, buf, len);
@@ -1349,10 +1345,7 @@ static int process_rx_data(t38_core_state_t *t, void *user_data, int data_type,
                 }
                 /*endif*/
                 if (hdlc_buf->contents != (data_type | FLAG_DATA))
-                {
                     queue_missing_indicator(s, data_type);
-                    hdlc_buf = &s->core.hdlc_to_modem.buf[s->core.hdlc_to_modem.in];
-                }
                 /*endif*/
                 /* Don't flow control the data any more. Just pump out the remainder as fast as we can. */
                 t38_non_ecm_buffer_push(&s->core.non_ecm_to_modem);
@@ -1590,7 +1583,9 @@ static void non_ecm_push_residue(t38_gateway_state_t *t)
         s->data[s->data_ptr++] = (uint8_t) (s->bit_stream << (8 - s->bit_no));
     }
     /*endif*/
-    t38_core_send_data(&t->t38x.t38, t->t38x.current_tx_data_type, T38_FIELD_T4_NON_ECM_SIG_END, s->data, s->data_ptr, T38_PACKET_CATEGORY_IMAGE_DATA_END);
+    if (t38_core_send_data(&t->t38x.t38, t->t38x.current_tx_data_type, T38_FIELD_T4_NON_ECM_SIG_END, s->data, s->data_ptr, T38_PACKET_CATEGORY_IMAGE_DATA_END) < 0)
+        span_log(&t->logging, SPAN_LOG_WARNING, "T.38 send failed\n");
+    /*endif*/
     s->in_bits += s->bits_absorbed;
     s->out_octets += s->data_ptr;
     s->data_ptr = 0;
@@ -1604,7 +1599,9 @@ static void non_ecm_push(t38_gateway_state_t *t)
     s = &t->core.to_t38;
     if (s->data_ptr)
     {
-        t38_core_send_data(&t->t38x.t38, t->t38x.current_tx_data_type, T38_FIELD_T4_NON_ECM_DATA, s->data, s->data_ptr, T38_PACKET_CATEGORY_IMAGE_DATA);
+        if (t38_core_send_data(&t->t38x.t38, t->t38x.current_tx_data_type, T38_FIELD_T4_NON_ECM_DATA, s->data, s->data_ptr, T38_PACKET_CATEGORY_IMAGE_DATA) < 0)
+            span_log(&t->logging, SPAN_LOG_WARNING, "T.38 send failed\n");
+        /*endif*/
         s->in_bits += s->bits_absorbed;
         s->out_octets += s->data_ptr;
         s->bits_absorbed = 0;
@@ -1727,7 +1724,9 @@ static void hdlc_rx_status(hdlc_rx_state_t *t, int status)
         if (t->framing_ok_announced)
         {
             category = (s->t38x.current_tx_data_type == T38_DATA_V21)  ?  T38_PACKET_CATEGORY_CONTROL_DATA_END  :  T38_PACKET_CATEGORY_IMAGE_DATA_END;
-            t38_core_send_data(&s->t38x.t38, s->t38x.current_tx_data_type, T38_FIELD_HDLC_SIG_END, NULL, 0, category);
+            if (t38_core_send_data(&s->t38x.t38, s->t38x.current_tx_data_type, T38_FIELD_HDLC_SIG_END, NULL, 0, category) < 0)
+                span_log(&s->logging, SPAN_LOG_WARNING, "T.38 send failed\n");
+            /*endif*/
             t38_core_send_indicator(&s->t38x.t38, T38_IND_NO_SIGNAL);
             t->framing_ok_announced = false;
         }
@@ -1785,7 +1784,9 @@ static void rx_flag_or_abort(hdlc_rx_state_t *t)
                     if (u->data_ptr)
                     {
                         bit_reverse(u->data, t->buffer + t->len - 2 - u->data_ptr, u->data_ptr);
-                        t38_core_send_data(&s->t38x.t38, s->t38x.current_tx_data_type, T38_FIELD_HDLC_DATA, u->data, u->data_ptr, category);
+                        if (t38_core_send_data(&s->t38x.t38, s->t38x.current_tx_data_type, T38_FIELD_HDLC_DATA, u->data, u->data_ptr, category) < 0)
+                            span_log(&s->logging, SPAN_LOG_WARNING, "T.38 send failed\n");
+                        /*endif*/
                     }
                     /*endif*/
                     if (t->num_bits != 7)
@@ -1795,7 +1796,11 @@ static void rx_flag_or_abort(hdlc_rx_state_t *t)
                         /* It seems some boxes may not like us sending a _SIG_END here, and then another
                            when the carrier actually drops. Lets just send T38_FIELD_HDLC_FCS_OK here. */
                         if (t->len > 2)
-                            t38_core_send_data(&s->t38x.t38, s->t38x.current_tx_data_type, T38_FIELD_HDLC_FCS_BAD, NULL, 0, category);
+                        {
+                            if (t38_core_send_data(&s->t38x.t38, s->t38x.current_tx_data_type, T38_FIELD_HDLC_FCS_BAD, NULL, 0, category) < 0)
+                                span_log(&s->logging, SPAN_LOG_WARNING, "T.38 send failed\n");
+                            /*endif*/
+                        }
                         /*endif*/
                     }
                     else if ((u->crc & 0xFFFF) != 0xF0B8)
@@ -1805,7 +1810,11 @@ static void rx_flag_or_abort(hdlc_rx_state_t *t)
                         /* It seems some boxes may not like us sending a _SIG_END here, and then another
                            when the carrier actually drops. Lets just send T38_FIELD_HDLC_FCS_OK here. */
                         if (t->len > 2)
-                            t38_core_send_data(&s->t38x.t38, s->t38x.current_tx_data_type, T38_FIELD_HDLC_FCS_BAD, NULL, 0, category);
+                        {
+                            if (t38_core_send_data(&s->t38x.t38, s->t38x.current_tx_data_type, T38_FIELD_HDLC_FCS_BAD, NULL, 0, category) < 0)
+                                span_log(&s->logging, SPAN_LOG_WARNING, "T.38 send failed\n");
+                            /*endif*/
+                        }
                         /*endif*/
                     }
                     else
@@ -1830,7 +1839,9 @@ static void rx_flag_or_abort(hdlc_rx_state_t *t)
                         /*endif*/
                         /* It seems some boxes may not like us sending a _SIG_END here, and then another
                            when the carrier actually drops. Lets just send T38_FIELD_HDLC_FCS_OK here. */
-                        t38_core_send_data(&s->t38x.t38, s->t38x.current_tx_data_type, T38_FIELD_HDLC_FCS_OK, NULL, 0, category);
+                        if (t38_core_send_data(&s->t38x.t38, s->t38x.current_tx_data_type, T38_FIELD_HDLC_FCS_OK, NULL, 0, category) < 0)
+                            span_log(&s->logging, SPAN_LOG_WARNING, "T.38 send failed\n");
+                        /*endif*/
                     }
                     /*endif*/
                 }
@@ -1936,7 +1947,9 @@ static void t38_hdlc_rx_put_bit(hdlc_rx_state_t *t, int new_bit)
     {
         bit_reverse(u->data, t->buffer + t->len - 2 - u->data_ptr, u->data_ptr);
         category = (s->t38x.current_tx_data_type == T38_DATA_V21)  ?  T38_PACKET_CATEGORY_CONTROL_DATA  :  T38_PACKET_CATEGORY_IMAGE_DATA;
-        t38_core_send_data(&s->t38x.t38, s->t38x.current_tx_data_type, T38_FIELD_HDLC_DATA, u->data, u->data_ptr, category);
+        if (t38_core_send_data(&s->t38x.t38, s->t38x.current_tx_data_type, T38_FIELD_HDLC_DATA, u->data, u->data_ptr, category) < 0)
+            span_log(&s->logging, SPAN_LOG_WARNING, "T.38 send failed\n");
+        /*endif*/
         /* Since we delay transmission by 2 octets, we should now have sent the last of the data octets when
            we have just received the last of the CRC octets. */
         u->data_ptr = 0;
@@ -2107,7 +2120,6 @@ SPAN_DECLARE_NONSTD(int) t38_gateway_tx(t38_gateway_state_t *s, int16_t amp[], i
 
     required_len = max_len;
 #endif
-    len = 0;
     if ((len = s->audio.modems.tx_handler(s->audio.modems.tx_user_data, amp, max_len)) < max_len)
     {
         if (set_next_tx_type(s))
index 75d8842d9af65c517d4d253a930409c3233fb5dc..0349eb4283374456fe3157440ccf174eb50deb27 100644 (file)
@@ -167,7 +167,6 @@ static int extra_bits_in_stuffed_frame(const uint8_t buf[], int len)
     int i;
     int j;
 
-    bitstream = 0;
     ones = 0;
     stuffed = 0;
     /* We should really append the CRC, and include the stuffed bits for that, to get
@@ -929,7 +928,6 @@ static int stream_hdlc(t38_terminal_state_t *s)
                     data_fields[0].field_len = i;
 
                     /* Now see about the next HDLC frame. This will tell us whether to send FCS_OK or FCS_OK_SIG_END */
-                    previous = fe->current_tx_data_type;
                     fe->hdlc_tx.ptr = 0;
                     fe->hdlc_tx.len = 0;
                     if (front_end_status(s, T30_FRONT_END_SEND_STEP_COMPLETE) < 0)
index 8735bd01ffcc1bc827f3db5dad6816fec53a85f8..d21bdbaeca74a06bb70f87aa4ac2bb490797bda1 100644 (file)
@@ -768,8 +768,6 @@ SPAN_DECLARE(int) t43_decode_put(t43_decode_state_t *s, const uint8_t data[], si
     result = 0;
     while (s->current_bit_plane < s->t85.bit_planes)
     {
-        j = s->current_bit_plane;
-
         result = t85_decode_put(&s->t85, data, len);
         if (result != T4_DECODE_OK)
         {
@@ -783,10 +781,10 @@ SPAN_DECLARE(int) t43_decode_put(t43_decode_state_t *s, const uint8_t data[], si
 
         /* Start the next plane */
         s->bit_plane_mask >>= 1;
-        s->current_bit_plane++;
         s->ptr = 0;
         s->row = 0;
         s->plane_ptr = 0;
+        s->current_bit_plane++;
         t85_decode_new_plane(&s->t85);
     }
     /* Apply the colour map, and produce the RGB data from the collected bit-planes */
index b092ecd3f076911b9a772c710143699b9d1b56a1..b62b2d5b1898c85ebfeb688fb1b779f29a64b001 100644 (file)
@@ -899,7 +899,6 @@ static int get_next_row(t4_t6_encode_state_t *s)
 
     if (s->row_bits < 0  ||  s->row_read_handler == NULL)
         return -1;
-    len = -1;
     s->bitstream_iptr = 0;
     s->bitstream_optr = 0;
     s->bit_pos = 7;
index 1096ca3e328bdc359166a2ef103ee0e79ccd67ea..6006333674446224c0806db24ca4b3fd0a52e9a2 100644 (file)
@@ -202,7 +202,7 @@ SPAN_DECLARE(int) time_scale(time_scale_state_t *s, int16_t out[], int16_t in[],
     {
         while (s->lcp >= s->buf_len)
         {
-            memcpy(out + out_len, s->buf, sizeof(int16_t)*s->buf_len);
+            memcpy(&out[out_len], s->buf, sizeof(int16_t)*s->buf_len);
             out_len += s->buf_len;
             if (len - in_len < s->buf_len)
             {
@@ -218,7 +218,7 @@ SPAN_DECLARE(int) time_scale(time_scale_state_t *s, int16_t out[], int16_t in[],
         }
         if (s->lcp > 0)
         {
-            memcpy(out + out_len, s->buf, sizeof(int16_t)*s->lcp);
+            memcpy(&out[out_len], s->buf, sizeof(int16_t)*s->lcp);
             out_len += s->lcp;
             memcpy(s->buf, s->buf + s->lcp, sizeof(int16_t)*(s->buf_len - s->lcp));
             if (len - in_len < s->lcp)
@@ -273,7 +273,7 @@ SPAN_DECLARE(int) time_scale(time_scale_state_t *s, int16_t out[], int16_t in[],
             else
             {
                 /* Slow down - insert a chunk of data */
-                memcpy(out + out_len, s->buf, sizeof(int16_t)*pitch);
+                memcpy(&out[out_len], s->buf, sizeof(int16_t)*pitch);
                 out_len += pitch;
                 overlap_add(s->buf + pitch, s->buf, pitch);
             }
index cd84dc42e2f6e5cf7053f4758ab7741180da647e..83e1ab766de1453afbafdcdee1edd112d2276f38 100644 (file)
@@ -643,7 +643,6 @@ static int tzparse(const char *name, struct tz_state_s * const sp, const int las
             }
             /* Initially we're assumed to be in standard time. */
             isdst = false;
-            theiroffset = theirstdoffset;
             /* Now juggle transition times and types tracking offsets as you do. */
             for (i = 0;  i < sp->timecnt;  i++)
             {
index 6372c5bb584bb0a05cc513f42ac14472e7ef4753..384d460fb3c0950ae8c553a38a1c18a73a307454 100644 (file)
@@ -73,7 +73,7 @@
 #include "spandsp/private/v17rx.h"
 
 #if defined(SPANDSP_USE_FIXED_POINTx)
-#define FP_SCALE(x)                     FP_Q_6_10(x)
+#define FP_SCALE(x)                     FP_Q6_10(x)
 #define FP_FACTOR                       1024
 #define FP_SHIFT_FACTOR                 12
 #else
@@ -81,8 +81,8 @@
 #endif
 
 #if defined(SPANDSP_USE_FIXED_POINTx)
-#define FP_SYNC_SCALE(x)                FP_Q_6_10(x)
-#define FP_SYNC_SCALE_32(x)             FP_Q_6_10_32(x)
+#define FP_SYNC_SCALE(x)                FP_Q6_10(x)
+#define FP_SYNC_SCALE_32(x)             FP_Q22_10(x)
 #define FP_SYNC_SHIFT_FACTOR            10
 #else
 #define FP_SYNC_SCALE(x)                (x)
@@ -746,21 +746,22 @@ static void process_half_baud(v17_rx_state_t *s, const complexf_t *sample)
             /* We should already know the accurate carrier frequency. All we need to sort
                out is the phase. */
             /* Check if we just saw A or B */
+            /* atan(1/3) = 18.433 degrees */
             if ((uint32_t) (angle - s->last_angles[0]) < 0x80000000U)
             {
                 angle = s->last_angles[0];
-                s->last_angles[0] = 0xC0000000 + 219937506;
-                s->last_angles[1] = 0x80000000 + 219937506;
+                s->last_angles[0] = DDS_PHASE(270.0f + 18.433f);
+                s->last_angles[1] = DDS_PHASE(180.0f + 18.433f);
             }
             else
             {
-                s->last_angles[0] = 0x80000000 + 219937506;
-                s->last_angles[1] = 0xC0000000 + 219937506;
+                s->last_angles[0] = DDS_PHASE(180.0f + 18.433f);
+                s->last_angles[1] = DDS_PHASE(270.0f + 18.433f);
             }
             /* Make a step shift in the phase, to pull it into line. We need to rotate the equalizer
                buffer, as well as the carrier phase, for this to play out nicely. */
             /* angle is now the difference between where A is, and where it should be */
-            phase_step = 0x80000000 + angle - 219937506;
+            phase_step = angle - DDS_PHASE(180.0f + 18.433f);
 #if defined(SPANDSP_USE_FIXED_POINTx)
             ip = phase_step >> 16;
             span_log(&s->logging, SPAN_LOG_FLOW, "Spin (short) by %d\n", ip);
@@ -769,7 +770,7 @@ static void process_half_baud(v17_rx_state_t *s, const complexf_t *sample)
                 s->eq_buf[i] = complex_mul_q1_15(&s->eq_buf[i], &z16);
             s->carrier_track_p = 500000;
 #else
-            p = phase_step*2.0f*3.14159f/(65536.0f*65536.0f);
+            p = dds_phase_to_radians(phase_step);
             span_log(&s->logging, SPAN_LOG_FLOW, "Spin (short) by %.5f rads\n", p);
             zz = complex_setf(cosf(p), -sinf(p));
             for (i = 0;  i < V17_EQUALIZER_LEN;  i++)
@@ -828,7 +829,7 @@ static void process_half_baud(v17_rx_state_t *s, const complexf_t *sample)
             /* Make a step shift in the phase, to pull it into line. We need to rotate the equalizer buffer,
                as well as the carrier phase, for this to play out nicely. */
             /* angle is now the difference between where C is, and where it should be */
-            phase_step = angle - 219937506;
+            phase_step = angle - DDS_PHASE(18.433f);
 #if defined(SPANDSP_USE_FIXED_POINTx)
             ip = phase_step >> 16;
             span_log(&s->logging, SPAN_LOG_FLOW, "Spin (long) by %d\n", ip);
@@ -836,7 +837,7 @@ static void process_half_baud(v17_rx_state_t *s, const complexf_t *sample)
             for (i = 0;  i < V17_EQUALIZER_LEN;  i++)
                 s->eq_buf[i] = complex_mul_q1_15(&s->eq_buf[i], &z16);
 #else
-            p = phase_step*2.0f*3.14159f/(65536.0f*65536.0f);
+            p = dds_phase_to_radians(phase_step);
             span_log(&s->logging, SPAN_LOG_FLOW, "Spin (long) by %.5f rads\n", p);
             zz = complex_setf(cosf(p), -sinf(p));
             for (i = 0;  i < V17_EQUALIZER_LEN;  i++)
@@ -1179,7 +1180,7 @@ static __inline__ int signal_detect(v17_rx_state_t *s, int16_t amp)
     /* There could be overflow here, but it isn't a problem in practice */
     diff = x - s->last_sample;
     s->last_sample = x;
-    power = power_meter_update(&(s->power), diff);
+    power = power_meter_update(&s->power, diff);
 #if defined(IAXMODEM_STUFF)
     /* Quick power drop fudge */
     diff = abs(diff);
index cbe261a6cfba5c4187c0c1f961912e748a672b7a..4d3d8f999047b30a04dbcaee5039663239a1213a 100644 (file)
@@ -110,6 +110,8 @@ static __inline__ int scramble(v17_tx_state_t *s, int in_bit)
 {
     int out_bit;
 
+    /* One of the scrambler taps is a variable, so it can be adjusted for caller or answerer operation
+       when used for V.32bis. */
     out_bit = (in_bit ^ (s->scramble_reg >> s->scrambler_tap) ^ (s->scramble_reg >> (23 - 1))) & 1;
     s->scramble_reg = (s->scramble_reg << 1) | out_bit;
     return out_bit;
index 9ab17783711300c73c2c7e9942fd7f45e9b8b14b..0af5a6313ae42292c396c6c7d272b73afadf766d 100644 (file)
@@ -898,7 +898,6 @@ static int decode_dtmf(v18_state_t *s, char msg[], const char dtmf[])
         if (ss)
         {
             len = strlen(ss->dtmf);
-            t += len;
             *u++ = ss->ascii;
             return len;
         }
index 27af3a81e7812b23f6467d73b15e848dad74dbb8..42c3e93c2a982ae81fc9ddd8a26cec5a5e179d27 100644 (file)
@@ -79,7 +79,7 @@
 #include "spandsp/private/v22bis.h"
 
 #if defined(SPANDSP_USE_FIXED_POINT)
-#define FP_SCALE(x)                     FP_Q_6_10(x)
+#define FP_SCALE(x)                     FP_Q6_10(x)
 #define FP_SHIFT_FACTOR                 10
 #else
 #define FP_SCALE(x)                     (x)
@@ -185,7 +185,7 @@ void v22bis_equalizer_coefficient_reset(v22bis_state_t *s)
 {
     /* Start with an equalizer based on everything being perfect */
 #if defined(SPANDSP_USE_FIXED_POINT)
-    static const complexi16_t x = {FP_Q_6_10(3.0f), FP_Q_6_10(0.0f)};
+    static const complexi16_t x = {FP_Q6_10(3.0f), FP_Q6_10(0.0f)};
 
     cvec_zeroi16(s->rx.eq_coeff, V22BIS_EQUALIZER_LEN);
     s->rx.eq_coeff[V22BIS_EQUALIZER_PRE_LEN] = x;
@@ -378,7 +378,7 @@ static __inline__ void symbol_sync(v22bis_state_t *s)
     complexi16_t a;
     complexi16_t b;
     complexi16_t c;
-    static const complexi16_t x = {FP_Q_1_15(0.894427f), FP_Q_1_15(0.44721f)};
+    static const complexi16_t x = {FP_Q1_15(0.894427f), FP_Q1_15(0.44721f)};
 #else
     float p;
     float q;
@@ -453,7 +453,7 @@ static __inline__ void process_half_baud(v22bis_state_t *s, const complexf_t *sa
     complexi16_t z;
     complexi16_t zz;
     const complexi16_t *target;
-    static const complexi16_t x = {FP_Q_1_15(0.894427f), FP_Q_1_15(0.44721f)};
+    static const complexi16_t x = {FP_Q1_15(0.894427f), FP_Q1_15(0.44721f)};
 #else
     complexf_t z;
     complexf_t zz;
@@ -487,8 +487,8 @@ static __inline__ void process_half_baud(v22bis_state_t *s, const complexf_t *sa
     if (s->rx.sixteen_way_decisions)
     {
 #if defined(SPANDSP_USE_FIXED_POINT)
-        re = (z.re + FP_Q_6_10(3.0f)) >> FP_SHIFT_FACTOR;
-        im = (z.im + FP_Q_6_10(3.0f)) >> FP_SHIFT_FACTOR;
+        re = (z.re + FP_Q6_10(3.0f)) >> FP_SHIFT_FACTOR;
+        im = (z.im + FP_Q6_10(3.0f)) >> FP_SHIFT_FACTOR;
 #else
         re = (int) (z.re + 3.0f);
         im = (int) (z.im + 3.0f);
index 15d31cb9d76c1965ab552becf0e0a5533314e410..430ebc5d8486e71c20809b566fbe495039c9afe9 100644 (file)
@@ -70,9 +70,9 @@
 #include "spandsp/private/v22bis.h"
 
 #if defined(SPANDSP_USE_FIXED_POINT)
-#define FP_SCALE(x) FP_Q_6_10(x)
+#define FP_SCALE(x)     FP_Q6_10(x)
 #else
-#define FP_SCALE(x) (x)
+#define FP_SCALE(x)     (x)
 #endif
 
 #include "v22bis_tx_rrc.h"
index d00c779c7f967d582ddbe97f017ee5f41dace3f6..6959d27ef21e3296f97e7bfce2125ab4a3e3e3b7 100644 (file)
@@ -72,7 +72,7 @@
 #include "spandsp/private/v27ter_rx.h"
 
 #if defined(SPANDSP_USE_FIXED_POINT)
-#define FP_SCALE(x)                     FP_Q_6_10(x)
+#define FP_SCALE(x)                     FP_Q6_10(x)
 #define FP_FACTOR                       4096
 #define FP_SHIFT_FACTOR                 12
 #else
@@ -553,7 +553,6 @@ static __inline__ void process_half_baud(v27ter_rx_state_t *s, const complexf_t
     z = equalizer_get(s);
 
     //span_log(&s->logging, SPAN_LOG_FLOW, "Equalized symbol - %15.5f %15.5f\n", z.re, z.im);
-    constellation_state = s->constellation_state;
     switch (s->training_stage)
     {
     case TRAINING_STAGE_NORMAL_OPERATION:
@@ -625,13 +624,13 @@ static __inline__ void process_half_baud(v27ter_rx_state_t *s, const complexf_t
 
             /* Make a step shift in the phase, to pull it into line. We need to rotate the equalizer
                buffer, as well as the carrier phase, for this to play out nicely. */
-            angle += 0x80000000;
+            angle += DDS_PHASE(180.0f);
 #if defined(SPANDSP_USE_FIXED_POINT)
             z16 = complex_seti16(fixed_cos(angle >> 16), -fixed_sin(angle >> 16));
             for (i = 0;  i < V27TER_EQUALIZER_LEN;  i++)
                 s->eq_buf[i] = complex_mul_q1_15(&s->eq_buf[i], &z16);
 #else
-            p = angle*2.0f*3.14159f/(65536.0f*65536.0f);
+            p = dds_phase_to_radians(angle);
             zz = complex_setf(cosf(p), -sinf(p));
             for (i = 0;  i < V27TER_EQUALIZER_LEN;  i++)
                 s->eq_buf[i] = complex_mulf(&s->eq_buf[i], &zz);
@@ -643,9 +642,8 @@ static __inline__ void process_half_baud(v27ter_rx_state_t *s, const complexf_t
             s->training_bc ^= descramble(s, 1);
             descramble(s, 1);
             descramble(s, 1);
-            constellation_state =
             s->constellation_state = abab_pos[s->training_bc];
-            target = &v27ter_constellation[constellation_state];
+            target = &v27ter_constellation[s->constellation_state];
             s->training_count = 1;
             s->training_stage = TRAINING_STAGE_TRAIN_ON_ABAB;
             report_status_change(s, SIG_STATUS_TRAINING_IN_PROGRESS);
@@ -665,9 +663,8 @@ static __inline__ void process_half_baud(v27ter_rx_state_t *s, const complexf_t
         s->training_bc ^= descramble(s, 1);
         descramble(s, 1);
         descramble(s, 1);
-        constellation_state =
         s->constellation_state = abab_pos[s->training_bc];
-        target = &v27ter_constellation[constellation_state];
+        target = &v27ter_constellation[s->constellation_state];
         track_carrier(s, &z, target);
         tune_equalizer(s, &z, target);
 
@@ -680,7 +677,6 @@ static __inline__ void process_half_baud(v27ter_rx_state_t *s, const complexf_t
 #endif
         if (++s->training_count >= V27TER_TRAINING_SEG_5_LEN)
         {
-            constellation_state = 4;
             s->constellation_state = (s->bit_rate == 4800)  ?  4  :  2;
             s->training_count = 0;
             s->training_stage = TRAINING_STAGE_TEST_ONES;
@@ -743,7 +739,20 @@ static __inline__ void process_half_baud(v27ter_rx_state_t *s, const complexf_t
         break;
     }
     if (s->qam_report)
+    {
+#if defined(SPANDSP_USE_FIXED_POINT)
+        complexi16_t zi;
+        complexi16_t targeti;
+
+        zi.re = z.re*1024.0f;
+        zi.im = z.im*1024.0f;
+        targeti.re = target->re*1024.0f;
+        targeti.im = target->im*1024.0f;
+        s->qam_report(s->qam_user_data, &zi, &targeti, s->constellation_state);
+#else
         s->qam_report(s->qam_user_data, &z, target, s->constellation_state);
+#endif
+    }
 }
 /*- End of function --------------------------------------------------------*/
 
index 1cb724b42e21fb3a90c9cd8b7201502c3f5c4ab2..5065c004bef9ab56303235fa8c3ac7384009486e 100644 (file)
@@ -65,7 +65,7 @@
 #include "spandsp/private/v27ter_tx.h"
 
 #if defined(SPANDSP_USE_FIXED_POINT)
-#define FP_SCALE                        FP_Q_6_10
+#define FP_SCALE                        FP_Q6_10
 #else
 #define FP_SCALE(x)                     (x)
 #endif
index 9f37644de16ddb6e37c7439c889c9297617d4d44..da1ef0c909a40b141e0bd00bff8b3e65921b8631 100644 (file)
@@ -71,7 +71,7 @@
 #include "spandsp/private/v29rx.h"
 
 #if defined(SPANDSP_USE_FIXED_POINT)
-#define FP_SCALE(x)                     FP_Q_4_12(x)
+#define FP_SCALE(x)                     FP_Q4_12(x)
 #define FP_FACTOR                       4096
 #define FP_SHIFT_FACTOR                 12
 #else
@@ -79,8 +79,8 @@
 #endif
 
 #if defined(SPANDSP_USE_FIXED_POINT)
-#define FP_SYNC_SCALE(x)                FP_Q_6_10(x)
-#define FP_SYNC_SCALE_32(x)             FP_Q_6_10_32(x)
+#define FP_SYNC_SCALE(x)                FP_Q6_10(x)
+#define FP_SYNC_SCALE_32(x)             FP_Q22_10(x)
 #define FP_SYNC_SHIFT_FACTOR            10
 #else
 #define FP_SYNC_SCALE(x)                (x)
@@ -206,8 +206,13 @@ SPAN_DECLARE(int) v29_rx_equalizer_state(v29_rx_state_t *s, complexi16_t **coeff
 SPAN_DECLARE(int) v29_rx_equalizer_state(v29_rx_state_t *s, complexf_t **coeffs)
 #endif
 {
+#if defined(SPANDSP_USE_FIXED_POINT)
+    *coeffs = NULL;
+    return 0;
+#else
     *coeffs = s->eq_coeff;
     return V29_EQUALIZER_LEN;
+#endif
 }
 /*- End of function --------------------------------------------------------*/
 
@@ -539,7 +544,6 @@ static __inline__ void symbol_sync(v29_rx_state_t *s)
         i = (v > FP_SYNC_SCALE_32(1000.0f))  ?  5  :  1;
         if (s->baud_phase < FP_SYNC_SCALE_32(0.0f))
             i = -i;
-        //printf("v = %10.5f %5d - %f %f %d\n", v, i, p, s->baud_phase, s->total_baud_timing_correction);
         s->eq_put_step += i;
         s->total_baud_timing_correction += i;
     }
@@ -674,7 +678,7 @@ static void process_half_baud(v29_rx_state_t *s, complexf_t *sample)
             for (i = 0;  i < V29_EQUALIZER_LEN;  i++)
                 s->eq_buf[i] = complex_mul_q1_15(&s->eq_buf[i], &z16);
 #else
-            p = angle*2.0f*3.14159f/(65536.0f*65536.0f);
+            p = dds_phase_to_radians(angle);
             span_log(&s->logging, SPAN_LOG_FLOW, "Spin by %.5f rads\n", p);
             zz = complex_setf(cosf(p), -sinf(p));
             for (i = 0;  i < V29_EQUALIZER_LEN;  i++)
@@ -817,7 +821,20 @@ static void process_half_baud(v29_rx_state_t *s, complexf_t *sample)
         break;
     }
     if (s->qam_report)
+    {
+#if defined(SPANDSP_USE_FIXED_POINT)
+        complexi16_t zi;
+        complexi16_t targeti;
+
+        zi.re = z.re*1024.0f;
+        zi.im = z.im*1024.0f;
+        targeti.re = target->re*1024.0f;
+        targeti.im = target->im*1024.0f;
+        s->qam_report(s->qam_user_data, &zi, &targeti, s->constellation_state);
+#else
         s->qam_report(s->qam_user_data, &z, target, s->constellation_state);
+#endif
+    }
 }
 /*- End of function --------------------------------------------------------*/
 
index 749047f0998c983e5846a75f0f233111b4821480..c36027701dc533c76a66ac9cdc05c67c233d7b63 100644 (file)
@@ -273,13 +273,13 @@ static void set_working_gain(v29_tx_state_t *s)
     switch (s->bit_rate)
     {
     case 9600:
-        s->gain = ((int32_t) FP_Q_4_12(0.387f)*s->base_gain) >> 12;
+        s->gain = ((int32_t) FP_Q4_12(0.387f)*s->base_gain) >> 12;
         break;
     case 7200:
-        s->gain = ((int32_t) FP_Q_4_12(0.605f)*s->base_gain) >> 12;
+        s->gain = ((int32_t) FP_Q4_12(0.605f)*s->base_gain) >> 12;
         break;
     case 4800:
-        s->gain = ((int32_t) FP_Q_4_12(0.470f)*s->base_gain) >> 12;
+        s->gain = ((int32_t) FP_Q4_12(0.470f)*s->base_gain) >> 12;
         break;
     default:
         break;
index 388f69e66fe812196411ce39b9fde5117a208339..fb54fa5b396de98c01d3d2e4fce7b987fc5af722 100644 (file)
@@ -314,6 +314,7 @@ static int receive_xid(v42_state_t *ss, const uint8_t *frame, int len)
                 switch (param_id)
                 {
                 case PI_HDLC_OPTIONAL_FUNCTIONS:
+                    /* TODO: param_val is never used right now. */
                     param_val = pack_value(buf, param_len);
                     break;
                 case PI_TX_INFO_MAXSIZE:
index 0c938caa01b3f1d899f5832513d1b1ddc3b7a55f..678c4f8e62d20dea10b4532b29ea35fb0427f4f6 100644 (file)
@@ -495,7 +495,7 @@ int main(int argc, char *argv[])
         {
             len = my_mf_generate(amp, ALL_POSSIBLE_DIGITS);
             for (sample = 0;  sample < len;  sample++)
-                amp[sample] = saturate(amp[sample] + awgn(&noise_source));
+                amp[sample] = sat_add16(amp[sample], awgn(&noise_source));
             codec_munge(amp, len);
             bell_mf_rx(mf_state, amp, len);
             if (bell_mf_rx_get(mf_state, buf, 128) != 15)
index 18267645f2c7b75f043ec583d3dfcda8f043bd2a..947f80589f5c00487b68353c3085943ab806b15e 100644 (file)
@@ -596,7 +596,7 @@ static void mitel_cm7291_side_1_tests(void)
 
             // TODO: Clip
             for (sample = 0;  sample < len;  sample++)
-                amp[sample] = saturate(amp[sample] + awgn(&noise_source));
+                amp[sample] = sat_add16(amp[sample], awgn(&noise_source));
 
             codec_munge(munge, amp, len);
             dtmf_rx(dtmf_state, amp, len);
@@ -722,7 +722,7 @@ static void dial_tone_tolerance_tests(void)
             tone_gen(&dial_tone, amp2, len);
 
             for (sample = 0;  sample < len;  sample++)
-                amp[sample] = saturate(amp[sample] + amp2[sample]);
+                amp[sample] = sat_add16(amp[sample], amp2[sample]);
             codec_munge(munge, amp, len);
             dtmf_rx(dtmf_state, amp, len);
 
index 93d496e302589e4e93280a6424fb96d9aeae3d43..bbb8c4151260b02317cd03f4244ab8f03a3c7541 100644 (file)
@@ -463,7 +463,7 @@ static int16_t channel_model(channel_model_state_t *chan, int16_t rout, int16_t
        the G.168 spec. However, there will generally be near end and far end analogue/echoey
        segments in the real world, unless an end is purely digital. */
     echo = fir32(&chan->impulse, rout*chan->gain);
-    sin = saturate(echo + sgen);
+    sin = sat_add16(echo, sgen);
 
     /* This mixed echo and far end signal will have been through codec munging
        when it came back into the digital network. */
@@ -617,7 +617,7 @@ static void run_test(echo_can_state_t *ctx, int16_t (*tx_source)(void), int16_t
 static void print_test_title(const char *title)
 {
     if (quiet == false)
-        printf(title);
+        printf("%s", title);
 }
 /*- End of function --------------------------------------------------------*/
 
index 77016202a51889dde0392e608f1882d6ed87958e..df6aeeaf60ff5c5817544768c23aa7b3a749c9f3 100644 (file)
@@ -554,7 +554,7 @@ faxtester_state_t *faxtester_init(faxtester_state_t *s, int calling_party)
     span_log_set_protocol(&s->logging, "TST");
     fax_modems_init(&s->modems,
                     false,
-                    NULL,
+                    hdlc_accept,
                     hdlc_underflow_handler,
                     non_ecm_put_bit,
                     t38_non_ecm_buffer_get_bit,
index a4d36ce501a933c3bdbb8e118659125c741c8cc6..0cacdcdd7bc165b3995a598bbddee7391bffdbad 100755 (executable)
@@ -94,32 +94,32 @@ LOCALTESTS_DIR=../test-data/local
 TIFFCMP=tiffcmp
 
 # Colour/gray -> bilevel by not allowing ECM
-for OPTS in "-p AA" "-p TT" "-p GG" "-p TG" "-p GT"
-do
-    IN_FILE="${LOCALTESTS_DIR}/lenna-colour.tif"
-    OUT_FILE="${LOCALTESTS_DIR}/lenna-colour-bilevel.tif"
-    run_colour_fax_test
+#for OPTS in "-p AA" "-p TT" "-p GG" "-p TG" "-p GT"
+#do
+#    IN_FILE="${LOCALTESTS_DIR}/lenna-colour.tif"
+#    OUT_FILE="${LOCALTESTS_DIR}/lenna-colour-bilevel.tif"
+#    run_colour_fax_test
 
-    IN_FILE="${LOCALTESTS_DIR}/lenna-bw.tif"
-    OUT_FILE="${LOCALTESTS_DIR}/lenna-bw-bilevel.tif"
-    run_colour_fax_test
+#    IN_FILE="${LOCALTESTS_DIR}/lenna-bw.tif"
+#    OUT_FILE="${LOCALTESTS_DIR}/lenna-bw-bilevel.tif"
+#    run_colour_fax_test
 
-    IN_FILE="${TIFFFX_DIR}/c03x_02x.tif"
-    OUT_FILE="${TIFFFX_DIR}/c03x_02x-bilevel.tif"
-    run_colour_fax_test
+#    IN_FILE="${TIFFFX_DIR}/c03x_02x.tif"
+#    OUT_FILE="${TIFFFX_DIR}/c03x_02x-bilevel.tif"
+#    run_colour_fax_test
 
-    IN_FILE="${TIFFFX_DIR}/l02x_02x.tif"
-    OUT_FILE="${TIFFFX_DIR}/l02x_02x-bilevel.tif"
-    run_colour_fax_test
+#    IN_FILE="${TIFFFX_DIR}/l02x_02x.tif"
+#    OUT_FILE="${TIFFFX_DIR}/l02x_02x-bilevel.tif"
+#    run_colour_fax_test
 
-    IN_FILE="${TIFFFX_DIR}/l04x_02x.tif"
-    OUT_FILE="${TIFFFX_DIR}/l04x_02x-bilevel.tif"
-    run_colour_fax_test
-done
+#    IN_FILE="${TIFFFX_DIR}/l04x_02x.tif"
+#    OUT_FILE="${TIFFFX_DIR}/l04x_02x-bilevel.tif"
+#    run_colour_fax_test
+#done
 
 # Colour/gray -> colour/gray
-for OPTS in "-p AA -C -e" "-p TT -C -e" "-p GG -C -e" "-p TG -C -e" "-p GT -C -e"
-do
+#for OPTS in "-p AA -C -e" "-p TT -C -e" "-p GG -C -e" "-p TG -C -e" "-p GT -C -e"
+#do
 #    IN_FILE="${LOCALTESTS_DIR}/lenna-colour.tif"
 #    OUT_FILE="${LOCALTESTS_DIR}/lenna-colour-out.tif"
 #    run_colour_fax_test
@@ -132,14 +132,14 @@ do
 #    OUT_FILE="${TIFFFX_DIR}/c03x_02x-out.tif"
 #    run_colour_fax_test
 
-    IN_FILE="${TIFFFX_DIR}/l02x_02x.tif"
-    OUT_FILE="${TIFFFX_DIR}/l02x_02x.tif"
-    run_colour_fax_test
+#    IN_FILE="${TIFFFX_DIR}/l02x_02x.tif"
+#    OUT_FILE="${TIFFFX_DIR}/l02x_02x.tif"
+#    run_colour_fax_test
 
 #    IN_FILE="${TIFFFX_DIR}/l04x_02x.tif"
 #    OUT_FILE="${TIFFFX_DIR}/l04x_02x.tif"
 #    run_colour_fax_test
-done
+#done
 
 # Bi-level tests with image squashing
 for OPTS in "-p AA" "-p AA -e" "-p TT" "-p TT -e" "-p GG" "-p GG -e" "-p TG" "-p TG -e" "-p GT" "-p GT -e"
@@ -398,3 +398,4 @@ done
 
 echo
 echo All fax tests successfully completed
+
index daafaef6d6a3f9e1b0798959eb6ca714b0d37261..ac72e4c7b65da4c07b4cb2c8917da08fa2d2f949 100644 (file)
@@ -556,6 +556,7 @@ int main(int argc, char *argv[])
                     fprintf(stderr, "    Unexpected number of channels in audio file '%s'\n", in_file);
                     exit(2);
                 }
+                enc_state = g722_encode_init(NULL, bit_rate, G722_PACKED | G722_SAMPLE_RATE_8000);
             }
             else
             {
@@ -574,11 +575,8 @@ int main(int argc, char *argv[])
                     fprintf(stderr, "    Unexpected number of channels in audio file '%s'\n", in_file);
                     exit(2);
                 }
-            }
-            if (eight_k_in)
-                enc_state = g722_encode_init(NULL, bit_rate, G722_PACKED | G722_SAMPLE_RATE_8000);
-            else
                 enc_state = g722_encode_init(NULL, bit_rate, G722_PACKED);
+            }
         }
         else
         {
index 2402634131067a0764c8d197fb5ede05b7807241..bc4c5b484033dcb5b2e6d8e05808440f3ef40e3f 100644 (file)
@@ -518,7 +518,7 @@ static int test_a_tone_set(int fwd)
             {
                 len = my_mf_generate(amp, digit);
                 for (sample = 0;  sample < len;  sample++)
-                    amp[sample] = saturate(amp[sample] + awgn(noise_source));
+                    amp[sample] = sat_add16(amp[sample], awgn(noise_source));
                 codec_munge(amp, len);
                 r2_mf_rx(mf_state, amp, len);
                 if (r2_mf_rx_get(mf_state) != digit)
@@ -550,13 +550,13 @@ static int test_a_tone_set(int fwd)
         digit = *s++;
         len = my_mf_generate(amp, digit);
         for (sample = 0;  sample < len;  sample++)
-            amp[sample] = saturate(amp[sample] + awgn(noise_source));
+            amp[sample] = sat_add16(amp[sample], awgn(noise_source));
         codec_munge(amp, len);
         r2_mf_rx(mf_state, amp, len);
         len = 160;
         memset(amp, '\0', len*sizeof(int16_t));
         for (sample = 0;  sample < len;  sample++)
-            amp[sample] = saturate(amp[sample] + awgn(noise_source));
+            amp[sample] = sat_add16(amp[sample], awgn(noise_source));
         codec_munge(amp, len);
         r2_mf_rx(mf_state, amp, len);
     }
index a3ece0e4366b4862de07d03e0f565e229df98709..67666cede9259e01a2774f7f4bf85aa8f5d7ab6f 100644 (file)
@@ -197,141 +197,149 @@ int main(int argc, char *argv[])
         exit(2);
     }
     printf("Testing 16 bit add\n");
-    if (saturated_add16(10000, 10000) != 20000)
-       printf("aaa1 %d\n", saturated_add16(10000, 10000));
-        if (saturated_add16(10000, -10000) != 0)
-        printf("aaa2 %d\n", saturated_add16(10000, -10000));
-        if (saturated_add16(-10000, 10000) != 0)
-        printf("aaa3 %d\n", saturated_add16(-10000, 10000));
-        if (saturated_add16(-10000, -10000) != -20000)
-        printf("aaa4 %d\n", saturated_add16(-10000, -10000));
-        if (saturated_add16(-30000, -30000) != INT16_MIN)
-        printf("aaa5 %d\n", saturated_add16(-30000, -30000));
-        if (saturated_add16(30000, 30000) != INT16_MAX)
+    if (sat_add16(10000, 10000) != 20000
+        ||
+        sat_add16(10000, -10000) != 0
+        ||
+        sat_add16(-10000, 10000) != 0
+        ||
+        sat_add16(-10000, -10000) != -20000
+        ||
+        sat_add16(-30000, -30000) != INT16_MIN
+        ||
+        sat_add16(30000, 30000) != INT16_MAX
+        ||
+        sat_add16(-32768, -32768) != INT16_MIN
+        ||
+        sat_add16(32767, 32767) != INT16_MAX)
     {
         printf("Test failed.\n");
         exit(2);
     }
     printf("Testing 32 bit add\n");
-    if (saturated_add32(10000, 10000) != 20000
+    if (sat_add32(10000, 10000) != 20000
         ||
-        saturated_add32(10000, -10000) != 0
+        sat_add32(10000, -10000) != 0
         ||
-        saturated_add32(-10000, 10000) != 0
+        sat_add32(-10000, 10000) != 0
         ||
-        saturated_add32(-10000, -10000) != -20000
+        sat_add32(-10000, -10000) != -20000
         ||
-        saturated_add32(-2000000000, -2000000000) != INT32_MIN
+        sat_add32(-2000000000, -2000000000) != INT32_MIN
         ||
-        saturated_add32(2000000000, 2000000000) != INT32_MAX)
+        sat_add32(2000000000, 2000000000) != INT32_MAX)
     {
         printf("Test failed.\n");
         exit(2);
     }
     printf("Testing 16 bit subtract\n");
-    if (saturated_sub16(10000, 10000) != 0
+    if (sat_sub16(10000, 10000) != 0
+        ||
+        sat_sub16(10000, -10000) != 20000
+        ||
+        sat_sub16(-10000, 10000) != -20000
         ||
-        saturated_sub16(10000, -10000) != 20000
+        sat_sub16(-10000, -10000) != 0
         ||
-        saturated_sub16(-10000, 10000) != -20000
+        sat_sub16(-30000, 30000) != INT16_MIN
         ||
-        saturated_sub16(-10000, -10000) != 0
+        sat_sub16(30000, -30000) != INT16_MAX
         ||
-        saturated_sub16(-30000, 30000) != INT16_MIN
+        sat_sub16(-32768, 32767) != INT16_MIN
         ||
-        saturated_sub16(30000, -30000) != INT16_MAX)
+        sat_sub16(32767, -32768) != INT16_MAX)
     {
         printf("Test failed.\n");
         exit(2);
     }
     printf("Testing 32 bit subtract\n");
-    if (saturated_sub32(10000, 10000) != 0
+    if (sat_sub32(10000, 10000) != 0
         ||
-        saturated_sub32(10000, -10000) != 20000
+        sat_sub32(10000, -10000) != 20000
         ||
-        saturated_sub32(-10000, 10000) != -20000
+        sat_sub32(-10000, 10000) != -20000
         ||
-        saturated_sub32(-10000, -10000) != 0
+        sat_sub32(-10000, -10000) != 0
         ||
-        saturated_sub32(-2000000000, 2000000000) != INT32_MIN
+        sat_sub32(-2000000000, 2000000000) != INT32_MIN
         ||
-        saturated_sub32(2000000000, -2000000000) != INT32_MAX)
+        sat_sub32(2000000000, -2000000000) != INT32_MAX)
     {
         printf("Test failed.\n");
         exit(2);
     }
     printf("Testing 16 x 16 => 16 bit multiply\n");
-    if (saturated_mul16(100, 100) != 0
+    if (sat_mul16(100, 100) != 0
         ||
-        saturated_mul16(255, 255) != 1
+        sat_mul16(255, 255) != 1
         ||
-        saturated_mul16(32767, -32768) != -32767
+        sat_mul16(32767, -32768) != -32767
         ||
-        saturated_mul16(-32768, 32767) != -32767
+        sat_mul16(-32768, 32767) != -32767
         ||
-        saturated_mul16(32767, 32767) != 32766
+        sat_mul16(32767, 32767) != 32766
         ||
-        saturated_mul16(-32768, -32768) != 32767)
+        sat_mul16(-32768, -32768) != 32767)
     {
         printf("Test failed.\n");
         exit(2);
     }
     printf("Testing 16 x 16 => 32 bit multiply\n");
-    if (saturated_mul16_32(100, 100) != 20000
+    if (sat_mul32_16(100, 100) != 20000
         ||
-        saturated_mul16_32(-100, 100) != -20000
+        sat_mul32_16(-100, 100) != -20000
         ||
-        saturated_mul16_32(32767, -32768) != -2147418112
+        sat_mul32_16(32767, -32768) != -2147418112
         ||
-        saturated_mul16_32(-32768, 32767) != -2147418112
+        sat_mul32_16(-32768, 32767) != -2147418112
         ||
-        saturated_mul16_32(32767, 32767) != 2147352578
+        sat_mul32_16(32767, 32767) != 2147352578
         ||
-        saturated_mul16_32(-32768, -32768) != INT32_MAX)
+        sat_mul32_16(-32768, -32768) != INT32_MAX)
     {
         printf("Test failed.\n");
         exit(2);
     }
     printf("Testing 32 + 16 x 16 => 32 bit MAC\n");
-    if (saturated_mac16_32(123, 100, 100) != 123 + 20000
+    if (sat_mac32_16(123, 100, 100) != 123 + 20000
         ||
-        saturated_mac16_32(123, -100, 100) != 123 - 20000
+        sat_mac32_16(123, -100, 100) != 123 - 20000
         ||
-        saturated_mac16_32(123, 32767, -32768) != 123 - 2147418112
+        sat_mac32_16(123, 32767, -32768) != 123 - 2147418112
         ||
-        saturated_mac16_32(123, -32768, 32767) != 123 - 2147418112
+        sat_mac32_16(123, -32768, 32767) != 123 - 2147418112
         ||
-        saturated_mac16_32(123, 32767, 32767) != 123 + 2147352578
+        sat_mac32_16(123, 32767, 32767) != 123 + 2147352578
         ||
-        saturated_mac16_32(123, -32768, -32768) != INT32_MAX)
+        sat_mac32_16(123, -32768, -32768) != INT32_MAX)
     {
         printf("Test failed.\n");
         exit(2);
     }
     printf("Testing 32 - 16 x 16 => 32 bit MSU\n");
-    if (saturated_msu16_32(123, 100, 100) != 123 - 20000
+    if (sat_msu32_16(123, 100, 100) != 123 - 20000
         ||
-        saturated_msu16_32(123, -100, 100) != 123 + 20000
+        sat_msu32_16(123, -100, 100) != 123 + 20000
         ||
-        saturated_msu16_32(123, 32767, -32768) != 123 + 2147418112
+        sat_msu32_16(123, 32767, -32768) != 123 + 2147418112
         ||
-        saturated_msu16_32(123, -32768, 32767) != 123 + 2147418112
+        sat_msu32_16(123, -32768, 32767) != 123 + 2147418112
         ||
-        saturated_msu16_32(123, 32767, 32767) != 123 - 2147352578
+        sat_msu32_16(123, 32767, 32767) != 123 - 2147352578
         ||
-        saturated_msu16_32(123, -32768, -32768) != 123 - INT32_MAX)
+        sat_msu32_16(123, -32768, -32768) != 123 - INT32_MAX)
     {
         printf("Test failed.\n");
         exit(2);
     }
     printf("Testing 16 bit absolute\n");
-    if (saturated_abs16(10000) != 10000
+    if (sat_abs16(10000) != 10000
         ||
-        saturated_abs16(-10000) != 10000
+        sat_abs16(-10000) != 10000
         ||
-        saturated_abs16(32767) != 32767
+        sat_abs16(32767) != 32767
         ||
-        saturated_abs16(-32768) != 32767)
+        sat_abs16(-32768) != 32767)
     {
         printf("Test failed.\n");
         exit(2);
index d090d7cce022812c0a6a6884fa8eb6df73ae7e11..747deca18d82fc25733a2f3ccf33bccd04957454 100644 (file)
@@ -33,6 +33,7 @@
 #include "config.h"
 #endif
 
+#include <inttypes.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
@@ -450,7 +451,7 @@ static int file_decode_tests(super_tone_rx_state_t *super, const char *file_name
     {
         /* Add some noise to the signal for a more meaningful test. */
         //for (sample = 0;  sample < frames;  sample++)
-        //    amp[sample] += saturate(amp[sample] + awgn (&noise_source));
+        //    amp[sample] += sat_add16(amp[sample], awgn (&noise_source));
         for (sample = 0;  sample < frames;  )
         {
             x = super_tone_rx(super, amp + sample, frames - sample);
index ea87b4eab3e5d868dc41906006ad83e10a9ab0ea..bfdaf80b8ed85e8b2097afa1cdabca0c94535345 100644 (file)
@@ -460,6 +460,8 @@ int main(int argc, char *argv[])
                 printf("Failed to convert to ITULAB\n");
                 return 1;
             }
+#else
+            outptr = 0;
 #endif
             free(data);
             data = (uint8_t *) outptr;
index 7d51d7dfb4788bd9c9423ae8b3a50c5d40319387..f6f6f0891a5ccd37baf0a9b3c18d04f511d47e29 100644 (file)
@@ -1174,6 +1174,8 @@ int main(int argc, char *argv[])
                     printf("Failed to convert to ITULAB (C).\n");
                     return 1;
                 }
+#else
+                outsize = 0;
 #endif
                 free(data);
                 data = (uint8_t *) outptr;
index 1ddb8e346d141c13fca33dee9e3a9809799496a7..f4bb05d2ebb7d0d09ed5a6393542cab264d924b3 100644 (file)
@@ -220,7 +220,8 @@ int udptl_rx_packet(udptl_state_t *s, const uint8_t buf[], int len)
     /* Save the new packet. Pure redundancy mode won't use this, but some systems will switch
        into FEC mode after sending some redundant packets. */
     x = seq_no & UDPTL_BUF_MASK;
-    memcpy(s->rx[x].buf, msg, msg_len);
+    if (msg_len > 0)
+        memcpy(s->rx[x].buf, msg, msg_len);
     s->rx[x].buf_len = msg_len;
     s->rx[x].fec_len[0] = 0;
     s->rx[x].fec_span = 0;
@@ -312,7 +313,8 @@ int udptl_rx_packet(udptl_state_t *s, const uint8_t buf[], int len)
                 return -1;
 
             /* Save the new FEC data */
-            memcpy(s->rx[x].fec[i], data, s->rx[x].fec_len[i]);
+            if (s->rx[x].fec_len[i])
+                memcpy(s->rx[x].fec[i], data, s->rx[x].fec_len[i]);
 #if 0
             fprintf(stderr, "FEC: ");
             for (j = 0;  j < s->rx[x].fec_len[i];  j++)
index df9243691e983af832d0516b926426ea52893184..43338583ef172611ca7fdd26a257e42ee6a50233 100644 (file)
@@ -208,11 +208,8 @@ static int v8_calls_v8_tests(SNDFILE *outhandle)
     v8_call_parms.pstn_access = 0;
     v8_call_parms.nsf = -1;
     v8_call_parms.t66 = -1;
-    v8_caller = v8_init(NULL,
-                        true,
-                        &v8_call_parms,
-                        handler,
-                        (void *) "caller");
+    v8_caller = v8_init(NULL, true, &v8_call_parms, handler, (void *) "caller");
+
     v8_answer_parms.modem_connect_tone = MODEM_CONNECT_TONES_ANSAM_PR;
     v8_answer_parms.send_ci = true;
     v8_answer_parms.v92 = -1;
@@ -223,11 +220,8 @@ static int v8_calls_v8_tests(SNDFILE *outhandle)
     v8_answer_parms.pstn_access = 0;
     v8_answer_parms.nsf = -1;
     v8_answer_parms.t66 = -1;
-    v8_answerer = v8_init(NULL,
-                          false,
-                          &v8_answer_parms,
-                          handler,
-                          (void *) "answerer");
+    v8_answerer = v8_init(NULL, false, &v8_answer_parms, handler, (void *) "answerer");
+
     caller_logging = v8_get_logging_state(v8_caller);
     span_log_set_level(caller_logging, SPAN_LOG_FLOW | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
     span_log_set_tag(caller_logging, "caller");
@@ -239,6 +233,7 @@ static int v8_calls_v8_tests(SNDFILE *outhandle)
         samples = v8_tx(v8_caller, amp, SAMPLES_PER_CHUNK);
         if (samples < SAMPLES_PER_CHUNK)
         {
+printf("Caller silence %d\n", SAMPLES_PER_CHUNK - samples);
             vec_zeroi16(amp + samples, SAMPLES_PER_CHUNK - samples);
             samples = SAMPLES_PER_CHUNK;
         }
@@ -252,6 +247,7 @@ static int v8_calls_v8_tests(SNDFILE *outhandle)
         samples = v8_tx(v8_answerer, amp, SAMPLES_PER_CHUNK);
         if (samples < SAMPLES_PER_CHUNK)
         {
+printf("Answerer silence %d\n", SAMPLES_PER_CHUNK - samples);
             vec_zeroi16(amp + samples, SAMPLES_PER_CHUNK - samples);
             samples = SAMPLES_PER_CHUNK;
         }