5
|
1 /*
|
|
2 * SpanDSP - a series of DSP components for telephony
|
|
3 *
|
|
4 * v27ter_tx.h - ITU V.27ter 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 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: v27ter_tx.h,v 1.25 2006/10/24 13:45:28 steveu Exp $
|
|
26 */
|
|
27
|
|
28 /*! \file */
|
|
29
|
|
30 #if !defined(_V27TER_TX_H_)
|
|
31 #define _V27TER_TX_H_
|
|
32
|
|
33 /*! \page v27ter_tx_page The V.27ter transmitter
|
|
34 \section v27ter_tx_page_sec_1 What does it do?
|
|
35 The V.27ter transmitter implements the transmit side of a V.27ter modem. This
|
|
36 can operate at data rates of 4800 and 2400 bits/s. The audio output is a stream
|
|
37 of 16 bit samples, at 8000 samples/second. The transmit and receive side of
|
|
38 V.27ter modems operate independantly. V.27ter is used for FAX transmission,
|
|
39 where it provides the standard 4800 and 2400 bits/s rates.
|
|
40
|
|
41 \section v27ter_tx_page_sec_2 How does it work?
|
|
42 V.27ter uses DPSK modulation. A common method of producing a DPSK modulated
|
|
43 signal is to use a sampling rate which is a multiple of the baud rate. The raw
|
|
44 signal is then a series of complex pulses, each an integer number of samples
|
|
45 long. These can be shaped, using a suitable complex filter, and multiplied by a
|
|
46 complex carrier signal to produce the final DPSK signal for transmission.
|
|
47
|
|
48 The pulse shaping filter for V.27ter is defined in the spec. It is a root raised
|
|
49 cosine filter with 50% excess bandwidth.
|
|
50
|
|
51 The sampling rate for our transmitter is defined by the channel - 8000 samples/s.
|
|
52 This is a multiple of the baud rate at 4800 bits/s (8-PSK at 1600 baud, 5 samples per
|
|
53 symbol), but not at 2400 bits/s (4-PSK at 1200 baud, 20/3 samples per symbol). The baud
|
|
54 interval is actually 20/3 sample periods at 2400bis/s. A symmetric FIR is used to
|
|
55 apply root raised cosine filtering in the 4800bits/s mode. In the 2400bits/s mode
|
|
56 a polyphase FIR filter is used. This consists of 20 sets of coefficients, offering
|
|
57 zero to 19/20ths of a baud phase shift as well as root raised cosine filtering.
|
|
58 The appropriate coefficient set is chosen for each signal sample generated.
|
|
59
|
|
60 The carrier is generated using the DDS method. Using 2 second order resonators,
|
|
61 started in quadrature, might be more efficient, as it would have less impact on
|
|
62 the processor cache than a table lookup approach. However, the DDS approach
|
|
63 suits the receiver better, so then same signal generator is also used for the
|
|
64 transmitter.
|
|
65 */
|
|
66
|
|
67 #define V27TER_TX_FILTER_STEPS 9
|
|
68
|
|
69 /*!
|
|
70 V.27ter modem transmit side descriptor. This defines the working state for a
|
|
71 single instance of a V.27ter modem transmitter.
|
|
72 */
|
|
73 typedef struct
|
|
74 {
|
|
75 /*! \brief The bit rate of the modem. Valid values are 2400 and 4800. */
|
|
76 int bit_rate;
|
|
77 /*! \brief The callback function used to get the next bit to be transmitted. */
|
|
78 get_bit_func_t get_bit;
|
|
79 /*! \brief A user specified opaque pointer passed to the callback function. */
|
|
80 void *user_data;
|
|
81
|
|
82 /*! \brief The gain factor needed to achieve the specified output power at 2400bps. */
|
|
83 float gain_2400;
|
|
84 /*! \brief The gain factor needed to achieve the specified output power at 4800bps. */
|
|
85 float gain_4800;
|
|
86
|
|
87 /*! \brief The route raised cosine (RRC) pulse shaping filter buffer. */
|
|
88 complexf_t rrc_filter[2*V27TER_TX_FILTER_STEPS];
|
|
89 /*! \brief Current offset into the RRC pulse shaping filter buffer. */
|
|
90 int rrc_filter_step;
|
|
91
|
|
92 /*! \brief The register for the training and data scrambler. */
|
|
93 unsigned int scramble_reg;
|
|
94 /*! \brief A counter for the number of consecutive bits of repeating pattern through
|
|
95 the scrambler. */
|
|
96 int scrambler_pattern_count;
|
|
97 /*! \brief TRUE if transmitting the training sequence, or shutting down transmission.
|
|
98 FALSE if transmitting user data. */
|
|
99 int in_training;
|
|
100 /*! \brief A counter used to track progress through sending the training sequence. */
|
|
101 int training_step;
|
|
102
|
|
103 /*! \brief The current phase of the carrier (i.e. the DDS parameter). */
|
|
104 uint32_t carrier_phase;
|
|
105 /*! \brief The update rate for the phase of the carrier (i.e. the DDS increment). */
|
|
106 int32_t carrier_phase_rate;
|
|
107 /*! \brief The current fractional phase of the baud timing. */
|
|
108 int baud_phase;
|
|
109 /*! \brief The code number for the current position in the constellation. */
|
|
110 int constellation_state;
|
|
111 /*! \brief The get_bit function in use at any instant. */
|
|
112 get_bit_func_t current_get_bit;
|
|
113 /*! \brief Error and flow logging control */
|
|
114 logging_state_t logging;
|
|
115 } v27ter_tx_state_t;
|
|
116
|
|
117 #ifdef __cplusplus
|
|
118 extern "C" {
|
|
119 #endif
|
|
120
|
|
121 /*! Adjust a V.27ter modem transmit context's power output.
|
|
122 \brief Adjust a V.27ter modem transmit context's output power.
|
|
123 \param s The modem context.
|
|
124 \param power The power level, in dBm0 */
|
|
125 void v27ter_tx_power(v27ter_tx_state_t *s, float power);
|
|
126
|
|
127 /*! Initialise a V.27ter modem transmit context.
|
|
128 \brief Initialise a V.27ter modem transmit context.
|
|
129 \param s The modem context.
|
|
130 \param rate The bit rate of the modem. Valid values are 2400 and 4800.
|
|
131 \param tep TRUE is the optional TEP tone is to be transmitted.
|
|
132 \param get_bit The callback routine used to get the data to be transmitted.
|
|
133 \param user_data An opaque pointer.
|
|
134 \return A pointer to the modem context, or NULL if there was a problem. */
|
|
135 v27ter_tx_state_t *v27ter_tx_init(v27ter_tx_state_t *s, int rate, int tep, get_bit_func_t get_bit, void *user_data);
|
|
136
|
|
137 /*! Reinitialise an existing V.27ter modem transmit context, so it may be reused.
|
|
138 \brief Reinitialise an existing V.27ter modem transmit context.
|
|
139 \param s The modem context.
|
|
140 \param rate The bit rate of the modem. Valid values are 2400 and 4800.
|
|
141 \param tep TRUE is the optional TEP tone is to be transmitted.
|
|
142 \return 0 for OK, -1 for bad parameter */
|
|
143 int v27ter_tx_restart(v27ter_tx_state_t *s, int rate, int tep);
|
|
144
|
|
145 /*! Release a V.27ter modem transmit context.
|
|
146 \brief Release a V.27ter modem transmit context.
|
|
147 \param s The modem context.
|
|
148 \return 0 for OK */
|
|
149 int v27ter_tx_release(v27ter_tx_state_t *s);
|
|
150
|
|
151 /*! Change the get_bit function associated with a V.27ter modem transmit context.
|
|
152 \brief Change the get_bit function associated with a V.27ter 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 void v27ter_tx_set_get_bit(v27ter_tx_state_t *s, get_bit_func_t get_bit, void *user_data);
|
|
157
|
|
158 /*! Generate a block of V.27ter modem audio samples.
|
|
159 \brief Generate a block of V.27ter modem audio samples.
|
|
160 \param s The modem context.
|
|
161 \param amp The audio sample buffer.
|
|
162 \param len The number of samples to be generated.
|
|
163 \return The number of samples actually generated.
|
|
164 */
|
|
165 int v27ter_tx(v27ter_tx_state_t *s, int16_t amp[], int len);
|
|
166
|
|
167 #ifdef __cplusplus
|
|
168 }
|
|
169 #endif
|
|
170
|
|
171 #endif
|
|
172 /*- End of file ------------------------------------------------------------*/
|