spandsp: v29tx.h Source File

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?
33The V.29 transmitter implements the transmit side of a V.29 modem. This can
34operate at data rates of 9600, 7200 and 4800 bits/s. The audio output is a
35stream of 16 bit samples, at 8000 samples/second. The transmit and receive side
36of V.29 modems operate independantly. V.29 is mostly used for FAX transmission,
37where it provides the standard 9600 and 7200 bits/s rates (the 4800 bits/s mode
38is not used for FAX).
39
40\section v29tx_page_sec_2 How does it work?
41V.29 uses QAM modulation. The standard method of producing a QAM modulated
42signal is to use a sampling rate which is a multiple of the baud rate. The raw
43signal is then a series of complex pulses, each an integer number of samples
44long. These can be shaped, using a suitable complex filter, and multiplied by a
45complex carrier signal to produce the final QAM signal for transmission.
46
47The pulse shaping filter is only vaguely defined by the V.29 spec. Some of the
48other ITU modem specs. fully define the filter, typically specifying a root
49raised cosine filter, with 50% excess bandwidth. This is a pity, since it
50increases the variability of the received signal. However, the receiver's
51adaptive equalizer will compensate for these differences. The current
52design uses a root raised cosine filter with 25% excess bandwidth. Greater
53excess bandwidth will not allow the tranmitted signal to meet the spectral
54requirements.
55
56The sampling rate for our transmitter is defined by the channel - 8000 per
57second. This is not a multiple of the baud rate (i.e. 2400 baud). The baud
58interval is actually 10/3 sample periods. Instead of using a symmetric
59FIR to pulse shape the signal, a polyphase filter is used. This consists of
6010 sets of coefficients, offering zero to 9/10ths of a baud phase shift as well
61as root raised cosine filtering. The appropriate coefficient set is chosen for
62each signal sample generated.
63
64The carrier is generated using the DDS method. Using two second order resonators,
65started in quadrature, might be more efficient, as it would have less impact on
66the processor cache than a table lookup approach. However, the DDS approach
67suits the receiver better, so the same signal generator is also used for the
68transmitter.
69
70The equation defining QAM modulation is:
71
72 s(n) = A*cos(2*pi*f*n + phi(n))
73
74where phi(n) is the phase of the information, and A is the amplitude of the information
75
76using the identity
77
78 cos(x + y) = cos(x)*cos(y) - sin(x)*sin(y)
79
80we get
81
82 s(n) = A {cos(2*pi*f*n)*cos(phi(n)) - sin(2*pi*f*n)*sin(phi(n))}
83
84substituting with the constellation positions
85
86 I(n) = A*cos(phi(n))
87 Q(n) = A*sin(phi(n))
88
89gives
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*/
99 typedef struct v29_tx_state_s v29_tx_state_t;
100
101#if defined(__cplusplus)
102extern "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 */
110SPAN_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. */
121SPAN_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 */
129SPAN_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 */
135SPAN_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 */
141SPAN_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 */
147SPAN_DECLARE(logging_state_t *) v29_tx_get_logging_state(v29_tx_state_t *s);
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. */
154SPAN_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. */
161SPAN_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 ------------------------------------------------------------*/
modem_status_func_t
void(* modem_status_func_t)(void *user_data, int status)
Definition async.h:114
SPAN_DECLARE_NONSTD
SPAN_DECLARE_NONSTD(void) async_rx_put_bit(void *user_data
Accept a bit from a received serial bit stream.
get_bit_func_t
int(* get_bit_func_t)(void *user_data)
Definition async.h:108
logging_state_t
struct logging_state_s logging_state_t
Definition logging.h:75
v29_tx_state_s
Definition private/v29tx.h:37
v29_tx_free
int v29_tx_free(v29_tx_state_t *s)
Free a V.29 modem transmit context.
Definition v29tx.c:403
v29_tx_init
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
v29_tx_get_logging_state
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
v29_tx_release
int v29_tx_release(v29_tx_state_t *s)
Release a V.29 modem transmit context.
Definition v29tx.c:397
v29_tx_restart
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
v29_tx_state_t
struct v29_tx_state_s v29_tx_state_t
Definition v29tx.h:99
v29_tx_set_get_bit
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
v29_tx_power
void v29_tx_power(v29_tx_state_t *s, float power)
Adjust a V.29 modem transmit context's output power.
Definition v29tx.c:300
v29_tx_set_modem_status_handler
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