v17tx.h

Go to the documentation of this file.
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 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: v17tx.h,v 1.36 2008/07/16 14:23:48 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 get_bit function. */
00097     void *get_bit_user_data;
00098 
00099     /*! \brief The callback function used to report modem status changes. */
00100     modem_tx_status_func_t status_handler;
00101     /*! \brief A user specified opaque pointer passed to the status function. */
00102     void *status_user_data;
00103 
00104     /*! \brief The gain factor needed to achieve the specified output power. */
00105 #if defined(SPANDSP_USE_FIXED_POINT)
00106     int32_t gain;
00107 #else
00108     float gain;
00109 #endif
00110 
00111     /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
00112 #if defined(SPANDSP_USE_FIXED_POINT)
00113     complexi16_t rrc_filter[2*V17_TX_FILTER_STEPS];
00114 #else
00115     complexf_t rrc_filter[2*V17_TX_FILTER_STEPS];
00116 #endif
00117     /*! \brief Current offset into the RRC pulse shaping filter buffer. */
00118     int rrc_filter_step;
00119 
00120     /*! \brief The current state of the differential encoder. */
00121     int diff;
00122     /*! \brief The current state of the convolutional encoder. */
00123     int convolution;
00124 
00125     /*! \brief The register for the data scrambler. */
00126     unsigned int scramble_reg;
00127     /*! \brief TRUE if transmitting the training sequence. FALSE if transmitting user data. */
00128     int in_training;
00129     /*! \brief TRUE if the short training sequence is to be used. */
00130     int short_train;
00131     /*! \brief A counter used to track progress through sending the training sequence. */
00132     int training_step;
00133 
00134     /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
00135     uint32_t carrier_phase;
00136     /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
00137     int32_t carrier_phase_rate;
00138     /*! \brief The current fractional phase of the baud timing. */
00139     int baud_phase;
00140     /*! \brief The code number for the current position in the constellation. */
00141     int constellation_state;
00142     
00143     /*! \brief A pointer to the constellation currently in use. */
00144 #if defined(SPANDSP_USE_FIXED_POINT)
00145     const complexi16_t *constellation;
00146 #else
00147     const complexf_t *constellation;
00148 #endif
00149     /*! \brief The current number of data bits per symbol. This does not include
00150                the redundant bit. */
00151     int bits_per_symbol;
00152     /*! \brief The get_bit function in use at any instant. */
00153     get_bit_func_t current_get_bit;
00154     /*! \brief Error and flow logging control */
00155     logging_state_t logging;
00156 } v17_tx_state_t;
00157 
00158 #if defined(__cplusplus)
00159 extern "C"
00160 {
00161 #endif
00162 
00163 /*! Adjust a V.17 modem transmit context's power output.
00164     \brief Adjust a V.17 modem transmit context's output power.
00165     \param s The modem context.
00166     \param power The power level, in dBm0 */
00167 void v17_tx_power(v17_tx_state_t *s, float power);
00168 
00169 /*! Initialise a V.17 modem transmit context. This must be called before the first
00170     use of the context, to initialise its contents.
00171     \brief Initialise a V.17 modem transmit context.
00172     \param s The modem context.
00173     \param rate The bit rate of the modem. Valid values are 7200, 9600, 12000 and 14400.
00174     \param tep TRUE is the optional TEP tone is to be transmitted.
00175     \param get_bit The callback routine used to get the data to be transmitted.
00176     \param user_data An opaque pointer.
00177     \return A pointer to the modem context, or NULL if there was a problem. */
00178 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);
00179 
00180 /*! Reinitialise an existing V.17 modem transmit context, so it may be reused.
00181     \brief Reinitialise an existing V.17 modem transmit context.
00182     \param s The modem context.
00183     \param bit_rate The bit rate of the modem. Valid values are 7200, 9600, 12000 and 14400.
00184     \param tep TRUE is the optional TEP tone is to be transmitted.
00185     \param short_train TRUE if the short training sequence should be used.
00186     \return 0 for OK, -1 for parameter error. */
00187 int v17_tx_restart(v17_tx_state_t *s, int bit_rate, int tep, int short_train);
00188 
00189 /*! Free a V.17 modem transmit context.
00190     \brief Free a V.17 modem transmit context.
00191     \param s The modem context.
00192     \return 0 for OK */
00193 int v17_tx_free(v17_tx_state_t *s);
00194 
00195 /*! Change the get_bit function associated with a V.17 modem transmit context.
00196     \brief Change the get_bit function associated with a V.17 modem transmit context.
00197     \param s The modem context.
00198     \param get_bit The callback routine used to get the data to be transmitted.
00199     \param user_data An opaque pointer. */
00200 void v17_tx_set_get_bit(v17_tx_state_t *s, get_bit_func_t get_bit, void *user_data);
00201 
00202 /*! Change the modem status report function associated with a V.17 modem transmit context.
00203     \brief Change the modem status report function associated with a V.17 modem transmit context.
00204     \param s The modem context.
00205     \param handler The callback routine used to report modem status changes.
00206     \param user_data An opaque pointer. */
00207 void v17_tx_set_modem_status_handler(v17_tx_state_t *s, modem_tx_status_func_t handler, void *user_data);
00208 
00209 /*! Generate a block of V.17 modem audio samples.
00210     \brief Generate a block of V.17 modem audio samples.
00211     \param s The modem context.
00212     \param amp The audio sample buffer.
00213     \param len The number of samples to be generated.
00214     \return The number of samples actually generated.
00215 */
00216 int v17_tx(v17_tx_state_t *s, int16_t amp[], int len);
00217 
00218 #if defined(__cplusplus)
00219 }
00220 #endif
00221 
00222 #endif
00223 /*- End of file ------------------------------------------------------------*/

Generated on Tue Oct 7 20:25:50 2008 for spandsp by  doxygen 1.5.6