00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * private/v22bis.h - ITU V.22bis modem 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 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 00026 #if !defined(_SPANDSP_PRIVATE_V22BIS_H_) 00027 #define _SPANDSP_PRIVATE_V22BIS_H_ 00028 00029 /*! The length of the equalizer buffer */ 00030 #define V22BIS_EQUALIZER_LEN 17 00031 /*! Samples before the target position in the equalizer buffer */ 00032 #define V22BIS_EQUALIZER_PRE_LEN 8 00033 00034 /*! The number of taps in the transmit pulse shaping filter */ 00035 #define V22BIS_TX_FILTER_STEPS 9 00036 00037 /*! The number of taps in the receive pulse shaping/bandpass filter */ 00038 #define V22BIS_RX_FILTER_STEPS 27 00039 00040 /*! Segments of the training sequence on the receive side */ 00041 enum 00042 { 00043 V22BIS_RX_TRAINING_STAGE_NORMAL_OPERATION, 00044 V22BIS_RX_TRAINING_STAGE_SYMBOL_ACQUISITION, 00045 V22BIS_RX_TRAINING_STAGE_LOG_PHASE, 00046 V22BIS_RX_TRAINING_STAGE_UNSCRAMBLED_ONES, 00047 V22BIS_RX_TRAINING_STAGE_UNSCRAMBLED_ONES_SUSTAINING, 00048 V22BIS_RX_TRAINING_STAGE_SCRAMBLED_ONES_AT_1200, 00049 V22BIS_RX_TRAINING_STAGE_SCRAMBLED_ONES_AT_1200_SUSTAINING, 00050 V22BIS_RX_TRAINING_STAGE_WAIT_FOR_SCRAMBLED_ONES_AT_2400, 00051 V22BIS_RX_TRAINING_STAGE_PARKED 00052 }; 00053 00054 /*! Segments of the training sequence on the transmit side */ 00055 enum 00056 { 00057 V22BIS_TX_TRAINING_STAGE_NORMAL_OPERATION = 0, 00058 V22BIS_TX_TRAINING_STAGE_INITIAL_TIMED_SILENCE, 00059 V22BIS_TX_TRAINING_STAGE_INITIAL_SILENCE, 00060 V22BIS_TX_TRAINING_STAGE_U11, 00061 V22BIS_TX_TRAINING_STAGE_U0011, 00062 V22BIS_TX_TRAINING_STAGE_S11, 00063 V22BIS_TX_TRAINING_STAGE_TIMED_S11, 00064 V22BIS_TX_TRAINING_STAGE_S1111, 00065 V22BIS_TX_TRAINING_STAGE_PARKED 00066 }; 00067 00068 #if defined(SPANDSP_USE_FIXED_POINT) 00069 extern const complexi16_t v22bis_constellation[16]; 00070 #else 00071 extern const complexf_t v22bis_constellation[16]; 00072 #endif 00073 00074 /*! 00075 V.22bis modem descriptor. This defines the working state for a single instance 00076 of a V.22bis modem. 00077 */ 00078 struct v22bis_state_s 00079 { 00080 /*! \brief The maximum permitted bit rate of the modem. Valid values are 1200 and 2400. */ 00081 int bit_rate; 00082 /*! \brief TRUE is this is the calling side modem. */ 00083 int calling_party; 00084 /*! \brief The callback function used to get the next bit to be transmitted. */ 00085 get_bit_func_t get_bit; 00086 /*! \brief A user specified opaque pointer passed to the get_bit callback routine. */ 00087 void *get_bit_user_data; 00088 /*! \brief The callback function used to put each bit received. */ 00089 put_bit_func_t put_bit; 00090 /*! \brief A user specified opaque pointer passed to the put_bit callback routine. */ 00091 void *put_bit_user_data; 00092 /*! \brief The callback function used to report modem status changes. */ 00093 modem_status_func_t status_handler; 00094 /*! \brief A user specified opaque pointer passed to the status function. */ 00095 void *status_user_data; 00096 00097 int negotiated_bit_rate; 00098 00099 /* Receive section */ 00100 struct 00101 { 00102 /*! \brief Current offset into the RRC pulse shaping filter buffer. */ 00103 int rrc_filter_step; 00104 00105 /*! \brief The register for the data scrambler. */ 00106 uint32_t scramble_reg; 00107 /*! \brief A counter for the number of consecutive bits of repeating pattern through 00108 the scrambler. */ 00109 int scrambler_pattern_count; 00110 00111 /*! \brief 0 if receiving user data. A training stage value during training */ 00112 int training; 00113 /*! \brief A count of how far through the current training step we are. */ 00114 int training_count; 00115 00116 /*! \brief >0 if a signal above the minimum is present. It may or may not be a V.22bis signal. */ 00117 int signal_present; 00118 00119 /*! \brief The current phase of the carrier (i.e. the DDS parameter). */ 00120 uint32_t carrier_phase; 00121 /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */ 00122 int32_t carrier_phase_rate; 00123 00124 /*! \brief A callback function which may be enabled to report every symbol's 00125 constellation position. */ 00126 qam_report_handler_t qam_report; 00127 /*! \brief A user specified opaque pointer passed to the qam_report callback 00128 routine. */ 00129 void *qam_user_data; 00130 00131 /*! \brief A power meter, to measure the HPF'ed signal power in the channel. */ 00132 power_meter_t rx_power; 00133 /*! \brief The power meter level at which carrier on is declared. */ 00134 int32_t carrier_on_power; 00135 /*! \brief The power meter level at which carrier off is declared. */ 00136 int32_t carrier_off_power; 00137 00138 int constellation_state; 00139 00140 #if defined(SPANDSP_USE_FIXED_POINT) 00141 /*! \brief The scaling factor accessed by the AGC algorithm. */ 00142 int16_t agc_scaling; 00143 /*! \brief The root raised cosine (RRC) pulse shaping filter buffer. */ 00144 int16_t rrc_filter[V22BIS_RX_FILTER_STEPS]; 00145 00146 /*! \brief The current delta factor for updating the equalizer coefficients. */ 00147 int16_t eq_delta; 00148 /*! \brief The adaptive equalizer coefficients. */ 00149 complexi16_t eq_coeff[V22BIS_EQUALIZER_LEN]; 00150 /*! \brief The equalizer signal buffer. */ 00151 complexi16_t eq_buf[V22BIS_EQUALIZER_LEN]; 00152 00153 /*! \brief A measure of how much mismatch there is between the real constellation, 00154 and the decoded symbol positions. */ 00155 int32_t training_error; 00156 /*! \brief The proportional part of the carrier tracking filter. */ 00157 int32_t carrier_track_p; 00158 /*! \brief The integral part of the carrier tracking filter. */ 00159 int32_t carrier_track_i; 00160 #else 00161 /*! \brief The scaling factor accessed by the AGC algorithm. */ 00162 float agc_scaling; 00163 /*! \brief The root raised cosine (RRC) pulse shaping filter buffer. */ 00164 float rrc_filter[V22BIS_RX_FILTER_STEPS]; 00165 00166 /*! \brief The current delta factor for updating the equalizer coefficients. */ 00167 float eq_delta; 00168 /*! \brief The adaptive equalizer coefficients. */ 00169 complexf_t eq_coeff[V22BIS_EQUALIZER_LEN]; 00170 /*! \brief The equalizer signal buffer. */ 00171 complexf_t eq_buf[V22BIS_EQUALIZER_LEN]; 00172 00173 /*! \brief A measure of how much mismatch there is between the real constellation, 00174 and the decoded symbol positions. */ 00175 float training_error; 00176 /*! \brief The proportional part of the carrier tracking filter. */ 00177 float carrier_track_p; 00178 /*! \brief The integral part of the carrier tracking filter. */ 00179 float carrier_track_i; 00180 #endif 00181 /*! \brief Current offset into the equalizer buffer. */ 00182 int eq_step; 00183 /*! \brief Current write offset into the equalizer buffer. */ 00184 int eq_put_step; 00185 00186 /*! \brief Integration variable for damping the Gardner algorithm tests. */ 00187 int gardner_integrate; 00188 /*! \brief Current step size of Gardner algorithm integration. */ 00189 int gardner_step; 00190 /*! \brief The total symbol timing correction since the carrier came up. 00191 This is only for performance analysis purposes. */ 00192 int total_baud_timing_correction; 00193 /*! \brief The current fractional phase of the baud timing. */ 00194 int baud_phase; 00195 00196 int sixteen_way_decisions; 00197 00198 int pattern_repeats; 00199 int last_raw_bits; 00200 } rx; 00201 00202 /* Transmit section */ 00203 struct 00204 { 00205 #if defined(SPANDSP_USE_FIXED_POINT) 00206 /*! \brief The guard tone level. */ 00207 int16_t guard_tone_gain; 00208 /*! \brief The gain factor needed to achieve the specified output power. */ 00209 int16_t gain; 00210 /*! \brief The root raised cosine (RRC) pulse shaping filter buffer. */ 00211 int16_t rrc_filter_re[V22BIS_TX_FILTER_STEPS]; 00212 int16_t rrc_filter_im[V22BIS_TX_FILTER_STEPS]; 00213 #else 00214 /*! \brief The guard tone level. */ 00215 float guard_tone_gain; 00216 /*! \brief The gain factor needed to achieve the specified output power. */ 00217 float gain; 00218 /*! \brief The root raised cosine (RRC) pulse shaping filter buffer. */ 00219 float rrc_filter_re[V22BIS_TX_FILTER_STEPS]; 00220 float rrc_filter_im[V22BIS_TX_FILTER_STEPS]; 00221 #endif 00222 00223 /*! \brief Current offset into the RRC pulse shaping filter buffer. */ 00224 int rrc_filter_step; 00225 00226 /*! \brief The register for the data scrambler. */ 00227 uint32_t scramble_reg; 00228 /*! \brief A counter for the number of consecutive bits of repeating pattern through 00229 the scrambler. */ 00230 int scrambler_pattern_count; 00231 00232 /*! \brief 0 if transmitting user data. A training stage value during training */ 00233 int training; 00234 /*! \brief A counter used to track progress through sending the training sequence. */ 00235 int training_count; 00236 /*! \brief The current phase of the carrier (i.e. the DDS parameter). */ 00237 uint32_t carrier_phase; 00238 /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */ 00239 int32_t carrier_phase_rate; 00240 /*! \brief The current phase of the guard tone (i.e. the DDS parameter). */ 00241 uint32_t guard_phase; 00242 /*! \brief The update rate for the phase of the guard tone (i.e. the DDS increment). */ 00243 int32_t guard_phase_rate; 00244 /*! \brief The current fractional phase of the baud timing. */ 00245 int baud_phase; 00246 /*! \brief The code number for the current position in the constellation. */ 00247 int constellation_state; 00248 /*! \brief An indicator to mark that we are tidying up to stop transmission. */ 00249 int shutdown; 00250 /*! \brief The get_bit function in use at any instant. */ 00251 get_bit_func_t current_get_bit; 00252 } tx; 00253 00254 /*! \brief Error and flow logging control */ 00255 logging_state_t logging; 00256 }; 00257 00258 #if defined(__cplusplus) 00259 extern "C" 00260 { 00261 #endif 00262 00263 /*! Reinitialise an existing V.22bis modem receive context. 00264 \brief Reinitialise an existing V.22bis modem receive context. 00265 \param s The modem context. 00266 \return 0 for OK, -1 for bad parameter */ 00267 int v22bis_rx_restart(v22bis_state_t *s); 00268 00269 void v22bis_report_status_change(v22bis_state_t *s, int status); 00270 00271 void v22bis_equalizer_coefficient_reset(v22bis_state_t *s); 00272 00273 #if defined(__cplusplus) 00274 } 00275 #endif 00276 00277 #endif 00278 /*- End of file ------------------------------------------------------------*/
1.6.1