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 The route raised cosine (RRC) pulse shaping filter buffer. */
97 #if defined(SPANDSP_USE_FIXED_POINTx)
98  int16_t rrc_filter[V22BIS_RX_FILTER_STEPS];
99 #else
100  float rrc_filter[V22BIS_RX_FILTER_STEPS];
101 #endif
102  /*! \brief Current offset into the RRC pulse shaping filter buffer. */
104 
105  /*! \brief The register for the data scrambler. */
106  uint32_t scramble_reg;
107  /*! \brief A counter for the number of consecutive bits of repeating pattern through
108  the scrambler. */
110 
111  /*! \brief 0 if receiving user data. A training stage value during training */
112  int training;
113  /*! \brief A count of how far through the current training step we are. */
115 
116  /*! \brief >0 if a signal above the minimum is present. It may or may not be a V.22bis signal. */
118 
119  /*! \brief A measure of how much mismatch there is between the real constellation,
120  and the decoded symbol positions. */
122 
123  /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
124  uint32_t carrier_phase;
125  /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
127  /*! \brief The proportional part of the carrier tracking filter. */
129  /*! \brief The integral part of the carrier tracking filter. */
131 
132  /*! \brief A callback function which may be enabled to report every symbol's
133  constellation position. */
134  qam_report_handler_t qam_report;
135  /*! \brief A user specified opaque pointer passed to the qam_report callback
136  routine. */
138 
139  /*! \brief A power meter, to measure the HPF'ed signal power in the channel. */
141  /*! \brief The power meter level at which carrier on is declared. */
143  /*! \brief The power meter level at which carrier off is declared. */
145  /*! \brief The scaling factor accessed by the AGC algorithm. */
146  float agc_scaling;
147 
149 
150  /*! \brief The current delta factor for updating the equalizer coefficients. */
151  float eq_delta;
152 #if defined(SPANDSP_USE_FIXED_POINTx)
153  /*! \brief The adaptive equalizer coefficients. */
154  complexi_t eq_coeff[2*V22BIS_EQUALIZER_LEN + 1];
155  /*! \brief The equalizer signal buffer. */
156  complexi_t eq_buf[V22BIS_EQUALIZER_MASK + 1];
157 #else
158  complexf_t eq_coeff[2*V22BIS_EQUALIZER_LEN + 1];
159  complexf_t eq_buf[V22BIS_EQUALIZER_MASK + 1];
160 #endif
161  /*! \brief Current offset into the equalizer buffer. */
162  int eq_step;
163  /*! \brief Current write offset into the equalizer buffer. */
165 
166  /*! \brief Integration variable for damping the Gardner algorithm tests. */
168  /*! \brief Current step size of Gardner algorithm integration. */
170  /*! \brief The total symbol timing correction since the carrier came up.
171  This is only for performance analysis purposes. */
173  /*! \brief The current fractional phase of the baud timing. */
175 
176  int sixteen_way_decisions;
177 
178  int pattern_repeats;
179  int last_raw_bits;
180  } rx;
181 
182  /* Transmit section */
183  struct
184  {
185  /*! \brief The gain factor needed to achieve the specified output power. */
186  float gain;
187 
188  /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
189  complexf_t rrc_filter[2*V22BIS_TX_FILTER_STEPS];
190  /*! \brief Current offset into the RRC pulse shaping filter buffer. */
191  int rrc_filter_step;
192 
193  /*! \brief The register for the data scrambler. */
194  unsigned int scramble_reg;
195  /*! \brief A counter for the number of consecutive bits of repeating pattern through
196  the scrambler. */
198 
199  /*! \brief 0 if transmitting user data. A training stage value during training */
200  int training;
201  /*! \brief A counter used to track progress through sending the training sequence. */
202  int training_count;
203  /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
204  uint32_t carrier_phase;
205  /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
206  int32_t carrier_phase_rate;
207  /*! \brief The current phase of the guard tone (i.e. the DDS parameter). */
208  uint32_t guard_phase;
209  /*! \brief The update rate for the phase of the guard tone (i.e. the DDS increment). */
211  float guard_level;
212  /*! \brief The current fractional phase of the baud timing. */
213  int baud_phase;
214  /*! \brief The code number for the current position in the constellation. */
216  /*! \brief An indicator to mark that we are tidying up to stop transmission. */
217  int shutdown;
218  /*! \brief The get_bit function in use at any instant. */
220  } tx;
221 
222  /*! \brief Error and flow logging control */
224 };
225 
226 #if defined(__cplusplus)
227 extern "C"
228 {
229 #endif
230 
231 /*! Reinitialise an existing V.22bis modem receive context.
232  \brief Reinitialise an existing V.22bis modem receive context.
233  \param s The modem context.
234  \return 0 for OK, -1 for bad parameter */
236 
237 void v22bis_report_status_change(v22bis_state_t *s, int status);
238 
239 void v22bis_equalizer_coefficient_reset(v22bis_state_t *s);
240 
241 #if defined(__cplusplus)
242 }
243 #endif
244 
245 #endif
246 /*- End of file ------------------------------------------------------------*/