00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * v22bis.h - ITU V.22bis modem receive part 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2004 Steve Underwood 00009 * 00010 * All rights reserved. 00011 * 00012 * This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU General Public License version 2, as 00014 * published by the Free Software Foundation. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License 00022 * along with this program; if not, write to the Free Software 00023 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00024 * 00025 * $Id: v22bis.h,v 1.21 2007/04/05 19:20:50 steveu Exp $ 00026 */ 00027 00028 /*! \file */ 00029 00030 /*! \page v22bis_page The V.22bis modem 00031 \section v22bis_page_sec_1 What does it do? 00032 The V.22bis modem is a duplex modem for general data use on the PSTN, at rates 00033 of 1200 and 2400 bits/second. It is a compatible extension of the V.22 modem, 00034 which is a 1200 bits/second only design. It is a band-split design, using carriers 00035 of 1200Hz and 2400Hz. It is the fastest PSTN modem in general use which does not 00036 use echo-cancellation. 00037 00038 \section v22bis__page_sec_2 How does it work? 00039 V.22bis uses 4PSK modulation at 1200 bits/second or 16QAM modulation at 2400 00040 bits/second. At 1200bps the symbols are so long that a fixed compromise equaliser 00041 is sufficient to recover the 4PSK signal reliably. At 2400bps an adaptive 00042 equaliser is necessary. 00043 00044 The V.22bis training sequence includes sections which allow the modems to determine 00045 if the far modem can support (or is willing to support) 2400bps operation. The 00046 modems will automatically use 2400bps if both ends are willing to use that speed, 00047 or 1200bps if one or both ends to not acknowledge that 2400bps is OK. 00048 */ 00049 00050 #if !defined(_SPANDSP_V22BIS_H_) 00051 #define _SPANDSP_V22BIS_H_ 00052 00053 #define V22BIS_EQUALIZER_LEN 7 /* this much to the left and this much to the right */ 00054 #define V22BIS_EQUALIZER_MASK 15 /* one less than a power of 2 >= (2*V22BIS_EQUALIZER_LEN + 1) */ 00055 00056 #define V22BIS_TX_FILTER_STEPS 9 00057 00058 #define V22BIS_RX_FILTER_STEPS 37 00059 00060 /*! 00061 V.22bis modem receive side descriptor. This defines the working state for a 00062 single instance of a V.22bis modem receiver. 00063 */ 00064 typedef struct 00065 { 00066 /*! \brief The bit rate of the modem. Valid values are 1200 and 2400. */ 00067 int bit_rate; 00068 /*! \brief TRUE is this is the calling side modem. */ 00069 int caller; 00070 /*! \brief The callback function used to put each bit received. */ 00071 put_bit_func_t put_bit; 00072 /*! \brief The callback function used to get the next bit to be transmitted. */ 00073 get_bit_func_t get_bit; 00074 /*! \brief A user specified opaque pointer passed to the callback routines. */ 00075 void *user_data; 00076 00077 /* RECEIVE SECTION */ 00078 00079 /*! \brief A callback function which may be enabled to report every symbol's 00080 constellation position. */ 00081 qam_report_handler_t *qam_report; 00082 /*! \brief A user specified opaque pointer passed to the qam_report callback 00083 routine. */ 00084 void *qam_user_data; 00085 00086 /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */ 00087 float rx_rrc_filter[2*V22BIS_RX_FILTER_STEPS]; 00088 /*! \brief Current offset into the RRC pulse shaping filter buffer. */ 00089 int rx_rrc_filter_step; 00090 00091 /*! \brief The register for the data scrambler. */ 00092 unsigned int rx_scramble_reg; 00093 /*! \brief A counter for the number of consecutive bits of repeating pattern through 00094 the scrambler. */ 00095 int rx_scrambler_pattern_count; 00096 /*! \brief 0 if receiving user data. A training stage value during training */ 00097 int rx_training; 00098 int rx_training_count; 00099 float training_error; 00100 int carrier_present; 00101 00102 /*! \brief The current phase of the carrier (i.e. the DDS parameter). */ 00103 uint32_t rx_carrier_phase; 00104 /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */ 00105 int32_t rx_carrier_phase_rate; 00106 float carrier_track_p; 00107 float carrier_track_i; 00108 00109 power_meter_t rx_power; 00110 int32_t carrier_on_power; 00111 int32_t carrier_off_power; 00112 float agc_scaling; 00113 00114 int rx_constellation_state; 00115 00116 float eq_delta; 00117 /*! \brief The adaptive equalizer coefficients */ 00118 complexf_t eq_coeff[2*V22BIS_EQUALIZER_LEN + 1]; 00119 complexf_t eq_buf[V22BIS_EQUALIZER_MASK + 1]; 00120 /*! \brief Current offset into equalizer buffer. */ 00121 int eq_step; 00122 int eq_put_step; 00123 00124 /*! \brief Integration variable for damping the Gardner algorithm tests. */ 00125 int gardner_integrate; 00126 /*! \brief Current step size of Gardner algorithm integration. */ 00127 int gardner_step; 00128 /*! \brief The total symbol timing correction since the carrier came up. 00129 This is only for performance analysis purposes. */ 00130 int total_baud_timing_correction; 00131 /*! \brief The current fractional phase of the baud timing. */ 00132 int rx_baud_phase; 00133 00134 int sixteen_way_decisions; 00135 00136 /* TRANSMIT SECTION */ 00137 00138 /*! \brief The gain factor needed to achieve the specified output power. */ 00139 float tx_gain; 00140 00141 /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */ 00142 complexf_t tx_rrc_filter[2*V22BIS_TX_FILTER_STEPS]; 00143 /*! \brief Current offset into the RRC pulse shaping filter buffer. */ 00144 int tx_rrc_filter_step; 00145 00146 /*! \brief The register for the data scrambler. */ 00147 unsigned int tx_scramble_reg; 00148 /*! \brief A counter for the number of consecutive bits of repeating pattern through 00149 the scrambler. */ 00150 int tx_scrambler_pattern_count; 00151 /*! \brief 0 if transmitting user data. A training stage value during training */ 00152 int tx_training; 00153 /*! \brief A counter used to track progress through sending the training sequence. */ 00154 int tx_training_count; 00155 00156 /*! \brief The current phase of the carrier (i.e. the DDS parameter). */ 00157 uint32_t tx_carrier_phase; 00158 /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */ 00159 int32_t tx_carrier_phase_rate; 00160 /*! \brief The current phase of the guard tone (i.e. the DDS parameter). */ 00161 uint32_t guard_phase; 00162 /*! \brief The update rate for the phase of the guard tone (i.e. the DDS increment). */ 00163 int32_t guard_phase_rate; 00164 float guard_level; 00165 /*! \brief The current fractional phase of the baud timing. */ 00166 int tx_baud_phase; 00167 /*! \brief The code number for the current position in the constellation. */ 00168 int tx_constellation_state; 00169 /*! \brief An indicator to mark that we are tidying up to stop transmission. */ 00170 int shutdown; 00171 /*! \brief The get_bit function in use at any instant. */ 00172 get_bit_func_t current_get_bit; 00173 00174 int detected_unscrambled_ones; 00175 int detected_unscrambled_zeros; 00176 00177 int detected_unscrambled_ones_or_zeros; 00178 int detected_unscrambled_0011_ending; 00179 int detected_scrambled_ones_or_zeros_at_1200bps; 00180 int detected_scrambled_ones_at_2400bps; 00181 00182 /*! \brief Error and flow logging control */ 00183 logging_state_t logging; 00184 } v22bis_state_t; 00185 00186 extern const complexf_t v22bis_constellation[16]; 00187 00188 #ifdef __cplusplus 00189 extern "C" 00190 { 00191 #endif 00192 00193 /*! Reinitialise an existing V.22bis modem receive context. 00194 \brief Reinitialise an existing V.22bis modem receive context. 00195 \param s The modem context. 00196 \param rate The bit rate of the modem. Valid values are 1200 and 2400. 00197 \return 0 for OK, -1 for bad parameter */ 00198 int v22bis_rx_restart(v22bis_state_t *s, int bit_rate); 00199 00200 /*! Process a block of received V.22bis modem audio samples. 00201 \brief Process a block of received V.22bis modem audio samples. 00202 \param s The modem context. 00203 \param amp The audio sample buffer. 00204 \param len The number of samples in the buffer. 00205 \return The number of samples unprocessed. */ 00206 int v22bis_rx(v22bis_state_t *s, const int16_t amp[], int len); 00207 00208 /*! Get a snapshot of the current equalizer coefficients. 00209 \brief Get a snapshot of the current equalizer coefficients. 00210 \param coeffs The vector of complex coefficients. 00211 \return The number of coefficients in the vector. */ 00212 int v22bis_rx_equalizer_state(v22bis_state_t *s, complexf_t **coeffs); 00213 00214 /*! Get the current received carrier frequency. 00215 \param s The modem context. 00216 \return The frequency, in Hertz. */ 00217 float v22bis_rx_carrier_frequency(v22bis_state_t *s); 00218 00219 /*! Get the current symbol timing correction since startup. 00220 \param s The modem context. 00221 \return The correction. */ 00222 float v22bis_rx_symbol_timing_correction(v22bis_state_t *s); 00223 00224 /*! Get a current received signal power. 00225 \param s The modem context. 00226 \return The signal power, in dBm0. */ 00227 float v22bis_rx_signal_power(v22bis_state_t *s); 00228 00229 /*! Set a handler routine to process QAM status reports 00230 \param s The modem context. 00231 \param handler The handler routine. 00232 \param user_data An opaque pointer passed to the handler routine. */ 00233 void v22bis_rx_set_qam_report_handler(v22bis_state_t *s, qam_report_handler_t *handler, void *user_data); 00234 00235 /*! Generate a block of V.22bis modem audio samples. 00236 \brief Generate a block of V.22bis modem audio samples. 00237 \param s The modem context. 00238 \param amp The audio sample buffer. 00239 \param len The number of samples to be generated. 00240 \return The number of samples actually generated. */ 00241 int v22bis_tx(v22bis_state_t *s, int16_t amp[], int len); 00242 00243 /*! Adjust a V.22bis modem transmit context's power output. 00244 \brief Adjust a V.22bis modem transmit context's output power. 00245 \param s The modem context. 00246 \param power The power level, in dBm0 */ 00247 void v22bis_tx_power(v22bis_state_t *s, float power); 00248 00249 /*! Reinitialise an existing V.22bis modem context, so it may be reused. 00250 \brief Reinitialise an existing V.22bis modem context. 00251 \param s The modem context. 00252 \param bit_rate The bit rate of the modem. Valid values are 1200 and 2400. 00253 \return 0 for OK, -1 for bad parameter. */ 00254 int v22bis_restart(v22bis_state_t *s, int bit_rate); 00255 00256 /*! Initialise a V.22bis modem context. This must be called before the first 00257 use of the context, to initialise its contents. 00258 \brief Initialise a V.22bis modem context. 00259 \param s The modem context. 00260 \param bit_rate The bit rate of the modem. Valid values are 1200 and 2400. 00261 \param guard The guard tone option. 0 = none, 1 = 550Hz, 2 = 1800Hz. 00262 \param caller TRUE if this is the calling modem. 00263 \param get_bit The callback routine used to get the data to be transmitted. 00264 \param put_bit The callback routine used to get the data to be transmitted. 00265 \param user_data An opaque pointer, passed in calls to the get and put routines. 00266 \return A pointer to the modem context, or NULL if there was a problem. */ 00267 v22bis_state_t *v22bis_init(v22bis_state_t *s, 00268 int bit_rate, 00269 int guard, 00270 int caller, 00271 get_bit_func_t get_bit, 00272 put_bit_func_t put_bit, 00273 void *user_data); 00274 00275 /*! Change the get_bit function associated with a V.2bis modem context. 00276 \brief Change the get_bit function associated with a V.22bis modem context. 00277 \param s The modem context. 00278 \param get_bit The callback routine used to get the data to be transmitted. 00279 \param user_data An opaque pointer. */ 00280 void v22bis_set_get_bit(v22bis_state_t *s, get_bit_func_t get_bit, void *user_data); 00281 00282 /*! Change the get_bit function associated with a V.2bis modem context. 00283 \brief Change the put_bit function associated with a V.22bis modem context. 00284 \param s The modem context. 00285 \param put_bit The callback routine used to process the data received. 00286 \param user_data An opaque pointer. */ 00287 void v22bis_set_put_bit(v22bis_state_t *s, put_bit_func_t put_bit, void *user_data); 00288 00289 #ifdef __cplusplus 00290 } 00291 #endif 00292 00293 #endif 00294 /*- End of file ------------------------------------------------------------*/