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