5
|
1 /*
|
|
2 * SpanDSP - a series of DSP components for telephony
|
|
3 *
|
|
4 * v27ter_rx.h - ITU V.27ter modem receive part
|
|
5 *
|
|
6 * Written by Steve Underwood <steveu@coppice.org>
|
|
7 *
|
|
8 * Copyright (C) 2003 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 General Public License version 2, as
|
|
14 * 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 General Public License for more details.
|
|
20 *
|
|
21 * You should have received a copy of the GNU General Public License
|
|
22 * along with this program; if not, write to the Free Software
|
|
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
24 *
|
|
25 * $Id: v27ter_rx.h,v 1.34 2006/10/24 13:45:28 steveu Exp $
|
|
26 */
|
|
27
|
|
28 /*! \file */
|
|
29
|
|
30 #if !defined(_V27TER_RX_H_)
|
|
31 #define _V27TER_RX_H_
|
|
32
|
|
33 /*! \page v27ter_rx_page The V.27ter receiver
|
|
34
|
|
35 \section v27ter_rx_page_sec_1 What does it do?
|
|
36 The V.27ter receiver implements the receive side of a V.27ter modem. This can operate
|
|
37 at data rates of 4800 and 2400 bits/s. The audio input is a stream of 16 bit samples,
|
|
38 at 8000 samples/second. The transmit and receive side of V.27ter modems operate
|
|
39 independantly. V.27ter is mostly used for FAX transmission, where it provides the
|
|
40 standard 4800 bits/s rate (the 2400 bits/s mode is not used for FAX).
|
|
41
|
|
42 \section v27ter_rx_page_sec_2 How does it work?
|
|
43 V.27ter defines two modes of operation. One uses 8-PSK at 1600 baud, giving 4800bps.
|
|
44 The other uses 4-PSK at 1200 baud, giving 2400bps. A training sequence is specified
|
|
45 at the start of transmission, which makes the design of a V.27ter receiver relatively
|
|
46 straightforward.
|
|
47 */
|
|
48
|
|
49 /* Target length for the equalizer is about 43 taps for 4800bps and 32 taps for 2400bps
|
|
50 to deal with the worst stuff in V.56bis. */
|
|
51 #define V27TER_EQUALIZER_PRE_LEN 15 /* this much before the real event */
|
|
52 #define V27TER_EQUALIZER_POST_LEN 15 /* this much after the real event */
|
|
53 #define V27TER_EQUALIZER_MASK 63 /* one less than a power of 2 >= (V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN) */
|
|
54
|
|
55 #define V27TER_RX_4800_FILTER_STEPS 27
|
|
56 #define V27TER_RX_2400_FILTER_STEPS 27
|
|
57
|
|
58 #if V27TER_RX_4800_FILTER_STEPS > V27TER_RX_2400_FILTER_STEPS
|
|
59 #define V27TER_RX_FILTER_STEPS V27TER_RX_4800_FILTER_STEPS
|
|
60 #else
|
|
61 #define V27TER_RX_FILTER_STEPS V27TER_RX_2400_FILTER_STEPS
|
|
62 #endif
|
|
63
|
|
64 /*!
|
|
65 V.27ter modem receive side descriptor. This defines the working state for a
|
|
66 single instance of a V.27ter modem receiver.
|
|
67 */
|
|
68 typedef struct
|
|
69 {
|
|
70 /*! \brief The bit rate of the modem. Valid values are 2400 and 4800. */
|
|
71 int bit_rate;
|
|
72 /*! \brief The callback function used to put each bit received. */
|
|
73 put_bit_func_t put_bit;
|
|
74 /*! \brief A user specified opaque pointer passed to the put_bit routine. */
|
|
75 void *user_data;
|
|
76 /*! \brief A callback function which may be enabled to report every symbol's
|
|
77 constellation position. */
|
|
78 qam_report_handler_t *qam_report;
|
|
79 /*! \brief A user specified opaque pointer passed to the qam_report callback
|
|
80 routine. */
|
|
81 void *qam_user_data;
|
|
82
|
|
83 /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
|
|
84 float rrc_filter[2*V27TER_RX_FILTER_STEPS];
|
|
85 /*! \brief Current offset into the RRC pulse shaping filter buffer. */
|
|
86 int rrc_filter_step;
|
|
87
|
|
88 /*! \brief The register for the training and data scrambler. */
|
|
89 unsigned int scramble_reg;
|
|
90 /*! \brief A counter for the number of consecutive bits of repeating pattern through
|
|
91 the scrambler. */
|
|
92 int scrambler_pattern_count;
|
|
93 int in_training;
|
|
94 int training_bc;
|
|
95 int training_count;
|
|
96 float training_error;
|
|
97 int carrier_present;
|
|
98 int16_t last_sample;
|
|
99 /*! \brief TRUE if the previous trained values are to be reused. */
|
|
100 int old_train;
|
|
101
|
|
102 /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
|
|
103 uint32_t carrier_phase;
|
|
104 /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
|
|
105 int32_t carrier_phase_rate;
|
|
106 /*! \brief The carrier update rate saved for reuse when using short training. */
|
|
107 int32_t carrier_phase_rate_save;
|
|
108 float carrier_track_p;
|
|
109 float carrier_track_i;
|
|
110
|
|
111 power_meter_t power;
|
|
112 int32_t carrier_on_power;
|
|
113 int32_t carrier_off_power;
|
|
114 float agc_scaling;
|
|
115 float agc_scaling_save;
|
|
116
|
|
117 int constellation_state;
|
|
118
|
|
119 float eq_delta;
|
|
120 /*! \brief The adaptive equalizer coefficients */
|
|
121 complexf_t eq_coeff[V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN];
|
|
122 complexf_t eq_coeff_save[V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN];
|
|
123 complexf_t eq_buf[V27TER_EQUALIZER_MASK + 1];
|
|
124 /*! \brief Current offset into equalizer buffer. */
|
|
125 int eq_step;
|
|
126 int eq_put_step;
|
|
127 int eq_skip;
|
|
128
|
|
129 /*! \brief Integration variable for damping the Gardner algorithm tests. */
|
|
130 int gardner_integrate;
|
|
131 /*! \brief Current step size of Gardner algorithm integration. */
|
|
132 int gardner_step;
|
|
133 /*! \brief The total symbol timing correction since the carrier came up.
|
|
134 This is only for performance analysis purposes. */
|
|
135 int total_baud_timing_correction;
|
|
136 /*! \brief The current fractional phase of the baud timing. */
|
|
137 int baud_phase;
|
|
138
|
|
139 /*! \brief Starting phase angles for the coarse carrier aquisition step. */
|
|
140 int32_t start_angles[2];
|
|
141 /*! \brief History list of phase angles for the coarse carrier aquisition step. */
|
|
142 int32_t angles[16];
|
|
143 /*! \brief Error and flow logging control */
|
|
144 logging_state_t logging;
|
|
145 } v27ter_rx_state_t;
|
|
146
|
|
147 #ifdef __cplusplus
|
|
148 extern "C" {
|
|
149 #endif
|
|
150
|
|
151 /*! Initialise a V.27ter modem receive context.
|
|
152 \brief Initialise a V.27ter modem receive context.
|
|
153 \param s The modem context.
|
|
154 \param rate The bit rate of the modem. Valid values are 2400 and 4800.
|
|
155 \param put_bit The callback routine used to put the received data.
|
|
156 \param user_data An opaque pointer passed to the put_bit routine.
|
|
157 \return A pointer to the modem context, or NULL if there was a problem. */
|
|
158 v27ter_rx_state_t *v27ter_rx_init(v27ter_rx_state_t *s, int rate, put_bit_func_t put_bit, void *user_data);
|
|
159
|
|
160 /*! Reinitialise an existing V.27ter modem receive context.
|
|
161 \brief Reinitialise an existing V.27ter modem receive context.
|
|
162 \param s The modem context.
|
|
163 \param rate The bit rate of the modem. Valid values are 2400 and 4800.
|
|
164 \param old_train TRUE if a previous trained values are to be reused.
|
|
165 \return 0 for OK, -1 for bad parameter */
|
|
166 int v27ter_rx_restart(v27ter_rx_state_t *s, int rate, int old_train);
|
|
167
|
|
168 /*! Release a V.27ter modem receive context.
|
|
169 \brief Release a V.27ter modem receive context.
|
|
170 \param s The modem context.
|
|
171 \return 0 for OK */
|
|
172 int v27ter_rx_release(v27ter_rx_state_t *s);
|
|
173
|
|
174 /*! Change the put_bit function associated with a V.27ter modem receive context.
|
|
175 \brief Change the put_bit function associated with a V.27ter modem receive context.
|
|
176 \param s The modem context.
|
|
177 \param put_bit The callback routine used to handle received bits.
|
|
178 \param user_data An opaque pointer. */
|
|
179 void v27ter_rx_set_put_bit(v27ter_rx_state_t *s, put_bit_func_t put_bit, void *user_data);
|
|
180
|
|
181 /*! Process a block of received V.27ter modem audio samples.
|
|
182 \brief Process a block of received V.27ter modem audio samples.
|
|
183 \param s The modem context.
|
|
184 \param amp The audio sample buffer.
|
|
185 \param len The number of samples in the buffer.
|
|
186 \return The number of samples unprocessed.
|
|
187 */
|
|
188 int v27ter_rx(v27ter_rx_state_t *s, const int16_t amp[], int len);
|
|
189
|
|
190 /*! Get a snapshot of the current equalizer coefficients.
|
|
191 \brief Get a snapshot of the current equalizer coefficients.
|
|
192 \param coeffs The vector of complex coefficients.
|
|
193 \return The number of coefficients in the vector. */
|
|
194 int v27ter_rx_equalizer_state(v27ter_rx_state_t *s, complexf_t **coeffs);
|
|
195
|
|
196 /*! Get the current received carrier frequency.
|
|
197 \param s The modem context.
|
|
198 \return The frequency, in Hertz. */
|
|
199 float v27ter_rx_carrier_frequency(v27ter_rx_state_t *s);
|
|
200
|
|
201 /*! Get the current symbol timing correction since startup.
|
|
202 \param s The modem context.
|
|
203 \return The correction. */
|
|
204 float v27ter_rx_symbol_timing_correction(v27ter_rx_state_t *s);
|
|
205
|
|
206 /*! Get a current received signal power.
|
|
207 \param s The modem context.
|
|
208 \return The signal power, in dBm0. */
|
|
209 float v27ter_rx_signal_power(v27ter_rx_state_t *s);
|
|
210
|
|
211 /*! Set the power level at which the carrier detection will cut in
|
|
212 \param s The modem context.
|
|
213 \param cutoff The signal cutoff power, in dBm0. */
|
|
214 void v27ter_rx_signal_cutoff(v27ter_rx_state_t *s, float cutoff);
|
|
215
|
|
216 /*! Set a handler routine to process QAM status reports
|
|
217 \param s The modem context.
|
|
218 \param handler The handler routine.
|
|
219 \param user_data An opaque pointer passed to the handler routine. */
|
|
220 void v27ter_rx_set_qam_report_handler(v27ter_rx_state_t *s, qam_report_handler_t *handler, void *user_data);
|
|
221
|
|
222 #ifdef __cplusplus
|
|
223 }
|
|
224 #endif
|
|
225
|
|
226 #endif
|
|
227 /*- End of file ------------------------------------------------------------*/
|