spandsp: modem_connect_tones.h Source File

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?
36Some telephony terminal equipment, such as modems, require a channel which is as
37clear as possible. They use their own echo cancellation. If the network is also
38performing echo cancellation the two cancellors can end up squabbling about the
39nature of the channel, with bad results. A special tone is defined which should
40cause the network to disable any echo cancellation processes. This is the echo
41canceller disable tone.
42
43The 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?
46A sharp notch filter is implemented as a single bi-quad section. The presence of
47the 2100Hz disable tone is detected by comparing the notched filtered energy
48with the unfiltered energy. If the notch filtered energy is much lower than the
49unfiltered energy, then a large proportion of the energy must be at the notch
50frequency. This type of detector may seem less intuitive than using a narrow
51bandpass filter to isolate the energy at the notch freqency. However, a sharp
52bandpass implemented as an IIR filter rings badly. The reciprocal notch filter
53is very well behaved for our purpose.
54*/
55
56enum
57{
58 /*! \brief This is reported when a tone stops. */
59 MODEM_CONNECT_TONES_NONE = 0,
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. */
62 MODEM_CONNECT_TONES_FAX_CNG = 1,
63 /*! \brief ANS tone is a pure continuous 2100Hz+-15Hz tone for 3.3s+-0.7s. */
64 MODEM_CONNECT_TONES_ANS = 2,
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. */
67 MODEM_CONNECT_TONES_ANS_PR = 3,
68 /*! \brief The ANSam tone is a version of ANS with 20% of 15Hz+-0.1Hz AM modulation, as per V.8 */
69 MODEM_CONNECT_TONES_ANSAM = 4,
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 */
72 MODEM_CONNECT_TONES_ANSAM_PR = 5,
73 /*! \brief FAX preamble in a string of V.21 HDLC flag octets. */
74 MODEM_CONNECT_TONES_FAX_PREAMBLE = 6,
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. */
78 MODEM_CONNECT_TONES_FAX_CED_OR_PREAMBLE = 7,
79 /*! \brief Bell ANS tone is a pure continuous 2225Hz+-15Hz tone for 3.3s+-0.7s. */
80 MODEM_CONNECT_TONES_BELL_ANS = 8,
81 /*! \brief Calling tone is a pure 1300Hz tone, in 0.6s bursts, with 2s silences in between. The
82 bursts repeat for as long as is required. */
83 MODEM_CONNECT_TONES_CALLING_TONE = 9
84};
85
86/*! \brief FAX CED tone is the same as ANS tone. */
87#define MODEM_CONNECT_TONES_FAX_CED MODEM_CONNECT_TONES_ANS
88
89/*!
90 Modem connect tones generator descriptor. This defines the state
91 of a single working instance of the tone generator.
92*/
93 typedef struct modem_connect_tones_tx_state_s modem_connect_tones_tx_state_t;
94
95/*!
96 Modem connect tones receiver descriptor. This defines the state
97 of a single working instance of the tone detector.
98*/
99 typedef struct modem_connect_tones_rx_state_s modem_connect_tones_rx_state_t;
100
101#if defined(__cplusplus)
102extern "C"
103{
104#endif
105
106/*! \brief Initialise an instance of the modem connect tones generator.
107 \param s The context.
108*/
109SPAN_DECLARE(modem_connect_tones_tx_state_t *) modem_connect_tones_tx_init(modem_connect_tones_tx_state_t *s,
110 int tone_type);
111
112/*! \brief Release an instance of the modem connect tones generator.
113 \param s The context.
114 \return 0 for OK, else -1.
115*/
116SPAN_DECLARE(int) modem_connect_tones_tx_release(modem_connect_tones_tx_state_t *s);
117
118/*! \brief Free an instance of the modem connect tones generator.
119 \param s The context.
120 \return 0 for OK, else -1.
121*/
122SPAN_DECLARE(int) modem_connect_tones_tx_free(modem_connect_tones_tx_state_t *s);
123
124/*! \brief Generate a block of modem connect tones samples.
125 \param s The context.
126 \param amp An array of signal samples.
127 \param len The number of samples to generate.
128 \return The number of samples generated.
129*/
130SPAN_DECLARE_NONSTD(int) modem_connect_tones_tx(modem_connect_tones_tx_state_t *s,
131 int16_t amp[],
132 int len);
133
134/*! \brief Process a block of samples through an instance of the modem connect
135 tones detector.
136 \param s The context.
137 \param amp An array of signal samples.
138 \param len The number of samples in the array.
139 \return The number of unprocessed samples.
140*/
141SPAN_DECLARE_NONSTD(int) modem_connect_tones_rx(modem_connect_tones_rx_state_t *s,
142 const int16_t amp[],
143 int len);
144
145/*! \brief Test if a modem_connect tone has been detected.
146 \param s The context.
147 \return TRUE if tone is detected, else FALSE.
148*/
149SPAN_DECLARE(int) modem_connect_tones_rx_get(modem_connect_tones_rx_state_t *s);
150
151/*! \brief Initialise an instance of the modem connect tones detector.
152 \param s The context.
153 \param tone_type The type of connect tone being tested for.
154 \param tone_callback An optional callback routine, used to report tones
155 \param user_data An opaque pointer passed to the callback routine,
156 \return A pointer to the context.
157*/
158SPAN_DECLARE(modem_connect_tones_rx_state_t *) modem_connect_tones_rx_init(modem_connect_tones_rx_state_t *s,
159 int tone_type,
160 tone_report_func_t tone_callback,
161 void *user_data);
162
163/*! \brief Release an instance of the modem connect tones detector.
164 \param s The context.
165 \return 0 for OK, else -1. */
166SPAN_DECLARE(int) modem_connect_tones_rx_release(modem_connect_tones_rx_state_t *s);
167
168/*! \brief Free an instance of the modem connect tones detector.
169 \param s The context.
170 \return 0 for OK, else -1. */
171SPAN_DECLARE(int) modem_connect_tones_rx_free(modem_connect_tones_rx_state_t *s);
172
173SPAN_DECLARE(const char *) modem_connect_tone_to_str(int tone);
174
175#if defined(__cplusplus)
176}
177#endif
178
179#endif
180/*- End of file ------------------------------------------------------------*/
modem_connect_tones_rx_init
modem_connect_tones_rx_state_t * modem_connect_tones_rx_init(modem_connect_tones_rx_state_t *s, int tone_type, tone_report_func_t tone_callback, void *user_data)
Initialise an instance of the modem connect tones detector.
Definition modem_connect_tones.c:706
modem_connect_tones_tx_free
int modem_connect_tones_tx_free(modem_connect_tones_tx_state_t *s)
Free an instance of the modem connect tones generator.
Definition modem_connect_tones.c:357
modem_connect_tones_rx_get
int modem_connect_tones_rx_get(modem_connect_tones_rx_state_t *s)
Test if a modem_connect tone has been detected.
Definition modem_connect_tones.c:696
modem_connect_tones_tx_release
int modem_connect_tones_tx_release(modem_connect_tones_tx_state_t *s)
Release an instance of the modem connect tones generator.
Definition modem_connect_tones.c:351
modem_connect_tones_rx_free
int modem_connect_tones_rx_free(modem_connect_tones_rx_state_t *s)
Free an instance of the modem connect tones detector.
Definition modem_connect_tones.c:760
modem_connect_tones_tx_init
modem_connect_tones_tx_state_t * modem_connect_tones_tx_init(modem_connect_tones_tx_state_t *s, int tone_type)
Initialise an instance of the modem connect tones generator.
Definition modem_connect_tones.c:253
modem_connect_tones_rx_release
int modem_connect_tones_rx_release(modem_connect_tones_rx_state_t *s)
Release an instance of the modem connect tones detector.
Definition modem_connect_tones.c:754
MODEM_CONNECT_TONES_NONE
@ MODEM_CONNECT_TONES_NONE
This is reported when a tone stops.
Definition modem_connect_tones.h:59
MODEM_CONNECT_TONES_CALLING_TONE
@ MODEM_CONNECT_TONES_CALLING_TONE
Calling tone is a pure 1300Hz tone, in 0.6s bursts, with 2s silences in between. The bursts repeat fo...
Definition modem_connect_tones.h:83
MODEM_CONNECT_TONES_BELL_ANS
@ MODEM_CONNECT_TONES_BELL_ANS
Bell ANS tone is a pure continuous 2225Hz+-15Hz tone for 3.3s+-0.7s.
Definition modem_connect_tones.h:80
MODEM_CONNECT_TONES_ANS
@ MODEM_CONNECT_TONES_ANS
ANS tone is a pure continuous 2100Hz+-15Hz tone for 3.3s+-0.7s.
Definition modem_connect_tones.h:64
MODEM_CONNECT_TONES_ANSAM
@ MODEM_CONNECT_TONES_ANSAM
The ANSam tone is a version of ANS with 20% of 15Hz+-0.1Hz AM modulation, as per V....
Definition modem_connect_tones.h:69
MODEM_CONNECT_TONES_FAX_CNG
@ MODEM_CONNECT_TONES_FAX_CNG
CNG tone is a pure 1100Hz tone, in 0.5s bursts, with 3s silences in between. The bursts repeat for as...
Definition modem_connect_tones.h:62
MODEM_CONNECT_TONES_FAX_CED_OR_PREAMBLE
@ MODEM_CONNECT_TONES_FAX_CED_OR_PREAMBLE
CED tone is the same as ANS tone. FAX preamble in a string of V.21 HDLC flag octets....
Definition modem_connect_tones.h:78
MODEM_CONNECT_TONES_ANS_PR
@ MODEM_CONNECT_TONES_ANS_PR
ANS with phase reversals tone is a 2100Hz+-15Hz tone for 3.3s+-0.7s, with a 180 degree phase jump eve...
Definition modem_connect_tones.h:67
MODEM_CONNECT_TONES_FAX_PREAMBLE
@ MODEM_CONNECT_TONES_FAX_PREAMBLE
FAX preamble in a string of V.21 HDLC flag octets.
Definition modem_connect_tones.h:74
MODEM_CONNECT_TONES_ANSAM_PR
@ MODEM_CONNECT_TONES_ANSAM_PR
The ANSam with phase reversals tone is a version of ANS_PR with 20% of 15Hz+-0.1Hz AM modulation,...
Definition modem_connect_tones.h:72
modem_connect_tones_rx_state_s
Definition private/modem_connect_tones.h:58
modem_connect_tones_rx_state_s::tone_callback
tone_report_func_t tone_callback
Callback routine, using to report detection of the tone.
Definition private/modem_connect_tones.h:62
modem_connect_tones_rx_state_s::tone_type
int tone_type
The tone type being detected.
Definition private/modem_connect_tones.h:60
modem_connect_tones_tx_state_s
Definition private/modem_connect_tones.h:38