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