v22bis.h

Go to the documentation of this file.
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.23 2007/04/10 16:12:20 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(_V22BIS_H_)
00051 #define _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     /*! \brief >0 if a signal above the minimum is present. It may or may not be a V.22bis signal. */
00101     int signal_present;
00102 
00103     /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
00104     uint32_t rx_carrier_phase;
00105     /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
00106     int32_t rx_carrier_phase_rate;
00107     float carrier_track_p;
00108     float carrier_track_i;
00109 
00110     power_meter_t rx_power;
00111     int32_t carrier_on_power;
00112     int32_t carrier_off_power;
00113     float agc_scaling;
00114     
00115     int rx_constellation_state;
00116 
00117     float eq_delta;
00118     /*! \brief The adaptive equalizer coefficients */
00119     complexf_t eq_coeff[2*V22BIS_EQUALIZER_LEN + 1];
00120     complexf_t eq_buf[V22BIS_EQUALIZER_MASK + 1];
00121     /*! \brief Current offset into equalizer buffer. */
00122     int eq_step;
00123     int eq_put_step;
00124 
00125     /*! \brief Integration variable for damping the Gardner algorithm tests. */
00126     int gardner_integrate;
00127     /*! \brief Current step size of Gardner algorithm integration. */
00128     int gardner_step;
00129     /*! \brief The total symbol timing correction since the carrier came up.
00130                This is only for performance analysis purposes. */
00131     int total_baud_timing_correction;
00132     /*! \brief The current fractional phase of the baud timing. */
00133     int rx_baud_phase;
00134     
00135     int sixteen_way_decisions;
00136 
00137     /* TRANSMIT SECTION */
00138 
00139     /*! \brief The gain factor needed to achieve the specified output power. */
00140     float tx_gain;
00141 
00142     /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
00143     complexf_t tx_rrc_filter[2*V22BIS_TX_FILTER_STEPS];
00144     /*! \brief Current offset into the RRC pulse shaping filter buffer. */
00145     int tx_rrc_filter_step;
00146 
00147     /*! \brief The register for the data scrambler. */
00148     unsigned int tx_scramble_reg;
00149     /*! \brief A counter for the number of consecutive bits of repeating pattern through
00150                the scrambler. */
00151     int tx_scrambler_pattern_count;
00152     /*! \brief 0 if transmitting user data. A training stage value during training */
00153     int tx_training;
00154     /*! \brief A counter used to track progress through sending the training sequence. */
00155     int tx_training_count;
00156 
00157     /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
00158     uint32_t tx_carrier_phase;
00159     /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
00160     int32_t tx_carrier_phase_rate;
00161     /*! \brief The current phase of the guard tone (i.e. the DDS parameter). */
00162     uint32_t guard_phase;
00163     /*! \brief The update rate for the phase of the guard tone (i.e. the DDS increment). */
00164     int32_t guard_phase_rate;
00165     float guard_level;
00166     /*! \brief The current fractional phase of the baud timing. */
00167     int tx_baud_phase;
00168     /*! \brief The code number for the current position in the constellation. */
00169     int tx_constellation_state;
00170     /*! \brief An indicator to mark that we are tidying up to stop transmission. */
00171     int shutdown;
00172     /*! \brief The get_bit function in use at any instant. */
00173     get_bit_func_t current_get_bit;
00174     
00175     int detected_unscrambled_ones;
00176     int detected_unscrambled_zeros;
00177 
00178     int detected_unscrambled_ones_or_zeros;
00179     int detected_unscrambled_0011_ending;
00180     int detected_scrambled_ones_or_zeros_at_1200bps;
00181     int detected_scrambled_ones_at_2400bps;
00182 
00183     /*! \brief Error and flow logging control */
00184     logging_state_t logging;
00185 } v22bis_state_t;
00186 
00187 extern const complexf_t v22bis_constellation[16];
00188 
00189 #ifdef __cplusplus
00190 extern "C"
00191 {
00192 #endif
00193 
00194 /*! Reinitialise an existing V.22bis modem receive context.
00195     \brief Reinitialise an existing V.22bis modem receive context.
00196     \param s The modem context.
00197     \param rate The bit rate of the modem. Valid values are 1200 and 2400.
00198     \return 0 for OK, -1 for bad parameter */
00199 int v22bis_rx_restart(v22bis_state_t *s, int bit_rate);
00200 
00201 /*! Process a block of received V.22bis modem audio samples.
00202     \brief Process a block of received V.22bis modem audio samples.
00203     \param s The modem context.
00204     \param amp The audio sample buffer.
00205     \param len The number of samples in the buffer.
00206     \return The number of samples unprocessed. */
00207 int v22bis_rx(v22bis_state_t *s, const int16_t amp[], int len);
00208 
00209 /*! Get a snapshot of the current equalizer coefficients.
00210     \brief Get a snapshot of the current equalizer coefficients.
00211     \param coeffs The vector of complex coefficients.
00212     \return The number of coefficients in the vector. */
00213 int v22bis_rx_equalizer_state(v22bis_state_t *s, complexf_t **coeffs);
00214 
00215 /*! Get the current received carrier frequency.
00216     \param s The modem context.
00217     \return The frequency, in Hertz. */
00218 float v22bis_rx_carrier_frequency(v22bis_state_t *s);
00219 
00220 /*! Get the current symbol timing correction since startup.
00221     \param s The modem context.
00222     \return The correction. */
00223 float v22bis_rx_symbol_timing_correction(v22bis_state_t *s);
00224 
00225 /*! Get a current received signal power.
00226     \param s The modem context.
00227     \return The signal power, in dBm0. */
00228 float v22bis_rx_signal_power(v22bis_state_t *s);
00229 
00230 /*! Set a handler routine to process QAM status reports
00231     \param s The modem context.
00232     \param handler The handler routine.
00233     \param user_data An opaque pointer passed to the handler routine. */
00234 void v22bis_rx_set_qam_report_handler(v22bis_state_t *s, qam_report_handler_t *handler, void *user_data);
00235 
00236 /*! Generate a block of V.22bis modem audio samples.
00237     \brief Generate a block of V.22bis modem audio samples.
00238     \param s The modem context.
00239     \param amp The audio sample buffer.
00240     \param len The number of samples to be generated.
00241     \return The number of samples actually generated. */
00242 int v22bis_tx(v22bis_state_t *s, int16_t amp[], int len);
00243 
00244 /*! Adjust a V.22bis modem transmit context's power output.
00245     \brief Adjust a V.22bis modem transmit context's output power.
00246     \param s The modem context.
00247     \param power The power level, in dBm0 */
00248 void v22bis_tx_power(v22bis_state_t *s, float power);
00249 
00250 /*! Reinitialise an existing V.22bis modem context, so it may be reused.
00251     \brief Reinitialise an existing V.22bis modem context.
00252     \param s The modem context.
00253     \param bit_rate The bit rate of the modem. Valid values are 1200 and 2400.
00254     \return 0 for OK, -1 for bad parameter. */
00255 int v22bis_restart(v22bis_state_t *s, int bit_rate);
00256 
00257 /*! Initialise a V.22bis modem context. This must be called before the first
00258     use of the context, to initialise its contents.
00259     \brief Initialise a V.22bis modem context.
00260     \param s The modem context.
00261     \param bit_rate The bit rate of the modem. Valid values are 1200 and 2400.
00262     \param guard The guard tone option. 0 = none, 1 = 550Hz, 2 = 1800Hz.
00263     \param caller TRUE if this is the calling modem.
00264     \param get_bit The callback routine used to get the data to be transmitted.
00265     \param put_bit The callback routine used to get the data to be transmitted.
00266     \param user_data An opaque pointer, passed in calls to the get and put routines.
00267     \return A pointer to the modem context, or NULL if there was a problem. */
00268 v22bis_state_t *v22bis_init(v22bis_state_t *s,
00269                             int bit_rate,
00270                             int guard,
00271                             int caller,
00272                             get_bit_func_t get_bit,
00273                             put_bit_func_t put_bit,
00274                             void *user_data);
00275 
00276 /*! Change the get_bit function associated with a V.2bis modem context.
00277     \brief Change the get_bit function associated with a V.22bis modem context.
00278     \param s The modem context.
00279     \param get_bit The callback routine used to get the data to be transmitted.
00280     \param user_data An opaque pointer. */
00281 void v22bis_set_get_bit(v22bis_state_t *s, get_bit_func_t get_bit, void *user_data);
00282 
00283 /*! Change the get_bit function associated with a V.2bis modem context.
00284     \brief Change the put_bit function associated with a V.22bis modem context.
00285     \param s The modem context.
00286     \param put_bit The callback routine used to process the data received.
00287     \param user_data An opaque pointer. */
00288 void v22bis_set_put_bit(v22bis_state_t *s, put_bit_func_t put_bit, void *user_data);
00289 
00290 #ifdef __cplusplus
00291 }
00292 #endif
00293 
00294 #endif
00295 /*- End of file ------------------------------------------------------------*/

Generated on Tue Jul 24 11:29:28 2007 for libspandsp by  doxygen 1.5.2