spandsp 3.0.0
fsk.h
Go to the documentation of this file.
1/*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * fsk.h - FSK modem transmit and receive parts
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/*! \page fsk_page FSK modems
29\section fsk_page_sec_1 What does it do?
30Most of the oldest telephony modems use incoherent FSK modulation. This module can
31be used to implement both the transmit and receive sides of a number of these
32modems. There are integrated definitions for:
33
34 - V.21
35 - V.23
36 - Bell 103
37 - Bell 202
38 - Weitbrecht (Used for TDD - Telecoms Device for the Deaf)
39
40The audio output or input is a stream of 16 bit samples, at 8000 samples/second.
41The transmit and receive sides can be used independantly.
42
43\section fsk_page_sec_2 The transmitter
44
45The FSK transmitter uses a DDS generator to synthesise the waveform. This
46naturally produces phase coherent transitions, as the phase update rate is
47switched, producing a clean spectrum. The symbols are not generally an integer
48number of samples long. However, the symbol time for the fastest data rate
49generally used (1200bps) is more than 7 samples long. The jitter resulting from
50switching at the nearest sample is, therefore, acceptable. No interpolation is
51used.
52
53\section fsk_page_sec_3 The receiver
54
55The FSK receiver uses a quadrature correlation technique to demodulate the
56signal. Two DDS quadrature oscillators are used. The incoming signal is
57correlated with the oscillator signals over a period of one symbol. The
58oscillator giving the highest net correlation from its I and Q outputs is the
59one that matches the frequency being transmitted during the correlation
60interval. Because the transmission is totally asynchronous, the demodulation
61process must run sample by sample to find the symbol transitions. The
62correlation is performed on a sliding window basis, so the computational load of
63demodulating sample by sample is not great.
64
65Two modes of symbol synchronisation are provided:
66
67 - In synchronous mode, symbol transitions are smoothed, to track their true
68 position in the prescence of high timing jitter. This provides the most
69 reliable symbol recovery in poor signal to noise conditions. However, it
70 takes a little time to settle, so it not really suitable for data streams
71 which must start up instantaneously (e.g. the TDD systems used by hearing
72 impaired people).
73
74 - In asynchronous mode each transition is taken at face value, with no temporal
75 smoothing. There is no settling time for this mode, but when the signal to
76 noise ratio is very poor it does not perform as well as the synchronous mode.
77*/
78
79#if !defined(_SPANDSP_FSK_H_)
80#define _SPANDSP_FSK_H_
81
82/*!
83 FSK modem specification. This defines the frequencies, signal levels and
84 baud rate (== bit rate for simple FSK) for a single channel of an FSK modem.
85*/
86typedef struct
87{
88 /*! Short text name for the modem. */
89 const char *name;
90 /*! The frequency of the zero bit state, in Hz */
92 /*! The frequency of the one bit state, in Hz */
94 /*! The transmit power level, in dBm0 */
96 /*! The minimum acceptable receive power level, in dBm0 */
98 /*! The bit rate of the modem, in units of 1/100th bps */
100} fsk_spec_t;
101
102/* Predefined FSK modem channels */
103enum
104{
105 FSK_V21CH1 = 0,
106 FSK_V21CH2,
107 FSK_V23CH1,
108 FSK_V23CH2,
109 FSK_BELL103CH1,
110 FSK_BELL103CH2,
111 FSK_BELL202,
112 FSK_WEITBRECHT_4545, /* 45.45 baud version, used for TDD (Telecom Device for the Deaf) */
113 FSK_WEITBRECHT_50, /* 50 baud version, used for TDD (Telecom Device for the Deaf) */
114 FSK_WEITBRECHT_476, /* 47.6 baud version, used for V.18 probing */
115 FSK_V21CH1_110 /* 110 bps version of V.21 channel 1, as used by V.18 */
116};
117
118enum
119{
120 FSK_FRAME_MODE_ASYNC = 0,
121 FSK_FRAME_MODE_SYNC = 1,
122 FSK_FRAME_MODE_5N1_FRAMES = 7, /* 5 bits of data + start bit + stop bit */
123 FSK_FRAME_MODE_7N1_FRAMES = 9, /* 7 bits of data + start bit + stop bit */
124 FSK_FRAME_MODE_7E1_FRAMES = 10, /* 7 bits of data + even parity + start bit + stop bit */
125 FSK_FRAME_MODE_7E2_FRAMES = 11 /* 7 bits of data + even parity + start bit + 2 stop bits */
126};
127
128SPAN_DECLARE_DATA extern const fsk_spec_t preset_fsk_specs[];
129
130/*!
131 FSK modem transmit descriptor. This defines the state of a single working
132 instance of an FSK modem transmitter.
133*/
135
136/* The longest window will probably be 106 for 75 baud */
137#define FSK_MAX_WINDOW_LEN 128
138
139/*!
140 FSK modem receive descriptor. This defines the state of a single working
141 instance of an FSK modem receiver.
142*/
144
145#if defined(__cplusplus)
146extern "C"
147{
148#endif
149
150/*! Initialise an FSK modem transmit context.
151 \brief Initialise an FSK modem transmit context.
152 \param s The modem context.
153 \param spec The specification of the modem tones and rate.
154 \param get_bit The callback routine used to get the data to be transmitted.
155 \param user_data An opaque pointer.
156 \return A pointer to the modem context, or NULL if there was a problem. */
157SPAN_DECLARE(fsk_tx_state_t *) fsk_tx_init(fsk_tx_state_t *s,
158 const fsk_spec_t *spec,
159 get_bit_func_t get_bit,
160 void *user_data);
161
162SPAN_DECLARE(int) fsk_tx_restart(fsk_tx_state_t *s, const fsk_spec_t *spec);
163
164SPAN_DECLARE(int) fsk_tx_release(fsk_tx_state_t *s);
165
166SPAN_DECLARE(int) fsk_tx_free(fsk_tx_state_t *s);
167
168/*! Adjust an FSK modem transmit context's power output.
169 \brief Adjust an FSK modem transmit context's power output.
170 \param s The modem context.
171 \param power The power level, in dBm0 */
172SPAN_DECLARE(void) fsk_tx_power(fsk_tx_state_t *s, float power);
173
174SPAN_DECLARE(void) fsk_tx_set_get_bit(fsk_tx_state_t *s, get_bit_func_t get_bit, void *user_data);
175
176/*! Change the modem status report function associated with an FSK modem transmit context.
177 \brief Change the modem status report function associated with an FSK modem transmit context.
178 \param s The modem context.
179 \param handler The callback routine used to report modem status changes.
180 \param user_data An opaque pointer. */
181SPAN_DECLARE(void) fsk_tx_set_modem_status_handler(fsk_tx_state_t *s, modem_status_func_t handler, void *user_data);
182
183/*! Generate a block of FSK modem audio samples.
184 \brief Generate a block of FSK modem audio samples.
185 \param s The modem context.
186 \param amp The audio sample buffer.
187 \param len The number of samples to be generated.
188 \return The number of samples actually generated.
189*/
190SPAN_DECLARE(int) fsk_tx(fsk_tx_state_t *s, int16_t amp[], int len);
191
192/*! Get the current received signal power.
193 \param s The modem context.
194 \return The signal power, in dBm0. */
195SPAN_DECLARE(float) fsk_rx_signal_power(fsk_rx_state_t *s);
196
197/*! Adjust an FSK modem receive context's carrier detect power threshold.
198 \brief Adjust an FSK modem receive context's carrier detect power threshold.
199 \param s The modem context.
200 \param cutoff The power level, in dBm0 */
201SPAN_DECLARE(void) fsk_rx_signal_cutoff(fsk_rx_state_t *s, float cutoff);
202
203/*! Initialise an FSK modem receive context.
204 \brief Initialise an FSK modem receive context.
205 \param s The modem context.
206 \param spec The specification of the modem tones and rate.
207 \param framing_mode 0 for fully asynchronous mode. 1 for synchronous mode. >1 for
208 this many bits per asynchronous character frame.
209 \param put_bit The callback routine used to put the received data.
210 \param user_data An opaque pointer.
211 \return A pointer to the modem context, or NULL if there was a problem. */
212SPAN_DECLARE(fsk_rx_state_t *) fsk_rx_init(fsk_rx_state_t *s,
213 const fsk_spec_t *spec,
214 int framing_mode,
216 void *user_data);
217
218SPAN_DECLARE(int) fsk_rx_restart(fsk_rx_state_t *s, const fsk_spec_t *spec, int framing_mode);
219
220SPAN_DECLARE(int) fsk_rx_release(fsk_rx_state_t *s);
221
222SPAN_DECLARE(int) fsk_rx_free(fsk_rx_state_t *s);
223
224/*! Process a block of received FSK modem audio samples.
225 \brief Process a block of received FSK modem audio samples.
226 \param s The modem context.
227 \param amp The audio sample buffer.
228 \param len The number of samples in the buffer.
229 \return The number of samples unprocessed.
230*/
231SPAN_DECLARE(int) fsk_rx(fsk_rx_state_t *s, const int16_t *amp, int len);
232
233/*! Fake processing of a missing block of received FSK modem audio samples
234 (e.g due to packet loss).
235 \brief Fake processing of a missing block of received FSK modem audio samples.
236 \param s The modem context.
237 \param len The number of samples to fake.
238 \return The number of samples unprocessed.
239*/
240SPAN_DECLARE(int) fsk_rx_fillin(fsk_rx_state_t *s, int len);
241
242SPAN_DECLARE(void) fsk_rx_set_put_bit(fsk_rx_state_t *s, put_bit_func_t put_bit, void *user_data);
243
244/*! Change the modem status report function associated with an FSK modem receive context.
245 \brief Change the modem status report function associated with an FSK modem receive context.
246 \param s The modem context.
247 \param handler The callback routine used to report modem status changes.
248 \param user_data An opaque pointer. */
249SPAN_DECLARE(void) fsk_rx_set_modem_status_handler(fsk_rx_state_t *s, modem_status_func_t handler, void *user_data);
250
251#if defined(__cplusplus)
252}
253#endif
254
255#endif
256/*- End of file ------------------------------------------------------------*/
void(* modem_status_func_t)(void *user_data, int status)
Definition: async.h:113
void(* put_bit_func_t)(void *user_data, int bit)
Definition: async.h:107
int(* get_bit_func_t)(void *user_data)
Definition: async.h:110
int fsk_tx(fsk_tx_state_t *s, int16_t amp[], int len)
Generate a block of FSK modem audio samples.
Definition: fsk.c:203
void fsk_rx_set_modem_status_handler(fsk_rx_state_t *s, modem_status_func_t handler, void *user_data)
Change the modem status report function associated with an FSK modem receive context.
Definition: fsk.c:283
int fsk_rx_fillin(fsk_rx_state_t *s, int len)
Fake processing of a missing block of received FSK modem audio samples.
Definition: fsk.c:629
void fsk_tx_set_modem_status_handler(fsk_tx_state_t *s, modem_status_func_t handler, void *user_data)
Change the modem status report function associated with an FSK modem transmit context.
Definition: fsk.c:255
fsk_rx_state_t * fsk_rx_init(fsk_rx_state_t *s, const fsk_spec_t *spec, int framing_mode, put_bit_func_t put_bit, void *user_data)
Initialise an FSK modem receive context.
Definition: fsk.c:340
float fsk_rx_signal_power(fsk_rx_state_t *s)
Definition: fsk.c:270
int fsk_rx(fsk_rx_state_t *s, const int16_t *amp, int len)
Process a block of received FSK modem audio samples.
Definition: fsk.c:385
void fsk_rx_signal_cutoff(fsk_rx_state_t *s, float cutoff)
Adjust an FSK modem receive context's carrier detect power threshold.
Definition: fsk.c:262
fsk_tx_state_t * fsk_tx_init(fsk_tx_state_t *s, const fsk_spec_t *spec, get_bit_func_t get_bit, void *user_data)
Initialise an FSK modem transmit context.
Definition: fsk.c:169
void fsk_tx_power(fsk_tx_state_t *s, float power)
Adjust an FSK modem transmit context's power output.
Definition: fsk.c:242
Definition: private/fsk.h:59
put_bit_func_t put_bit
The callback function used to put each bit received.
Definition: private/fsk.h:64
int framing_mode
Synchronous/asynchronous framing control.
Definition: private/fsk.h:62
Definition: fsk.h:87
int freq_one
Definition: fsk.h:93
const char * name
Definition: fsk.h:89
int tx_level
Definition: fsk.h:95
int min_level
Definition: fsk.h:97
int baud_rate
Definition: fsk.h:99
int freq_zero
Definition: fsk.h:91
Definition: private/fsk.h:34