private/v27ter_rx.h

00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * private/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 Lesser General Public License version 2.1,
00014  * as 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 Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public
00022  * License along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00024  *
00025  * $Id: v27ter_rx.h,v 1.2 2009/07/09 13:52:09 steveu Exp $
00026  */
00027 
00028 #if !defined(_SPANDSP_PRIVATE_V27TER_RX_H_)
00029 #define _SPANDSP_PRIVATE_V27TER_RX_H_
00030 
00031 /* Target length for the equalizer is about 43 taps for 4800bps and 32 taps for 2400bps
00032    to deal with the worst stuff in V.56bis. */
00033 /*! Samples before the target position in the equalizer buffer */
00034 #define V27TER_EQUALIZER_PRE_LEN        16  /* This much before the real event */
00035 /*! Samples after the target position in the equalizer buffer */
00036 #define V27TER_EQUALIZER_POST_LEN       14  /* This much after the real event (must be even) */
00037 
00038 /*! The number of taps in the 4800bps pulse shaping/bandpass filter */
00039 #define V27TER_RX_4800_FILTER_STEPS     27
00040 /*! The number of taps in the 2400bps pulse shaping/bandpass filter */
00041 #define V27TER_RX_2400_FILTER_STEPS     27
00042 
00043 #if V27TER_RX_4800_FILTER_STEPS > V27TER_RX_2400_FILTER_STEPS
00044 #define V27TER_RX_FILTER_STEPS V27TER_RX_4800_FILTER_STEPS
00045 #else
00046 #define V27TER_RX_FILTER_STEPS V27TER_RX_2400_FILTER_STEPS
00047 #endif
00048 
00049 /*!
00050     V.27ter modem receive side descriptor. This defines the working state for a
00051     single instance of a V.27ter modem receiver.
00052 */
00053 struct v27ter_rx_state_s
00054 {
00055     /*! \brief The bit rate of the modem. Valid values are 2400 and 4800. */
00056     int bit_rate;
00057     /*! \brief The callback function used to put each bit received. */
00058     put_bit_func_t put_bit;
00059     /*! \brief A user specified opaque pointer passed to the put_bit routine. */
00060     void *put_bit_user_data;
00061 
00062     /*! \brief The callback function used to report modem status changes. */
00063     modem_rx_status_func_t status_handler;
00064     /*! \brief A user specified opaque pointer passed to the status function. */
00065     void *status_user_data;
00066 
00067     /*! \brief A callback function which may be enabled to report every symbol's
00068                constellation position. */
00069     qam_report_handler_t qam_report;
00070     /*! \brief A user specified opaque pointer passed to the qam_report callback
00071                routine. */
00072     void *qam_user_data;
00073 
00074     /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
00075 #if defined(SPANDSP_USE_FIXED_POINT)
00076     int16_t rrc_filter[V27TER_RX_FILTER_STEPS];
00077 #else
00078     float rrc_filter[V27TER_RX_FILTER_STEPS];
00079 #endif
00080     /*! \brief Current offset into the RRC pulse shaping filter buffer. */
00081     int rrc_filter_step;
00082 
00083     /*! \brief The register for the training and data scrambler. */
00084     unsigned int scramble_reg;
00085     /*! \brief A counter for the number of consecutive bits of repeating pattern through
00086                the scrambler. */
00087     int scrambler_pattern_count;
00088     /*! \brief The current step in the table of BC constellation positions. */
00089     int training_bc;
00090     /*! \brief TRUE if the previous trained values are to be reused. */
00091     int old_train;
00092     /*! \brief The section of the training data we are currently in. */
00093     int training_stage;
00094     /*! \brief A count of how far through the current training step we are. */
00095     int training_count;
00096     /*! \brief A measure of how much mismatch there is between the real constellation,
00097         and the decoded symbol positions. */
00098     float training_error;
00099     /*! \brief The value of the last signal sample, using the a simple HPF for signal power estimation. */
00100     int16_t last_sample;
00101     /*! \brief >0 if a signal above the minimum is present. It may or may not be a V.27ter signal. */
00102     int signal_present;
00103     /*! \brief Whether or not a carrier drop was detected and the signal delivery is pending. */
00104     int carrier_drop_pending;
00105     /*! \brief A count of the current consecutive samples below the carrier off threshold. */
00106     int low_samples;
00107     /*! \brief A highest magnitude sample seen. */
00108     int16_t high_sample;
00109 
00110     /*! \brief The position of the current symbol in the constellation, used for
00111                differential decoding. */
00112     int constellation_state;
00113 
00114     /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
00115     uint32_t carrier_phase;
00116     /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
00117     int32_t carrier_phase_rate;
00118     /*! \brief The carrier update rate saved for reuse when using short training. */
00119     int32_t carrier_phase_rate_save;
00120 #if defined(SPANDSP_USE_FIXED_POINTx)
00121     /*! \brief The proportional part of the carrier tracking filter. */
00122     float carrier_track_p;
00123     /*! \brief The integral part of the carrier tracking filter. */
00124     float carrier_track_i;
00125 #else
00126     /*! \brief The proportional part of the carrier tracking filter. */
00127     float carrier_track_p;
00128     /*! \brief The integral part of the carrier tracking filter. */
00129     float carrier_track_i;
00130 #endif
00131 
00132     /*! \brief A power meter, to measure the HPF'ed signal power in the channel. */    
00133     power_meter_t power;
00134     /*! \brief The power meter level at which carrier on is declared. */
00135     int32_t carrier_on_power;
00136     /*! \brief The power meter level at which carrier off is declared. */
00137     int32_t carrier_off_power;
00138 
00139     /*! \brief Current read offset into the equalizer buffer. */
00140     int eq_step;
00141     /*! \brief Current write offset into the equalizer buffer. */
00142     int eq_put_step;
00143     /*! \brief Symbol counter to the next equalizer update. */
00144     int eq_skip;
00145 
00146     /*! \brief The current half of the baud. */
00147     int baud_half;
00148 
00149 #if defined(SPANDSP_USE_FIXED_POINT)
00150     /*! \brief The scaling factor accessed by the AGC algorithm. */
00151     int16_t agc_scaling;
00152     /*! \brief The previous value of agc_scaling, needed to reuse old training. */
00153     int16_t agc_scaling_save;
00154 
00155     /*! \brief The current delta factor for updating the equalizer coefficients. */
00156     float eq_delta;
00157     /*! \brief The adaptive equalizer coefficients. */
00158     /*complexi16_t*/ complexf_t  eq_coeff[V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN];
00159     /*! \brief A saved set of adaptive equalizer coefficients for use after restarts. */
00160     /*complexi16_t*/ complexf_t  eq_coeff_save[V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN];
00161     /*! \brief The equalizer signal buffer. */
00162     /*complexi16_t*/ complexf_t eq_buf[V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN];
00163 #else
00164     /*! \brief The scaling factor accessed by the AGC algorithm. */
00165     float agc_scaling;
00166     /*! \brief The previous value of agc_scaling, needed to reuse old training. */
00167     float agc_scaling_save;
00168 
00169     /*! \brief The current delta factor for updating the equalizer coefficients. */
00170     float eq_delta;
00171     /*! \brief The adaptive equalizer coefficients. */
00172     complexf_t eq_coeff[V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN];
00173     /*! \brief A saved set of adaptive equalizer coefficients for use after restarts. */
00174     complexf_t eq_coeff_save[V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN];
00175     /*! \brief The equalizer signal buffer. */
00176     complexf_t eq_buf[V27TER_EQUALIZER_PRE_LEN + 1 + V27TER_EQUALIZER_POST_LEN];
00177 #endif
00178 
00179     /*! \brief Integration variable for damping the Gardner algorithm tests. */
00180     int gardner_integrate;
00181     /*! \brief Current step size of Gardner algorithm integration. */
00182     int gardner_step;
00183     /*! \brief The total symbol timing correction since the carrier came up.
00184                This is only for performance analysis purposes. */
00185     int total_baud_timing_correction;
00186 
00187     /*! \brief Starting phase angles for the coarse carrier aquisition step. */
00188     int32_t start_angles[2];
00189     /*! \brief History list of phase angles for the coarse carrier aquisition step. */
00190     int32_t angles[16];
00191     /*! \brief Error and flow logging control */
00192     logging_state_t logging;
00193 };
00194 
00195 #endif
00196 /*- End of file ------------------------------------------------------------*/