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 */
41 enum
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 */
55 enum
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 */
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. */
78  /*! \brief The callback function used to get the next bit to be transmitted. */
80  /*! \brief A user specified opaque pointer passed to the get_bit callback routine. */
82  /*! \brief The callback function used to put each bit received. */
84  /*! \brief A user specified opaque pointer passed to the put_bit callback routine. */
86  /*! \brief The callback function used to report modem status changes. */
88  /*! \brief A user specified opaque pointer passed to the status function. */
90 
91  int negotiated_bit_rate;
92 
93  /* Receive section */
94  struct
95  {
96  /*! \brief Current offset into the RRC pulse shaping filter buffer. */
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. */
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. */
109 
110  /*! \brief >0 if a signal above the minimum is present. It may or may not be a V.22bis signal. */
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). */
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. */
124 
125  /*! \brief A power meter, to measure the HPF'ed signal power in the channel. */
127  /*! \brief The power meter level at which carrier on is declared. */
129  /*! \brief The power meter level at which carrier off is declared. */
131 
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. */
170  /*! \brief The proportional part of the carrier tracking filter. */
172  /*! \brief The integral part of the carrier tracking filter. */
174 #endif
175  /*! \brief Current offset into the equalizer buffer. */
176  int eq_step;
177  /*! \brief Current write offset into the equalizer buffer. */
179 
180  /*! \brief Integration variable for damping the Gardner algorithm tests. */
182  /*! \brief Current step size of Gardner algorithm integration. */
184  /*! \brief The total symbol timing correction since the carrier came up.
185  This is only for performance analysis purposes. */
187  /*! \brief The current fractional phase of the baud timing. */
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. */
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). */
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. */
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. */
243  } tx;
244 
245  /*! \brief Error and flow logging control */
247 };
248 
249 #if defined(__cplusplus)
250 extern "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 */
259 
260 void v22bis_report_status_change(v22bis_state_t *s, int status);
261 
262 void v22bis_equalizer_coefficient_reset(v22bis_state_t *s);
263 
264 #if defined(__cplusplus)
265 }
266 #endif
267 
268 #endif
269 /*- End of file ------------------------------------------------------------*/
power_meter_t rx_power
A power meter, to measure the HPF&#39;ed signal power in the channel.
Definition: private/v22bis.h:126
float eq_delta
The current delta factor for updating the equalizer coefficients.
Definition: private/v22bis.h:161
qam_report_handler_t qam_report
A callback function which may be enabled to report every symbol&#39;s constellation position.
Definition: private/v22bis.h:120
int shutdown
An indicator to mark that we are tidying up to stop transmission.
Definition: private/v22bis.h:240
uint32_t scramble_reg
The register for the data scrambler.
Definition: private/v22bis.h:100
float gain
The gain factor needed to achieve the specified output power.
Definition: private/v22bis.h:210
int32_t carrier_on_power
The power meter level at which carrier on is declared.
Definition: private/v22bis.h:128
int scrambler_pattern_count
A counter for the number of consecutive bits of repeating pattern through the scrambler.
Definition: private/v22bis.h:103
logging_state_t logging
Error and flow logging control.
Definition: private/v22bis.h:246
complexf_t eq_coeff[2 *7+1]
The adaptive equalizer coefficients.
Definition: private/v22bis.h:163
uint32_t carrier_phase
The current phase of the carrier (i.e. the DDS parameter).
Definition: private/v22bis.h:114
int gardner_step
Current step size of Gardner algorithm integration.
Definition: private/v22bis.h:183
complexf_t eq_buf[15+1]
The equalizer signal buffer.
Definition: private/v22bis.h:165
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
int bit_rate
The maximum permitted bit rate of the modem. Valid values are 1200 and 2400.
Definition: private/v22bis.h:75
int32_t carrier_off_power
The power meter level at which carrier off is declared.
Definition: private/v22bis.h:130
int gardner_integrate
Integration variable for damping the Gardner algorithm tests.
Definition: private/v22bis.h:181
get_bit_func_t current_get_bit
The get_bit function in use at any instant.
Definition: private/v22bis.h:242
put_bit_func_t put_bit
The callback function used to put each bit received.
Definition: private/v22bis.h:83
float carrier_track_p
The proportional part of the carrier tracking filter.
Definition: private/v22bis.h:171
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
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
Definition: complex.h:77
void(* put_bit_func_t)(void *user_data, int bit)
Definition: async.h:105
int training_count
A count of how far through the current training step we are.
Definition: private/v22bis.h:108
modem_status_func_t status_handler
The callback function used to report modem status changes.
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:79
void * status_user_data
A user specified opaque pointer passed to the status function.
Definition: private/v22bis.h:89
void(* modem_status_func_t)(void *user_data, int status)
Definition: async.h:114
int(* get_bit_func_t)(void *user_data)
Definition: async.h:108
int training
0 if receiving user data. A training stage value during training
Definition: private/v22bis.h:106
int v22bis_rx_restart(v22bis_state_t *s)
Reinitialise an existing V.22bis modem receive context.
Definition: v22bis_rx.c:835
float carrier_track_i
The integral part of the carrier tracking filter.
Definition: private/v22bis.h:173
void * get_bit_user_data
A user specified opaque pointer passed to the get_bit callback routine.
Definition: private/v22bis.h:81
uint32_t guard_phase
The current phase of the guard tone (i.e. the DDS parameter).
Definition: private/v22bis.h:232
void * qam_user_data
A user specified opaque pointer passed to the qam_report callback routine.
Definition: private/v22bis.h:123
void * put_bit_user_data
A user specified opaque pointer passed to the put_bit callback routine.
Definition: private/v22bis.h:85
Definition: complex.h:42
int calling_party
TRUE is this is the calling side modem.
Definition: private/v22bis.h:77
int rrc_filter_step
Current offset into the RRC pulse shaping filter buffer.
Definition: private/v22bis.h:97
Definition: private/logging.h:33
int baud_phase
The current fractional phase of the baud timing.
Definition: private/v22bis.h:188
Definition: private/v22bis.h:72
int constellation_state
The code number for the current position in the constellation.
Definition: private/v22bis.h:132
float rrc_filter[27]
The root raised cosine (RRC) pulse shaping filter buffer.
Definition: private/v22bis.h:158
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
float agc_scaling
The scaling factor accessed by the AGC algorithm.
Definition: private/v22bis.h:156
Definition: power_meter.h:48
int32_t carrier_phase_rate
The update rate for the phase of the carrier (i.e. the DDS increment).
Definition: private/v22bis.h:116
float guard_level
The guard tone level.
Definition: private/v22bis.h:208
int eq_put_step
Current write offset into the equalizer buffer.
Definition: private/v22bis.h:178
int eq_step
Current offset into the equalizer buffer.
Definition: private/v22bis.h:176