spandsp 3.0.0
v22bis.h
Go to the documentation of this file.
1/*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * v22bis.h - ITU V.22bis modem
5 *
6 * Written by Steve Underwood <steveu@coppice.org>
7 *
8 * Copyright (C) 2004 Steve Underwood
9 *
10 * All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 2.1,
14 * as published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26/*! \file */
27
28/*! \page v22bis_page The V.22bis modem
29\section v22bis_page_sec_1 What does it do?
30The V.22bis modem is a duplex modem for general data use on the PSTN, at rates
31of 1200 and 2400 bits/second. It is a compatible extension of the V.22 modem,
32which is a 1200 bits/second only design. It is a band-split design, using carriers
33of 1200Hz and 2400Hz. It is the fastest PSTN modem in general use which does not
34use echo-cancellation.
35
36\section v22bis__page_sec_2 How does it work?
37V.22bis uses 4PSK modulation at 1200 bits/second or 16QAM modulation at 2400
38bits/second. At 1200bps the symbols are so long that a fixed compromise equaliser
39is sufficient to recover the 4PSK signal reliably. At 2400bps an adaptive
40equaliser is necessary.
41
42The V.22bis training sequence includes sections which allow the modems to determine
43if the far modem can support (or is willing to support) 2400bps operation. The
44modems will automatically use 2400bps if both ends are willing to use that speed,
45or 1200bps if one or both ends to not acknowledge that 2400bps is OK.
46*/
47
48#if !defined(_SPANDSP_V22BIS_H_)
49#define _SPANDSP_V22BIS_H_
50
51#if defined(SPANDSP_USE_FIXED_POINT)
52#define V22BIS_CONSTELLATION_SCALING_FACTOR 1024.0
53#else
54#define V22BIS_CONSTELLATION_SCALING_FACTOR 1.0
55#endif
56
57enum
58{
59 V22BIS_GUARD_TONE_NONE,
60 V22BIS_GUARD_TONE_550HZ,
61 V22BIS_GUARD_TONE_1800HZ
62};
63
64/*!
65 V.22bis modem descriptor. This defines the working state for a single instance
66 of a V.22bis modem.
67*/
69
70#if defined(__cplusplus)
71extern "C"
72{
73#endif
74
75/*! Process a block of received V.22bis modem audio samples.
76 \brief Process a block of received V.22bis modem audio samples.
77 \param s The modem context.
78 \param amp The audio sample buffer.
79 \param len The number of samples in the buffer.
80 \return The number of samples unprocessed. */
81SPAN_DECLARE(int) v22bis_rx(v22bis_state_t *s, const int16_t amp[], int len);
82
83/*! Fake processing of a missing block of received V.22bis modem audio samples.
84 (e.g due to packet loss).
85 \brief Fake processing of a missing block of received V.22bis modem audio samples.
86 \param s The modem context.
87 \param len The number of samples to fake.
88 \return The number of samples unprocessed. */
89SPAN_DECLARE(int) v22bis_rx_fillin(v22bis_state_t *s, int len);
90
91/*! Get a snapshot of the current equalizer coefficients.
92 \brief Get a snapshot of the current equalizer coefficients.
93 \param coeffs The vector of complex coefficients.
94 \return The number of coefficients in the vector. */
95#if defined(SPANDSP_USE_FIXED_POINT)
96SPAN_DECLARE(int) v22bis_rx_equalizer_state(v22bis_state_t *s, complexi16_t **coeffs);
97#else
98SPAN_DECLARE(int) v22bis_rx_equalizer_state(v22bis_state_t *s, complexf_t **coeffs);
99#endif
100
101/*! Get the current received carrier frequency.
102 \param s The modem context.
103 \return The frequency, in Hertz. */
104SPAN_DECLARE(float) v22bis_rx_carrier_frequency(v22bis_state_t *s);
105
106/*! Get the current symbol timing correction since startup.
107 \param s The modem context.
108 \return The correction. */
110
111/*! Get a current received signal power.
112 \param s The modem context.
113 \return The signal power, in dBm0. */
114SPAN_DECLARE(float) v22bis_rx_signal_power(v22bis_state_t *s);
115
116/*! Set the power level at which the carrier detection will cut in
117 \param s The modem context.
118 \param cutoff The signal cutoff power, in dBm0. */
119SPAN_DECLARE(void) v22bis_rx_signal_cutoff(v22bis_state_t *s, float cutoff);
120
121/*! Set a handler routine to process QAM status reports
122 \param s The modem context.
123 \param handler The handler routine.
124 \param user_data An opaque pointer passed to the handler routine. */
125SPAN_DECLARE(void) v22bis_rx_set_qam_report_handler(v22bis_state_t *s, qam_report_handler_t handler, void *user_data);
126
127/*! Generate a block of V.22bis modem audio samples.
128 \brief Generate a block of V.22bis modem audio samples.
129 \param s The modem context.
130 \param amp The audio sample buffer.
131 \param len The number of samples to be generated.
132 \return The number of samples actually generated. */
133SPAN_DECLARE(int) v22bis_tx(v22bis_state_t *s, int16_t amp[], int len);
134
135/*! Adjust a V.22bis modem transmit context's power output.
136 \brief Adjust a V.22bis modem transmit context's output power.
137 \param s The modem context.
138 \param power The power level, in dBm0 */
139SPAN_DECLARE(void) v22bis_tx_power(v22bis_state_t *s, float power);
140
141/*! Reinitialise an existing V.22bis modem context, so it may be reused.
142 \brief Reinitialise an existing V.22bis modem context.
143 \param s The modem context.
144 \param bit_rate The bit rate of the modem. Valid values are 1200 and 2400.
145 \return 0 for OK, -1 for bad parameter. */
146SPAN_DECLARE(int) v22bis_restart(v22bis_state_t *s, int bit_rate);
147
148/*! Request a retrain for a V.22bis modem context. A rate change may also be requested.
149 \brief Request a retrain for a V.22bis modem context.
150 \param s The modem context.
151 \param bit_rate The bit rate of the modem. Valid values are 1200 and 2400.
152 \return 0 for OK, -1 for request rejected. */
153SPAN_DECLARE(int) v22bis_request_retrain(v22bis_state_t *s, int bit_rate);
154
155/*! Request a loopback 2 for a V.22bis modem context.
156 \brief Request a loopback 2 for a V.22bis modem context.
157 \param s The modem context.
158 \param enable True to enable loopback, or false to disable it.
159 \return 0 for OK, -1 for request reject. */
160SPAN_DECLARE(int) v22bis_remote_loopback(v22bis_state_t *s, bool enable);
161
162/*! Report the current operating bit rate of a V.22bis modem context.
163 \brief Report the current operating bit rate of a V.22bis modem context
164 \param s The modem context. */
165SPAN_DECLARE(int) v22bis_get_current_bit_rate(v22bis_state_t *s);
166
167/*! Initialise a V.22bis modem context. This must be called before the first
168 use of the context, to initialise its contents.
169 \brief Initialise a V.22bis modem context.
170 \param s The modem context.
171 \param bit_rate The bit rate of the modem. Valid values are 1200 and 2400.
172 \param guard The guard tone option. 0 = none, 1 = 550Hz, 2 = 1800Hz.
173 \param calling_party True if this is the calling modem.
174 \param get_bit The callback routine used to get the data to be transmitted.
175 \param get_bit_user_data An opaque pointer, passed in calls to the get_bit routine.
176 \param put_bit The callback routine used to put the data received.
177 \param put_bit_user_data An opaque pointer, passed in calls to the put_bit routine.
178 \return A pointer to the modem context, or NULL if there was a problem. */
179SPAN_DECLARE(v22bis_state_t *) v22bis_init(v22bis_state_t *s,
180 int bit_rate,
181 int guard,
182 bool calling_party,
184 void *get_bit_user_data,
186 void *put_bit_user_data);
187
188/*! Release a V.22bis modem receive context.
189 \brief Release a V.22bis modem receive context.
190 \param s The modem context.
191 \return 0 for OK */
192SPAN_DECLARE(int) v22bis_release(v22bis_state_t *s);
193
194/*! Free a V.22bis modem receive context.
195 \brief Free a V.22bis modem receive context.
196 \param s The modem context.
197 \return 0 for OK */
198SPAN_DECLARE(int) v22bis_free(v22bis_state_t *s);
199
200/*! Get the logging context associated with a V.22bis modem context.
201 \brief Get the logging context associated with a V.22bis modem context.
202 \param s The modem context.
203 \return A pointer to the logging context */
205
206/*! Change the get_bit function associated with a V.22bis modem context.
207 \brief Change the get_bit function associated with a V.22bis modem context.
208 \param s The modem context.
209 \param get_bit The callback routine used to get the data to be transmitted.
210 \param user_data An opaque pointer. */
211SPAN_DECLARE(void) v22bis_set_get_bit(v22bis_state_t *s, get_bit_func_t get_bit, void *user_data);
212
213/*! Change the get_bit function associated with a V.22bis modem context.
214 \brief Change the put_bit function associated with a V.22bis modem context.
215 \param s The modem context.
216 \param put_bit The callback routine used to process the data received.
217 \param user_data An opaque pointer. */
218SPAN_DECLARE(void) v22bis_set_put_bit(v22bis_state_t *s, put_bit_func_t put_bit, void *user_data);
219
220/*! Change the modem status report function associated with a V.22bis modem receive context.
221 \brief Change the modem status report function associated with a V.22bis modem receive context.
222 \param s The modem context.
223 \param handler The callback routine used to report modem status changes.
224 \param user_data An opaque pointer. */
225SPAN_DECLARE(void) v22bis_set_modem_status_handler(v22bis_state_t *s, modem_status_func_t handler, void *user_data);
226
227#if defined(__cplusplus)
228}
229#endif
230
231#endif
232/*- End of file ------------------------------------------------------------*/
void(* modem_status_func_t)(void *user_data, int status)
Definition: async.h:113
void(* put_bit_func_t)(void *user_data, int bit)
Definition: async.h:107
int(* get_bit_func_t)(void *user_data)
Definition: async.h:110
Definition: complex.h:43
Definition: complex.h:89
Definition: private/logging.h:34
Definition: private/v22bis.h:79
int bit_rate
The maximum permitted bit rate of the modem. Valid values are 1200 and 2400.
Definition: private/v22bis.h:81
bool calling_party
True is this is the calling side modem.
Definition: private/v22bis.h:83
void * put_bit_user_data
A user specified opaque pointer passed to the put_bit callback routine.
Definition: private/v22bis.h:91
put_bit_func_t put_bit
The callback function used to put each bit received.
Definition: private/v22bis.h:89
void * get_bit_user_data
A user specified opaque pointer passed to the get_bit callback routine.
Definition: private/v22bis.h:87
get_bit_func_t get_bit
The callback function used to get the next bit to be transmitted.
Definition: private/v22bis.h:85
void v22bis_rx_signal_cutoff(v22bis_state_t *s, float cutoff)
Definition: v22bis_rx.c:157
v22bis_state_t * v22bis_init(v22bis_state_t *s, int bit_rate, int guard, bool calling_party, get_bit_func_t get_bit, void *get_bit_user_data, put_bit_func_t put_bit, void *put_bit_user_data)
Initialise a V.22bis modem context.
Definition: v22bis_tx.c:691
int v22bis_remote_loopback(v22bis_state_t *s, bool enable)
Request a loopback 2 for a V.22bis modem context.
Definition: v22bis_tx.c:678
void v22bis_tx_power(v22bis_state_t *s, float power)
Adjust a V.22bis modem transmit context's output power.
Definition: v22bis_tx.c:535
int v22bis_get_current_bit_rate(v22bis_state_t *s)
Report the current operating bit rate of a V.22bis modem context.
Definition: v22bis_tx.c:685
void v22bis_set_put_bit(v22bis_state_t *s, put_bit_func_t put_bit, void *user_data)
Change the put_bit function associated with a V.22bis modem context.
Definition: v22bis_tx.c:605
int v22bis_rx(v22bis_state_t *s, const int16_t amp[], int len)
Process a block of received V.22bis modem audio samples.
Definition: v22bis_rx.c:779
void v22bis_set_modem_status_handler(v22bis_state_t *s, modem_status_func_t handler, void *user_data)
Change the modem status report function associated with a V.22bis modem receive context.
Definition: v22bis_tx.c:612
float v22bis_rx_carrier_frequency(v22bis_state_t *s)
Definition: v22bis_rx.c:139
int v22bis_restart(v22bis_state_t *s, int bit_rate)
Reinitialise an existing V.22bis modem context.
Definition: v22bis_tx.c:625
int v22bis_free(v22bis_state_t *s)
Free a V.22bis modem receive context.
Definition: v22bis_tx.c:756
int v22bis_rx_fillin(v22bis_state_t *s, int len)
Fake processing of a missing block of received V.22bis modem audio samples.
Definition: v22bis_rx.c:922
void v22bis_set_get_bit(v22bis_state_t *s, get_bit_func_t get_bit, void *user_data)
Change the get_bit function associated with a V.22bis modem context.
Definition: v22bis_tx.c:598
int v22bis_release(v22bis_state_t *s)
Release a V.22bis modem receive context.
Definition: v22bis_tx.c:750
float v22bis_rx_signal_power(v22bis_state_t *s)
Definition: v22bis_rx.c:151
int v22bis_request_retrain(v22bis_state_t *s, int bit_rate)
Request a retrain for a V.22bis modem context.
Definition: v22bis_tx.c:643
int v22bis_tx(v22bis_state_t *s, int16_t amp[], int len)
Generate a block of V.22bis modem audio samples.
Definition: v22bis_tx.c:472
void v22bis_rx_set_qam_report_handler(v22bis_state_t *s, qam_report_handler_t handler, void *user_data)
Definition: v22bis_rx.c:996
float v22bis_rx_symbol_timing_correction(v22bis_state_t *s)
Definition: v22bis_rx.c:145
int v22bis_rx_equalizer_state(v22bis_state_t *s, complexf_t **coeffs)
Get a snapshot of the current equalizer coefficients.
Definition: v22bis_rx.c:176
logging_state_t * v22bis_get_logging_state(v22bis_state_t *s)
Get the logging context associated with a V.22bis modem context.
Definition: v22bis_tx.c:619