#define __ISO_C_VISIBLE 2011
#endif
#include <stdlib.h>
-#if defined(HAVE_MALLOC_H) && !defined(__OpenBSD__) && !defined(__DragonFly__)
+#if defined(HAVE_MALLOC_H) && !defined(__OpenBSD__) && !defined(__DragonFly__)
#include <malloc.h>
#endif
#include <inttypes.h>
/* 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')
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;
static const char *at_cmd_D(at_state_t *s, const char *t)
{
- int ok;
char *u;
char num[100 + 1];
char ch;
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;
}
}
*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. */
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))
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))
int limit;
uint8_t hit;
- hit = 0;
for (sample = 0; sample < samples; sample = limit)
{
/* The block length is optimised to meet the DTMF specs. */
coeff[1] = z;
z = coeff[0] >> 15;
- return saturate(z);
+ return saturate16(z);
}
/*- End of function --------------------------------------------------------*/
/* ... 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
#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;
}
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);
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);
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 --------------------------------------------------------*/
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:
t->transmit = false;
break;
}
+ /*endswitch*/
t->tx_bit_rate = bit_rate;
t->current_tx_type = type;
}
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;
{
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");
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;
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)
coeffs[h + i] = -x;
coeffs[h - i] = x;
}
+ else
+ {
+ coeffs[h + i] =
+ coeffs[h - i] = 0.0;
+ }
}
}
/*- End of function --------------------------------------------------------*/
{
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;
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
{
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 --------------------------------------------------------*/
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;
s->scaling_shift++;
chop >>= 1;
}
+ /*endwhile*/
/* Initialise the baud/bit rate tracking. */
s->baud_phase = 0;
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;
}
{
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;
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 --------------------------------------------------------*/
complexi_t ph;
buf_ptr = s->buf_ptr;
-
for (i = 0; i < len; i++)
{
/* The *totally* asynchronous character to character behaviour of these
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;
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)
{
s->baud_phase = 0;
continue;
}
+ /*endif*/
}
+ /*endif*/
}
else
{
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;
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
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
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 */
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
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:
s->frame_bits = 0;
s->last_bit = -1;
}
+ /*endif*/
}
else if (s->frame_state == -1)
{
s->frame_state = 1;
s->last_bit = baudstate;
}
+ /*endif*/
}
+ /*endif*/
}
else
{
{
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)
{
/* 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
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;
}
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 --------------------------------------------------------*/
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];
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 --------------------------------------------------------*/
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;
{
/* 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;
}
}
/* 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;
}
/* 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;
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;
/* 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;
*/
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' */
{
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;
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;
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;
s->LARc[0] = sr & 0x3F;
sr >>= 6;
s->LARc[1] = sr & 0x3F;
- sr >>= 6;
sr = *c++;
s->LARc[2] = sr & 0x1F;
sr >>= 5;
s->LARc[6] = sr & 0x7;
sr >>= 3;
s->LARc[7] = sr & 0x7;
- sr >>= 3;
for (i = 0; i < 4; i++)
{
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;
s->xMc[i][11] = sr & 0x7;
sr >>= 3;
s->xMc[i][12] = sr & 0x7;
- sr >>= 3;
}
return 65;
}
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;
int32_t sum;
sum = (int32_t) a + (int32_t) b;
- return saturate(sum);
+ return saturate16(sum);
#endif
}
/*- End of function --------------------------------------------------------*/
int32_t diff;
diff = (int32_t) a - (int32_t) b;
- return saturate(diff);
+ return saturate16(diff);
}
/*- End of function --------------------------------------------------------*/
for (k = 0; k < 40; k++)
{
temp = d[k];
- temp = saturated_abs16(temp);
+ temp = sat_abs16(temp);
if (temp > dmax)
dmax = temp;
/*endif*/
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*/
}
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*/
}
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*/
/* 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*/
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++)
/* 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*/
}
/* 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)
#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) \
? \
* 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);
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*/
/* 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);
* }
*/
/* 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
/* The signal x[0..39] is used to select the RPE grid which is
represented by Mc. */
-
EM = 0;
Mc = 0;
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]
for (i = 0; i < 13; i++)
{
temp = xM[i];
- temp = saturated_abs16(temp);
+ temp = sat_abs16(temp);
if (temp > xmax)
xmax = temp;
/*endif*/
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] */
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 */
}
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
};
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++)
{
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*/
#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);
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*/
}
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 --------------------------------------------------------*/
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*/
}
else if (temp < 20070)
temp += 11059;
else
- temp = saturated_add16(temp >> 2, 26112);
+ temp = sat_add16(temp >> 2, 26112);
/*endif*/
*LARpx = -temp;
}
else if (temp < 20070)
temp += 11059;
else
- temp = saturated_add16(temp >> 2, 26112);
+ temp = sat_add16(temp >> 2, 26112);
/*endif*/
*LARpx = temp;
}
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;
:
(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)
?
:
(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++ =
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)
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)
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;
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)
{
switch (image_format)
{
- default:
case T4_IMAGE_TYPE_BILEVEL:
case T4_IMAGE_TYPE_GRAY_8BIT:
return 1;
case T4_IMAGE_TYPE_4COLOUR_12BIT:
return 8;
}
+ return 1;
}
/*- End of function --------------------------------------------------------*/
/*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)
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;
}
/*- 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;
}
/*- 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;
*ratio = *rms/(s->rmso + 8.0f);
if (s->first_pitsyn)
{
- lsamp = 0;
ivoice = voice[1];
if (ivoice == 0)
*pitch = LPC10_SAMPLES_PER_FRAME/4;
{
vflag = 0;
lsamp = LPC10_SAMPLES_PER_FRAME + s->jsamp;
- slope = (*pitch - s->ipito)/(float) lsamp;
*nout = 0;
jused = 0;
istart = 1;
rci[i + (rci_dim1 << 1) + 1] = s->rco[i];
s->rco[i] = rc[i];
}
- slope = 0.0f;
*nout = 2;
s->ipito = *pitch;
jused = nl;
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) */
/* 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): */
/* 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)
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]));
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++)
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++)
/* 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);
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++)
{
#if defined(SPANDSP_USE_SSE5)
#include <bmmintrin.h>
#endif
+#if defined(SPANDSP_USE_AVX)
+#include <immintrin.h>
+#endif
+#if defined(SPANDSP_USE_AVX2)
+#include <x86intrin.h>
+#endif
#endif
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 --------------------------------------------------------*/
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*/
}
/*
- * SpanDSP a series of DSP components for telephony
+ * SpanDSP - a series of DSP components for telephony
*
* ademco_contactid.h Ademco ContactID alarm protocol
*
: [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;
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
};
/*!
{
#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.
*/
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);
/*! \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;
*/
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;
*/
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;
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. */
#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
{
#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__))
}
/*- 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*/
}
/*- 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;
}
/*- 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 --------------------------------------------------------*/
#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 */
#define ms_to_samples(t) ((t)*(SAMPLE_RATE/1000))
#define us_to_samples(t) ((t)/(1000000/SAMPLE_RATE))
-/* Fixed point constant macros */
-#define FP_Q_9_7(x) ((int16_t) (128.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_8_8(x) ((int16_t) (256.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_7_9(x) ((int16_t) (512.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_6_10(x) ((int16_t) (1024.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_5_11(x) ((int16_t) (2048.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_4_12(x) ((int16_t) (4096.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_3_13(x) ((int16_t) (8192.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_2_14(x) ((int16_t) (16384.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_1_15(x) ((int16_t) (32768.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-
-#define FP_Q_9_7_32(x) ((int32_t) (128.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_8_8_32(x) ((int32_t) (256.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_7_9_32(x) ((int32_t) (512.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_6_10_32(x) ((int32_t) (1024.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_5_11_32(x) ((int32_t) (2048.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_4_12_32(x) ((int32_t) (4096.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_3_13_32(x) ((int32_t) (8192.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_2_14_32(x) ((int32_t) (16384.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_1_15_32(x) ((int32_t) (32768.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+/* Fixed point constant macros for 16 bit values */
+#define FP_Q16_0(x) ((int16_t) (1.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q15_1(x) ((int16_t) (2.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q14_2(x) ((int16_t) (4.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q13_3(x) ((int16_t) (8.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q12_4(x) ((int16_t) (16.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q11_5(x) ((int16_t) (32.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q10_6(x) ((int16_t) (64.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q9_7(x) ((int16_t) (128.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q8_8(x) ((int16_t) (256.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q7_9(x) ((int16_t) (512.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q6_10(x) ((int16_t) (1024.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q5_11(x) ((int16_t) (2048.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q4_12(x) ((int16_t) (4096.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q3_13(x) ((int16_t) (8192.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q2_14(x) ((int16_t) (16384.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q1_15(x) ((int16_t) (32768.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_9_23(x) ((int32_t) (65536.0*128.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_8_24(x) ((int32_t) (65536.0*256.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_7_25(x) ((int32_t) (65536.0*512.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_6_26(x) ((int32_t) (65536.0*1024.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_5_27(x) ((int32_t) (65536.0*2048.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_4_28(x) ((int32_t) (65536.0*4096.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_3_29(x) ((int32_t) (65536.0*8192.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_2_30(x) ((int32_t) (65536.0*16384.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
-#define FP_Q_1_31(x) ((int32_t) (65536.0*32768.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+/* Fixed point constant macros for 32 bit values */
+#define FP_Q32_0(x) ((int32_t) (1.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q31_1(x) ((int32_t) (2.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q30_2(x) ((int32_t) (4.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q29_3(x) ((int32_t) (8.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q28_4(x) ((int32_t) (16.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q27_5(x) ((int32_t) (32.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q26_6(x) ((int32_t) (64.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q25_7(x) ((int32_t) (128.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q24_8(x) ((int32_t) (256.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q23_9(x) ((int32_t) (512.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q22_10(x) ((int32_t) (1024.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q21_11(x) ((int32_t) (2048.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q20_12(x) ((int32_t) (4096.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q19_13(x) ((int32_t) (8192.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q18_14(x) ((int32_t) (16384.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q17_15(x) ((int32_t) (32768.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q16_16(x) ((int32_t) (65536.0*1.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q15_17(x) ((int32_t) (65536.0*2.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q14_18(x) ((int32_t) (65536.0*4.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q13_19(x) ((int32_t) (65536.0*8.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q12_20(x) ((int32_t) (65536.0*16.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q11_21(x) ((int32_t) (65536.0*32.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q10_22(x) ((int32_t) (65536.0*64.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q9_23(x) ((int32_t) (65536.0*128.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q8_24(x) ((int32_t) (65536.0*256.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q7_25(x) ((int32_t) (65536.0*512.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q6_26(x) ((int32_t) (65536.0*1024.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q5_27(x) ((int32_t) (65536.0*2048.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q4_28(x) ((int32_t) (65536.0*4096.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q3_29(x) ((int32_t) (65536.0*8192.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q2_30(x) ((int32_t) (65536.0*16384.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
+#define FP_Q1_31(x) ((int32_t) (65536.0*32768.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
#if defined(__cplusplus)
/* C++ doesn't seem to have sane rounding functions/macros yet */
\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);
\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,
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
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)
{
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);
}
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':
/*endif*/
}
/*endif*/
- immediate_response = false;
span_log(&s->logging, SPAN_LOG_FLOW, "Silence %dms\n", val*10);
break;
case 'H':
/*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)
while (msg[0] == AT_RESPONSE_CODE_CONNECT);
}
/*endif*/
- immediate_response = false;
break;
default:
switch (val)
}
/*endif*/
restart_modem(s, new_modem);
- immediate_response = false;
break;
}
/*endswitch*/
- return immediate_response;
+ return false;
}
/*- End of function --------------------------------------------------------*/
/* 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)
}
else
{
- t30_field_type = (buf[ptr++] >> 3) & 0x7;
+ ptr++;
}
}
/* Decode field_data */
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;
}
/* 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 */
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)
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);
}
/*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);
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;
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;
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;
}
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)
/* 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)
/* 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
/*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*/
}
{
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;
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))
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
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)
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)
{
/* 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 */
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;
{
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)
{
}
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)
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);
}
}
/* 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++)
{
#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
#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)
/* 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);
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++)
/* 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);
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++)
/* 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);
{
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;
if (ss)
{
len = strlen(ss->dtmf);
- t += len;
*u++ = ss->ascii;
return len;
}
#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)
{
/* 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;
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;
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;
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);
#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"
#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
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:
/* 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);
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);
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);
#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;
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 --------------------------------------------------------*/
#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
#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
#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)
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 --------------------------------------------------------*/
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;
}
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++)
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 --------------------------------------------------------*/
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;
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:
{
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)
// 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);
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);
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. */
static void print_test_title(const char *title)
{
if (quiet == false)
- printf(title);
+ printf("%s", title);
}
/*- End of function --------------------------------------------------------*/
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,
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
# 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"
echo
echo All fax tests successfully completed
+
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
{
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
{
{
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)
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);
}
exit(2);
}
printf("Testing 16 bit add\n");
- if (saturated_add16(10000, 10000) != 20000)
- printf("aaa1 %d\n", saturated_add16(10000, 10000));
- if (saturated_add16(10000, -10000) != 0)
- printf("aaa2 %d\n", saturated_add16(10000, -10000));
- if (saturated_add16(-10000, 10000) != 0)
- printf("aaa3 %d\n", saturated_add16(-10000, 10000));
- if (saturated_add16(-10000, -10000) != -20000)
- printf("aaa4 %d\n", saturated_add16(-10000, -10000));
- if (saturated_add16(-30000, -30000) != INT16_MIN)
- printf("aaa5 %d\n", saturated_add16(-30000, -30000));
- if (saturated_add16(30000, 30000) != INT16_MAX)
+ if (sat_add16(10000, 10000) != 20000
+ ||
+ sat_add16(10000, -10000) != 0
+ ||
+ sat_add16(-10000, 10000) != 0
+ ||
+ sat_add16(-10000, -10000) != -20000
+ ||
+ sat_add16(-30000, -30000) != INT16_MIN
+ ||
+ sat_add16(30000, 30000) != INT16_MAX
+ ||
+ sat_add16(-32768, -32768) != INT16_MIN
+ ||
+ sat_add16(32767, 32767) != INT16_MAX)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 32 bit add\n");
- if (saturated_add32(10000, 10000) != 20000
+ if (sat_add32(10000, 10000) != 20000
||
- saturated_add32(10000, -10000) != 0
+ sat_add32(10000, -10000) != 0
||
- saturated_add32(-10000, 10000) != 0
+ sat_add32(-10000, 10000) != 0
||
- saturated_add32(-10000, -10000) != -20000
+ sat_add32(-10000, -10000) != -20000
||
- saturated_add32(-2000000000, -2000000000) != INT32_MIN
+ sat_add32(-2000000000, -2000000000) != INT32_MIN
||
- saturated_add32(2000000000, 2000000000) != INT32_MAX)
+ sat_add32(2000000000, 2000000000) != INT32_MAX)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 16 bit subtract\n");
- if (saturated_sub16(10000, 10000) != 0
+ if (sat_sub16(10000, 10000) != 0
+ ||
+ sat_sub16(10000, -10000) != 20000
+ ||
+ sat_sub16(-10000, 10000) != -20000
||
- saturated_sub16(10000, -10000) != 20000
+ sat_sub16(-10000, -10000) != 0
||
- saturated_sub16(-10000, 10000) != -20000
+ sat_sub16(-30000, 30000) != INT16_MIN
||
- saturated_sub16(-10000, -10000) != 0
+ sat_sub16(30000, -30000) != INT16_MAX
||
- saturated_sub16(-30000, 30000) != INT16_MIN
+ sat_sub16(-32768, 32767) != INT16_MIN
||
- saturated_sub16(30000, -30000) != INT16_MAX)
+ sat_sub16(32767, -32768) != INT16_MAX)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 32 bit subtract\n");
- if (saturated_sub32(10000, 10000) != 0
+ if (sat_sub32(10000, 10000) != 0
||
- saturated_sub32(10000, -10000) != 20000
+ sat_sub32(10000, -10000) != 20000
||
- saturated_sub32(-10000, 10000) != -20000
+ sat_sub32(-10000, 10000) != -20000
||
- saturated_sub32(-10000, -10000) != 0
+ sat_sub32(-10000, -10000) != 0
||
- saturated_sub32(-2000000000, 2000000000) != INT32_MIN
+ sat_sub32(-2000000000, 2000000000) != INT32_MIN
||
- saturated_sub32(2000000000, -2000000000) != INT32_MAX)
+ sat_sub32(2000000000, -2000000000) != INT32_MAX)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 16 x 16 => 16 bit multiply\n");
- if (saturated_mul16(100, 100) != 0
+ if (sat_mul16(100, 100) != 0
||
- saturated_mul16(255, 255) != 1
+ sat_mul16(255, 255) != 1
||
- saturated_mul16(32767, -32768) != -32767
+ sat_mul16(32767, -32768) != -32767
||
- saturated_mul16(-32768, 32767) != -32767
+ sat_mul16(-32768, 32767) != -32767
||
- saturated_mul16(32767, 32767) != 32766
+ sat_mul16(32767, 32767) != 32766
||
- saturated_mul16(-32768, -32768) != 32767)
+ sat_mul16(-32768, -32768) != 32767)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 16 x 16 => 32 bit multiply\n");
- if (saturated_mul16_32(100, 100) != 20000
+ if (sat_mul32_16(100, 100) != 20000
||
- saturated_mul16_32(-100, 100) != -20000
+ sat_mul32_16(-100, 100) != -20000
||
- saturated_mul16_32(32767, -32768) != -2147418112
+ sat_mul32_16(32767, -32768) != -2147418112
||
- saturated_mul16_32(-32768, 32767) != -2147418112
+ sat_mul32_16(-32768, 32767) != -2147418112
||
- saturated_mul16_32(32767, 32767) != 2147352578
+ sat_mul32_16(32767, 32767) != 2147352578
||
- saturated_mul16_32(-32768, -32768) != INT32_MAX)
+ sat_mul32_16(-32768, -32768) != INT32_MAX)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 32 + 16 x 16 => 32 bit MAC\n");
- if (saturated_mac16_32(123, 100, 100) != 123 + 20000
+ if (sat_mac32_16(123, 100, 100) != 123 + 20000
||
- saturated_mac16_32(123, -100, 100) != 123 - 20000
+ sat_mac32_16(123, -100, 100) != 123 - 20000
||
- saturated_mac16_32(123, 32767, -32768) != 123 - 2147418112
+ sat_mac32_16(123, 32767, -32768) != 123 - 2147418112
||
- saturated_mac16_32(123, -32768, 32767) != 123 - 2147418112
+ sat_mac32_16(123, -32768, 32767) != 123 - 2147418112
||
- saturated_mac16_32(123, 32767, 32767) != 123 + 2147352578
+ sat_mac32_16(123, 32767, 32767) != 123 + 2147352578
||
- saturated_mac16_32(123, -32768, -32768) != INT32_MAX)
+ sat_mac32_16(123, -32768, -32768) != INT32_MAX)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 32 - 16 x 16 => 32 bit MSU\n");
- if (saturated_msu16_32(123, 100, 100) != 123 - 20000
+ if (sat_msu32_16(123, 100, 100) != 123 - 20000
||
- saturated_msu16_32(123, -100, 100) != 123 + 20000
+ sat_msu32_16(123, -100, 100) != 123 + 20000
||
- saturated_msu16_32(123, 32767, -32768) != 123 + 2147418112
+ sat_msu32_16(123, 32767, -32768) != 123 + 2147418112
||
- saturated_msu16_32(123, -32768, 32767) != 123 + 2147418112
+ sat_msu32_16(123, -32768, 32767) != 123 + 2147418112
||
- saturated_msu16_32(123, 32767, 32767) != 123 - 2147352578
+ sat_msu32_16(123, 32767, 32767) != 123 - 2147352578
||
- saturated_msu16_32(123, -32768, -32768) != 123 - INT32_MAX)
+ sat_msu32_16(123, -32768, -32768) != 123 - INT32_MAX)
{
printf("Test failed.\n");
exit(2);
}
printf("Testing 16 bit absolute\n");
- if (saturated_abs16(10000) != 10000
+ if (sat_abs16(10000) != 10000
||
- saturated_abs16(-10000) != 10000
+ sat_abs16(-10000) != 10000
||
- saturated_abs16(32767) != 32767
+ sat_abs16(32767) != 32767
||
- saturated_abs16(-32768) != 32767)
+ sat_abs16(-32768) != 32767)
{
printf("Test failed.\n");
exit(2);
#include "config.h"
#endif
+#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
{
/* 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);
printf("Failed to convert to ITULAB\n");
return 1;
}
+#else
+ outptr = 0;
#endif
free(data);
data = (uint8_t *) outptr;
printf("Failed to convert to ITULAB (C).\n");
return 1;
}
+#else
+ outsize = 0;
#endif
free(data);
data = (uint8_t *) outptr;
/* 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;
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++)
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;
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");
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;
}
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;
}