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 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: v27ter_tx.h,v 1.36 2008/07/16 14:23:48 steveu Exp $ 00026 */ 00027 00028 /*! \file */ 00029 00030 #if !defined(_SPANDSP_V27TER_TX_H_) 00031 #define _SPANDSP_V27TER_TX_H_ 00032 00033 /*! \page v27ter_tx_page The V.27ter transmitter 00034 \section v27ter_tx_page_sec_1 What does it do? 00035 The V.27ter transmitter implements the transmit side of a V.27ter modem. This 00036 can operate at data rates of 4800 and 2400 bits/s. The audio output is a stream 00037 of 16 bit samples, at 8000 samples/second. The transmit and receive side of 00038 V.27ter modems operate independantly. V.27ter is used for FAX transmission, 00039 where it provides the standard 4800 and 2400 bits/s rates. 00040 00041 \section v27ter_tx_page_sec_2 How does it work? 00042 V.27ter uses DPSK modulation. A common method of producing a DPSK modulated 00043 signal is to use a sampling rate which is a multiple of the baud rate. The raw 00044 signal is then a series of complex pulses, each an integer number of samples 00045 long. These can be shaped, using a suitable complex filter, and multiplied by a 00046 complex carrier signal to produce the final DPSK signal for transmission. 00047 00048 The pulse shaping filter for V.27ter is defined in the spec. It is a root raised 00049 cosine filter with 50% excess bandwidth. 00050 00051 The sampling rate for our transmitter is defined by the channel - 8000 samples/s. 00052 This is a multiple of the baud rate at 4800 bits/s (8-PSK at 1600 baud, 5 samples per 00053 symbol), but not at 2400 bits/s (4-PSK at 1200 baud, 20/3 samples per symbol). The baud 00054 interval is actually 20/3 sample periods at 2400bis/s. A symmetric FIR is used to 00055 apply root raised cosine filtering in the 4800bits/s mode. In the 2400bits/s mode 00056 a polyphase FIR filter is used. This consists of 20 sets of coefficients, offering 00057 zero to 19/20ths of a baud phase shift as well as root raised cosine filtering. 00058 The appropriate coefficient set is chosen for each signal sample generated. 00059 00060 The carrier is generated using the DDS method. Using 2 second order resonators, 00061 started in quadrature, might be more efficient, as it would have less impact on 00062 the processor cache than a table lookup approach. However, the DDS approach 00063 suits the receiver better, so then same signal generator is also used for the 00064 transmitter. 00065 */ 00066 00067 #define V27TER_TX_FILTER_STEPS 9 00068 00069 /*! 00070 V.27ter modem transmit side descriptor. This defines the working state for a 00071 single instance of a V.27ter modem transmitter. 00072 */ 00073 typedef struct 00074 { 00075 /*! \brief The bit rate of the modem. Valid values are 2400 and 4800. */ 00076 int bit_rate; 00077 /*! \brief The callback function used to get the next bit to be transmitted. */ 00078 get_bit_func_t get_bit; 00079 /*! \brief A user specified opaque pointer passed to the get_bit function. */ 00080 void *get_bit_user_data; 00081 00082 /*! \brief The callback function used to report modem status changes. */ 00083 modem_tx_status_func_t status_handler; 00084 /*! \brief A user specified opaque pointer passed to the status function. */ 00085 void *status_user_data; 00086 00087 #if defined(SPANDSP_USE_FIXED_POINT) 00088 /*! \brief The gain factor needed to achieve the specified output power at 2400bps. */ 00089 int32_t gain_2400; 00090 /*! \brief The gain factor needed to achieve the specified output power at 4800bps. */ 00091 int32_t gain_4800; 00092 #else 00093 /*! \brief The gain factor needed to achieve the specified output power at 2400bps. */ 00094 float gain_2400; 00095 /*! \brief The gain factor needed to achieve the specified output power at 4800bps. */ 00096 float gain_4800; 00097 #endif 00098 /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */ 00099 #if defined(SPANDSP_USE_FIXED_POINT) 00100 complexi16_t rrc_filter[2*V27TER_TX_FILTER_STEPS]; 00101 #else 00102 complexf_t rrc_filter[2*V27TER_TX_FILTER_STEPS]; 00103 #endif 00104 /*! \brief Current offset into the RRC pulse shaping filter buffer. */ 00105 int rrc_filter_step; 00106 00107 /*! \brief The register for the training and data scrambler. */ 00108 unsigned int scramble_reg; 00109 /*! \brief A counter for the number of consecutive bits of repeating pattern through 00110 the scrambler. */ 00111 int scrambler_pattern_count; 00112 /*! \brief TRUE if transmitting the training sequence, or shutting down transmission. 00113 FALSE if transmitting user data. */ 00114 int in_training; 00115 /*! \brief A counter used to track progress through sending the training sequence. */ 00116 int training_step; 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 } v27ter_tx_state_t; 00131 00132 #if defined(__cplusplus) 00133 extern "C" 00134 { 00135 #endif 00136 00137 /*! Adjust a V.27ter modem transmit context's power output. 00138 \brief Adjust a V.27ter modem transmit context's output power. 00139 \param s The modem context. 00140 \param power The power level, in dBm0 */ 00141 void v27ter_tx_power(v27ter_tx_state_t *s, float power); 00142 00143 /*! Initialise a V.27ter modem transmit context. 00144 \brief Initialise a V.27ter modem transmit context. 00145 \param s The modem context. 00146 \param bit_rate The bit rate of the modem. Valid values are 2400 and 4800. 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 v27ter_tx_state_t *v27ter_tx_init(v27ter_tx_state_t *s, int bit_rate, int tep, get_bit_func_t get_bit, void *user_data); 00152 00153 /*! Reinitialise an existing V.27ter modem transmit context, so it may be reused. 00154 \brief Reinitialise an existing V.27ter modem transmit context. 00155 \param s The modem context. 00156 \param bit_rate The bit rate of the modem. Valid values are 2400 and 4800. 00157 \param tep TRUE is the optional TEP tone is to be transmitted. 00158 \return 0 for OK, -1 for bad parameter */ 00159 int v27ter_tx_restart(v27ter_tx_state_t *s, int bit_rate, int tep); 00160 00161 /*! Free a V.27ter modem transmit context. 00162 \brief Free a V.27ter modem transmit context. 00163 \param s The modem context. 00164 \return 0 for OK */ 00165 int v27ter_tx_free(v27ter_tx_state_t *s); 00166 00167 /*! Change the get_bit function associated with a V.27ter modem transmit context. 00168 \brief Change the get_bit function associated with a V.27ter 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 v27ter_tx_set_get_bit(v27ter_tx_state_t *s, get_bit_func_t get_bit, void *user_data); 00173 00174 /*! Change the modem status report function associated with a V.27ter modem transmit context. 00175 \brief Change the modem status report function associated with a V.27ter modem transmit context. 00176 \param s The modem context. 00177 \param handler The callback routine used to report modem status changes. 00178 \param user_data An opaque pointer. */ 00179 void v27ter_tx_set_modem_status_handler(v27ter_tx_state_t *s, modem_tx_status_func_t handler, void *user_data); 00180 00181 /*! Generate a block of V.27ter modem audio samples. 00182 \brief Generate a block of V.27ter modem audio samples. 00183 \param s The modem context. 00184 \param amp The audio sample buffer. 00185 \param len The number of samples to be generated. 00186 \return The number of samples actually generated. 00187 */ 00188 int v27ter_tx(v27ter_tx_state_t *s, int16_t amp[], int len); 00189 00190 #if defined(__cplusplus) 00191 } 00192 #endif 00193 00194 #endif 00195 /*- End of file ------------------------------------------------------------*/