spandsp  0.0.6
v29tx.h
Go to the documentation of this file.
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 
26 /*! \file */
27 
28 #if !defined(_SPANDSP_V29TX_H_)
29 #define _SPANDSP_V29TX_H_
30 
31 /*! \page v29tx_page The V.29 transmitter
32 \section v29tx_page_sec_1 What does it do?
33 The V.29 transmitter implements the transmit side of a V.29 modem. This can
34 operate at data rates of 9600, 7200 and 4800 bits/s. The audio output is a
35 stream of 16 bit samples, at 8000 samples/second. The transmit and receive side
36 of V.29 modems operate independantly. V.29 is mostly used for FAX transmission,
37 where it provides the standard 9600 and 7200 bits/s rates (the 4800 bits/s mode
38 is not used for FAX).
39 
40 \section v29tx_page_sec_2 How does it work?
41 V.29 uses QAM modulation. The standard method of producing a QAM modulated
42 signal is to use a sampling rate which is a multiple of the baud rate. The raw
43 signal is then a series of complex pulses, each an integer number of samples
44 long. These can be shaped, using a suitable complex filter, and multiplied by a
45 complex carrier signal to produce the final QAM signal for transmission.
46 
47 The pulse shaping filter is only vaguely defined by the V.29 spec. Some of the
48 other ITU modem specs. fully define the filter, typically specifying a root
49 raised cosine filter, with 50% excess bandwidth. This is a pity, since it
50 increases the variability of the received signal. However, the receiver's
51 adaptive equalizer will compensate for these differences. The current
52 design uses a root raised cosine filter with 25% excess bandwidth. Greater
53 excess bandwidth will not allow the tranmitted signal to meet the spectral
54 requirements.
55 
56 The sampling rate for our transmitter is defined by the channel - 8000 per
57 second. This is not a multiple of the baud rate (i.e. 2400 baud). The baud
58 interval is actually 10/3 sample periods. Instead of using a symmetric
59 FIR to pulse shape the signal, a polyphase filter is used. This consists of
60 10 sets of coefficients, offering zero to 9/10ths of a baud phase shift as well
61 as root raised cosine filtering. The appropriate coefficient set is chosen for
62 each signal sample generated.
63 
64 The carrier is generated using the DDS method. Using two second order resonators,
65 started in quadrature, might be more efficient, as it would have less impact on
66 the processor cache than a table lookup approach. However, the DDS approach
67 suits the receiver better, so the same signal generator is also used for the
68 transmitter.
69 
70 The equation defining QAM modulation is:
71 
72  s(n) = A*cos(2*pi*f*n + phi(n))
73 
74 where phi(n) is the phase of the information, and A is the amplitude of the information
75 
76 using the identity
77 
78  cos(x + y) = cos(x)*cos(y) - sin(x)*sin(y)
79 
80 we get
81 
82  s(n) = A {cos(2*pi*f*n)*cos(phi(n)) - sin(2*pi*f*n)*sin(phi(n))}
83 
84 substituting with the constellation positions
85 
86  I(n) = A*cos(phi(n))
87  Q(n) = A*sin(phi(n))
88 
89 gives
90 
91  s(n) = I(n)*cos(2*pi*f*n) - Q(n)*sin(2*pi*f*n)
92 
93 */
94 
95 /*!
96  V.29 modem transmit side descriptor. This defines the working state for a
97  single instance of a V.29 modem transmitter.
98 */
100 
101 #if defined(__cplusplus)
102 extern "C"
103 {
104 #endif
105 
106 /*! Adjust a V.29 modem transmit context's power output.
107  \brief Adjust a V.29 modem transmit context's output power.
108  \param s The modem context.
109  \param power The power level, in dBm0 */
110 SPAN_DECLARE(void) v29_tx_power(v29_tx_state_t *s, float power);
111 
112 /*! Initialise a V.29 modem transmit context. This must be called before the first
113  use of the context, to initialise its contents.
114  \brief Initialise a V.29 modem transmit context.
115  \param s The modem context.
116  \param bit_rate The bit rate of the modem. Valid values are 4800, 7200 and 9600.
117  \param tep TRUE is the optional TEP tone is to be transmitted.
118  \param get_bit The callback routine used to get the data to be transmitted.
119  \param user_data An opaque pointer.
120  \return A pointer to the modem context, or NULL if there was a problem. */
121 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);
122 
123 /*! Reinitialise an existing V.29 modem transmit context, so it may be reused.
124  \brief Reinitialise an existing V.29 modem transmit context.
125  \param s The modem context.
126  \param bit_rate The bit rate of the modem. Valid values are 4800, 7200 and 9600.
127  \param tep TRUE is the optional TEP tone is to be transmitted.
128  \return 0 for OK, -1 for bad parameter */
129 SPAN_DECLARE(int) v29_tx_restart(v29_tx_state_t *s, int bit_rate, int tep);
130 
131 /*! Release a V.29 modem transmit context.
132  \brief Release a V.29 modem transmit context.
133  \param s The modem context.
134  \return 0 for OK */
135 SPAN_DECLARE(int) v29_tx_release(v29_tx_state_t *s);
136 
137 /*! Free a V.29 modem transmit context.
138  \brief Free a V.29 modem transmit context.
139  \param s The modem context.
140  \return 0 for OK */
141 SPAN_DECLARE(int) v29_tx_free(v29_tx_state_t *s);
142 
143 /*! Get the logging context associated with a V.29 modem transmit context.
144  \brief Get the logging context associated with a V.29 modem transmit context.
145  \param s The modem context.
146  \return A pointer to the logging context */
148 
149 /*! Change the get_bit function associated with a V.29 modem transmit context.
150  \brief Change the get_bit function associated with a V.29 modem transmit context.
151  \param s The modem context.
152  \param get_bit The callback routine used to get the data to be transmitted.
153  \param user_data An opaque pointer. */
154 SPAN_DECLARE(void) v29_tx_set_get_bit(v29_tx_state_t *s, get_bit_func_t get_bit, void *user_data);
155 
156 /*! Change the modem status report function associated with a V.29 modem transmit context.
157  \brief Change the modem status report function associated with a V.29 modem transmit context.
158  \param s The modem context.
159  \param handler The callback routine used to report modem status changes.
160  \param user_data An opaque pointer. */
161 SPAN_DECLARE(void) v29_tx_set_modem_status_handler(v29_tx_state_t *s, modem_status_func_t handler, void *user_data);
162 
163 /*! Generate a block of V.29 modem audio samples.
164  \brief Generate a block of V.29 modem audio samples.
165  \param s The modem context.
166  \param amp The audio sample buffer.
167  \param len The number of samples to be generated.
168  \return The number of samples actually generated.
169 */
170 SPAN_DECLARE_NONSTD(int) v29_tx(v29_tx_state_t *s, int16_t amp[], int len);
171 
172 #if defined(__cplusplus)
173 }
174 #endif
175 
176 #endif
177 /*- End of file ------------------------------------------------------------*/
get_bit_func_t get_bit
The callback function used to get the next bit to be transmitted.
Definition: private/v29tx.h:41
int bit_rate
The bit rate of the modem. Valid values are 4800, 7200 and 9600.
Definition: private/v29tx.h:39
int v29_tx_free(v29_tx_state_t *s)
Free a V.29 modem transmit context.
Definition: v29tx.c:403
Definition: private/v29tx.h:36
void v29_tx_set_get_bit(v29_tx_state_t *s, get_bit_func_t get_bit, void *user_data)
Change the get_bit function associated with a V.29 modem transmit context.
Definition: v29tx.c:310
int v29_tx_release(v29_tx_state_t *s)
Release a V.29 modem transmit context.
Definition: v29tx.c:397
void(* modem_status_func_t)(void *user_data, int status)
Definition: async.h:114
int(* get_bit_func_t)(void *user_data)
Definition: async.h:108
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)
Initialise a V.29 modem transmit context.
Definition: v29tx.c:369
void v29_tx_set_modem_status_handler(v29_tx_state_t *s, modem_status_func_t handler, void *user_data)
Change the modem status report function associated with a V.29 modem transmit context.
Definition: v29tx.c:319
Definition: private/logging.h:33
void v29_tx_power(v29_tx_state_t *s, float power)
Adjust a V.29 modem transmit context&#39;s output power.
Definition: v29tx.c:300
SPAN_DECLARE_NONSTD(int) v29_tx(v29_tx_state_t *s
Generate a block of V.29 modem audio samples.
int v29_tx_restart(v29_tx_state_t *s, int bit_rate, int tep)
Reinitialise an existing V.29 modem transmit context.
Definition: v29tx.c:332
logging_state_t * v29_tx_get_logging_state(v29_tx_state_t *s)
Get the logging context associated with a V.29 modem transmit context.
Definition: v29tx.c:326