v27ter_rx.h

Go to the documentation of this file.
00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * v27ter_rx.h - ITU V.27ter modem receive part
00005  *
00006  * Written by Steve Underwood <steveu@coppice.org>
00007  *
00008  * Copyright (C) 2003 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 as published by
00014  * the Free Software Foundation; either version 2 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program; if not, write to the Free Software
00024  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00025  *
00026  * $Id: v27ter_rx.h,v 1.23 2005/12/09 19:36:00 steveu Exp $
00027  */
00028 
00029 /*! \file */
00030 
00031 #if !defined(_V27TER_RX_H_)
00032 #define _V27TER_RX_H_
00033 
00034 /*! \page v27ter_rx_page The V.27ter receiver
00035 
00036 \section v27ter_rx_page_sec_1 What does it do?
00037 
00038 \section v27ter_rx_page_sec_2 How does it work?
00039 */
00040 
00041 #define V27TER_EQUALIZER_LEN            7   /* this much to the left and this much to the right */
00042 #define V27TER_EQUALIZER_MASK           15  /* one less than a power of 2 >= (2*V27TER_EQUALIZER_LEN + 1) */
00043 
00044 #define V27TER_RX_4800_FILTER_STEPS     27
00045 #define V27TER_RX_2400_FILTER_STEPS     27
00046 
00047 #if V27TER_RX_4800_FILTER_STEPS > V27TER_RX_2400_FILTER_STEPS
00048 #define V27TER_RX_FILTER_STEPS V27TER_RX_4800_FILTER_STEPS
00049 #else
00050 #define V27TER_RX_FILTER_STEPS V27TER_RX_2400_FILTER_STEPS
00051 #endif
00052 
00053 /*!
00054     V.27ter modem receive side descriptor. This defines the working state for a
00055     single instance of a V.27ter modem receiver.
00056 */
00057 typedef struct
00058 {
00059     /*! \brief The bit rate of the modem. Valid values are 2400 and 4800. */
00060     int bit_rate;
00061     /*! \brief The callback function used to put each bit received. */
00062     put_bit_func_t put_bit;
00063     /*! \brief A user specified opaque pointer passed to the put_bit routine. */
00064     void *user_data;
00065     /*! \brief A callback function which may be enabled to report every symbol's
00066                constellation position. */
00067     qam_report_handler_t *qam_report;
00068     /*! \brief A user specified opaque pointer passed to the qam_report callback
00069                routine. */
00070     void *qam_user_data;
00071 
00072     /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
00073     complex_t rrc_filter[2*V27TER_RX_FILTER_STEPS];
00074     /*! \brief Current offset into the RRC pulse shaping filter buffer. */
00075     int rrc_filter_step;
00076 
00077     /*! \brief The register for the training and data scrambler. */
00078     unsigned int scramble_reg;
00079     /*! \brief A counter for the number of consecutive bits of repeating pattern through
00080                the scrambler. */
00081     int scrambler_pattern_count;
00082     int in_training;
00083     int training_bc;
00084     int training_count;
00085     float training_error;
00086     int carrier_present;
00087 
00088     /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
00089     uint32_t carrier_phase;
00090     /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
00091     int32_t carrier_phase_rate;
00092     float carrier_track_p;
00093     float carrier_track_i;
00094 
00095     power_meter_t power;
00096     int32_t carrier_on_power;
00097     int32_t carrier_off_power;
00098     float agc_scaling;
00099     
00100     int constellation_state;
00101 
00102     float eq_delta;
00103     /*! \brief The adaptive equalizer coefficients */
00104     complex_t eq_coeff[2*V27TER_EQUALIZER_LEN + 1];
00105     complex_t eq_buf[V27TER_EQUALIZER_MASK + 1];
00106     /*! \brief Current offset into equalizer buffer. */
00107     int eq_step;
00108     int eq_put_step;
00109     int eq_skip;
00110 
00111     /*! \brief Integration variable for damping the Gardner algorithm tests. */
00112     int gardner_integrate;
00113     /*! \brief Current step size of Gardner algorithm integration. */
00114     int gardner_step;
00115     /*! \brief The total gardner timing correction, since the carrier came up.
00116                This is only for performance analysis purposes. */
00117     int gardner_total_correction;
00118     /*! \brief The current fractional phase of the baud timing. */
00119     int baud_phase;
00120 
00121     /*! \brief Starting phase angles for the coarse carrier aquisition step. */
00122     int32_t start_angles[2];
00123     /*! \brief History list of phase angles for the coarse carrier aquisition step. */
00124     int32_t angles[16];
00125     /*! \brief Error and flow logging control */
00126     logging_state_t logging;
00127 } v27ter_rx_state_t;
00128 
00129 #ifdef __cplusplus
00130 extern "C" {
00131 #endif
00132 
00133 /*! Initialise a V.27ter modem receive context.
00134     \brief Initialise a V.27ter modem receive context.
00135     \param s The modem context.
00136     \param rate The bit rate of the modem. Valid values are 2400 and 4800.
00137     \param put_bit The callback routine used to put the received data.
00138     \param user_data An opaque pointer passed to the put_bit routine.
00139     \return A pointer to the modem context, or NULL if there was a problem. */
00140 v27ter_rx_state_t *v27ter_rx_init(v27ter_rx_state_t *s, int rate, put_bit_func_t put_bit, void *user_data);
00141 
00142 /*! Reinitialise an existing V.27ter modem receive context.
00143     \brief Reinitialise an existing V.27ter modem receive context.
00144     \param s The modem context.
00145     \param rate The bit rate of the modem. Valid values are 2400 and 4800.
00146     \return 0 for OK, -1 for bad parameter */
00147 int v27ter_rx_restart(v27ter_rx_state_t *s, int rate);
00148 
00149 /*! Release a V.27ter modem receive context.
00150     \brief Release a V.27ter modem receive context.
00151     \param s The modem context.
00152     \return 0 for OK */
00153 int v27ter_rx_release(v27ter_rx_state_t *s);
00154 
00155 /*! Change the put_bit function associated with a V.27ter modem receive context.
00156     \brief Change the put_bit function associated with a V.27ter modem receive context.
00157     \param s The modem context.
00158     \param put_bit The callback routine used to handle received bits.
00159     \param user_data An opaque pointer. */
00160 void v27ter_rx_set_put_bit(v27ter_rx_state_t *s, put_bit_func_t put_bit, void *user_data);
00161 
00162 /*! Process a block of received V.27ter modem audio samples.
00163     \brief Process a block of received V.27ter modem audio samples.
00164     \param s The modem context.
00165     \param amp The audio sample buffer.
00166     \param len The number of samples in the buffer.
00167     \return The number of samples unprocessed.
00168 */
00169 int v27ter_rx(v27ter_rx_state_t *s, const int16_t *amp, int len);
00170 
00171 /*! Get a snapshot of the current equalizer coefficients.
00172     \brief Get a snapshot of the current equalizer coefficients.
00173     \param coeffs The vector of complex coefficients.
00174     \return The number of coefficients in the vector. */
00175 int v27ter_rx_equalizer_state(v27ter_rx_state_t *s, complex_t **coeffs);
00176 
00177 /*! Get the current received carrier frequency.
00178     \param s The modem context.
00179     \return The frequency, in Hertz. */
00180 float v27ter_rx_carrier_frequency(v27ter_rx_state_t *s);
00181 
00182 /*! Get the current symbol timing correction since startup.
00183     \param s The modem context.
00184     \return The correction. */
00185 float v27ter_rx_symbol_timing_correction(v27ter_rx_state_t *s);
00186 
00187 /*! Get a current received signal power.
00188     \param s The modem context.
00189     \return The signal power, in dBm0. */
00190 float v27ter_rx_signal_power(v27ter_rx_state_t *s);
00191 
00192 /*! Set the power level at which the carrier detection will cut in
00193     \param s The modem context.
00194     \param cutoff The signal cutoff power, in dBm0. */
00195 void v27ter_rx_signal_cutoff(v27ter_rx_state_t *s, float cutoff);
00196 
00197 /*! Set a handler routine to process QAM status reports
00198     \param s The modem context.
00199     \param handler The handler routine.
00200     \param user_data An opaque pointer passed to the handler routine. */
00201 void v27ter_rx_set_qam_report_handler(v27ter_rx_state_t *s, qam_report_handler_t *handler, void *user_data);
00202 
00203 #ifdef __cplusplus
00204 }
00205 #endif
00206 
00207 #endif
00208 /*- End of file ------------------------------------------------------------*/

Generated on Fri Nov 10 09:40:24 2006 for libspandsp by  doxygen 1.5.1