spandsp 0.0.6
private/sig_tone.h
00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * private/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.4 2009/09/04 14:38:47 steveu Exp $
00027  */
00028 
00029 #if !defined(_SPANDSP_PRIVATE_SIG_TONE_H_)
00030 #define _SPANDSP_PRIVATE_SIG_TONE_H_
00031 
00032 /*!
00033     Signaling tone descriptor. This defines the working state for a
00034     single instance of the transmit and receive sides of a signaling
00035     tone processor.
00036 */
00037 struct sig_tone_descriptor_s
00038 {
00039     /*! \brief The tones used. */
00040     int tone_freq[2];
00041     /*! \brief The high and low tone amplitudes for each of the tones. */
00042     int tone_amp[2][2];
00043 
00044     /*! \brief The delay, in audio samples, before the high level tone drops
00045                to a low level tone. */
00046     int high_low_timeout;
00047 
00048     /*! \brief Some signaling tone detectors use a sharp initial filter,
00049                changing to a broader band filter after some delay. This
00050                parameter defines the delay. 0 means it never changes. */
00051     int sharp_flat_timeout;
00052 
00053     /*! \brief Parameters to control the behaviour of the notch filter, used
00054                to remove the tone from the voice path in some protocols. */
00055     int notch_lag_time;
00056     /*! \brief TRUE if the notch may be used in the media flow. */
00057     int notch_allowed;
00058 
00059     /*! \brief The tone on persistence check, in audio samples. */
00060     int tone_on_check_time;
00061     /*! \brief The tone off persistence check, in audio samples. */
00062     int tone_off_check_time;
00063 
00064     /*! \brief ??? */
00065     int tones;
00066     /*! \brief The coefficients for the cascaded bi-quads notch filter. */
00067     struct
00068     {
00069 #if defined(SPANDSP_USE_FIXED_POINT)
00070         int32_t notch_a1[3];
00071         int32_t notch_b1[3];
00072         int32_t notch_a2[3];
00073         int32_t notch_b2[3];
00074         int notch_postscale;
00075 #else
00076         float notch_a1[3];
00077         float notch_b1[3];
00078         float notch_a2[3];
00079         float notch_b2[3];
00080 #endif
00081     } tone[2];
00082 
00083 #if defined(SPANDSP_USE_FIXED_POINT)
00084     /*! \brief Flat mode bandpass bi-quad parameters */
00085     int32_t broad_a[3];
00086     /*! \brief Flat mode bandpass bi-quad parameters */
00087     int32_t broad_b[3];
00088     /*! \brief Post filter scaling */
00089     int broad_postscale;
00090 #else
00091     /*! \brief Flat mode bandpass bi-quad parameters */
00092     float broad_a[3];
00093     /*! \brief Flat mode bandpass bi-quad parameters */
00094     float broad_b[3];
00095 #endif
00096     /*! \brief The coefficients for the post notch leaky integrator. */
00097     int32_t notch_slugi;
00098     /*! \brief ??? */
00099     int32_t notch_slugp;
00100 
00101     /*! \brief The coefficients for the post modulus leaky integrator in the
00102                unfiltered data path.  The prescale value incorporates the
00103                detection ratio. This is called the guard ratio in some
00104                protocols. */
00105     int32_t unfiltered_slugi;
00106     /*! \brief ??? */
00107     int32_t unfiltered_slugp;
00108 
00109     /*! \brief The coefficients for the post modulus leaky integrator in the
00110                bandpass filter data path. */
00111     int32_t broad_slugi;
00112     /*! \brief ??? */
00113     int32_t broad_slugp;
00114 
00115     /*! \brief Masks which effectively threshold the notched, weighted and
00116                bandpassed data. */
00117     int32_t notch_threshold;
00118     /*! \brief ??? */
00119     int32_t unfiltered_threshold;
00120     /*! \brief ??? */
00121     int32_t broad_threshold;
00122 };
00123 
00124 /*!
00125     Signaling tone transmit state
00126  */
00127 struct sig_tone_tx_state_s
00128 {
00129     /*! \brief The callback function used to handle signaling changes. */
00130     tone_report_func_t sig_update;
00131     /*! \brief A user specified opaque pointer passed to the callback function. */
00132     void *user_data;
00133 
00134     /*! \brief Tone descriptor */
00135     sig_tone_descriptor_t *desc;
00136 
00137     /*! The phase rates for the one or two tones */
00138     int32_t phase_rate[2];
00139     /*! The phase accumulators for the one or two tones */
00140     uint32_t phase_acc[2];
00141 
00142     /*! The scaling values for the one or two tones, and the high and low level of each tone */
00143     int16_t tone_scaling[2][2];
00144     /*! The sample timer, used to switch between the high and low level tones. */
00145     int high_low_timer;
00146 
00147     /*! \brief Current transmit tone */
00148     int current_tx_tone;
00149     /*! \brief Current transmit timeout */
00150     int current_tx_timeout;
00151     /*! \brief Time in current signaling state, in samples. */
00152     int signaling_state_duration;
00153 };
00154 
00155 /*!
00156     Signaling tone receive state
00157  */
00158 struct sig_tone_rx_state_s
00159 {
00160     /*! \brief The callback function used to handle signaling changes. */
00161     tone_report_func_t sig_update;
00162     /*! \brief A user specified opaque pointer passed to the callback function. */
00163     void *user_data;
00164 
00165     /*! \brief Tone descriptor */
00166     sig_tone_descriptor_t *desc;
00167 
00168     /*! \brief The current receive tone */
00169     int current_rx_tone;
00170     /*! \brief The timeout for switching from the high level to low level tone detector. */
00171     int high_low_timer;
00172 
00173     struct
00174     {
00175 #if defined(SPANDSP_USE_FIXED_POINT)
00176         /*! \brief The z's for the notch filter */
00177         int32_t notch_z1[3];
00178         /*! \brief The z's for the notch filter */
00179         int32_t notch_z2[3];
00180 #else
00181         /*! \brief The z's for the notch filter */
00182         float notch_z1[3];
00183         /*! \brief The z's for the notch filter */
00184         float notch_z2[3];
00185 #endif
00186 
00187         /*! \brief The z's for the notch integrators. */
00188         int32_t notch_zl;
00189     } tone[2];
00190 
00191 #if defined(SPANDSP_USE_FIXED_POINT)
00192     /*! \brief The z's for the weighting/bandpass filter. */
00193     int32_t broad_z[3];
00194 #else
00195     /*! \brief The z's for the weighting/bandpass filter. */
00196     float broad_z[3];
00197 #endif
00198     /*! \brief The z for the broadband integrator. */
00199     int32_t broad_zl;
00200 
00201     /*! \brief ??? */
00202     int flat_mode;
00203     /*! \brief ??? */
00204     int tone_present;
00205     /*! \brief ??? */
00206     int notch_enabled;
00207     /*! \brief ??? */
00208     int flat_mode_timeout;
00209     /*! \brief ??? */
00210     int notch_insertion_timeout;
00211     /*! \brief ??? */
00212     int tone_persistence_timeout;
00213     
00214     /*! \brief ??? */
00215     int signaling_state_duration;
00216 };
00217 
00218 #endif
00219 /*- End of file ------------------------------------------------------------*/