spandsp: v22bis.h Source File

spandsp 0.0.6

private/v22bis.h
1/*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * private/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#if !defined(_SPANDSP_PRIVATE_V22BIS_H_)
27#define _SPANDSP_PRIVATE_V22BIS_H_
28
29/*! The number of steps to the left and to the right of the target position in the equalizer buffer. */
30#define V22BIS_EQUALIZER_LEN 7
31/*! One less than a power of 2 >= (2*V22BIS_EQUALIZER_LEN + 1) */
32#define V22BIS_EQUALIZER_MASK 15
33
34/*! The number of taps in the transmit pulse shaping filter */
35#define V22BIS_TX_FILTER_STEPS 9
36
37/*! The number of taps in the receive pulse shaping/bandpass filter */
38#define V22BIS_RX_FILTER_STEPS 27
39
40/*! Segments of the training sequence on the receive side */
41enum
42{
43 V22BIS_RX_TRAINING_STAGE_NORMAL_OPERATION,
44 V22BIS_RX_TRAINING_STAGE_SYMBOL_ACQUISITION,
45 V22BIS_RX_TRAINING_STAGE_LOG_PHASE,
46 V22BIS_RX_TRAINING_STAGE_UNSCRAMBLED_ONES,
47 V22BIS_RX_TRAINING_STAGE_UNSCRAMBLED_ONES_SUSTAINING,
48 V22BIS_RX_TRAINING_STAGE_SCRAMBLED_ONES_AT_1200,
49 V22BIS_RX_TRAINING_STAGE_SCRAMBLED_ONES_AT_1200_SUSTAINING,
50 V22BIS_RX_TRAINING_STAGE_WAIT_FOR_SCRAMBLED_ONES_AT_2400,
51 V22BIS_RX_TRAINING_STAGE_PARKED
52};
53
54/*! Segments of the training sequence on the transmit side */
55enum
56{
57 V22BIS_TX_TRAINING_STAGE_NORMAL_OPERATION = 0,
58 V22BIS_TX_TRAINING_STAGE_INITIAL_TIMED_SILENCE,
59 V22BIS_TX_TRAINING_STAGE_INITIAL_SILENCE,
60 V22BIS_TX_TRAINING_STAGE_U11,
61 V22BIS_TX_TRAINING_STAGE_U0011,
62 V22BIS_TX_TRAINING_STAGE_S11,
63 V22BIS_TX_TRAINING_STAGE_TIMED_S11,
64 V22BIS_TX_TRAINING_STAGE_S1111,
65 V22BIS_TX_TRAINING_STAGE_PARKED
66};
67
68/*!
69 V.22bis modem descriptor. This defines the working state for a single instance
70 of a V.22bis modem.
71*/
72 struct v22bis_state_s
73{
74 /*! \brief The maximum permitted bit rate of the modem. Valid values are 1200 and 2400. */
75 int bit_rate;
76 /*! \brief TRUE is this is the calling side modem. */
77 int calling_party;
78 /*! \brief The callback function used to get the next bit to be transmitted. */
79 get_bit_func_t get_bit;
80 /*! \brief A user specified opaque pointer passed to the get_bit callback routine. */
81 void *get_bit_user_data;
82 /*! \brief The callback function used to put each bit received. */
83 put_bit_func_t put_bit;
84 /*! \brief A user specified opaque pointer passed to the put_bit callback routine. */
85 void *put_bit_user_data;
86 /*! \brief The callback function used to report modem status changes. */
87 modem_status_func_t status_handler;
88 /*! \brief A user specified opaque pointer passed to the status function. */
89 void *status_user_data;
90
91 int negotiated_bit_rate;
92
93 /* Receive section */
94 struct
95 {
96 /*! \brief Current offset into the RRC pulse shaping filter buffer. */
97 int rrc_filter_step;
98
99 /*! \brief The register for the data scrambler. */
100 uint32_t scramble_reg;
101 /*! \brief A counter for the number of consecutive bits of repeating pattern through
102 the scrambler. */
103 int scrambler_pattern_count;
104
105 /*! \brief 0 if receiving user data. A training stage value during training */
106 int training;
107 /*! \brief A count of how far through the current training step we are. */
108 int training_count;
109
110 /*! \brief >0 if a signal above the minimum is present. It may or may not be a V.22bis signal. */
111 int signal_present;
112
113 /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
114 uint32_t carrier_phase;
115 /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
116 int32_t carrier_phase_rate;
117
118 /*! \brief A callback function which may be enabled to report every symbol's
119 constellation position. */
120 qam_report_handler_t qam_report;
121 /*! \brief A user specified opaque pointer passed to the qam_report callback
122 routine. */
123 void *qam_user_data;
124
125 /*! \brief A power meter, to measure the HPF'ed signal power in the channel. */
126 power_meter_t rx_power;
127 /*! \brief The power meter level at which carrier on is declared. */
128 int32_t carrier_on_power;
129 /*! \brief The power meter level at which carrier off is declared. */
130 int32_t carrier_off_power;
131
132 int constellation_state;
133
134#if defined(SPANDSP_USE_FIXED_POINTx)
135 /*! \brief The scaling factor accessed by the AGC algorithm. */
136 float agc_scaling;
137 /*! \brief The root raised cosine (RRC) pulse shaping filter buffer. */
138 int16_t rrc_filter[V22BIS_RX_FILTER_STEPS];
139
140 /*! \brief The current delta factor for updating the equalizer coefficients. */
141 float eq_delta;
142 /*! \brief The adaptive equalizer coefficients. */
143 complexi_t eq_coeff[2*V22BIS_EQUALIZER_LEN + 1];
144 /*! \brief The equalizer signal buffer. */
145 complexi_t eq_buf[V22BIS_EQUALIZER_MASK + 1];
146
147 /*! \brief A measure of how much mismatch there is between the real constellation,
148 and the decoded symbol positions. */
149 float training_error;
150 /*! \brief The proportional part of the carrier tracking filter. */
151 float carrier_track_p;
152 /*! \brief The integral part of the carrier tracking filter. */
153 float carrier_track_i;
154#else
155 /*! \brief The scaling factor accessed by the AGC algorithm. */
156 float agc_scaling;
157 /*! \brief The root raised cosine (RRC) pulse shaping filter buffer. */
158 float rrc_filter[V22BIS_RX_FILTER_STEPS];
159
160 /*! \brief The current delta factor for updating the equalizer coefficients. */
161 float eq_delta;
162 /*! \brief The adaptive equalizer coefficients. */
163 complexf_t eq_coeff[2*V22BIS_EQUALIZER_LEN + 1];
164 /*! \brief The equalizer signal buffer. */
165 complexf_t eq_buf[V22BIS_EQUALIZER_MASK + 1];
166
167 /*! \brief A measure of how much mismatch there is between the real constellation,
168 and the decoded symbol positions. */
169 float training_error;
170 /*! \brief The proportional part of the carrier tracking filter. */
171 float carrier_track_p;
172 /*! \brief The integral part of the carrier tracking filter. */
173 float carrier_track_i;
174#endif
175 /*! \brief Current offset into the equalizer buffer. */
176 int eq_step;
177 /*! \brief Current write offset into the equalizer buffer. */
178 int eq_put_step;
179
180 /*! \brief Integration variable for damping the Gardner algorithm tests. */
181 int gardner_integrate;
182 /*! \brief Current step size of Gardner algorithm integration. */
183 int gardner_step;
184 /*! \brief The total symbol timing correction since the carrier came up.
185 This is only for performance analysis purposes. */
186 int total_baud_timing_correction;
187 /*! \brief The current fractional phase of the baud timing. */
188 int baud_phase;
189
190 int sixteen_way_decisions;
191
192 int pattern_repeats;
193 int last_raw_bits;
194 } rx;
195
196 /* Transmit section */
197 struct
198 {
199#if defined(SPANDSP_USE_FIXED_POINTx)
200 /*! \brief The guard tone level. */
201 float guard_level;
202 /*! \brief The gain factor needed to achieve the specified output power. */
203 float gain;
204 /*! \brief The root raised cosine (RRC) pulse shaping filter buffer. */
205 complexf_t rrc_filter[2*V22BIS_TX_FILTER_STEPS];
206#else
207 /*! \brief The guard tone level. */
208 float guard_level;
209 /*! \brief The gain factor needed to achieve the specified output power. */
210 float gain;
211 /*! \brief The root raised cosine (RRC) pulse shaping filter buffer. */
212 complexf_t rrc_filter[2*V22BIS_TX_FILTER_STEPS];
213#endif
214 /*! \brief Current offset into the RRC pulse shaping filter buffer. */
215 int rrc_filter_step;
216
217 /*! \brief The register for the data scrambler. */
218 uint32_t scramble_reg;
219 /*! \brief A counter for the number of consecutive bits of repeating pattern through
220 the scrambler. */
221 int scrambler_pattern_count;
222
223 /*! \brief 0 if transmitting user data. A training stage value during training */
224 int training;
225 /*! \brief A counter used to track progress through sending the training sequence. */
226 int training_count;
227 /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
228 uint32_t carrier_phase;
229 /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
230 int32_t carrier_phase_rate;
231 /*! \brief The current phase of the guard tone (i.e. the DDS parameter). */
232 uint32_t guard_phase;
233 /*! \brief The update rate for the phase of the guard tone (i.e. the DDS increment). */
234 int32_t guard_phase_rate;
235 /*! \brief The current fractional phase of the baud timing. */
236 int baud_phase;
237 /*! \brief The code number for the current position in the constellation. */
238 int constellation_state;
239 /*! \brief An indicator to mark that we are tidying up to stop transmission. */
240 int shutdown;
241 /*! \brief The get_bit function in use at any instant. */
242 get_bit_func_t current_get_bit;
243 } tx;
244
245 /*! \brief Error and flow logging control */
246 logging_state_t logging;
247};
248
249#if defined(__cplusplus)
250extern "C"
251{
252#endif
253
254/*! Reinitialise an existing V.22bis modem receive context.
255 \brief Reinitialise an existing V.22bis modem receive context.
256 \param s The modem context.
257 \return 0 for OK, -1 for bad parameter */
258int v22bis_rx_restart(v22bis_state_t *s);
259
260void v22bis_report_status_change(v22bis_state_t *s, int status);
261
262void v22bis_equalizer_coefficient_reset(v22bis_state_t *s);
263
264#if defined(__cplusplus)
265}
266#endif
267
268#endif
269/*- End of file ------------------------------------------------------------*/
modem_status_func_t
void(* modem_status_func_t)(void *user_data, int status)
Definition async.h:114
put_bit_func_t
void(* put_bit_func_t)(void *user_data, int bit)
Definition async.h:105
get_bit_func_t
int(* get_bit_func_t)(void *user_data)
Definition async.h:108
complexf_t
Definition complex.h:43
complexi_t
Definition complex.h:78
logging_state_s
Definition private/logging.h:34
power_meter_t
Definition power_meter.h:49
v22bis_state_s
Definition private/v22bis.h:73
v22bis_state_s::logging
logging_state_t logging
Error and flow logging control.
Definition private/v22bis.h:246
v22bis_state_s::baud_phase
int baud_phase
The current fractional phase of the baud timing.
Definition private/v22bis.h:188
v22bis_state_s::bit_rate
int bit_rate
The maximum permitted bit rate of the modem. Valid values are 1200 and 2400.
Definition private/v22bis.h:75
v22bis_state_s::current_get_bit
get_bit_func_t current_get_bit
The get_bit function in use at any instant.
Definition private/v22bis.h:242
v22bis_state_s::eq_put_step
int eq_put_step
Current write offset into the equalizer buffer.
Definition private/v22bis.h:178
v22bis_state_s::rrc_filter
float rrc_filter[27]
The root raised cosine (RRC) pulse shaping filter buffer.
Definition private/v22bis.h:158
v22bis_state_s::qam_report
qam_report_handler_t qam_report
A callback function which may be enabled to report every symbol's constellation position.
Definition private/v22bis.h:120
v22bis_state_s::constellation_state
int constellation_state
The code number for the current position in the constellation.
Definition private/v22bis.h:132
v22bis_state_s::training_count
int training_count
A count of how far through the current training step we are.
Definition private/v22bis.h:108
v22bis_state_s::gain
float gain
The gain factor needed to achieve the specified output power.
Definition private/v22bis.h:210
v22bis_state_s::status_user_data
void * status_user_data
A user specified opaque pointer passed to the status function.
Definition private/v22bis.h:89
v22bis_state_s::eq_coeff
complexf_t eq_coeff[2 *7+1]
The adaptive equalizer coefficients.
Definition private/v22bis.h:163
v22bis_state_s::scrambler_pattern_count
int scrambler_pattern_count
A counter for the number of consecutive bits of repeating pattern through the scrambler.
Definition private/v22bis.h:103
v22bis_state_s::total_baud_timing_correction
int total_baud_timing_correction
The total symbol timing correction since the carrier came up. This is only for performance analysis p...
Definition private/v22bis.h:186
v22bis_state_s::qam_user_data
void * qam_user_data
A user specified opaque pointer passed to the qam_report callback routine.
Definition private/v22bis.h:123
v22bis_state_s::eq_buf
complexf_t eq_buf[15+1]
The equalizer signal buffer.
Definition private/v22bis.h:165
v22bis_state_s::shutdown
int shutdown
An indicator to mark that we are tidying up to stop transmission.
Definition private/v22bis.h:240
v22bis_state_s::put_bit_user_data
void * put_bit_user_data
A user specified opaque pointer passed to the put_bit callback routine.
Definition private/v22bis.h:85
v22bis_state_s::gardner_integrate
int gardner_integrate
Integration variable for damping the Gardner algorithm tests.
Definition private/v22bis.h:181
v22bis_state_s::eq_delta
float eq_delta
The current delta factor for updating the equalizer coefficients.
Definition private/v22bis.h:161
v22bis_state_s::training
int training
0 if receiving user data. A training stage value during training
Definition private/v22bis.h:106
v22bis_state_s::guard_phase
uint32_t guard_phase
The current phase of the guard tone (i.e. the DDS parameter).
Definition private/v22bis.h:232
v22bis_state_s::carrier_on_power
int32_t carrier_on_power
The power meter level at which carrier on is declared.
Definition private/v22bis.h:128
v22bis_state_s::rx_power
power_meter_t rx_power
A power meter, to measure the HPF'ed signal power in the channel.
Definition private/v22bis.h:126
v22bis_state_s::carrier_track_p
float carrier_track_p
The proportional part of the carrier tracking filter.
Definition private/v22bis.h:171
v22bis_state_s::calling_party
int calling_party
TRUE is this is the calling side modem.
Definition private/v22bis.h:77
v22bis_state_s::agc_scaling
float agc_scaling
The scaling factor accessed by the AGC algorithm.
Definition private/v22bis.h:156
v22bis_state_s::put_bit
put_bit_func_t put_bit
The callback function used to put each bit received.
Definition private/v22bis.h:83
v22bis_state_s::carrier_phase
uint32_t carrier_phase
The current phase of the carrier (i.e. the DDS parameter).
Definition private/v22bis.h:114
v22bis_state_s::signal_present
int signal_present
>0 if a signal above the minimum is present. It may or may not be a V.22bis signal.
Definition private/v22bis.h:111
v22bis_state_s::status_handler
modem_status_func_t status_handler
The callback function used to report modem status changes.
Definition private/v22bis.h:87
v22bis_state_s::guard_level
float guard_level
The guard tone level.
Definition private/v22bis.h:208
v22bis_state_s::eq_step
int eq_step
Current offset into the equalizer buffer.
Definition private/v22bis.h:176
v22bis_state_s::gardner_step
int gardner_step
Current step size of Gardner algorithm integration.
Definition private/v22bis.h:183
v22bis_state_s::scramble_reg
uint32_t scramble_reg
The register for the data scrambler.
Definition private/v22bis.h:100
v22bis_state_s::rrc_filter_step
int rrc_filter_step
Current offset into the RRC pulse shaping filter buffer.
Definition private/v22bis.h:97
v22bis_state_s::get_bit_user_data
void * get_bit_user_data
A user specified opaque pointer passed to the get_bit callback routine.
Definition private/v22bis.h:81
v22bis_state_s::guard_phase_rate
int32_t guard_phase_rate
The update rate for the phase of the guard tone (i.e. the DDS increment).
Definition private/v22bis.h:234
v22bis_state_s::carrier_phase_rate
int32_t carrier_phase_rate
The update rate for the phase of the carrier (i.e. the DDS increment).
Definition private/v22bis.h:116
v22bis_state_s::carrier_off_power
int32_t carrier_off_power
The power meter level at which carrier off is declared.
Definition private/v22bis.h:130
v22bis_state_s::get_bit
get_bit_func_t get_bit
The callback function used to get the next bit to be transmitted.
Definition private/v22bis.h:79
v22bis_state_s::training_error
float training_error
A measure of how much mismatch there is between the real constellation, and the decoded symbol positi...
Definition private/v22bis.h:169
v22bis_state_s::carrier_track_i
float carrier_track_i
The integral part of the carrier tracking filter.
Definition private/v22bis.h:173