spandsp 3.0.0
v27ter_rx.h
Go to the documentation of this file.
1/*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * v27ter_rx.h - ITU V.27ter modem receive 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_V27TER_RX_H_)
29#define _SPANDSP_V27TER_RX_H_
30
31/*! \page v27ter_rx_page The V.27ter receiver
32
33\section v27ter_rx_page_sec_1 What does it do?
34The V.27ter receiver implements the receive side of a V.27ter modem. This can operate
35at data rates of 4800 and 2400 bits/s. The audio input is a stream of 16 bit samples,
36at 8000 samples/second. The transmit and receive side of V.27ter modems operate
37independantly. V.27ter is mostly used for FAX transmission, where it provides the
38standard 4800 bits/s rate (the 2400 bits/s mode is not used for FAX).
39
40\section v27ter_rx_page_sec_2 How does it work?
41V.27ter defines two modes of operation. One uses 8-PSK at 1600 baud, giving 4800bps.
42The other uses 4-PSK at 1200 baud, giving 2400bps. A training sequence is specified
43at the start of transmission, which makes the design of a V.27ter receiver relatively
44straightforward.
45*/
46
47#if defined(SPANDSP_USE_FIXED_POINT)
48#define V27TER_CONSTELLATION_SCALING_FACTOR 1024.0
49#else
50#define V27TER_CONSTELLATION_SCALING_FACTOR 1.0
51#endif
52
53/*!
54 V.27ter modem receive side descriptor. This defines the working state for a
55 single instance of a V.27ter modem receiver.
56*/
58
59#if defined(__cplusplus)
60extern "C"
61{
62#endif
63
64/*! Initialise a V.27ter modem receive context.
65 \brief Initialise a V.27ter modem receive context.
66 \param s The modem context.
67 \param bit_rate The bit rate of the modem. Valid values are 2400 and 4800.
68 \param put_bit The callback routine used to put the received data.
69 \param user_data An opaque pointer passed to the put_bit routine.
70 \return A pointer to the modem context, or NULL if there was a problem. */
71SPAN_DECLARE(v27ter_rx_state_t *) v27ter_rx_init(v27ter_rx_state_t *s, int bit_rate, put_bit_func_t put_bit, void *user_data);
72
73/*! Reinitialise an existing V.27ter modem receive context.
74 \brief Reinitialise an existing V.27ter modem receive context.
75 \param s The modem context.
76 \param bit_rate The bit rate of the modem. Valid values are 2400 and 4800.
77 \param old_train True if a previous trained values are to be reused.
78 \return 0 for OK, -1 for bad parameter */
79SPAN_DECLARE(int) v27ter_rx_restart(v27ter_rx_state_t *s, int bit_rate, bool old_train);
80
81/*! Release a V.27ter modem receive context.
82 \brief Release a V.27ter modem receive context.
83 \param s The modem context.
84 \return 0 for OK */
85SPAN_DECLARE(int) v27ter_rx_release(v27ter_rx_state_t *s);
86
87/*! Free a V.27ter modem receive context.
88 \brief Free a V.27ter modem receive context.
89 \param s The modem context.
90 \return 0 for OK */
91SPAN_DECLARE(int) v27ter_rx_free(v27ter_rx_state_t *s);
92
93/*! Get the logging context associated with a V.27ter modem receive context.
94 \brief Get the logging context associated with a V.27ter modem receive context.
95 \param s The modem context.
96 \return A pointer to the logging context */
98
99/*! Change the put_bit function associated with a V.27ter modem receive context.
100 \brief Change the put_bit function associated with a V.27ter modem receive context.
101 \param s The modem context.
102 \param put_bit The callback routine used to handle received bits.
103 \param user_data An opaque pointer. */
104SPAN_DECLARE(void) v27ter_rx_set_put_bit(v27ter_rx_state_t *s, put_bit_func_t put_bit, void *user_data);
105
106/*! Change the modem status report function associated with a V.27ter modem receive context.
107 \brief Change the modem status report function associated with a V.27ter modem receive context.
108 \param s The modem context.
109 \param handler The callback routine used to report modem status changes.
110 \param user_data An opaque pointer. */
111SPAN_DECLARE(void) v27ter_rx_set_modem_status_handler(v27ter_rx_state_t *s, modem_status_func_t handler, void *user_data);
112
113/*! Process a block of received V.27ter modem audio samples.
114 \brief Process a block of received V.27ter modem audio samples.
115 \param s The modem context.
116 \param amp The audio sample buffer.
117 \param len The number of samples in the buffer.
118 \return The number of samples unprocessed.
119*/
120SPAN_DECLARE(int) v27ter_rx(v27ter_rx_state_t *s, const int16_t amp[], int len);
121
122/*! Fake processing of a missing block of received V.27ter modem audio samples.
123 (e.g due to packet loss).
124 \brief Fake processing of a missing block of received V.27ter modem audio samples.
125 \param s The modem context.
126 \param len The number of samples to fake.
127 \return The number of samples unprocessed.
128*/
129SPAN_DECLARE(int) v27ter_rx_fillin(v27ter_rx_state_t *s, int len);
130
131/*! Get a snapshot of the current equalizer coefficients.
132 \brief Get a snapshot of the current equalizer coefficients.
133 \param coeffs The vector of complex coefficients.
134 \return The number of coefficients in the vector. */
135#if defined(SPANDSP_USE_FIXED_POINT)
136SPAN_DECLARE(int) v27ter_rx_equalizer_state(v27ter_rx_state_t *s, complexi16_t **coeffs);
137#else
138SPAN_DECLARE(int) v27ter_rx_equalizer_state(v27ter_rx_state_t *s, complexf_t **coeffs);
139#endif
140
141/*! Get the current received carrier frequency.
142 \param s The modem context.
143 \return The frequency, in Hertz. */
144SPAN_DECLARE(float) v27ter_rx_carrier_frequency(v27ter_rx_state_t *s);
145
146/*! Get the current symbol timing correction since startup.
147 \param s The modem context.
148 \return The correction. */
150
151/*! Get a current received signal power.
152 \param s The modem context.
153 \return The signal power, in dBm0. */
154SPAN_DECLARE(float) v27ter_rx_signal_power(v27ter_rx_state_t *s);
155
156/*! Set the power level at which the carrier detection will cut in
157 \param s The modem context.
158 \param cutoff The signal cutoff power, in dBm0. */
159SPAN_DECLARE(void) v27ter_rx_signal_cutoff(v27ter_rx_state_t *s, float cutoff);
160
161/*! Set a handler routine to process QAM status reports
162 \param s The modem context.
163 \param handler The handler routine.
164 \param user_data An opaque pointer passed to the handler routine. */
165SPAN_DECLARE(void) v27ter_rx_set_qam_report_handler(v27ter_rx_state_t *s, qam_report_handler_t handler, void *user_data);
166
167#if defined(__cplusplus)
168}
169#endif
170
171#endif
172/*- 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
Definition complex.h:43
Definition complex.h:89
Definition private/logging.h:34
Definition private/v27ter_rx.h:52
int bit_rate
The bit rate of the modem. Valid values are 2400 and 4800.
Definition private/v27ter_rx.h:54
put_bit_func_t put_bit
The callback function used to put each bit received.
Definition private/v27ter_rx.h:56
bool old_train
True if the previous trained values are to be reused.
Definition private/v27ter_rx.h:134
void v27ter_rx_signal_cutoff(v27ter_rx_state_t *s, float cutoff)
Definition v27ter_rx.c:158
void v27ter_rx_set_modem_status_handler(v27ter_rx_state_t *s, modem_status_func_t handler, void *user_data)
Change the modem status report function associated with a V.27ter modem receive context.
Definition v27ter_rx.c:1023
v27ter_rx_state_t * v27ter_rx_init(v27ter_rx_state_t *s, int bit_rate, put_bit_func_t put_bit, void *user_data)
Initialise a V.27ter modem receive context.
Definition v27ter_rx.c:1104
int v27ter_rx_fillin(v27ter_rx_state_t *s, int len)
Fake processing of a missing block of received V.27ter modem audio samples.
Definition v27ter_rx.c:981
void v27ter_rx_set_put_bit(v27ter_rx_state_t *s, put_bit_func_t put_bit, void *user_data)
Change the put_bit function associated with a V.27ter modem receive context.
Definition v27ter_rx.c:1016
float v27ter_rx_symbol_timing_correction(v27ter_rx_state_t *s)
Definition v27ter_rx.c:143
float v27ter_rx_signal_power(v27ter_rx_state_t *s)
Definition v27ter_rx.c:152
void v27ter_rx_set_qam_report_handler(v27ter_rx_state_t *s, qam_report_handler_t handler, void *user_data)
Definition v27ter_rx.c:1144
int v27ter_rx_release(v27ter_rx_state_t *s)
Release a V.27ter modem receive context.
Definition v27ter_rx.c:1131
int v27ter_rx(v27ter_rx_state_t *s, const int16_t amp[], int len)
Process a block of received V.27ter modem audio samples.
Definition v27ter_rx.c:831
int v27ter_rx_free(v27ter_rx_state_t *s)
Free a V.27ter modem receive context.
Definition v27ter_rx.c:1137
int v27ter_rx_equalizer_state(v27ter_rx_state_t *s, complexf_t **coeffs)
Get a snapshot of the current equalizer coefficients.
Definition v27ter_rx.c:178
logging_state_t * v27ter_rx_get_logging_state(v27ter_rx_state_t *s)
Get the logging context associated with a V.27ter modem receive context.
Definition v27ter_rx.c:1030
int v27ter_rx_restart(v27ter_rx_state_t *s, int bit_rate, bool old_train)
Reinitialise an existing V.27ter modem receive context.
Definition v27ter_rx.c:1036
float v27ter_rx_carrier_frequency(v27ter_rx_state_t *s)
Definition v27ter_rx.c:137