00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * modem_connect_tones.c - Generation and detection of tones 00005 * associated with modems calling and answering calls. 00006 * 00007 * Written by Steve Underwood <steveu@coppice.org> 00008 * 00009 * Copyright (C) 2006 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 General Public License version 2, as 00015 * 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 General Public License for more details. 00021 * 00022 * You should have received a copy of the GNU General Public License 00023 * along with this program; if not, write to the Free Software 00024 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00025 * 00026 * $Id: modem_connect_tones.h,v 1.7 2007/04/08 08:16:18 steveu Exp $ 00027 */ 00028 00029 /*! \file */ 00030 00031 #if !defined(_SPANDSP_MODEM_CONNECT_TONES_H_) 00032 #define _SPANDSP_MODEM_CONNECT_TONES_H_ 00033 00034 /*! \page modem_connect_tones_page Echo cancellor disable tone detection 00035 00036 \section modem_connect_tones_page_sec_1 What does it do? 00037 Some telephony terminal equipment, such as modems, require a channel which is as 00038 clear as possible. They use their own echo cancellation. If the network is also 00039 performing echo cancellation the two cancellors can end of squabbling about the 00040 nature of the channel, with bad results. A special tone is defined which should 00041 cause the network to disable any echo cancellation processes. 00042 00043 \section modem_connect_tones_page_sec_2 How does it work? 00044 A sharp notch filter is implemented as a single bi-quad section. The presence of 00045 the 2100Hz disable tone is detected by comparing the notched filtered energy 00046 with the unfiltered energy. If the notch filtered energy is much lower than the 00047 unfiltered energy, then a large proportion of the energy must be at the notch 00048 frequency. This type of detector may seem less intuitive than using a narrow 00049 bandpass filter to isolate the energy at the notch freqency. However, a sharp 00050 bandpass implemented as an IIR filter rings badly, The reciprocal notch filter 00051 is very well behaved. 00052 */ 00053 00054 enum 00055 { 00056 MODEM_CONNECT_TONES_FAX_CNG, 00057 MODEM_CONNECT_TONES_FAX_CED, 00058 MODEM_CONNECT_TONES_EC_DISABLE, 00059 /*! \brief The version of EC disable with some 15Hz AM content, as in V.8 */ 00060 MODEM_CONNECT_TONES_EC_DISABLE_MOD, 00061 }; 00062 00063 /*! 00064 Modem connect tones generator descriptor. This defines the state 00065 of a single working instance of the tone generator. 00066 */ 00067 typedef struct 00068 { 00069 int tone_type; 00070 00071 tone_gen_state_t tone_tx; 00072 uint32_t tone_phase; 00073 int32_t tone_phase_rate; 00074 int level; 00075 /*! \brief Countdown to the next phase hop */ 00076 int hop_timer; 00077 uint32_t mod_phase; 00078 int32_t mod_phase_rate; 00079 int mod_level; 00080 } modem_connect_tones_tx_state_t; 00081 00082 /*! 00083 Modem connect tones receiver descriptor. This defines the state 00084 of a single working instance of the tone detector. 00085 */ 00086 typedef struct 00087 { 00088 int tone_type; 00089 tone_report_func_t tone_callback; 00090 void *callback_data; 00091 00092 float z1; 00093 float z2; 00094 int notch_level; 00095 int channel_level; 00096 int tone_present; 00097 int tone_cycle_duration; 00098 int good_cycles; 00099 int hit; 00100 } modem_connect_tones_rx_state_t; 00101 00102 #if defined(__cplusplus) 00103 extern "C" 00104 { 00105 #endif 00106 00107 /*! \brief Initialse an instance of the echo canceller disable tone generator. 00108 \param s The context. 00109 */ 00110 modem_connect_tones_tx_state_t *modem_connect_tones_tx_init(modem_connect_tones_tx_state_t *s, 00111 int tone_type); 00112 00113 /*! \brief Generate a block of echo canceller disable tone samples. 00114 \param s The context. 00115 \param amp An array of signal samples. 00116 \param len The number of samples to generate. 00117 \return The number of samples generated. 00118 */ 00119 int modem_connect_tones_tx(modem_connect_tones_tx_state_t *s, 00120 int16_t amp[], 00121 int len); 00122 00123 /*! \brief Process a block of samples through an instance of the modem_connect 00124 tones detector. 00125 \param s The context. 00126 \param amp An array of signal samples. 00127 \param len The number of samples in the array. 00128 \return The number of unprocessed samples. 00129 */ 00130 int modem_connect_tones_rx(modem_connect_tones_rx_state_t *s, 00131 const int16_t amp[], 00132 int len); 00133 00134 /*! \brief Test if a modem_connect tone has been detected. 00135 \param s The context. 00136 \return TRUE if tone is detected, else FALSE. 00137 */ 00138 int modem_connect_tones_rx_get(modem_connect_tones_rx_state_t *s); 00139 00140 /*! \brief Initialise an instance of the modem_connect tones detector. 00141 \param s The context. 00142 \param tone_type The type of connect tone being tested for. 00143 \param tone_callback An optional callback routine, used to report tones 00144 \param user_data An opaque pointer passed to the callback routine, 00145 \return A pointer to the context. 00146 */ 00147 modem_connect_tones_rx_state_t *modem_connect_tones_rx_init(modem_connect_tones_rx_state_t *s, 00148 int tone_type, 00149 tone_report_func_t tone_callback, 00150 void *user_data); 00151 00152 #if defined(__cplusplus) 00153 } 00154 #endif 00155 00156 #endif 00157 /*- End of file ------------------------------------------------------------*/