diff --git a/libs/spandsp/src/alloc.c b/libs/spandsp/src/alloc.c index b8cb6810c8..3785293ea2 100644 --- a/libs/spandsp/src/alloc.c +++ b/libs/spandsp/src/alloc.c @@ -41,7 +41,7 @@ #define __ISO_C_VISIBLE 2011 #endif #include -#if defined(HAVE_MALLOC_H) && !defined(__OpenBSD__) && !defined(__DragonFly__) +#if defined(HAVE_MALLOC_H) && !defined(__OpenBSD__) && !defined(__DragonFly__) #include #endif #include diff --git a/libs/spandsp/src/at_interpreter.c b/libs/spandsp/src/at_interpreter.c index c009a19a52..9bebde6272 100644 --- a/libs/spandsp/src/at_interpreter.c +++ b/libs/spandsp/src/at_interpreter.c @@ -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. */ diff --git a/libs/spandsp/src/bell_r2_mf.c b/libs/spandsp/src/bell_r2_mf.c index 8f74b7a86a..b8e507026e 100644 --- a/libs/spandsp/src/bell_r2_mf.c +++ b/libs/spandsp/src/bell_r2_mf.c @@ -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)) diff --git a/libs/spandsp/src/dtmf.c b/libs/spandsp/src/dtmf.c index 39c475a554..1f4e012dd3 100644 --- a/libs/spandsp/src/dtmf.c +++ b/libs/spandsp/src/dtmf.c @@ -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. */ diff --git a/libs/spandsp/src/echo.c b/libs/spandsp/src/echo.c index 5d6a1cadd2..70c1730bc7 100644 --- a/libs/spandsp/src/echo.c +++ b/libs/spandsp/src/echo.c @@ -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 diff --git a/libs/spandsp/src/fax.c b/libs/spandsp/src/fax.c index c43abd0243..998af14177 100644 --- a/libs/spandsp/src/fax.c +++ b/libs/spandsp/src/fax.c @@ -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; diff --git a/libs/spandsp/src/fax_modems.c b/libs/spandsp/src/fax_modems.c index b32fba7ada..a09b0c9506 100644 --- a/libs/spandsp/src/fax_modems.c +++ b/libs/spandsp/src/fax_modems.c @@ -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) diff --git a/libs/spandsp/src/filter_tools.c b/libs/spandsp/src/filter_tools.c index ff625bb13d..4411226074 100644 --- a/libs/spandsp/src/filter_tools.c +++ b/libs/spandsp/src/filter_tools.c @@ -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 --------------------------------------------------------*/ diff --git a/libs/spandsp/src/fsk.c b/libs/spandsp/src/fsk.c index 29b32c65ea..07c242bfc4 100644 --- a/libs/spandsp/src/fsk.c +++ b/libs/spandsp/src/fsk.c @@ -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 --------------------------------------------------------*/ diff --git a/libs/spandsp/src/g722.c b/libs/spandsp/src/g722.c index 2f11715c10..aebe9a575e 100644 --- a/libs/spandsp/src/g722.c +++ b/libs/spandsp/src/g722.c @@ -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; diff --git a/libs/spandsp/src/g726.c b/libs/spandsp/src/g726.c index 4f3bea3b6b..3219465d11 100644 --- a/libs/spandsp/src/g726.c +++ b/libs/spandsp/src/g726.c @@ -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' */ diff --git a/libs/spandsp/src/gsm0610_decode.c b/libs/spandsp/src/gsm0610_decode.c index d3e21f390f..81097d1a21 100644 --- a/libs/spandsp/src/gsm0610_decode.c +++ b/libs/spandsp/src/gsm0610_decode.c @@ -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; } diff --git a/libs/spandsp/src/gsm0610_encode.c b/libs/spandsp/src/gsm0610_encode.c index eeac7d2881..c810fa2c69 100644 --- a/libs/spandsp/src/gsm0610_encode.c +++ b/libs/spandsp/src/gsm0610_encode.c @@ -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; diff --git a/libs/spandsp/src/gsm0610_local.h b/libs/spandsp/src/gsm0610_local.h index 84c4c20edc..8aaac612e0 100644 --- a/libs/spandsp/src/gsm0610_local.h +++ b/libs/spandsp/src/gsm0610_local.h @@ -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 --------------------------------------------------------*/ diff --git a/libs/spandsp/src/gsm0610_long_term.c b/libs/spandsp/src/gsm0610_long_term.c index 32d4ab39b7..2ec7aa7818 100644 --- a/libs/spandsp/src/gsm0610_long_term.c +++ b/libs/spandsp/src/gsm0610_long_term.c @@ -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*/ diff --git a/libs/spandsp/src/gsm0610_lpc.c b/libs/spandsp/src/gsm0610_lpc.c index 8d32edab6b..70e06d4122 100644 --- a/libs/spandsp/src/gsm0610_lpc.c +++ b/libs/spandsp/src/gsm0610_lpc.c @@ -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) \ ? \ diff --git a/libs/spandsp/src/gsm0610_preprocess.c b/libs/spandsp/src/gsm0610_preprocess.c index 92ca2e30b3..b4191b78c8 100644 --- a/libs/spandsp/src/gsm0610_preprocess.c +++ b/libs/spandsp/src/gsm0610_preprocess.c @@ -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*/ diff --git a/libs/spandsp/src/gsm0610_rpe.c b/libs/spandsp/src/gsm0610_rpe.c index 0a6cbb649c..b21e43af14 100644 --- a/libs/spandsp/src/gsm0610_rpe.c +++ b/libs/spandsp/src/gsm0610_rpe.c @@ -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*/ diff --git a/libs/spandsp/src/gsm0610_short_term.c b/libs/spandsp/src/gsm0610_short_term.c index 1eb46a7e97..62130fdf28 100644 --- a/libs/spandsp/src/gsm0610_short_term.c +++ b/libs/spandsp/src/gsm0610_short_term.c @@ -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++ = diff --git a/libs/spandsp/src/ima_adpcm.c b/libs/spandsp/src/ima_adpcm.c index fbd59df621..c974424cb4 100644 --- a/libs/spandsp/src/ima_adpcm.c +++ b/libs/spandsp/src/ima_adpcm.c @@ -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; diff --git a/libs/spandsp/src/image_translate.c b/libs/spandsp/src/image_translate.c index 217e560260..d337ee98a2 100644 --- a/libs/spandsp/src/image_translate.c +++ b/libs/spandsp/src/image_translate.c @@ -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 --------------------------------------------------------*/ diff --git a/libs/spandsp/src/logging.c b/libs/spandsp/src/logging.c index 09bc29b6c6..808ee7e392 100644 --- a/libs/spandsp/src/logging.c +++ b/libs/spandsp/src/logging.c @@ -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; diff --git a/libs/spandsp/src/lpc10_decode.c b/libs/spandsp/src/lpc10_decode.c index 2242133591..e56b16ecf0 100644 --- a/libs/spandsp/src/lpc10_decode.c +++ b/libs/spandsp/src/lpc10_decode.c @@ -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) */ diff --git a/libs/spandsp/src/lpc10_voicing.c b/libs/spandsp/src/lpc10_voicing.c index fdb1b3f7c5..e41f26a269 100644 --- a/libs/spandsp/src/lpc10_voicing.c +++ b/libs/spandsp/src/lpc10_voicing.c @@ -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): */ diff --git a/libs/spandsp/src/make_at_dictionary.c b/libs/spandsp/src/make_at_dictionary.c index 3a881af992..6259207368 100644 --- a/libs/spandsp/src/make_at_dictionary.c +++ b/libs/spandsp/src/make_at_dictionary.c @@ -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])); diff --git a/libs/spandsp/src/make_cielab_luts.c b/libs/spandsp/src/make_cielab_luts.c index dc5172817d..b780355543 100644 --- a/libs/spandsp/src/make_cielab_luts.c +++ b/libs/spandsp/src/make_cielab_luts.c @@ -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++) diff --git a/libs/spandsp/src/make_math_fixed_tables.c b/libs/spandsp/src/make_math_fixed_tables.c index 8e290b44ce..1f568286f7 100644 --- a/libs/spandsp/src/make_math_fixed_tables.c +++ b/libs/spandsp/src/make_math_fixed_tables.c @@ -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++) diff --git a/libs/spandsp/src/make_modem_filter.c b/libs/spandsp/src/make_modem_filter.c index bd9427e24f..2579461db1 100644 --- a/libs/spandsp/src/make_modem_filter.c +++ b/libs/spandsp/src/make_modem_filter.c @@ -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); diff --git a/libs/spandsp/src/make_t43_gray_code_tables.c b/libs/spandsp/src/make_t43_gray_code_tables.c index 90117c5d83..0016c988a0 100644 --- a/libs/spandsp/src/make_t43_gray_code_tables.c +++ b/libs/spandsp/src/make_t43_gray_code_tables.c @@ -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++) { diff --git a/libs/spandsp/src/mmx_sse_decs.h b/libs/spandsp/src/mmx_sse_decs.h index 4dff6fe26a..5ebd5f95c9 100644 --- a/libs/spandsp/src/mmx_sse_decs.h +++ b/libs/spandsp/src/mmx_sse_decs.h @@ -53,6 +53,12 @@ #if defined(SPANDSP_USE_SSE5) #include #endif +#if defined(SPANDSP_USE_AVX) +#include +#endif +#if defined(SPANDSP_USE_AVX2) +#include +#endif #endif diff --git a/libs/spandsp/src/noise.c b/libs/spandsp/src/noise.c index 3ad164cf7f..1a8f58842e 100644 --- a/libs/spandsp/src/noise.c +++ b/libs/spandsp/src/noise.c @@ -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 --------------------------------------------------------*/ diff --git a/libs/spandsp/src/sig_tone.c b/libs/spandsp/src/sig_tone.c index 1b30d8e583..20e16df3e4 100644 --- a/libs/spandsp/src/sig_tone.c +++ b/libs/spandsp/src/sig_tone.c @@ -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*/ } diff --git a/libs/spandsp/src/spandsp/ademco_contactid.h b/libs/spandsp/src/spandsp/ademco_contactid.h index abae8e701b..43d807fb9b 100644 --- a/libs/spandsp/src/spandsp/ademco_contactid.h +++ b/libs/spandsp/src/spandsp/ademco_contactid.h @@ -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 * diff --git a/libs/spandsp/src/spandsp/bit_operations.h b/libs/spandsp/src/spandsp/bit_operations.h index 311408123e..c7f4093ab3 100644 --- a/libs/spandsp/src/spandsp/bit_operations.h +++ b/libs/spandsp/src/spandsp/bit_operations.h @@ -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; diff --git a/libs/spandsp/src/spandsp/fax_modems.h b/libs/spandsp/src/spandsp/fax_modems.h index 6edfa967e7..a076c0332f 100644 --- a/libs/spandsp/src/spandsp/fax_modems.h +++ b/libs/spandsp/src/spandsp/fax_modems.h @@ -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. diff --git a/libs/spandsp/src/spandsp/logging.h b/libs/spandsp/src/spandsp/logging.h index 78db086ef0..cd0d73355c 100644 --- a/libs/spandsp/src/spandsp/logging.h +++ b/libs/spandsp/src/spandsp/logging.h @@ -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); diff --git a/libs/spandsp/src/spandsp/private/fax_modems.h b/libs/spandsp/src/spandsp/private/fax_modems.h index 373a692994..d11397793b 100644 --- a/libs/spandsp/src/spandsp/private/fax_modems.h +++ b/libs/spandsp/src/spandsp/private/fax_modems.h @@ -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; diff --git a/libs/spandsp/src/spandsp/private/g722.h b/libs/spandsp/src/spandsp/private/g722.h index 81dfc68c30..a98a574ce6 100644 --- a/libs/spandsp/src/spandsp/private/g722.h +++ b/libs/spandsp/src/spandsp/private/g722.h @@ -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; diff --git a/libs/spandsp/src/spandsp/private/t31.h b/libs/spandsp/src/spandsp/private/t31.h index 2bfed82d0b..373ca74fc7 100644 --- a/libs/spandsp/src/spandsp/private/t31.h +++ b/libs/spandsp/src/spandsp/private/t31.h @@ -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. */ diff --git a/libs/spandsp/src/spandsp/private/timezone.h b/libs/spandsp/src/spandsp/private/timezone.h index b2397cf2d2..78519f0f7a 100644 --- a/libs/spandsp/src/spandsp/private/timezone.h +++ b/libs/spandsp/src/spandsp/private/timezone.h @@ -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 diff --git a/libs/spandsp/src/spandsp/saturated.h b/libs/spandsp/src/spandsp/saturated.h index 41b8ba3db0..db9baf4f4b 100644 --- a/libs/spandsp/src/spandsp/saturated.h +++ b/libs/spandsp/src/spandsp/saturated.h @@ -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 --------------------------------------------------------*/ diff --git a/libs/spandsp/src/spandsp/telephony.h b/libs/spandsp/src/spandsp/telephony.h index b32ecfa0f5..58a8e29c6a 100644 --- a/libs/spandsp/src/spandsp/telephony.h +++ b/libs/spandsp/src/spandsp/telephony.h @@ -46,6 +46,10 @@ #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))) +/* 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_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))) - -#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 */ diff --git a/libs/spandsp/src/spandsp/v17rx.h b/libs/spandsp/src/spandsp/v17rx.h index d99674ddd5..8aebe85263 100644 --- a/libs/spandsp/src/spandsp/v17rx.h +++ b/libs/spandsp/src/spandsp/v17rx.h @@ -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); diff --git a/libs/spandsp/src/spandsp/v22bis.h b/libs/spandsp/src/spandsp/v22bis.h index f20656919f..50b2fb4467 100644 --- a/libs/spandsp/src/spandsp/v22bis.h +++ b/libs/spandsp/src/spandsp/v22bis.h @@ -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, diff --git a/libs/spandsp/src/t31.c b/libs/spandsp/src/t31.c index d0c42bd84d..47f26c9e49 100644 --- a/libs/spandsp/src/t31.c +++ b/libs/spandsp/src/t31.c @@ -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 --------------------------------------------------------*/ diff --git a/libs/spandsp/src/t38_core.c b/libs/spandsp/src/t38_core.c index 0bbbd18fb6..5fb57bbc82 100644 --- a/libs/spandsp/src/t38_core.c +++ b/libs/spandsp/src/t38_core.c @@ -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 */ diff --git a/libs/spandsp/src/t38_gateway.c b/libs/spandsp/src/t38_gateway.c index 402c7cded2..8535f2d59c 100644 --- a/libs/spandsp/src/t38_gateway.c +++ b/libs/spandsp/src/t38_gateway.c @@ -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)) diff --git a/libs/spandsp/src/t38_terminal.c b/libs/spandsp/src/t38_terminal.c index 75d8842d9a..0349eb4283 100644 --- a/libs/spandsp/src/t38_terminal.c +++ b/libs/spandsp/src/t38_terminal.c @@ -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) diff --git a/libs/spandsp/src/t43.c b/libs/spandsp/src/t43.c index 8735bd01ff..d21bdbaeca 100644 --- a/libs/spandsp/src/t43.c +++ b/libs/spandsp/src/t43.c @@ -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 */ diff --git a/libs/spandsp/src/t4_t6_encode.c b/libs/spandsp/src/t4_t6_encode.c index b092ecd3f0..b62b2d5b18 100644 --- a/libs/spandsp/src/t4_t6_encode.c +++ b/libs/spandsp/src/t4_t6_encode.c @@ -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; diff --git a/libs/spandsp/src/time_scale.c b/libs/spandsp/src/time_scale.c index 1096ca3e32..6006333674 100644 --- a/libs/spandsp/src/time_scale.c +++ b/libs/spandsp/src/time_scale.c @@ -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); } diff --git a/libs/spandsp/src/timezone.c b/libs/spandsp/src/timezone.c index cd84dc42e2..83e1ab766d 100644 --- a/libs/spandsp/src/timezone.c +++ b/libs/spandsp/src/timezone.c @@ -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++) { diff --git a/libs/spandsp/src/v17rx.c b/libs/spandsp/src/v17rx.c index 6372c5bb58..384d460fb3 100644 --- a/libs/spandsp/src/v17rx.c +++ b/libs/spandsp/src/v17rx.c @@ -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); diff --git a/libs/spandsp/src/v17tx.c b/libs/spandsp/src/v17tx.c index cbe261a6cf..4d3d8f9990 100644 --- a/libs/spandsp/src/v17tx.c +++ b/libs/spandsp/src/v17tx.c @@ -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; diff --git a/libs/spandsp/src/v18.c b/libs/spandsp/src/v18.c index 9ab1778371..0af5a6313a 100644 --- a/libs/spandsp/src/v18.c +++ b/libs/spandsp/src/v18.c @@ -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; } diff --git a/libs/spandsp/src/v22bis_rx.c b/libs/spandsp/src/v22bis_rx.c index 27af3a81e7..42c3e93c2a 100644 --- a/libs/spandsp/src/v22bis_rx.c +++ b/libs/spandsp/src/v22bis_rx.c @@ -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); diff --git a/libs/spandsp/src/v22bis_tx.c b/libs/spandsp/src/v22bis_tx.c index 15d31cb9d7..430ebc5d84 100644 --- a/libs/spandsp/src/v22bis_tx.c +++ b/libs/spandsp/src/v22bis_tx.c @@ -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" diff --git a/libs/spandsp/src/v27ter_rx.c b/libs/spandsp/src/v27ter_rx.c index d00c779c7f..6959d27ef2 100644 --- a/libs/spandsp/src/v27ter_rx.c +++ b/libs/spandsp/src/v27ter_rx.c @@ -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 --------------------------------------------------------*/ diff --git a/libs/spandsp/src/v27ter_tx.c b/libs/spandsp/src/v27ter_tx.c index 1cb724b42e..5065c004be 100644 --- a/libs/spandsp/src/v27ter_tx.c +++ b/libs/spandsp/src/v27ter_tx.c @@ -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 diff --git a/libs/spandsp/src/v29rx.c b/libs/spandsp/src/v29rx.c index 9f37644de1..da1ef0c909 100644 --- a/libs/spandsp/src/v29rx.c +++ b/libs/spandsp/src/v29rx.c @@ -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 --------------------------------------------------------*/ diff --git a/libs/spandsp/src/v29tx.c b/libs/spandsp/src/v29tx.c index 749047f099..c36027701d 100644 --- a/libs/spandsp/src/v29tx.c +++ b/libs/spandsp/src/v29tx.c @@ -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; diff --git a/libs/spandsp/src/v42.c b/libs/spandsp/src/v42.c index 388f69e66f..fb54fa5b39 100644 --- a/libs/spandsp/src/v42.c +++ b/libs/spandsp/src/v42.c @@ -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: diff --git a/libs/spandsp/tests/bell_mf_rx_tests.c b/libs/spandsp/tests/bell_mf_rx_tests.c index 0c938caa01..678c4f8e62 100644 --- a/libs/spandsp/tests/bell_mf_rx_tests.c +++ b/libs/spandsp/tests/bell_mf_rx_tests.c @@ -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) diff --git a/libs/spandsp/tests/dtmf_rx_tests.c b/libs/spandsp/tests/dtmf_rx_tests.c index 18267645f2..947f80589f 100644 --- a/libs/spandsp/tests/dtmf_rx_tests.c +++ b/libs/spandsp/tests/dtmf_rx_tests.c @@ -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); diff --git a/libs/spandsp/tests/echo_tests.c b/libs/spandsp/tests/echo_tests.c index 93d496e302..bbb8c41512 100644 --- a/libs/spandsp/tests/echo_tests.c +++ b/libs/spandsp/tests/echo_tests.c @@ -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 --------------------------------------------------------*/ diff --git a/libs/spandsp/tests/fax_tester.c b/libs/spandsp/tests/fax_tester.c index 77016202a5..df6aeeaf60 100644 --- a/libs/spandsp/tests/fax_tester.c +++ b/libs/spandsp/tests/fax_tester.c @@ -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, diff --git a/libs/spandsp/tests/fax_tests.sh b/libs/spandsp/tests/fax_tests.sh index a4d36ce501..0cacdcdd7b 100755 --- a/libs/spandsp/tests/fax_tests.sh +++ b/libs/spandsp/tests/fax_tests.sh @@ -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 + diff --git a/libs/spandsp/tests/g722_tests.c b/libs/spandsp/tests/g722_tests.c index daafaef6d6..ac72e4c7b6 100644 --- a/libs/spandsp/tests/g722_tests.c +++ b/libs/spandsp/tests/g722_tests.c @@ -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 { diff --git a/libs/spandsp/tests/r2_mf_rx_tests.c b/libs/spandsp/tests/r2_mf_rx_tests.c index 2402634131..bc4c5b4840 100644 --- a/libs/spandsp/tests/r2_mf_rx_tests.c +++ b/libs/spandsp/tests/r2_mf_rx_tests.c @@ -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); } diff --git a/libs/spandsp/tests/saturated_tests.c b/libs/spandsp/tests/saturated_tests.c index a3ece0e436..67666cede9 100644 --- a/libs/spandsp/tests/saturated_tests.c +++ b/libs/spandsp/tests/saturated_tests.c @@ -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 || - saturated_sub16(10000, -10000) != 20000 + sat_sub16(10000, -10000) != 20000 || - saturated_sub16(-10000, 10000) != -20000 + sat_sub16(-10000, 10000) != -20000 || - saturated_sub16(-10000, -10000) != 0 + sat_sub16(-10000, -10000) != 0 || - saturated_sub16(-30000, 30000) != INT16_MIN + sat_sub16(-30000, 30000) != INT16_MIN || - saturated_sub16(30000, -30000) != INT16_MAX) + sat_sub16(30000, -30000) != INT16_MAX + || + sat_sub16(-32768, 32767) != INT16_MIN + || + 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); diff --git a/libs/spandsp/tests/super_tone_rx_tests.c b/libs/spandsp/tests/super_tone_rx_tests.c index d090d7cce0..747deca18d 100644 --- a/libs/spandsp/tests/super_tone_rx_tests.c +++ b/libs/spandsp/tests/super_tone_rx_tests.c @@ -33,6 +33,7 @@ #include "config.h" #endif +#include #include #include #include @@ -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); diff --git a/libs/spandsp/tests/t42_tests.c b/libs/spandsp/tests/t42_tests.c index ea87b4eab3..bfdaf80b8e 100644 --- a/libs/spandsp/tests/t42_tests.c +++ b/libs/spandsp/tests/t42_tests.c @@ -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; diff --git a/libs/spandsp/tests/t43_tests.c b/libs/spandsp/tests/t43_tests.c index 7d51d7dfb4..f6f6f0891a 100644 --- a/libs/spandsp/tests/t43_tests.c +++ b/libs/spandsp/tests/t43_tests.c @@ -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; diff --git a/libs/spandsp/tests/udptl.c b/libs/spandsp/tests/udptl.c index 1ddb8e346d..f4bb05d2eb 100644 --- a/libs/spandsp/tests/udptl.c +++ b/libs/spandsp/tests/udptl.c @@ -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++) diff --git a/libs/spandsp/tests/v8_tests.c b/libs/spandsp/tests/v8_tests.c index df9243691e..43338583ef 100644 --- a/libs/spandsp/tests/v8_tests.c +++ b/libs/spandsp/tests/v8_tests.c @@ -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; }