mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-12 04:27:06 +00:00
Fixed a typo in spandsp's msvc/inttypes.h
Updated sig_tone processing in spandsp to the latest, to allow moy to proceed with his signaling work.
This commit is contained in:
1 parent
1d0ce5570d
commit
3e30434a0c
4 files changed
+698
-567
No files matched your search
+279
-346
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* SpanDSP - a series of DSP components for telephony
|
||||
*
|
||||
* sig_tone.c - Signalling tone processing for the 2280Hz, 2600Hz and similar
|
||||
* signalling tone used in older protocols.
|
||||
* sig_tone.c - Signalling tone processing for the 2280Hz, 2400Hz, 2600Hz
|
||||
* and similar signalling tones used in older protocols.
|
||||
*
|
||||
* Written by Steve Underwood <steveu@coppice.org>
|
||||
*
|
||||
@@ -23,7 +23,7 @@
|
||||
* License along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* $Id: sig_tone.c,v 1.33 2009/09/04 14:38:46 steveu Exp $
|
||||
* $Id: sig_tone.c,v 1.39 2010/03/11 14:22:30 steveu Exp $
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
@@ -53,6 +53,7 @@
|
||||
#include "spandsp/saturated.h"
|
||||
#include "spandsp/vector_int.h"
|
||||
#include "spandsp/complex.h"
|
||||
#include "spandsp/power_meter.h"
|
||||
#include "spandsp/dds.h"
|
||||
#include "spandsp/super_tone_rx.h"
|
||||
#include "spandsp/sig_tone.h"
|
||||
@@ -62,56 +63,64 @@
|
||||
/*! PI */
|
||||
#define PI 3.14159265358979323
|
||||
|
||||
/* The coefficients for the data notch filter. This filter is also the
|
||||
guard filter for tone detection. */
|
||||
enum
|
||||
{
|
||||
NOTCH_COEFF_SET_2280HZ = 0,
|
||||
NOTCH_COEFF_SET_2400HZ,
|
||||
NOTCH_COEFF_SET_2600HZ
|
||||
};
|
||||
|
||||
sig_tone_descriptor_t sig_tones[4] =
|
||||
/* The coefficients for the data notch filters. These filters are also the
|
||||
guard filters for tone detection. */
|
||||
static const sig_tone_notch_coeffs_t notch_coeffs[3] =
|
||||
{
|
||||
{ /* 2280 Hz */
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
{ 3600, 14397, 32767},
|
||||
{ 0, -9425, -28954},
|
||||
{ 0, 14196, 32767},
|
||||
{ 0, -17393, -28954},
|
||||
12,
|
||||
#else
|
||||
{0.878906f, 0.439362f, 1.0f},
|
||||
{0.0f, -0.287627f, -0.883605f},
|
||||
{0.0f, 0.433228f, 1.0f},
|
||||
{0.0f, -0.530792f, -0.883605f},
|
||||
#endif
|
||||
},
|
||||
{ /* 2400Hz */
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
{ 3530, 20055, 32767},
|
||||
{ 0, -14950, -28341},
|
||||
{ 0, 20349, 32767},
|
||||
{ 0, -22633, -28341},
|
||||
12,
|
||||
#else
|
||||
{0.862000f, 0.612055f, 1.0f},
|
||||
{0.0f, -0.456264f, -0.864899f},
|
||||
{0.0f, 0.621021f, 1.0f},
|
||||
{0.0f, -0.690738f, -0.864899f},
|
||||
#endif
|
||||
},
|
||||
{ /* 2600Hz */
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
{ 3530, 29569, 32767},
|
||||
{ 0, -24010, -28341},
|
||||
{ 0, 29844, 32767},
|
||||
{ 0, -31208, -28341},
|
||||
12,
|
||||
#else
|
||||
{0.862000f, 0.902374f, 1.0f},
|
||||
{0.0f, -0.732727f, -0.864899f},
|
||||
{0.0f, 0.910766f, 1.0f},
|
||||
{0.0f, -0.952393f, -0.864899f},
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
static const sig_tone_flat_coeffs_t flat_coeffs[1] =
|
||||
{
|
||||
{
|
||||
/* 2280Hz (e.g. AC15, and many other European protocols) */
|
||||
{2280, 0},
|
||||
{{-10, -20}, {0, 0}}, /* -10+-1 dBmO and -20+-1 dBm0 */
|
||||
ms_to_samples(400), /* 300ms to 550ms */
|
||||
|
||||
ms_to_samples(225),
|
||||
|
||||
ms_to_samples(225),
|
||||
TRUE,
|
||||
|
||||
24,
|
||||
64,
|
||||
|
||||
1,
|
||||
{
|
||||
{
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
{ 3600, 14397, 32767},
|
||||
{ 0, -9425, -28954},
|
||||
{ 0, 14196, 32767},
|
||||
{ 0, -17393, -28954},
|
||||
12,
|
||||
#else
|
||||
{0.878906f, 0.439362f, 1.0f},
|
||||
{0.0f, -0.287627f, -0.883605f},
|
||||
{0.0f, 0.433228f, 1.0f},
|
||||
{0.0f, -0.530792f, -0.883605f},
|
||||
#endif
|
||||
},
|
||||
{
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
{ 0, 0, 0},
|
||||
{ 0, 0, 0},
|
||||
{ 0, 0, 0},
|
||||
{ 0, 0, 0},
|
||||
0,
|
||||
#else
|
||||
{0.0f, 0.0f, 0.0f},
|
||||
{0.0f, 0.0f, 0.0f},
|
||||
{0.0f, 0.0f, 0.0f},
|
||||
{0.0f, 0.0f, 0.0f},
|
||||
#endif
|
||||
}
|
||||
},
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
{ 12900, -16384, -16384},
|
||||
{ 0, -8578, -11796},
|
||||
@@ -120,163 +129,96 @@ sig_tone_descriptor_t sig_tones[4] =
|
||||
{0.393676f, -0.5f, -0.5f},
|
||||
{0.0f, -0.261778f, -0.359985f},
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
31744,
|
||||
1024,
|
||||
static const sig_tone_descriptor_t sig_tones[3] =
|
||||
{
|
||||
{
|
||||
/* 2280Hz (e.g. AC15, and many other European protocols) */
|
||||
{2280, 0},
|
||||
{{-10, -20}, {0, 0}}, /* -10+-1 dBm0 and -20+-1 dBm0 */
|
||||
ms_to_samples(400), /* High to low timout - 300ms to 550ms */
|
||||
ms_to_samples(225), /* Sharp to flat timeout */
|
||||
ms_to_samples(225), /* Notch insertion timeout */
|
||||
|
||||
31744,
|
||||
187,
|
||||
|
||||
31744,
|
||||
187,
|
||||
|
||||
-1,
|
||||
-32,
|
||||
|
||||
57
|
||||
ms_to_samples(3), /* Tone on persistence check */
|
||||
ms_to_samples(8), /* Tone off persistence check */
|
||||
|
||||
1,
|
||||
{
|
||||
¬ch_coeffs[NOTCH_COEFF_SET_2280HZ],
|
||||
NULL,
|
||||
},
|
||||
&flat_coeffs[NOTCH_COEFF_SET_2280HZ],
|
||||
|
||||
13.0f,
|
||||
-30.0f,
|
||||
-30.0f
|
||||
},
|
||||
{
|
||||
/* 2600Hz (e.g. many US protocols) */
|
||||
{2600, 0},
|
||||
{{-8, -8}, {0, 0}},
|
||||
ms_to_samples(400),
|
||||
|
||||
ms_to_samples(0),
|
||||
ms_to_samples(0),
|
||||
ms_to_samples(225),
|
||||
|
||||
ms_to_samples(225),
|
||||
FALSE,
|
||||
|
||||
24,
|
||||
64,
|
||||
ms_to_samples(3),
|
||||
ms_to_samples(8),
|
||||
|
||||
1,
|
||||
{
|
||||
{
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
{ 3539, 29569, 32767},
|
||||
{ 0, -24010, -28341},
|
||||
{ 0, 29844, 32767},
|
||||
{ 0, -31208, -28341},
|
||||
12,
|
||||
#else
|
||||
{0.864014f, 0.902374f, 1.0f},
|
||||
{0.0f, -0.732727f, -0.864899f},
|
||||
{0.0f, 0.910766f, 1.0f},
|
||||
{0.0f, -0.952393f, -0.864899f},
|
||||
#endif
|
||||
},
|
||||
{
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
{ 0, 0, 0},
|
||||
{ 0, 0, 0},
|
||||
{ 0, 0, 0},
|
||||
{ 0, 0, 0},
|
||||
0,
|
||||
#else
|
||||
{0.0f, 0.0f, 0.0f},
|
||||
{0.0f, 0.0f, 0.0f},
|
||||
{0.0f, 0.0f, 0.0f},
|
||||
{0.0f, 0.0f, 0.0f},
|
||||
#endif
|
||||
}
|
||||
¬ch_coeffs[NOTCH_COEFF_SET_2600HZ],
|
||||
NULL,
|
||||
},
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
{ 32768, 0, 0},
|
||||
{ 0, 0, 0},
|
||||
15,
|
||||
#else
|
||||
{1.0f, 0.0f, 0.0f},
|
||||
{0.0f, 0.0f, 0.0f},
|
||||
#endif
|
||||
NULL,
|
||||
|
||||
31744,
|
||||
1024,
|
||||
|
||||
31744,
|
||||
170,
|
||||
|
||||
31744,
|
||||
170,
|
||||
|
||||
-1,
|
||||
-32,
|
||||
|
||||
52
|
||||
15.6f,
|
||||
-30.0f,
|
||||
-30.0f
|
||||
},
|
||||
{
|
||||
/* 2400Hz/2600Hz (e.g. SS5 and SS5bis) */
|
||||
{2600, 2400},
|
||||
{2400, 2600},
|
||||
{{-8, -8}, {-8, -8}},
|
||||
ms_to_samples(400),
|
||||
|
||||
ms_to_samples(0),
|
||||
ms_to_samples(0),
|
||||
ms_to_samples(225),
|
||||
|
||||
ms_to_samples(225),
|
||||
FALSE,
|
||||
|
||||
24,
|
||||
64,
|
||||
ms_to_samples(3),
|
||||
ms_to_samples(8),
|
||||
|
||||
2,
|
||||
{
|
||||
{
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
{ 3539, 29569, 32767},
|
||||
{ 0, -24010, -28341},
|
||||
{ 0, 29844, 32767},
|
||||
{ 0, -31208, -28341},
|
||||
12,
|
||||
#else
|
||||
{0.864014f, 0.902374f, 1.0f},
|
||||
{0.0f, -0.732727f, -0.864899f},
|
||||
{0.0f, 0.910766f, 1.0f},
|
||||
{0.0f, -0.952393f, -0.864899f},
|
||||
#endif
|
||||
},
|
||||
{
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
{ 3539, 20349, 32767},
|
||||
{ 0, -22075, -31856},
|
||||
{ 0, 20174, 32767},
|
||||
{ 0, -17832, -31836},
|
||||
12,
|
||||
#else
|
||||
{0.864014f, 0.621007f, 1.0f},
|
||||
{0.0f, -0.673667f, -0.972167f},
|
||||
{0.0f, 0.615669f, 1.0f},
|
||||
{0.0f, -0.544180f, -0.971546f},
|
||||
#endif
|
||||
}
|
||||
¬ch_coeffs[NOTCH_COEFF_SET_2400HZ],
|
||||
¬ch_coeffs[NOTCH_COEFF_SET_2600HZ]
|
||||
},
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
{ 32768, 0, 0},
|
||||
{ 0, 0, 0},
|
||||
15,
|
||||
#else
|
||||
{1.0f, 0.0f, 0.0f},
|
||||
{0.0f, 0.0f, 0.0f},
|
||||
#endif
|
||||
NULL,
|
||||
|
||||
31744,
|
||||
1024,
|
||||
|
||||
31744,
|
||||
170,
|
||||
|
||||
31744,
|
||||
170,
|
||||
|
||||
-1,
|
||||
-32,
|
||||
|
||||
52
|
||||
15.6f,
|
||||
-30.0f,
|
||||
-30.0f
|
||||
}
|
||||
};
|
||||
|
||||
static const int tone_present_bits[2] =
|
||||
{
|
||||
SIG_TONE_1_PRESENT,
|
||||
SIG_TONE_2_PRESENT
|
||||
};
|
||||
|
||||
static const int tone_change_bits[2] =
|
||||
{
|
||||
SIG_TONE_1_CHANGE,
|
||||
SIG_TONE_2_CHANGE
|
||||
};
|
||||
|
||||
SPAN_DECLARE(int) sig_tone_tx(sig_tone_tx_state_t *s, int16_t amp[], int len)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
int n;
|
||||
int16_t tone;
|
||||
int need_update;
|
||||
@@ -306,7 +248,7 @@ SPAN_DECLARE(int) sig_tone_tx(sig_tone_tx_state_t *s, int16_t amp[], int len)
|
||||
if (!(s->current_tx_tone & SIG_TONE_TX_PASSTHROUGH))
|
||||
vec_zeroi16(&[i], n);
|
||||
/*endif*/
|
||||
if ((s->current_tx_tone & (SIG_TONE_1_PRESENT || SIG_TONE_2_PRESENT)))
|
||||
if ((s->current_tx_tone & (SIG_TONE_1_PRESENT | SIG_TONE_2_PRESENT)))
|
||||
{
|
||||
/* Are we in the early phase (high tone energy level), or the sustaining
|
||||
phase (low tone energy level) of tone generation? */
|
||||
@@ -325,26 +267,19 @@ SPAN_DECLARE(int) sig_tone_tx(sig_tone_tx_state_t *s, int16_t amp[], int len)
|
||||
high_low = 1;
|
||||
}
|
||||
/*endif*/
|
||||
if ((s->current_tx_tone & SIG_TONE_1_PRESENT) && s->phase_rate[0])
|
||||
for (k = 0; k < s->desc->tones; k++)
|
||||
{
|
||||
for (j = i; j < i + n; j++)
|
||||
if ((s->current_tx_tone & tone_present_bits[k]) && s->phase_rate[k])
|
||||
{
|
||||
tone = dds_mod(&(s->phase_acc[0]), s->phase_rate[0], s->tone_scaling[0][high_low], 0);
|
||||
amp[j] = saturate(amp[j] + tone);
|
||||
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] = saturate(amp[j] + tone);
|
||||
}
|
||||
/*endfor*/
|
||||
}
|
||||
/*endfor*/
|
||||
/*endif*/
|
||||
}
|
||||
/*endif*/
|
||||
if ((s->current_tx_tone & SIG_TONE_2_PRESENT) && s->phase_rate[1])
|
||||
{
|
||||
for (j = i; j < i + n; j++)
|
||||
{
|
||||
tone = dds_mod(&(s->phase_acc[1]), s->phase_rate[1], s->tone_scaling[1][high_low], 0);
|
||||
amp[j] = saturate(amp[j] + tone);
|
||||
}
|
||||
/*endfor*/
|
||||
}
|
||||
/*endif*/
|
||||
}
|
||||
/*endif*/
|
||||
if (need_update && s->sig_update)
|
||||
@@ -421,82 +356,74 @@ SPAN_DECLARE(int) sig_tone_tx_free(sig_tone_tx_state_t *s)
|
||||
SPAN_DECLARE(int) sig_tone_rx(sig_tone_rx_state_t *s, int16_t amp[], int len)
|
||||
{
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
int32_t x;
|
||||
int32_t notched_signal;
|
||||
int32_t bandpass_signal;
|
||||
int16_t x;
|
||||
int32_t v;
|
||||
int16_t notched_signal[2];
|
||||
int16_t bandpass_signal;
|
||||
#else
|
||||
float x;
|
||||
float notched_signal;
|
||||
float v;
|
||||
float notched_signal[2];
|
||||
float bandpass_signal;
|
||||
#endif
|
||||
int i;
|
||||
int j;
|
||||
int32_t mown_notch[2];
|
||||
int32_t mown_bandpass;
|
||||
int32_t notch_power[2];
|
||||
int32_t flat_power;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (s->signaling_state_duration < INT_MAX)
|
||||
s->signaling_state_duration++;
|
||||
if (s->signalling_state_duration < INT_MAX)
|
||||
s->signalling_state_duration++;
|
||||
/*endif*/
|
||||
notched_signal = 0;
|
||||
for (j = 0; j < s->desc->tones; j++)
|
||||
{
|
||||
/* The notch filter is two cascaded biquads. */
|
||||
notched_signal = amp[i];
|
||||
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
notched_signal *= s->desc->tone[j].notch_a1[0];
|
||||
notched_signal += s->tone[j].notch_z1[1]*s->desc->tone[j].notch_b1[1];
|
||||
notched_signal += s->tone[j].notch_z1[2]*s->desc->tone[j].notch_b1[2];
|
||||
x = notched_signal;
|
||||
notched_signal += s->tone[j].notch_z1[1]*s->desc->tone[j].notch_a1[1];
|
||||
notched_signal += s->tone[j].notch_z1[2]*s->desc->tone[j].notch_a1[2];
|
||||
s->tone[j].notch_z1[2] = s->tone[j].notch_z1[1];
|
||||
s->tone[j].notch_z1[1] = x >> 15;
|
||||
|
||||
notched_signal += s->tone[j].notch_z2[1]*s->desc->tone[j].notch_b2[1];
|
||||
notched_signal += s->tone[j].notch_z2[2]*s->desc->tone[j].notch_b2[2];
|
||||
x = notched_signal;
|
||||
notched_signal += s->tone[j].notch_z2[1]*s->desc->tone[j].notch_a2[1];
|
||||
notched_signal += s->tone[j].notch_z2[2]*s->desc->tone[j].notch_a2[2];
|
||||
s->tone[j].notch_z2[2] = s->tone[j].notch_z2[1];
|
||||
s->tone[j].notch_z2[1] = x >> 15;
|
||||
|
||||
notched_signal >>= s->desc->notch_postscale;
|
||||
v = ((int32_t) amp[i]*s->desc->notch[j]->a1[0])
|
||||
+ ((int32_t) s->tone[j].notch_z1[0]*s->desc->notch[j]->b1[1])
|
||||
+ ((int32_t) s->tone[j].notch_z1[1]*s->desc->notch[j]->b1[2]);
|
||||
x = v >> 15;
|
||||
v += ((int32_t) s->tone[j].notch_z1[0]*s->desc->notch[j]->a1[1])
|
||||
+ ((int32_t) s->tone[j].notch_z1[1]*s->desc->notch[j]->a1[2]);
|
||||
s->tone[j].notch_z1[1] = s->tone[j].notch_z1[0];
|
||||
s->tone[j].notch_z1[0] = x;
|
||||
v += ((int32_t) s->tone[j].notch_z2[0]*s->desc->notch[j]->b2[1])
|
||||
+ ((int32_t) s->tone[j].notch_z2[1]*s->desc->notch[j]->b2[2]);
|
||||
x = v >> 15;
|
||||
v += ((int32_t) s->tone[j].notch_z2[0]*s->desc->notch[j]->a2[1])
|
||||
+ ((int32_t) s->tone[j].notch_z2[1]*s->desc->notch[j]->a2[2]);
|
||||
s->tone[j].notch_z2[1] = s->tone[j].notch_z2[0];
|
||||
s->tone[j].notch_z2[0] = x;
|
||||
notched_signal[j] = v >> s->desc->notch[j]->postscale;
|
||||
#else
|
||||
notched_signal *= s->desc->tone[j].notch_a1[0];
|
||||
notched_signal += s->tone[j].notch_z1[1]*s->desc->tone[j].notch_b1[1];
|
||||
notched_signal += s->tone[j].notch_z1[2]*s->desc->tone[j].notch_b1[2];
|
||||
x = notched_signal;
|
||||
notched_signal += s->tone[j].notch_z1[1]*s->desc->tone[j].notch_a1[1];
|
||||
notched_signal += s->tone[j].notch_z1[2]*s->desc->tone[j].notch_a1[2];
|
||||
s->tone[j].notch_z1[2] = s->tone[j].notch_z1[1];
|
||||
s->tone[j].notch_z1[1] = x;
|
||||
|
||||
notched_signal += s->tone[j].notch_z2[1]*s->desc->tone[j].notch_b2[1];
|
||||
notched_signal += s->tone[j].notch_z2[2]*s->desc->tone[j].notch_b2[2];
|
||||
x = notched_signal;
|
||||
notched_signal += s->tone[j].notch_z2[1]*s->desc->tone[j].notch_a2[1];
|
||||
notched_signal += s->tone[j].notch_z2[2]*s->desc->tone[j].notch_a2[2];
|
||||
s->tone[j].notch_z2[2] = s->tone[j].notch_z2[1];
|
||||
s->tone[j].notch_z2[1] = x;
|
||||
v = amp[i]*s->desc->notch[j]->a1[0]
|
||||
+ s->tone[j].notch_z1[0]*s->desc->notch[j]->b1[1]
|
||||
+ s->tone[j].notch_z1[1]*s->desc->notch[j]->b1[2];
|
||||
x = v;
|
||||
v += s->tone[j].notch_z1[0]*s->desc->notch[j]->a1[1]
|
||||
+ s->tone[j].notch_z1[1]*s->desc->notch[j]->a1[2];
|
||||
s->tone[j].notch_z1[1] = s->tone[j].notch_z1[0];
|
||||
s->tone[j].notch_z1[0] = x;
|
||||
v += s->tone[j].notch_z2[0]*s->desc->notch[j]->b2[1]
|
||||
+ s->tone[j].notch_z2[1]*s->desc->notch[j]->b2[2];
|
||||
x = v;
|
||||
v += s->tone[j].notch_z2[0]*s->desc->notch[j]->a2[1]
|
||||
+ s->tone[j].notch_z2[1]*s->desc->notch[j]->a2[2];
|
||||
s->tone[j].notch_z2[1] = s->tone[j].notch_z2[0];
|
||||
s->tone[j].notch_z2[0] = x;
|
||||
notched_signal[j] = v;
|
||||
#endif
|
||||
/* Modulus and leaky integrate the notched data. The result of
|
||||
this isn't used in low tone detect mode, but we must keep notch_zl
|
||||
rolling along. */
|
||||
s->tone[j].notch_zl = ((s->tone[j].notch_zl*s->desc->notch_slugi) >> 15)
|
||||
+ ((abs((int) notched_signal)*s->desc->notch_slugp) >> 15);
|
||||
/* Mow the grass to weed out the noise! */
|
||||
mown_notch[j] = s->tone[0].notch_zl & s->desc->notch_threshold;
|
||||
this isn't used in low tone detect mode, but we must keep the
|
||||
power measurement rolling along. */
|
||||
notch_power[j] = power_meter_update(&s->tone[j].power, notched_signal[j]);
|
||||
}
|
||||
|
||||
if (s->tone_present)
|
||||
if (s->tone[0].tone_present || s->tone[1].tone_present)
|
||||
{
|
||||
if (s->flat_mode_timeout <= 0)
|
||||
if (s->flat_mode_timeout && --s->flat_mode_timeout == 0)
|
||||
s->flat_mode = TRUE;
|
||||
else
|
||||
s->flat_mode_timeout--;
|
||||
/*endif*/
|
||||
}
|
||||
else
|
||||
@@ -509,55 +436,51 @@ SPAN_DECLARE(int) sig_tone_rx(sig_tone_rx_state_t *s, int16_t amp[], int len)
|
||||
if (s->flat_mode)
|
||||
{
|
||||
/* Flat mode */
|
||||
|
||||
/* The bandpass filter is a single bi-quad stage */
|
||||
bandpass_signal = amp[i];
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
bandpass_signal *= s->desc->broad_a[0];
|
||||
bandpass_signal += s->broad_z[1]*s->desc->broad_b[1];
|
||||
bandpass_signal += s->broad_z[2]*s->desc->broad_b[2];
|
||||
x = bandpass_signal;
|
||||
bandpass_signal += s->broad_z[1]*s->desc->broad_a[1];
|
||||
bandpass_signal += s->broad_z[2]*s->desc->broad_a[2];
|
||||
s->broad_z[2] = s->broad_z[1];
|
||||
s->broad_z[1] = x >> 15;
|
||||
bandpass_signal >>= s->desc->broad_postscale;
|
||||
#else
|
||||
bandpass_signal *= s->desc->broad_a[0];
|
||||
bandpass_signal += s->broad_z[1]*s->desc->broad_b[1];
|
||||
bandpass_signal += s->broad_z[2]*s->desc->broad_b[2];
|
||||
x = bandpass_signal;
|
||||
bandpass_signal += s->broad_z[1]*s->desc->broad_a[1];
|
||||
bandpass_signal += s->broad_z[2]*s->desc->broad_a[2];
|
||||
s->broad_z[2] = s->broad_z[1];
|
||||
s->broad_z[1] = x;
|
||||
#endif
|
||||
/* Leaky integrate the bandpassed data */
|
||||
s->broad_zl = ((s->broad_zl*s->desc->broad_slugi) >> 15)
|
||||
+ ((abs((int) bandpass_signal)*s->desc->broad_slugp) >> 15);
|
||||
|
||||
/* For the broad band receiver we use a simple linear threshold! */
|
||||
if (s->tone_present)
|
||||
if (s->desc->flat)
|
||||
{
|
||||
s->tone_present = (s->broad_zl > s->desc->broad_threshold);
|
||||
if (!s->tone_present)
|
||||
/* The bandpass filter is a single bi-quad stage */
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
v = ((int32_t) amp[i]*s->desc->flat->a[0])
|
||||
+ ((int32_t) s->flat_z[0]*s->desc->flat->b[1])
|
||||
+ ((int32_t) s->flat_z[1]*s->desc->flat->b[2]);
|
||||
x = v >> 15;
|
||||
v += ((int32_t) s->flat_z[0]*s->desc->flat->a[1])
|
||||
+ ((int32_t) s->flat_z[1]*s->desc->flat->a[2]);
|
||||
s->flat_z[1] = s->flat_z[0];
|
||||
s->flat_z[0] = x;
|
||||
bandpass_signal = v >> s->desc->flat->postscale;
|
||||
#else
|
||||
v = amp[i]*s->desc->flat->a[0]
|
||||
+ s->flat_z[0]*s->desc->flat->b[1]
|
||||
+ s->flat_z[1]*s->desc->flat->b[2];
|
||||
x = v;
|
||||
v += s->flat_z[0]*s->desc->flat->a[1]
|
||||
+ s->flat_z[1]*s->desc->flat->a[2];
|
||||
s->flat_z[1] = s->flat_z[0];
|
||||
s->flat_z[0] = x;
|
||||
bandpass_signal = v;
|
||||
#endif
|
||||
}
|
||||
flat_power = power_meter_update(&s->flat_power, bandpass_signal);
|
||||
|
||||
/* For the flat receiver we use a simple power threshold! */
|
||||
if (s->tone[0].tone_present)
|
||||
{
|
||||
s->tone[0].tone_present = (flat_power > s->flat_detection_threshold);
|
||||
if (!s->tone[0].tone_present)
|
||||
{
|
||||
if (s->sig_update)
|
||||
s->sig_update(s->user_data, SIG_TONE_1_CHANGE, 0, s->signaling_state_duration);
|
||||
/*endif*/
|
||||
s->signaling_state_duration = 0;
|
||||
s->signalling_state &= ~tone_present_bits[0];
|
||||
s->signalling_state |= tone_change_bits[0];
|
||||
}
|
||||
/*endif*/
|
||||
}
|
||||
else
|
||||
{
|
||||
s->tone_present = (s->broad_zl > s->desc->broad_threshold);
|
||||
if (s->tone_present)
|
||||
s->tone[0].tone_present = (flat_power > s->flat_detection_threshold);
|
||||
if (s->tone[0].tone_present)
|
||||
{
|
||||
if (s->sig_update)
|
||||
s->sig_update(s->user_data, SIG_TONE_1_CHANGE | SIG_TONE_1_PRESENT, 0, s->signaling_state_duration);
|
||||
/*endif*/
|
||||
s->signaling_state_duration = 0;
|
||||
s->signalling_state |= (tone_present_bits[0] | tone_change_bits[0]);
|
||||
}
|
||||
/*endif*/
|
||||
}
|
||||
@@ -565,17 +488,14 @@ SPAN_DECLARE(int) sig_tone_rx(sig_tone_rx_state_t *s, int16_t amp[], int len)
|
||||
|
||||
/* Notch insertion logic */
|
||||
/* tone_present and tone_on are equivalent in flat mode */
|
||||
if (s->tone_present)
|
||||
if (s->tone[0].tone_present)
|
||||
{
|
||||
s->notch_enabled = s->desc->notch_allowed;
|
||||
s->notch_insertion_timeout = s->desc->notch_lag_time;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s->notch_insertion_timeout > 0)
|
||||
if (s->notch_insertion_timeout)
|
||||
s->notch_insertion_timeout--;
|
||||
else
|
||||
s->notch_enabled = FALSE;
|
||||
/*endif*/
|
||||
}
|
||||
/*endif*/
|
||||
@@ -583,91 +503,84 @@ SPAN_DECLARE(int) sig_tone_rx(sig_tone_rx_state_t *s, int16_t amp[], int len)
|
||||
else
|
||||
{
|
||||
/* Sharp mode */
|
||||
flat_power = power_meter_update(&s->flat_power, amp[i]);
|
||||
|
||||
/* Modulus and leaky integrate the data */
|
||||
s->broad_zl = ((s->broad_zl*s->desc->unfiltered_slugi) >> 15)
|
||||
+ ((abs((int) amp[i])*s->desc->unfiltered_slugp) >> 15);
|
||||
|
||||
/* Mow the grass to weed out the noise! */
|
||||
mown_bandpass = s->broad_zl & s->desc->unfiltered_threshold;
|
||||
|
||||
/* Persistence checking and notch insertion logic */
|
||||
if (!s->tone_present)
|
||||
for (j = 0; j < s->desc->tones; j++)
|
||||
{
|
||||
if (mown_notch[0] < mown_bandpass)
|
||||
/* Persistence checking and notch insertion logic */
|
||||
if (s->tone[j].tone_present)
|
||||
{
|
||||
/* Tone is detected this sample */
|
||||
if (s->tone_persistence_timeout <= 0)
|
||||
if (flat_power < s->sharp_detection_threshold
|
||||
||
|
||||
(notch_power[j] >> 6)*s->detection_ratio > (flat_power >> 6))
|
||||
{
|
||||
s->tone_present = TRUE;
|
||||
s->notch_enabled = s->desc->notch_allowed;
|
||||
s->tone_persistence_timeout = s->desc->tone_off_check_time;
|
||||
s->notch_insertion_timeout = s->desc->notch_lag_time;
|
||||
if (s->sig_update)
|
||||
s->sig_update(s->user_data, SIG_TONE_1_CHANGE | SIG_TONE_1_PRESENT, 0, s->signaling_state_duration);
|
||||
/* Tone is not detected this sample */
|
||||
if (--s->tone[j].tone_persistence_timeout == 0)
|
||||
{
|
||||
/* Tone off is confirmed */
|
||||
s->tone[j].tone_present = FALSE;
|
||||
s->tone[j].tone_persistence_timeout = s->desc->tone_on_check_time;
|
||||
s->signalling_state &= ~tone_present_bits[j];
|
||||
s->signalling_state |= tone_change_bits[j];
|
||||
}
|
||||
/*endif*/
|
||||
s->signaling_state_duration = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
s->tone_persistence_timeout--;
|
||||
if (s->notch_insertion_timeout > 0)
|
||||
s->notch_insertion_timeout--;
|
||||
else
|
||||
s->notch_enabled = FALSE;
|
||||
/*endif*/
|
||||
s->tone[j].tone_persistence_timeout = s->desc->tone_off_check_time;
|
||||
}
|
||||
/*endif*/
|
||||
}
|
||||
else
|
||||
{
|
||||
s->tone_persistence_timeout = s->desc->tone_on_check_time;
|
||||
if (s->notch_insertion_timeout > 0)
|
||||
if (s->notch_insertion_timeout)
|
||||
s->notch_insertion_timeout--;
|
||||
else
|
||||
s->notch_enabled = FALSE;
|
||||
/*endif*/
|
||||
}
|
||||
/*endif*/
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mown_notch[0] > mown_bandpass)
|
||||
{
|
||||
/* Tone is not detected this sample */
|
||||
if (s->tone_persistence_timeout <= 0)
|
||||
if (flat_power > s->sharp_detection_threshold
|
||||
&&
|
||||
(notch_power[j] >> 6)*s->detection_ratio < (flat_power >> 6))
|
||||
{
|
||||
s->tone_present = FALSE;
|
||||
s->tone_persistence_timeout = s->desc->tone_on_check_time;
|
||||
if (s->sig_update)
|
||||
s->sig_update(s->user_data, SIG_TONE_1_CHANGE, 0, s->signaling_state_duration);
|
||||
/* Tone is detected this sample */
|
||||
if (--s->tone[j].tone_persistence_timeout == 0)
|
||||
{
|
||||
/* Tone on is confirmed */
|
||||
s->tone[j].tone_present = TRUE;
|
||||
s->tone[j].tone_persistence_timeout = s->desc->tone_off_check_time;
|
||||
s->notch_insertion_timeout = s->desc->notch_lag_time;
|
||||
s->signalling_state |= (tone_present_bits[j] | tone_change_bits[j]);
|
||||
}
|
||||
/*endif*/
|
||||
s->signaling_state_duration = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
s->tone_persistence_timeout--;
|
||||
s->tone[j].tone_persistence_timeout = s->desc->tone_on_check_time;
|
||||
}
|
||||
/*endif*/
|
||||
}
|
||||
else
|
||||
{
|
||||
s->tone_persistence_timeout = s->desc->tone_off_check_time;
|
||||
}
|
||||
/*endif*/
|
||||
}
|
||||
/*endfor*/
|
||||
}
|
||||
/*endif*/
|
||||
if (s->signalling_state & (SIG_TONE_1_CHANGE | SIG_TONE_2_CHANGE))
|
||||
{
|
||||
if (s->sig_update)
|
||||
s->sig_update(s->user_data, s->signalling_state, 0, s->signalling_state_duration);
|
||||
/*endif*/
|
||||
s->signalling_state &= ~(SIG_TONE_1_CHANGE | SIG_TONE_2_CHANGE);
|
||||
s->signalling_state_duration = 0;
|
||||
}
|
||||
/*endif*/
|
||||
|
||||
if ((s->current_rx_tone & SIG_TONE_RX_PASSTHROUGH))
|
||||
{
|
||||
if ((s->current_rx_tone & SIG_TONE_RX_FILTER_TONE) || s->notch_enabled)
|
||||
amp[i] = (int16_t) notched_signal;
|
||||
if ((s->current_rx_tone & SIG_TONE_RX_FILTER_TONE) || s->notch_insertion_timeout)
|
||||
amp[i] = saturate16(notched_signal[0]);
|
||||
/*endif*/
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Simply mute the media path */
|
||||
amp[i] = 0;
|
||||
}
|
||||
/*endif*/
|
||||
@@ -685,6 +598,11 @@ SPAN_DECLARE(void) sig_tone_rx_set_mode(sig_tone_rx_state_t *s, int mode, int du
|
||||
|
||||
SPAN_DECLARE(sig_tone_rx_state_t *) sig_tone_rx_init(sig_tone_rx_state_t *s, int tone_type, tone_report_func_t sig_update, void *user_data)
|
||||
{
|
||||
#if !defined(SPANDSP_USE_FIXED_POINT)
|
||||
int i;
|
||||
int j;
|
||||
#endif
|
||||
|
||||
if (sig_update == NULL || tone_type < 1 || tone_type > 3)
|
||||
return NULL;
|
||||
/*endif*/
|
||||
@@ -695,16 +613,31 @@ SPAN_DECLARE(sig_tone_rx_state_t *) sig_tone_rx_init(sig_tone_rx_state_t *s, int
|
||||
return NULL;
|
||||
}
|
||||
memset(s, 0, sizeof(*s));
|
||||
#if !defined(SPANDSP_USE_FIXED_POINT)
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
for (j = 0; j < 2; j++)
|
||||
{
|
||||
s->tone[j].notch_z1[i] = 0.0f;
|
||||
s->tone[j].notch_z2[i] = 0.0f;
|
||||
}
|
||||
s->flat_z[i] = 0.0f;
|
||||
}
|
||||
#endif
|
||||
|
||||
s->sig_update = sig_update;
|
||||
s->user_data = user_data;
|
||||
|
||||
s->desc = &sig_tones[tone_type - 1];
|
||||
|
||||
s->flat_mode_timeout = 0;
|
||||
s->notch_insertion_timeout = 0;
|
||||
s->tone_persistence_timeout = 0;
|
||||
s->signaling_state_duration = 0;
|
||||
power_meter_init(&s->tone[0].power, 5);
|
||||
power_meter_init(&s->tone[1].power, 5);
|
||||
power_meter_init(&s->flat_power, 5);
|
||||
|
||||
s->flat_detection_threshold = power_meter_level_dbm0(s->desc->flat_detection_threshold);
|
||||
s->sharp_detection_threshold = power_meter_level_dbm0(s->desc->sharp_detection_threshold);
|
||||
s->detection_ratio = powf(10.0f, s->desc->detection_ratio/10.0f) + 1.0f;
|
||||
|
||||
return s;
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
Reference in new issue
Block a user