00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * sig_tone.h - Signalling tone processing for the 2280Hz, 2400Hz, 2600Hz 00005 * and similar signalling tone used in older protocols. 00006 * 00007 * Written by Steve Underwood <steveu@coppice.org> 00008 * 00009 * Copyright (C) 2004 Steve Underwood 00010 * 00011 * All rights reserved. 00012 * 00013 * This program is free software; you can redistribute it and/or modify 00014 * it under the terms of the GNU Lesser General Public License version 2.1, 00015 * as published by the Free Software Foundation. 00016 * 00017 * This program is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU Lesser General Public License for more details. 00021 * 00022 * You should have received a copy of the GNU Lesser General Public 00023 * License along with this program; if not, write to the Free Software 00024 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00025 * 00026 * $Id: sig_tone.h,v 1.14 2008/07/29 14:15:21 steveu Exp $ 00027 */ 00028 00029 /*! \file */ 00030 00031 /*! \page sig_tone_page The signaling tone processor 00032 \section sig_tone_sec_1 What does it do? 00033 The signaling tone processor handles the 2280Hz, 2400Hz and 2600Hz tones, used 00034 in many analogue signaling procotols, and digital ones derived from them. 00035 00036 \section sig_tone_sec_2 How does it work? 00037 Most single and two voice frequency signalling systems share many features, as these 00038 features have developed in similar ways over time, to address the limitations of 00039 early tone signalling systems. 00040 00041 The usual practice is to start the generation of tone at a high energy level, so a 00042 strong signal is available at the receiver, for crisp tone detection. If the tone 00043 remains on for a significant period, the energy level is reduced, to minimise crosstalk. 00044 During the signalling transitions, only the tone is sent through the channel, and the media 00045 signal is suppressed. This means the signalling receiver has a very clean signal to work with, 00046 allowing for crisp detection of the signalling tone. However, when the signalling tone is on 00047 for extended periods, there may be supervisory information in the media signal, such as voice 00048 announcements. To allow these to pass through the system, the signalling tone is mixed with 00049 the media signal. It is the job of the signalling receiver to separate the signalling tone 00050 and the media. The necessary filtering may degrade the quality of the voice signal, but at 00051 least supervisory information may be heard. 00052 */ 00053 00054 #if !defined(_SPANDSP_SIG_TONE_H_) 00055 #define _SPANDSP_SIG_TONE_H_ 00056 00057 typedef int (*sig_tone_func_t)(void *user_data, int what); 00058 00059 /* The optional tone sets */ 00060 enum 00061 { 00062 /*! European 2280Hz signaling tone */ 00063 SIG_TONE_2280HZ = 1, 00064 /*! US 2600Hz signaling tone */ 00065 SIG_TONE_2600HZ, 00066 /*! US 2400Hz + 2600Hz signaling tones */ 00067 SIG_TONE_2400HZ_2600HZ 00068 }; 00069 00070 enum 00071 { 00072 /*! Signaling tone 1 is present */ 00073 SIG_TONE_1_PRESENT = 0x001, 00074 SIG_TONE_1_CHANGE = 0x002, 00075 /*! Signaling tone 2 is present */ 00076 SIG_TONE_2_PRESENT = 0x004, 00077 SIG_TONE_2_CHANGE = 0x008, 00078 /*! The media signal is passing through. Tones might be added to it. */ 00079 SIG_TONE_TX_PASSTHROUGH = 0x010, 00080 /*! The media signal is passing through. Tones might be extracted from it, if detected. */ 00081 SIG_TONE_RX_PASSTHROUGH = 0x020, 00082 SIG_TONE_UPDATE_REQUEST = 0x100 00083 }; 00084 00085 /*! 00086 Signaling tone descriptor. This defines the working state for a 00087 single instance of the transmit and receive sides of a signaling 00088 tone processor. 00089 */ 00090 typedef struct 00091 { 00092 /*! \brief The tones used. */ 00093 int tone_freq[2]; 00094 /*! \brief The high and low tone amplitudes. */ 00095 int tone_amp[2]; 00096 00097 /*! \brief The delay, in audio samples, before the high level tone drops 00098 to a low level tone. */ 00099 int high_low_timeout; 00100 00101 /*! \brief Some signaling tone detectors use a sharp initial filter, 00102 changing to a broader band filter after some delay. This 00103 parameter defines the delay. 0 means it never changes. */ 00104 int sharp_flat_timeout; 00105 00106 /*! \brief Parameters to control the behaviour of the notch filter, used 00107 to remove the tone from the voice path in some protocols. */ 00108 int notch_lag_time; 00109 int notch_allowed; 00110 00111 /*! \brief The tone on persistence check, in audio samples. */ 00112 int tone_on_check_time; 00113 /*! \brief The tone off persistence check, in audio samples. */ 00114 int tone_off_check_time; 00115 00116 int tones; 00117 /*! \brief The coefficients for the cascaded bi-quads notch filter. */ 00118 struct 00119 { 00120 #if defined(SPANDSP_USE_FIXED_POINT) 00121 int32_t notch_a1[3]; 00122 int32_t notch_b1[3]; 00123 int32_t notch_a2[3]; 00124 int32_t notch_b2[3]; 00125 int notch_postscale; 00126 #else 00127 float notch_a1[3]; 00128 float notch_b1[3]; 00129 float notch_a2[3]; 00130 float notch_b2[3]; 00131 #endif 00132 } tone[2]; 00133 00134 00135 /*! \brief Flat mode bandpass bi-quad parameters */ 00136 #if defined(SPANDSP_USE_FIXED_POINT) 00137 int32_t broad_a[3]; 00138 int32_t broad_b[3]; 00139 int broad_postscale; 00140 #else 00141 float broad_a[3]; 00142 float broad_b[3]; 00143 #endif 00144 /*! \brief The coefficients for the post notch leaky integrator. */ 00145 int32_t notch_slugi; 00146 int32_t notch_slugp; 00147 00148 /*! \brief The coefficients for the post modulus leaky integrator in the 00149 unfiltered data path. The prescale value incorporates the 00150 detection ratio. This is called the guard ratio in some 00151 protocols. */ 00152 int32_t unfiltered_slugi; 00153 int32_t unfiltered_slugp; 00154 00155 /*! \brief The coefficients for the post modulus leaky integrator in the 00156 bandpass filter data path. */ 00157 int32_t broad_slugi; 00158 int32_t broad_slugp; 00159 00160 /*! \brief Masks which effectively threshold the notched, weighted and 00161 bandpassed data. */ 00162 int32_t notch_threshold; 00163 int32_t unfiltered_threshold; 00164 int32_t broad_threshold; 00165 } sig_tone_descriptor_t; 00166 00167 typedef struct 00168 { 00169 /*! \brief The callback function used to handle signaling changes. */ 00170 sig_tone_func_t sig_update; 00171 /*! \brief A user specified opaque pointer passed to the callback function. */ 00172 void *user_data; 00173 00174 sig_tone_descriptor_t *desc; 00175 00176 /*! The scaling values for the high and low level tones */ 00177 int32_t tone_scaling[2]; 00178 /*! The sample timer, used to switch between the high and low level tones. */ 00179 int high_low_timer; 00180 00181 /*! The phase rates for the one or two tones */ 00182 int32_t phase_rate[2]; 00183 /*! The phase accumulators for the one or two tones */ 00184 uint32_t phase_acc[2]; 00185 00186 int current_tx_tone; 00187 int current_tx_timeout; 00188 int signaling_state_duration; 00189 } sig_tone_tx_state_t; 00190 00191 typedef struct 00192 { 00193 /*! \brief The callback function used to handle signaling changes. */ 00194 sig_tone_func_t sig_update; 00195 /*! \brief A user specified opaque pointer passed to the callback function. */ 00196 void *user_data; 00197 00198 sig_tone_descriptor_t *desc; 00199 00200 int current_rx_tone; 00201 int high_low_timer; 00202 00203 struct 00204 { 00205 /*! \brief The z's for the notch filter */ 00206 #if defined(SPANDSP_USE_FIXED_POINT) 00207 int32_t notch_z1[3]; 00208 int32_t notch_z2[3]; 00209 #else 00210 float notch_z1[3]; 00211 float notch_z2[3]; 00212 #endif 00213 00214 /*! \brief The z's for the notch integrators. */ 00215 int32_t notch_zl; 00216 } tone[2]; 00217 00218 /*! \brief The z's for the weighting/bandpass filter. */ 00219 #if defined(SPANDSP_USE_FIXED_POINT) 00220 int32_t broad_z[3]; 00221 #else 00222 float broad_z[3]; 00223 #endif 00224 /*! \brief The z for the broadband integrator. */ 00225 int32_t broad_zl; 00226 00227 int flat_mode; 00228 int tone_present; 00229 int notch_enabled; 00230 int flat_mode_timeout; 00231 int notch_insertion_timeout; 00232 int tone_persistence_timeout; 00233 00234 int signaling_state_duration; 00235 } sig_tone_rx_state_t; 00236 00237 #if defined(__cplusplus) 00238 extern "C" 00239 { 00240 #endif 00241 00242 /*! Process a block of received audio samples. 00243 \brief Process a block of received audio samples. 00244 \param s The signaling tone context. 00245 \param amp The audio sample buffer. 00246 \param len The number of samples in the buffer. 00247 \return The number of samples unprocessed. */ 00248 int sig_tone_rx(sig_tone_rx_state_t *s, int16_t amp[], int len); 00249 00250 /*! Initialise a signaling tone receiver context. 00251 \brief Initialise a signaling tone context. 00252 \param s The signaling tone context. 00253 \param tone_type The type of signaling tone. 00254 \param sig_update Callback function to handle signaling updates. 00255 \param user_data An opaque pointer. 00256 \return A pointer to the signalling tone context, or NULL if there was a problem. */ 00257 sig_tone_rx_state_t *sig_tone_rx_init(sig_tone_rx_state_t *s, int tone_type, sig_tone_func_t sig_update, void *user_data); 00258 00259 /*! Generate a block of signaling tone audio samples. 00260 \brief Generate a block of signaling tone audio samples. 00261 \param s The signaling tone context. 00262 \param amp The audio sample buffer. 00263 \param len The number of samples to be generated. 00264 \return The number of samples actually generated. */ 00265 int sig_tone_tx(sig_tone_tx_state_t *s, int16_t amp[], int len); 00266 00267 /*! Set the tone mode. 00268 \brief Set the tone mode. 00269 \param s The signaling tone context. 00270 \param mode The new mode for the transmitted tones. */ 00271 void sig_tone_tx_set_mode(sig_tone_tx_state_t *s, int mode); 00272 00273 /*! Initialise a signaling tone transmitter context. 00274 \brief Initialise a signaling tone context. 00275 \param s The signaling tone context. 00276 \param tone_type The type of signaling tone. 00277 \param sig_update Callback function to handle signaling updates. 00278 \param user_data An opaque pointer. 00279 \return A pointer to the signalling tone context, or NULL if there was a problem. */ 00280 sig_tone_tx_state_t *sig_tone_tx_init(sig_tone_tx_state_t *s, int tone_type, sig_tone_func_t sig_update, void *user_data); 00281 00282 #if defined(__cplusplus) 00283 } 00284 #endif 00285 00286 #endif 00287 /*- End of file ------------------------------------------------------------*/