00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * ec_disable_tone.h - A detector which should eventually meet the 00005 * G.164/G.165 requirements for detecting the 00006 * 2100Hz echo cancellor disable tone. 00007 * 00008 * Written by Steve Underwood <steveu@coppice.org> 00009 * 00010 * Copyright (C) 2001 Steve Underwood 00011 * 00012 * All rights reserved. 00013 * 00014 * This program is free software; you can redistribute it and/or modify 00015 * it under the terms of the GNU General Public License as published by 00016 * the Free Software Foundation; either version 2 of the License, or 00017 * (at your option) any later version. 00018 * 00019 * This program is distributed in the hope that it will be useful, 00020 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 * GNU General Public License for more details. 00023 * 00024 * You should have received a copy of the GNU General Public License 00025 * along with this program; if not, write to the Free Software 00026 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00027 * 00028 * $Id: ec_disable_tone.h,v 1.2 2005/11/25 14:52:00 steveu Exp $ 00029 */ 00030 00031 /*! \file */ 00032 00033 #if !defined(_EC_DISABLE_TONE_H_) 00034 #define _EC_DISABLE_TONE_H_ 00035 00036 /*! \page echo_can_disable_page Echo cancellor disable tone detection 00037 00038 \section echo_can_disable_page_sec_1 What does it do? 00039 Some telephony terminal equipment, such as modems, require a channel which is as 00040 clear as possible. They use their own echo cancellation. If the network is also 00041 performing echo cancellation the two cancellors can end of squabbling about the 00042 nature of the channel, with bad results. A special tone is defined which should 00043 cause the network to disable any echo cancellation processes. 00044 00045 \section echo_can_disable_page_sec_2 How does it work? 00046 A sharp notch filter is implemented as a single bi-quad section. The presence of 00047 the 2100Hz disable tone is detected by comparing the notched filtered energy 00048 with the unfiltered energy. If the notch filtered energy is much lower than the 00049 unfiltered energy, then a large proportion of the energy must be at the notch 00050 frequency. This type of detector may seem less intuitive than using a narrow 00051 bandpass filter to isolate the energy at the notch freqency. However, a sharp 00052 bandpass implemented as an IIR filter rings badly, The reciprocal notch filter 00053 is very well behaved. 00054 */ 00055 00056 /*! 00057 Echo canceller disable tone generator descriptor. This defines the state 00058 of a single working instance of the tone generator. 00059 */ 00060 typedef struct 00061 { 00062 /*! \brief TRUE if we are generating the version with some 15Hz AM content, 00063 as in V.8 */ 00064 int with_am; 00065 00066 uint32_t tone_phase; 00067 int32_t tone_phase_rate; 00068 int level; 00069 /*! \brief Countdown to the next phase hop */ 00070 int hop_timer; 00071 uint32_t mod_phase; 00072 int32_t mod_phase_rate; 00073 int mod_level; 00074 } echo_can_disable_tx_state_t; 00075 00076 /*! 00077 Echo canceller disable tone receiver descriptor. This defines the state 00078 of a single working instance of the tone detector. 00079 */ 00080 typedef struct 00081 { 00082 biquad2_state_t notch; 00083 int notch_level; 00084 int channel_level; 00085 int tone_present; 00086 int tone_cycle_duration; 00087 int good_cycles; 00088 int hit; 00089 } echo_can_disable_rx_state_t; 00090 00091 #ifdef __cplusplus 00092 extern "C" { 00093 #endif 00094 00095 /*! \brief Initialse an instance of the echo canceller disable tone generator. 00096 \param s The context. 00097 */ 00098 void echo_can_disable_tone_tx_init(echo_can_disable_tx_state_t *s, int with_am); 00099 00100 /*! \brief Generate a block of echo canceller disable tone samples. 00101 \param s The context. 00102 \param amp An array of signal samples. 00103 \param len The number of samples to generate. 00104 \return The number of samples generated. 00105 */ 00106 int echo_can_disable_tone_tx(echo_can_disable_tx_state_t *s, 00107 int16_t *amp, 00108 int len); 00109 00110 /*! \brief Initialse an instance of the echo canceller disable tone detector. 00111 \param s The context. 00112 */ 00113 void echo_can_disable_tone_rx_init(echo_can_disable_rx_state_t *s); 00114 00115 /*! \brief Process a block of samples through an instance of the echo canceller 00116 disable tone detector. 00117 \param s The context. 00118 \param amp An array of signal samples. 00119 \param len The number of samples in the array. 00120 \return The number of unprocessed samples. 00121 */ 00122 int echo_can_disable_tone_rx(echo_can_disable_rx_state_t *s, 00123 const int16_t *amp, 00124 int len); 00125 00126 #ifdef __cplusplus 00127 } 00128 #endif 00129 00130 #endif 00131 /*- End of file ------------------------------------------------------------*/