v27ter_tx.h

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

Generated on Fri Nov 10 09:40:24 2006 for libspandsp by  doxygen 1.5.1