spandsp  0.0.6
modem_connect_tones.h
Go to the documentation of this file.
1 /*
2  * SpanDSP - a series of DSP components for telephony
3  *
4  * modem_connect_tones.c - Generation and detection of tones
5  * associated with modems calling and
6  * answering calls.
7  *
8  * Written by Steve Underwood <steveu@coppice.org>
9  *
10  * Copyright (C) 2006 Steve Underwood
11  *
12  * All rights reserved.
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU Lesser General Public License version 2.1,
16  * as published by the Free Software Foundation.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public
24  * License along with this program; if not, write to the Free Software
25  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26  */
27 
28 /*! \file */
29 
30 #if !defined(_SPANDSP_MODEM_CONNECT_TONES_H_)
31 #define _SPANDSP_MODEM_CONNECT_TONES_H_
32 
33 /*! \page modem_connect_tones_page Modem connect tone detection
34 
35 \section modem_connect_tones_page_sec_1 What does it do?
36 Some telephony terminal equipment, such as modems, require a channel which is as
37 clear as possible. They use their own echo cancellation. If the network is also
38 performing echo cancellation the two cancellors can end up squabbling about the
39 nature of the channel, with bad results. A special tone is defined which should
40 cause the network to disable any echo cancellation processes. This is the echo
41 canceller disable tone.
42 
43 The tone detector's design assumes the channel is free of any DC component.
44 
45 \section modem_connect_tones_page_sec_2 How does it work?
46 A sharp notch filter is implemented as a single bi-quad section. The presence of
47 the 2100Hz disable tone is detected by comparing the notched filtered energy
48 with the unfiltered energy. If the notch filtered energy is much lower than the
49 unfiltered energy, then a large proportion of the energy must be at the notch
50 frequency. This type of detector may seem less intuitive than using a narrow
51 bandpass filter to isolate the energy at the notch freqency. However, a sharp
52 bandpass implemented as an IIR filter rings badly. The reciprocal notch filter
53 is very well behaved for our purpose.
54 */
55 
56 enum
57 {
58  /*! \brief This is reported when a tone stops. */
60  /*! \brief CNG tone is a pure 1100Hz tone, in 0.5s bursts, with 3s silences in between. The
61  bursts repeat for as long as is required. */
63  /*! \brief ANS tone is a pure continuous 2100Hz+-15Hz tone for 3.3s+-0.7s. */
65  /*! \brief ANS with phase reversals tone is a 2100Hz+-15Hz tone for 3.3s+-0.7s, with a 180 degree
66  phase jump every 450ms+-25ms. */
68  /*! \brief The ANSam tone is a version of ANS with 20% of 15Hz+-0.1Hz AM modulation, as per V.8 */
70  /*! \brief The ANSam with phase reversals tone is a version of ANS_PR with 20% of 15Hz+-0.1Hz AM
71  modulation, as per V.8 */
73  /*! \brief FAX preamble in a string of V.21 HDLC flag octets. */
75  /*! \brief CED tone is the same as ANS tone. FAX preamble in a string of V.21 HDLC flag octets.
76  This is only valid as a tone type to receive. It is never reported as a detected tone
77  type. The report will either be for FAX preamble or CED/ANS tone. */
79 };
80 
81 /*! \brief FAX CED tone is the same as ANS tone. */
82 #define MODEM_CONNECT_TONES_FAX_CED MODEM_CONNECT_TONES_ANS
83 
84 /*!
85  Modem connect tones generator descriptor. This defines the state
86  of a single working instance of the tone generator.
87 */
89 
90 /*!
91  Modem connect tones receiver descriptor. This defines the state
92  of a single working instance of the tone detector.
93 */
95 
96 #if defined(__cplusplus)
97 extern "C"
98 {
99 #endif
100 
101 /*! \brief Initialise an instance of the modem connect tones generator.
102  \param s The context.
103 */
105  int tone_type);
106 
107 /*! \brief Release an instance of the modem connect tones generator.
108  \param s The context.
109  \return 0 for OK, else -1.
110 */
112 
113 /*! \brief Free an instance of the modem connect tones generator.
114  \param s The context.
115  \return 0 for OK, else -1.
116 */
118 
119 /*! \brief Generate a block of modem connect tones samples.
120  \param s The context.
121  \param amp An array of signal samples.
122  \param len The number of samples to generate.
123  \return The number of samples generated.
124 */
125 SPAN_DECLARE_NONSTD(int) modem_connect_tones_tx(modem_connect_tones_tx_state_t *s,
126  int16_t amp[],
127  int len);
128 
129 /*! \brief Process a block of samples through an instance of the modem connect
130  tones detector.
131  \param s The context.
132  \param amp An array of signal samples.
133  \param len The number of samples in the array.
134  \return The number of unprocessed samples.
135 */
136 SPAN_DECLARE_NONSTD(int) modem_connect_tones_rx(modem_connect_tones_rx_state_t *s,
137  const int16_t amp[],
138  int len);
139 
140 /*! \brief Test if a modem_connect tone has been detected.
141  \param s The context.
142  \return TRUE if tone is detected, else FALSE.
143 */
145 
146 /*! \brief Initialise an instance of the modem connect tones detector.
147  \param s The context.
148  \param tone_type The type of connect tone being tested for.
149  \param tone_callback An optional callback routine, used to report tones
150  \param user_data An opaque pointer passed to the callback routine,
151  \return A pointer to the context.
152 */
154  int tone_type,
155  tone_report_func_t tone_callback,
156  void *user_data);
157 
158 /*! \brief Release an instance of the modem connect tones detector.
159  \param s The context.
160  \return 0 for OK, else -1. */
162 
163 /*! \brief Free an instance of the modem connect tones detector.
164  \param s The context.
165  \return 0 for OK, else -1. */
167 
168 SPAN_DECLARE(const char *) modem_connect_tone_to_str(int tone);
169 
170 #if defined(__cplusplus)
171 }
172 #endif
173 
174 #endif
175 /*- End of file ------------------------------------------------------------*/