00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * v17tx.h - ITU V.17 modem transmit 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 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: v17tx.h,v 1.19 2005/12/29 09:54:24 steveu Exp $ 00027 */ 00028 00029 /*! \file */ 00030 00031 #if !defined(_V17TX_H_) 00032 #define _V17TX_H_ 00033 00034 /*! \page v17tx_page The V.17 transmitter 00035 \section v17tx_page_sec_1 What does it do? 00036 The V.17 transmitter implements the transmit side of a V.17 modem. This can 00037 operate at data rates of 14400, 12000, 9600 and 7200 bits/second. The audio 00038 output is a stream of 16 bit samples, at 8000 samples/second. The transmit and 00039 receive side of V.17 modems operate independantly. V.17 is mostly used for FAX 00040 transmission, where it provides the standard 14400 bits/second rate. 00041 00042 \section v17tx_page_sec_2 How does it work? 00043 V.17 uses QAM modulation and trellis coding. The data to be transmitted is 00044 scrambled, to whiten it. The least significant 2 bits of each symbol are then 00045 differentially encoded, using a simple lookup approach. The resulting 2 bits are 00046 convolutionally encoded, producing 3 bits. The extra bit is the redundant bit 00047 of the trellis code. The other bits of the symbol pass by the differential 00048 and convolutional coding unchanged. The resulting bits define the constellation 00049 point to be transmitted for the symbol. The redundant bit doubles the size of the 00050 constellation, and so increases the error rate for detecting individual symbols 00051 at the receiver. However, when a number of successive symbols are processed at 00052 the receiver, the redundancy actually provides several dB of improved error 00053 performance. 00054 00055 The standard method of producing a QAM modulated signal is to use a sampling 00056 rate which is a multiple of the baud rate. The raw signal is then a series of 00057 complex pulses, each an integer number of samples long. These can be shaped, 00058 using a suitable complex filter, and multiplied by a complex carrier signal 00059 to produce the final QAM signal for transmission. 00060 00061 The sampling rate for our transmitter is defined by the channel - 8000 per 00062 second. This is not a multiple of the baud rate (i.e. 2400 baud). The baud 00063 interval is actually 10/3 sample periods. Generating at the lowest common 00064 multiple of the baud rate and channel sample rate (i.e. 24000 samples/second), 00065 and then decimating to 8000 samples/second, would give good results. However, 00066 this would require considerable computation. A shortcut is to use slightly 00067 shaped pulses, instead of simple square ones. We can achieve the effect of pulse 00068 transitions at the 1/2 and 2/3 sample points by adjusting the first sample of 00069 each new pulse. The adjustment is simple. We need the effect of being 60 degrees 00070 or 120 degrees through a sine wave cycle at the Shannon rate at the sample 00071 point. This simply means we need to step by 0.25 or 0.75 of the actual step size 00072 on the first sample of those pulses which should start at the 1/3 or 2/3 sample 00073 positions. The logic and computation needed for this is much less than the 00074 computation needed for oversampling at 24000 samples/second. 00075 00076 The pulse shaping filter is only vaguely defined by the V.17 spec. Some of the 00077 other ITU modem specs. fully define the filter, typically specifying a root 00078 raised cosine filter, with 50% excess bandwidth. This is a pity, since it 00079 increases the variability of the received signal. However, the receiver's 00080 adaptive equalizer will largely compensate for these differences. The current 00081 design uses a root raised cosine filter with 50% excess bandwidth. 00082 00083 The carrier is generated using the DDS method. Using two second order resonators, 00084 started in quadrature, might be more efficient, as it would have less impact on 00085 the processor cache than a table lookup approach. However, the DDS approach 00086 suits the receiver better, so the same signal generator is also used for the 00087 transmitter. 00088 */ 00089 00090 #define V17TX_FILTER_STEPS 27 00091 00092 /*! 00093 V.17 modem transmit side descriptor. This defines the working state for a 00094 single instance of a V.17 modem transmitter. 00095 */ 00096 typedef struct 00097 { 00098 /*! \brief The bit rate of the modem. Valid values are 4800, 7200 and 9600. */ 00099 int bit_rate; 00100 /*! \brief The callback function used to get the next bit to be transmitted. */ 00101 get_bit_func_t get_bit; 00102 /*! \brief A user specified opaque pointer passed to the callback function. */ 00103 void *user_data; 00104 00105 float gain; 00106 00107 /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */ 00108 complex_t rrc_filter[2*V17TX_FILTER_STEPS]; 00109 /*! \brief Current offset into the RRC pulse shaping filter buffer. */ 00110 int rrc_filter_step; 00111 /*! \brief The current constellation position. */ 00112 complex_t current_point; 00113 00114 int diff; 00115 int convolution; 00116 00117 /*! \brief The register for the data scrambler. */ 00118 unsigned int scramble_reg; 00119 /*! \brief TRUE if transmitting the training sequence. FALSE if transmitting user data. */ 00120 int in_training; 00121 /*! A counter used to track progress through the optional TEP tone burst */ 00122 int tep_step; 00123 /*! \brief TRUE if the short training sequence is to be used. */ 00124 int short_train; 00125 /*! \brief A counter used to track progress through sending the training sequence. */ 00126 int training_step; 00127 00128 /*! \brief The current phase of the carrier (i.e. the DDS parameter). */ 00129 uint32_t carrier_phase; 00130 /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */ 00131 int32_t carrier_phase_rate; 00132 /*! \brief The current fractional phase of the baud timing. */ 00133 int baud_phase; 00134 /*! \brief The code number for the current position in the constellation. */ 00135 int constellation_state; 00136 00137 /*! \brief A pointer to the constellation currently in use. */ 00138 const complex_t *constellation; 00139 /*! \brief The current number of data bits per symbol. This does not include 00140 the redundant bit. */ 00141 int bits_per_symbol; 00142 /*! \brief An indicator to mark that we are tidying up to stop transmission. */ 00143 int shutdown; 00144 /*! \brief The get_bit function in use at any instant. */ 00145 get_bit_func_t current_get_bit; 00146 /*! \brief Error and flow logging control */ 00147 logging_state_t logging; 00148 } v17_tx_state_t; 00149 00150 #ifdef __cplusplus 00151 extern "C" { 00152 #endif 00153 00154 /*! Adjust a V.17 modem transmit context's power output. 00155 \brief Adjust a V.17 modem transmit context's output power. 00156 \param s The modem context. 00157 \param power The power level, in dBm0 */ 00158 void v17_tx_power(v17_tx_state_t *s, float power); 00159 00160 /*! Initialise a V.17 modem transmit context. This must be called before the first 00161 use of the context, to initialise its contents. 00162 \brief Initialise a V.17 modem transmit context. 00163 \param s The modem context. 00164 \param rate The bit rate of the modem. Valid values are 7200, 9600, 12000 and 14400. 00165 \param tep TRUE is the optional TEP tone is to be transmitted. 00166 \param get_bit The callback routine used to get the data to be transmitted. 00167 \param user_data An opaque pointer. 00168 \return A pointer to the modem context, or NULL if there was a problem. */ 00169 v17_tx_state_t *v17_tx_init(v17_tx_state_t *s, int rate, int tep, get_bit_func_t get_bit, void *user_data); 00170 00171 /*! Reinitialise an existing V.17 modem transmit context, so it may be reused. 00172 \brief Reinitialise an existing V.17 modem transmit context. 00173 \param s The modem context. 00174 \param rate The bit rate of the modem. Valid values are 7200, 9600, 12000 and 14400. 00175 \param tep TRUE is the optional TEP tone is to be transmitted. 00176 \param short_train TRUE if the short training sequence should be used. 00177 \return 0 for OK, -1 for parameter error. */ 00178 int v17_tx_restart(v17_tx_state_t *s, int rate, int tep, int short_train); 00179 00180 /*! Release a V.17 modem transmit context. 00181 \brief Release a V.17 modem transmit context. 00182 \param s The modem context. 00183 \return 0 for OK */ 00184 int v17_tx_release(v17_tx_state_t *s); 00185 00186 /*! Change the get_bit function associated with a V.17 modem transmit context. 00187 \brief Change the get_bit function associated with a V.17 modem transmit context. 00188 \param s The modem context. 00189 \param get_bit The callback routine used to get the data to be transmitted. 00190 \param user_data An opaque pointer. */ 00191 void v17_tx_set_get_bit(v17_tx_state_t *s, get_bit_func_t get_bit, void *user_data); 00192 00193 /*! Generate a block of V.17 modem audio samples. 00194 \brief Generate a block of V.17 modem audio samples. 00195 \param s The modem context. 00196 \param amp The audio sample buffer. 00197 \param len The number of samples to be generated. 00198 \return The number of samples actually generated. 00199 */ 00200 int v17_tx(v17_tx_state_t *s, int16_t *amp, int len); 00201 00202 #ifdef __cplusplus 00203 } 00204 #endif 00205 00206 #endif 00207 /*- End of file ------------------------------------------------------------*/