5
|
1 /*
|
|
2 * SpanDSP - a series of DSP components for telephony
|
|
3 *
|
|
4 * sig_tone.h - Signalling tone processing for the 2280Hz, 2600Hz and similar
|
|
5 * signalling tone used in older protocols.
|
|
6 *
|
|
7 * Written by Steve Underwood <steveu@coppice.org>
|
|
8 *
|
|
9 * Copyright (C) 2004 Steve Underwood
|
|
10 *
|
|
11 * All rights reserved.
|
|
12 *
|
|
13 * This program is free software; you can redistribute it and/or modify
|
|
14 * it under the terms of the GNU General Public License version 2, as
|
|
15 * published by the Free Software Foundation.
|
|
16 *
|
|
17 * This program is distributed in the hope that it will be useful,
|
|
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 * GNU General Public License for more details.
|
|
21 *
|
|
22 * You should have received a copy of the GNU General Public License
|
|
23 * along with this program; if not, write to the Free Software
|
|
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
25 *
|
|
26 * $Id: sig_tone.h,v 1.7 2006/10/24 13:22:02 steveu Exp $
|
|
27 */
|
|
28
|
|
29 /*! \file */
|
|
30
|
|
31 /*! \page sig_tone_page The signaling tone processor
|
|
32 \section sig_tone_sec_1 What does it do?
|
|
33 The signaling tone processor handles the 2280Hz, 2400Hz and 2600Hz tones, used
|
|
34 in many analogue signaling procotols, and digital ones derived from them.
|
|
35
|
|
36 \section sig_tone_sec_2 How does it work?
|
|
37 TBD
|
|
38 */
|
|
39
|
|
40 #if !defined(_SIG_TONE_H_)
|
|
41 #define _SIG_TONE_H_
|
|
42
|
|
43 typedef int (*sig_tone_func_t)(void *user_data, int what);
|
|
44
|
|
45 /* The optional tone sets */
|
|
46 enum
|
|
47 {
|
|
48 SIG_TONE_2280HZ = 1,
|
|
49 SIG_TONE_2600HZ,
|
|
50 SIG_TONE_2400HZ_2600HZ
|
|
51 };
|
|
52
|
|
53 #define SIG_TONE_1_PRESENT 0x001
|
|
54 #define SIG_TONE_1_CHANGE 0x002
|
|
55 #define SIG_TONE_2_PRESENT 0x004
|
|
56 #define SIG_TONE_2_CHANGE 0x008
|
|
57 #define SIG_TONE_TX_PASSTHROUGH 0x010
|
|
58 #define SIG_TONE_RX_PASSTHROUGH 0x020
|
|
59 #define SIG_TONE_UPDATE_REQUEST 0x100
|
|
60
|
|
61 /*!
|
|
62 Signaling tone descriptor. This defines the working state for a
|
|
63 single instance of the transmit and receive sides of a signaling
|
|
64 tone processor.
|
|
65 */
|
|
66 typedef struct
|
|
67 {
|
|
68 /*! \brief The tones used. */
|
|
69 int tone_freq[2];
|
|
70 /*! \brief The high and low tone amplitudes. */
|
|
71 int tone_amp[2];
|
|
72
|
|
73 /*! \brief The delay, in audio samples, before the high level tone drops
|
|
74 to a low level tone. */
|
|
75 int high_low_timeout;
|
|
76
|
|
77 /*! \brief Some signaling tone detectors use a sharp initial filter,
|
|
78 changing to a broader band filter after some delay. This
|
|
79 parameter defines the delay. 0 means it never changes. */
|
|
80 int sharp_flat_timeout;
|
|
81
|
|
82 /*! \brief Parameters to control the behaviour of the notch filter, used
|
|
83 to remove the tone from the voice path in some protocols. */
|
|
84 int notch_lag_time;
|
|
85 int notch_allowed;
|
|
86
|
|
87 /*! \brief The tone on persistence check, in audio samples. */
|
|
88 int tone_on_check_time;
|
|
89 /*! \brief The tone off persistence check, in audio samples. */
|
|
90 int tone_off_check_time;
|
|
91
|
|
92 /*! \brief The coefficients for the cascaded bi-quads notch filter. */
|
|
93 int32_t notch_a1[3];
|
|
94 int32_t notch_b1[3];
|
|
95 int32_t notch_a2[3];
|
|
96 int32_t notch_b2[3];
|
|
97 int notch_postscale;
|
|
98
|
|
99 /*! \brief Flat mode bandpass bi-quad parameters */
|
|
100 int32_t broad_a[3];
|
|
101 int32_t broad_b[3];
|
|
102 int broad_postscale;
|
|
103
|
|
104 /*! \brief The coefficients for the post notch leaky integrator. */
|
|
105 int32_t notch_slugi;
|
|
106 int32_t notch_slugp;
|
|
107
|
|
108 /*! \brief The coefficients for the post modulus leaky integrator in the
|
|
109 unfiltered data path. The prescale value incorporates the
|
|
110 detection ratio. This is called the guard ratio in some
|
|
111 protocols. */
|
|
112 int32_t unfiltered_slugi;
|
|
113 int32_t unfiltered_slugp;
|
|
114
|
|
115 /*! \brief The coefficients for the post modulus leaky integrator in the
|
|
116 bandpass filter data path. */
|
|
117 int32_t broad_slugi;
|
|
118 int32_t broad_slugp;
|
|
119
|
|
120 /*! \brief Masks which effectively threshold the notched, weighted and
|
|
121 bandpassed data. */
|
|
122 int32_t notch_threshold;
|
|
123 int32_t unfiltered_threshold;
|
|
124 int32_t broad_threshold;
|
|
125 } sig_tone_descriptor_t;
|
|
126
|
|
127 typedef struct
|
|
128 {
|
|
129 /*! \brief The callback function used to handle signaling changes. */
|
|
130 sig_tone_func_t sig_update;
|
|
131 /*! \brief A user specified opaque pointer passed to the callback function. */
|
|
132 void *user_data;
|
|
133
|
|
134 /*! \brief Transmit side parameters */
|
|
135 sig_tone_descriptor_t *desc;
|
|
136 int32_t phase_rate[2];
|
|
137 int32_t tone_scaling[2];
|
|
138 uint32_t phase_acc[2];
|
|
139
|
|
140 int high_low_timer;
|
|
141
|
|
142 /*! \brief The z's for the notch filter */
|
|
143 int32_t notch_z1[3];
|
|
144 int32_t notch_z2[3];
|
|
145
|
|
146 /*! \brief The z's for the weighting/bandpass filter. */
|
|
147 int32_t broad_z[3];
|
|
148
|
|
149 /*! \brief The z's for the integrators. */
|
|
150 int32_t notch_zl;
|
|
151 int32_t broad_zl;
|
|
152
|
|
153 /*! \brief The thresholded data. */
|
|
154 int32_t mown_notch;
|
|
155 int32_t mown_bandpass;
|
|
156
|
|
157 int flat_mode;
|
|
158 int tone_present;
|
|
159 int notch_enabled;
|
|
160 int flat_mode_timeout;
|
|
161 int notch_insertion_timeout;
|
|
162 int tone_persistence_timeout;
|
|
163
|
|
164 int current_tx_tone;
|
|
165 int current_tx_timeout;
|
|
166 int signaling_state_duration;
|
|
167 } sig_tone_state_t;
|
|
168
|
|
169 /*! Initialise a signaling tone context.
|
|
170 \brief Initialise a signaling tone context.
|
|
171 \param s The signaling tone context.
|
|
172 \param tone_type The type of signaling tone.
|
|
173 \param sig_update Callback function to handle signaling updates.
|
|
174 \param user_data An opaque pointer.
|
|
175 \return A pointer to the signalling tone context, or NULL if there was a problem. */
|
|
176 sig_tone_state_t *sig_tone_init(sig_tone_state_t *s, int tone_type, sig_tone_func_t sig_update, void *user_data);
|
|
177
|
|
178 /*! Process a block of received audio samples.
|
|
179 \brief Process a block of received audio samples.
|
|
180 \param s The signaling tone context.
|
|
181 \param amp The audio sample buffer.
|
|
182 \param len The number of samples in the buffer.
|
|
183 \return The number of samples unprocessed. */
|
|
184 int sig_tone_rx(sig_tone_state_t *s, int16_t amp[], int len);
|
|
185
|
|
186 /*! Generate a block of signaling tone audio samples.
|
|
187 \brief Generate a block of signaling tone audio samples.
|
|
188 \param s The signaling tone context.
|
|
189 \param amp The audio sample buffer.
|
|
190 \param len The number of samples to be generated.
|
|
191 \return The number of samples actually generated. */
|
|
192 int sig_tone_tx(sig_tone_state_t *s, int16_t amp[], int len);
|
|
193
|
|
194 #endif
|
|
195 /*- End of file ------------------------------------------------------------*/
|