00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * fsk.h - FSK modem transmit and receive parts 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2003 Steve Underwood 00009 * 00010 * All rights reserved. 00011 * 00012 * This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU General Public License version 2, as 00014 * published by the Free Software Foundation. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License 00022 * along with this program; if not, write to the Free Software 00023 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00024 * 00025 * $Id: fsk.h,v 1.22 2007/04/10 16:12:20 steveu Exp $ 00026 */ 00027 00028 /*! \file */ 00029 00030 /*! \page fsk_page FSK modems 00031 \section fsk_page_sec_1 What does it do? 00032 Most of the oldest telephony modems use incoherent FSK modulation. This module can 00033 be used to implement both the transmit and receive sides of a number of these 00034 modems. There are integrated definitions for: 00035 00036 - V.21 00037 - V.23 00038 - Bell 103 00039 - Bell 202 00040 - Weitbrecht (Used for TDD - Telecoms Device for the Deaf) 00041 00042 The audio output or input is a stream of 16 bit samples, at 8000 samples/second. 00043 The transmit and receive sides can be used independantly. 00044 00045 \section fsk_page_sec_2 The transmitter 00046 00047 The FSK transmitter uses a DDS generator to synthesise the waveform. This 00048 naturally produces phase coherent transitions, as the phase update rate is 00049 switched, producing a clean spectrum. The symbols are not generally an integer 00050 number of samples long. However, the symbol time for the fastest data rate 00051 generally used (1200bps) is more than 7 samples long. The jitter resulting from 00052 switching at the nearest sample is, therefore, acceptable. No interpolation is 00053 used. 00054 00055 \section fsk_page_sec_3 The receiver 00056 00057 The FSK receiver uses a quadrature correlation technique to demodulate the 00058 signal. Two DDS quadrature oscillators are used. The incoming signal is 00059 correlated with the oscillator signals over a period of one symbol. The 00060 oscillator giving the highest net correlation from its I and Q outputs is the 00061 one that matches the frequency being transmitted during the correlation 00062 interval. Because the transmission is totally asynchronous, the demodulation 00063 process must run sample by sample to find the symbol transitions. The 00064 correlation is performed on a sliding window basis, so the computational load of 00065 demodulating sample by sample is not great. 00066 00067 Two modes of symbol synchronisation are provided: 00068 00069 - In synchronous mode, symbol transitions are smoothed, to track their true 00070 position in the prescence of high timing jitter. This provides the most 00071 reliable symbol recovery in poor signal to noise conditions. However, it 00072 takes a little time to settle, so it not really suitable for data streams 00073 which must start up instantaneously (e.g. the TDD systems used by hearing 00074 impaired people). 00075 00076 - In asynchronous mode each transition is taken at face value, with no temporal 00077 smoothing. There is no settling time for this mode, but when the signal to 00078 noise ratio is very poor it does not perform as well as the synchronous mode. 00079 */ 00080 00081 #if !defined(_SPANDSP_FSK_H_) 00082 #define _SPANDSP_FSK_H_ 00083 00084 /*! 00085 FSK modem specification. This defines the frequencies, signal levels and 00086 baud rate (== bit rate for simple FSK) for a single channel of an FSK modem. 00087 */ 00088 typedef struct 00089 { 00090 const char *name; 00091 int freq_zero; 00092 int freq_one; 00093 int tx_level; 00094 int min_level; 00095 int baud_rate; 00096 } fsk_spec_t; 00097 00098 /* Predefined FSK modem channels */ 00099 enum 00100 { 00101 FSK_V21CH1 = 0, 00102 FSK_V21CH2, 00103 FSK_V23CH1, 00104 FSK_V23CH2, 00105 FSK_BELL103CH1, 00106 FSK_BELL103CH2, 00107 FSK_BELL202, 00108 FSK_WEITBRECHT, /* Used for TDD (Telecom Device for the Deaf) */ 00109 }; 00110 00111 extern fsk_spec_t preset_fsk_specs[]; 00112 00113 /*! 00114 FSK modem transmit descriptor. This defines the state of a single working 00115 instance of an FSK modem transmitter. 00116 */ 00117 typedef struct 00118 { 00119 int baud_rate; 00120 get_bit_func_t get_bit; 00121 void *user_data; 00122 00123 int32_t phase_rates[2]; 00124 int scaling; 00125 int32_t current_phase_rate; 00126 uint32_t phase_acc; 00127 int baud_frac; 00128 int baud_inc; 00129 int shutdown; 00130 } fsk_tx_state_t; 00131 00132 /* The longest window will probably be 106 for 75 baud */ 00133 #define FSK_MAX_WINDOW_LEN 128 00134 00135 /*! 00136 FSK modem receive descriptor. This defines the state of a single working 00137 instance of an FSK modem receiver. 00138 */ 00139 typedef struct 00140 { 00141 int baud_rate; 00142 int sync_mode; 00143 put_bit_func_t put_bit; 00144 void *user_data; 00145 00146 int min_power; 00147 power_meter_t power; 00148 /*! \brief The value of the last signal sample, using the a simple HPF for signal power estimation. */ 00149 int16_t last_sample; 00150 /*! \brief >0 if a signal above the minimum is present. It may or may not be a V.29 signal. */ 00151 int signal_present; 00152 00153 int32_t phase_rate[2]; 00154 uint32_t phase_acc[2]; 00155 00156 int correlation_span; 00157 00158 int32_t window_i[2][FSK_MAX_WINDOW_LEN]; 00159 int32_t window_q[2][FSK_MAX_WINDOW_LEN]; 00160 int32_t dot_i[2]; 00161 int32_t dot_q[2]; 00162 int buf_ptr; 00163 00164 int baud_inc; 00165 int baud_pll; 00166 int lastbit; 00167 int scaling_shift; 00168 } fsk_rx_state_t; 00169 00170 #if defined(__cplusplus) 00171 extern "C" 00172 { 00173 #endif 00174 00175 /*! Initialise an FSK modem transmit context. 00176 \brief Initialise an FSK modem transmit context. 00177 \param s The modem context. 00178 \param spec The specification of the modem tones and rate. 00179 \param get_bit The callback routine used to get the data to be transmitted. 00180 \param user_data An opaque pointer. 00181 \return A pointer to the modem context, or NULL if there was a problem. */ 00182 fsk_tx_state_t *fsk_tx_init(fsk_tx_state_t *s, 00183 fsk_spec_t *spec, 00184 get_bit_func_t get_bit, 00185 void *user_data); 00186 00187 /*! Adjust an FSK modem transmit context's power output. 00188 \brief Adjust an FSK modem transmit context's power output. 00189 \param s The modem context. 00190 \param power The power level, in dBm0 */ 00191 void fsk_tx_power(fsk_tx_state_t *s, float power); 00192 00193 void fsk_tx_set_get_bit(fsk_tx_state_t *s, get_bit_func_t get_bit, void *user_data); 00194 00195 /*! Generate a block of FSK modem audio samples. 00196 \brief Generate a block of FSK modem audio samples. 00197 \param s The modem context. 00198 \param amp The audio sample buffer. 00199 \param len The number of samples to be generated. 00200 \return The number of samples actually generated. 00201 */ 00202 int fsk_tx(fsk_tx_state_t *s, int16_t *amp, int len); 00203 00204 /*! Get the current received signal power. 00205 \param s The modem context. 00206 \return The signal power, in dBm0. */ 00207 float fsk_rx_signal_power(fsk_rx_state_t *s); 00208 00209 /*! Adjust an FSK modem receive context's carrier detect power threshold. 00210 \brief Adjust an FSK modem receive context's carrier detect power threshold. 00211 \param s The modem context. 00212 \param power The power level, in dBm0 */ 00213 void fsk_rx_signal_cutoff(fsk_rx_state_t *s, float cutoff); 00214 00215 /*! Initialise an FSK modem receive context. 00216 \brief Initialise an FSK modem receive context. 00217 \param s The modem context. 00218 \param spec The specification of the modem tones and rate. 00219 \param sync_mode TRUE for synchronous modem. FALSE for asynchronous mode. 00220 \param put_bit The callback routine used to put the received data. 00221 \param user_data An opaque pointer. 00222 \return A pointer to the modem context, or NULL if there was a problem. */ 00223 fsk_rx_state_t *fsk_rx_init(fsk_rx_state_t *s, 00224 fsk_spec_t *spec, 00225 int sync_mode, 00226 put_bit_func_t put_bit, 00227 void *user_data); 00228 00229 /*! Process a block of received FSK modem audio samples. 00230 \brief Process a block of received FSK modem audio samples. 00231 \param s The modem context. 00232 \param amp The audio sample buffer. 00233 \param len The number of samples in the buffer. 00234 \return The number of samples unprocessed. 00235 */ 00236 int fsk_rx(fsk_rx_state_t *s, const int16_t *amp, int len); 00237 00238 void fsk_rx_set_put_bit(fsk_rx_state_t *s, put_bit_func_t put_bit, void *user_data); 00239 00240 #if defined(__cplusplus) 00241 } 00242 #endif 00243 00244 #endif 00245 /*- End of file ------------------------------------------------------------*/