Mercurial > hg > audiostuff
comparison spandsp-0.0.3/spandsp-0.0.3/src/spandsp/v17tx.h @ 5:f762bf195c4b
import spandsp-0.0.3
author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
---|---|
date | Fri, 25 Jun 2010 16:00:21 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:26cd8f1ef0b1 | 5:f762bf195c4b |
---|---|
1 /* | |
2 * SpanDSP - a series of DSP components for telephony | |
3 * | |
4 * v17tx.h - ITU V.17 modem transmit part | |
5 * | |
6 * Written by Steve Underwood <steveu@coppice.org> | |
7 * | |
8 * Copyright (C) 2004 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 General Public License version 2, as | |
14 * 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 General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 * | |
25 * $Id: v17tx.h,v 1.26 2006/10/24 13:45:28 steveu Exp $ | |
26 */ | |
27 | |
28 /*! \file */ | |
29 | |
30 #if !defined(_V17TX_H_) | |
31 #define _V17TX_H_ | |
32 | |
33 /*! \page v17tx_page The V.17 transmitter | |
34 \section v17tx_page_sec_1 What does it do? | |
35 The V.17 transmitter implements the transmit side of a V.17 modem. This can | |
36 operate at data rates of 14400, 12000, 9600 and 7200 bits/second. The audio | |
37 output is a stream of 16 bit samples, at 8000 samples/second. The transmit and | |
38 receive side of V.17 modems operate independantly. V.17 is mostly used for FAX | |
39 transmission, where it provides the standard 14400 bits/second rate. | |
40 | |
41 \section v17tx_page_sec_2 How does it work? | |
42 V.17 uses QAM modulation and trellis coding. The data to be transmitted is | |
43 scrambled, to whiten it. The least significant 2 bits of each symbol are then | |
44 differentially encoded, using a simple lookup approach. The resulting 2 bits are | |
45 convolutionally encoded, producing 3 bits. The extra bit is the redundant bit | |
46 of the trellis code. The other bits of the symbol pass by the differential | |
47 and convolutional coding unchanged. The resulting bits define the constellation | |
48 point to be transmitted for the symbol. The redundant bit doubles the size of the | |
49 constellation, and so increases the error rate for detecting individual symbols | |
50 at the receiver. However, when a number of successive symbols are processed at | |
51 the receiver, the redundancy actually provides several dB of improved error | |
52 performance. | |
53 | |
54 The standard method of producing a QAM modulated signal is to use a sampling | |
55 rate which is a multiple of the baud rate. The raw signal is then a series of | |
56 complex pulses, each an integer number of samples long. These can be shaped, | |
57 using a suitable complex filter, and multiplied by a complex carrier signal | |
58 to produce the final QAM signal for transmission. | |
59 | |
60 The pulse shaping filter is only vaguely defined by the V.17 spec. Some of the | |
61 other ITU modem specs. fully define the filter, typically specifying a root | |
62 raised cosine filter, with 50% excess bandwidth. This is a pity, since it | |
63 increases the variability of the received signal. However, the receiver's | |
64 adaptive equalizer will compensate for these differences. The current | |
65 design uses a root raised cosine filter with 25% excess bandwidth. Greater | |
66 excess bandwidth will not allow the tranmitted signal to meet the spectral | |
67 requirements. | |
68 | |
69 The sampling rate for our transmitter is defined by the channel - 8000 per | |
70 second. This is not a multiple of the baud rate (i.e. 2400 baud). The baud | |
71 interval is actually 10/3 sample periods. Instead of using a symmetric | |
72 FIR to pulse shape the signal, a polyphase filter is used. This consists of | |
73 10 sets of coefficients, offering zero to 9/10ths of a baud phase shift as well | |
74 as root raised cosine filtering. The appropriate coefficient set is chosen for | |
75 each signal sample generated. | |
76 | |
77 The carrier is generated using the DDS method. Using two second order resonators, | |
78 started in quadrature, might be more efficient, as it would have less impact on | |
79 the processor cache than a table lookup approach. However, the DDS approach | |
80 suits the receiver better, so the same signal generator is also used for the | |
81 transmitter. | |
82 */ | |
83 | |
84 #define V17_TX_FILTER_STEPS 9 | |
85 | |
86 /*! | |
87 V.17 modem transmit side descriptor. This defines the working state for a | |
88 single instance of a V.17 modem transmitter. | |
89 */ | |
90 typedef struct | |
91 { | |
92 /*! \brief The bit rate of the modem. Valid values are 4800, 7200 and 9600. */ | |
93 int bit_rate; | |
94 /*! \brief The callback function used to get the next bit to be transmitted. */ | |
95 get_bit_func_t get_bit; | |
96 /*! \brief A user specified opaque pointer passed to the callback function. */ | |
97 void *user_data; | |
98 | |
99 /*! \brief The gain factor needed to achieve the specified output power. */ | |
100 float gain; | |
101 | |
102 /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */ | |
103 complexf_t rrc_filter[2*V17_TX_FILTER_STEPS]; | |
104 /*! \brief Current offset into the RRC pulse shaping filter buffer. */ | |
105 int rrc_filter_step; | |
106 | |
107 /*! \brief The current state of the differential encoder. */ | |
108 int diff; | |
109 /*! \brief The current state of the convolutional encoder. */ | |
110 int convolution; | |
111 | |
112 /*! \brief The register for the data scrambler. */ | |
113 unsigned int scramble_reg; | |
114 /*! \brief TRUE if transmitting the training sequence. FALSE if transmitting user data. */ | |
115 int in_training; | |
116 /*! \brief TRUE if the short training sequence is to be used. */ | |
117 int short_train; | |
118 /*! \brief A counter used to track progress through sending the training sequence. */ | |
119 int training_step; | |
120 | |
121 /*! \brief The current phase of the carrier (i.e. the DDS parameter). */ | |
122 uint32_t carrier_phase; | |
123 /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */ | |
124 int32_t carrier_phase_rate; | |
125 /*! \brief The current fractional phase of the baud timing. */ | |
126 int baud_phase; | |
127 /*! \brief The code number for the current position in the constellation. */ | |
128 int constellation_state; | |
129 | |
130 /*! \brief A pointer to the constellation currently in use. */ | |
131 const complexf_t *constellation; | |
132 /*! \brief The current number of data bits per symbol. This does not include | |
133 the redundant bit. */ | |
134 int bits_per_symbol; | |
135 /*! \brief The get_bit function in use at any instant. */ | |
136 get_bit_func_t current_get_bit; | |
137 /*! \brief Error and flow logging control */ | |
138 logging_state_t logging; | |
139 } v17_tx_state_t; | |
140 | |
141 #ifdef __cplusplus | |
142 extern "C" { | |
143 #endif | |
144 | |
145 /*! Adjust a V.17 modem transmit context's power output. | |
146 \brief Adjust a V.17 modem transmit context's output power. | |
147 \param s The modem context. | |
148 \param power The power level, in dBm0 */ | |
149 void v17_tx_power(v17_tx_state_t *s, float power); | |
150 | |
151 /*! Initialise a V.17 modem transmit context. This must be called before the first | |
152 use of the context, to initialise its contents. | |
153 \brief Initialise a V.17 modem transmit context. | |
154 \param s The modem context. | |
155 \param rate The bit rate of the modem. Valid values are 7200, 9600, 12000 and 14400. | |
156 \param tep TRUE is the optional TEP tone is to be transmitted. | |
157 \param get_bit The callback routine used to get the data to be transmitted. | |
158 \param user_data An opaque pointer. | |
159 \return A pointer to the modem context, or NULL if there was a problem. */ | |
160 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); | |
161 | |
162 /*! Reinitialise an existing V.17 modem transmit context, so it may be reused. | |
163 \brief Reinitialise an existing V.17 modem transmit context. | |
164 \param s The modem context. | |
165 \param rate The bit rate of the modem. Valid values are 7200, 9600, 12000 and 14400. | |
166 \param tep TRUE is the optional TEP tone is to be transmitted. | |
167 \param short_train TRUE if the short training sequence should be used. | |
168 \return 0 for OK, -1 for parameter error. */ | |
169 int v17_tx_restart(v17_tx_state_t *s, int rate, int tep, int short_train); | |
170 | |
171 /*! Release a V.17 modem transmit context. | |
172 \brief Release a V.17 modem transmit context. | |
173 \param s The modem context. | |
174 \return 0 for OK */ | |
175 int v17_tx_release(v17_tx_state_t *s); | |
176 | |
177 /*! Change the get_bit function associated with a V.17 modem transmit context. | |
178 \brief Change the get_bit function associated with a V.17 modem transmit context. | |
179 \param s The modem context. | |
180 \param get_bit The callback routine used to get the data to be transmitted. | |
181 \param user_data An opaque pointer. */ | |
182 void v17_tx_set_get_bit(v17_tx_state_t *s, get_bit_func_t get_bit, void *user_data); | |
183 | |
184 /*! Generate a block of V.17 modem audio samples. | |
185 \brief Generate a block of V.17 modem audio samples. | |
186 \param s The modem context. | |
187 \param amp The audio sample buffer. | |
188 \param len The number of samples to be generated. | |
189 \return The number of samples actually generated. | |
190 */ | |
191 int v17_tx(v17_tx_state_t *s, int16_t amp[], int len); | |
192 | |
193 #ifdef __cplusplus | |
194 } | |
195 #endif | |
196 | |
197 #endif | |
198 /*- End of file ------------------------------------------------------------*/ |