Mercurial > hg > audiostuff
comparison spandsp-0.0.6pre17/src/spandsp/v29tx.h @ 4:26cd8f1ef0b1
import spandsp-0.0.6pre17
| author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
|---|---|
| date | Fri, 25 Jun 2010 15:50:58 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 3:c6c5a16ce2f2 | 4:26cd8f1ef0b1 |
|---|---|
| 1 /* | |
| 2 * SpanDSP - a series of DSP components for telephony | |
| 3 * | |
| 4 * v29tx.h - ITU V.29 modem transmit part | |
| 5 * | |
| 6 * Written by Steve Underwood <steveu@coppice.org> | |
| 7 * | |
| 8 * Copyright (C) 2003 Steve Underwood | |
| 9 * | |
| 10 * All rights reserved. | |
| 11 * | |
| 12 * This program is free software; you can redistribute it and/or modify | |
| 13 * it under the terms of the GNU Lesser General Public License version 2.1, | |
| 14 * as published by the Free Software Foundation. | |
| 15 * | |
| 16 * This program is distributed in the hope that it will be useful, | |
| 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 * GNU Lesser General Public License for more details. | |
| 20 * | |
| 21 * You should have received a copy of the GNU Lesser General Public | |
| 22 * License along with this program; if not, write to the Free Software | |
| 23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
| 24 * | |
| 25 * $Id: v29tx.h,v 1.41 2009/07/09 13:52:09 steveu Exp $ | |
| 26 */ | |
| 27 | |
| 28 /*! \file */ | |
| 29 | |
| 30 #if !defined(_SPANDSP_V29TX_H_) | |
| 31 #define _SPANDSP_V29TX_H_ | |
| 32 | |
| 33 /*! \page v29tx_page The V.29 transmitter | |
| 34 \section v29tx_page_sec_1 What does it do? | |
| 35 The V.29 transmitter implements the transmit side of a V.29 modem. This can | |
| 36 operate at data rates of 9600, 7200 and 4800 bits/s. The audio output is a | |
| 37 stream of 16 bit samples, at 8000 samples/second. The transmit and receive side | |
| 38 of V.29 modems operate independantly. V.29 is mostly used for FAX transmission, | |
| 39 where it provides the standard 9600 and 7200 bits/s rates (the 4800 bits/s mode | |
| 40 is not used for FAX). | |
| 41 | |
| 42 \section v29tx_page_sec_2 How does it work? | |
| 43 V.29 uses QAM modulation. The standard method of producing a QAM modulated | |
| 44 signal is to use a sampling rate which is a multiple of the baud rate. The raw | |
| 45 signal is then a series of complex pulses, each an integer number of samples | |
| 46 long. These can be shaped, using a suitable complex filter, and multiplied by a | |
| 47 complex carrier signal to produce the final QAM signal for transmission. | |
| 48 | |
| 49 The pulse shaping filter is only vaguely defined by the V.29 spec. Some of the | |
| 50 other ITU modem specs. fully define the filter, typically specifying a root | |
| 51 raised cosine filter, with 50% excess bandwidth. This is a pity, since it | |
| 52 increases the variability of the received signal. However, the receiver's | |
| 53 adaptive equalizer will compensate for these differences. The current | |
| 54 design uses a root raised cosine filter with 25% excess bandwidth. Greater | |
| 55 excess bandwidth will not allow the tranmitted signal to meet the spectral | |
| 56 requirements. | |
| 57 | |
| 58 The sampling rate for our transmitter is defined by the channel - 8000 per | |
| 59 second. This is not a multiple of the baud rate (i.e. 2400 baud). The baud | |
| 60 interval is actually 10/3 sample periods. Instead of using a symmetric | |
| 61 FIR to pulse shape the signal, a polyphase filter is used. This consists of | |
| 62 10 sets of coefficients, offering zero to 9/10ths of a baud phase shift as well | |
| 63 as root raised cosine filtering. The appropriate coefficient set is chosen for | |
| 64 each signal sample generated. | |
| 65 | |
| 66 The carrier is generated using the DDS method. Using two second order resonators, | |
| 67 started in quadrature, might be more efficient, as it would have less impact on | |
| 68 the processor cache than a table lookup approach. However, the DDS approach | |
| 69 suits the receiver better, so the same signal generator is also used for the | |
| 70 transmitter. | |
| 71 | |
| 72 The equation defining QAM modulation is: | |
| 73 | |
| 74 s(n) = A*cos(2*pi*f*n + phi(n)) | |
| 75 | |
| 76 where phi(n) is the phase of the information, and A is the amplitude of the information | |
| 77 | |
| 78 using the identity | |
| 79 | |
| 80 cos(x + y) = cos(x)*cos(y) - sin(x)*sin(y) | |
| 81 | |
| 82 we get | |
| 83 | |
| 84 s(n) = A {cos(2*pi*f*n)*cos(phi(n)) - sin(2*pi*f*n)*sin(phi(n))} | |
| 85 | |
| 86 substituting with the constellation positions | |
| 87 | |
| 88 I(n) = A*cos(phi(n)) | |
| 89 Q(n) = A*sin(phi(n)) | |
| 90 | |
| 91 gives | |
| 92 | |
| 93 s(n) = I(n)*cos(2*pi*f*n) - Q(n)*sin(2*pi*f*n) | |
| 94 | |
| 95 */ | |
| 96 | |
| 97 /*! | |
| 98 V.29 modem transmit side descriptor. This defines the working state for a | |
| 99 single instance of a V.29 modem transmitter. | |
| 100 */ | |
| 101 typedef struct v29_tx_state_s v29_tx_state_t; | |
| 102 | |
| 103 #if defined(__cplusplus) | |
| 104 extern "C" | |
| 105 { | |
| 106 #endif | |
| 107 | |
| 108 /*! Adjust a V.29 modem transmit context's power output. | |
| 109 \brief Adjust a V.29 modem transmit context's output power. | |
| 110 \param s The modem context. | |
| 111 \param power The power level, in dBm0 */ | |
| 112 SPAN_DECLARE(void) v29_tx_power(v29_tx_state_t *s, float power); | |
| 113 | |
| 114 /*! Initialise a V.29 modem transmit context. This must be called before the first | |
| 115 use of the context, to initialise its contents. | |
| 116 \brief Initialise a V.29 modem transmit context. | |
| 117 \param s The modem context. | |
| 118 \param bit_rate The bit rate of the modem. Valid values are 4800, 7200 and 9600. | |
| 119 \param tep TRUE is the optional TEP tone is to be transmitted. | |
| 120 \param get_bit The callback routine used to get the data to be transmitted. | |
| 121 \param user_data An opaque pointer. | |
| 122 \return A pointer to the modem context, or NULL if there was a problem. */ | |
| 123 SPAN_DECLARE(v29_tx_state_t *) v29_tx_init(v29_tx_state_t *s, int bit_rate, int tep, get_bit_func_t get_bit, void *user_data); | |
| 124 | |
| 125 /*! Reinitialise an existing V.29 modem transmit context, so it may be reused. | |
| 126 \brief Reinitialise an existing V.29 modem transmit context. | |
| 127 \param s The modem context. | |
| 128 \param bit_rate The bit rate of the modem. Valid values are 4800, 7200 and 9600. | |
| 129 \param tep TRUE is the optional TEP tone is to be transmitted. | |
| 130 \return 0 for OK, -1 for bad parameter */ | |
| 131 SPAN_DECLARE(int) v29_tx_restart(v29_tx_state_t *s, int bit_rate, int tep); | |
| 132 | |
| 133 /*! Release a V.29 modem transmit context. | |
| 134 \brief Release a V.29 modem transmit context. | |
| 135 \param s The modem context. | |
| 136 \return 0 for OK */ | |
| 137 SPAN_DECLARE(int) v29_tx_release(v29_tx_state_t *s); | |
| 138 | |
| 139 /*! Free a V.29 modem transmit context. | |
| 140 \brief Free a V.29 modem transmit context. | |
| 141 \param s The modem context. | |
| 142 \return 0 for OK */ | |
| 143 SPAN_DECLARE(int) v29_tx_free(v29_tx_state_t *s); | |
| 144 | |
| 145 /*! Get the logging context associated with a V.29 modem transmit context. | |
| 146 \brief Get the logging context associated with a V.29 modem transmit context. | |
| 147 \param s The modem context. | |
| 148 \return A pointer to the logging context */ | |
| 149 SPAN_DECLARE(logging_state_t *) v29_tx_get_logging_state(v29_tx_state_t *s); | |
| 150 | |
| 151 /*! Change the get_bit function associated with a V.29 modem transmit context. | |
| 152 \brief Change the get_bit function associated with a V.29 modem transmit context. | |
| 153 \param s The modem context. | |
| 154 \param get_bit The callback routine used to get the data to be transmitted. | |
| 155 \param user_data An opaque pointer. */ | |
| 156 SPAN_DECLARE(void) v29_tx_set_get_bit(v29_tx_state_t *s, get_bit_func_t get_bit, void *user_data); | |
| 157 | |
| 158 /*! Change the modem status report function associated with a V.29 modem transmit context. | |
| 159 \brief Change the modem status report function associated with a V.29 modem transmit context. | |
| 160 \param s The modem context. | |
| 161 \param handler The callback routine used to report modem status changes. | |
| 162 \param user_data An opaque pointer. */ | |
| 163 SPAN_DECLARE(void) v29_tx_set_modem_status_handler(v29_tx_state_t *s, modem_tx_status_func_t handler, void *user_data); | |
| 164 | |
| 165 /*! Generate a block of V.29 modem audio samples. | |
| 166 \brief Generate a block of V.29 modem audio samples. | |
| 167 \param s The modem context. | |
| 168 \param amp The audio sample buffer. | |
| 169 \param len The number of samples to be generated. | |
| 170 \return The number of samples actually generated. | |
| 171 */ | |
| 172 SPAN_DECLARE_NONSTD(int) v29_tx(v29_tx_state_t *s, int16_t amp[], int len); | |
| 173 | |
| 174 #if defined(__cplusplus) | |
| 175 } | |
| 176 #endif | |
| 177 | |
| 178 #endif | |
| 179 /*- End of file ------------------------------------------------------------*/ |
