spandsp 3.0.0
v29rx.c File Reference
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include <stdio.h>
#include "spandsp/stdbool.h"
#include "floating_fudge.h"
#include "spandsp/telephony.h"
#include "spandsp/alloc.h"
#include "spandsp/logging.h"
#include "spandsp/fast_convert.h"
#include "spandsp/math_fixed.h"
#include "spandsp/saturated.h"
#include "spandsp/complex.h"
#include "spandsp/vector_float.h"
#include "spandsp/complex_vector_float.h"
#include "spandsp/vector_int.h"
#include "spandsp/complex_vector_int.h"
#include "spandsp/async.h"
#include "spandsp/power_meter.h"
#include "spandsp/arctan2.h"
#include "spandsp/dds.h"
#include "spandsp/complex_filters.h"
#include "spandsp/v29rx.h"
#include "spandsp/private/logging.h"
#include "spandsp/private/power_meter.h"
#include "spandsp/private/v29rx.h"
#include "v29rx_rrc.h"
#include "v29tx_constellation_maps.h"

Macros

#define IAXMODEM_STUFF
 
#define FP_SCALE(x)   (x)
 
#define FP_SYNC_SCALE(x)   (x)
 
#define FP_SYNC_SCALE_32(x)   (x)
 
#define FP_CONSTELLATION_SCALE(x)   FP_SCALE(x)
 
#define CARRIER_NOMINAL_FREQ   1700.0f
 
#define BAUD_RATE   2400
 
#define EQUALIZER_DELTA   0.21f
 
#define V29_TRAINING_SEG_2_LEN   128
 
#define V29_TRAINING_SEG_3_LEN   384
 
#define V29_TRAINING_SEG_4_LEN   48
 
#define SIN_LOW_BAND_EDGE   0.382683432f
 
#define COS_LOW_BAND_EDGE   0.923879533f
 
#define SIN_HIGH_BAND_EDGE   0.760405966f
 
#define COS_HIGH_BAND_EDGE   -0.649448048f
 
#define ALPHA   0.99f
 
#define SYNC_LOW_BAND_EDGE_COEFF_0   FP_SYNC_SCALE(2.0f*ALPHA*COS_LOW_BAND_EDGE)
 
#define SYNC_LOW_BAND_EDGE_COEFF_1   FP_SYNC_SCALE(-ALPHA*ALPHA)
 
#define SYNC_LOW_BAND_EDGE_COEFF_2   FP_SYNC_SCALE(-ALPHA*SIN_LOW_BAND_EDGE)
 
#define SYNC_HIGH_BAND_EDGE_COEFF_0   FP_SYNC_SCALE(2.0f*ALPHA*COS_HIGH_BAND_EDGE)
 
#define SYNC_HIGH_BAND_EDGE_COEFF_1   FP_SYNC_SCALE(-ALPHA*ALPHA)
 
#define SYNC_HIGH_BAND_EDGE_COEFF_2   FP_SYNC_SCALE(-ALPHA*SIN_HIGH_BAND_EDGE)
 
#define SYNC_MIXED_EDGES_COEFF_3   FP_SYNC_SCALE(-ALPHA*ALPHA*(SIN_HIGH_BAND_EDGE*COS_LOW_BAND_EDGE - SIN_LOW_BAND_EDGE*COS_HIGH_BAND_EDGE))
 

Enumerations

enum  {
  TRAINING_STAGE_NORMAL_OPERATION = 0 , TRAINING_STAGE_SYMBOL_ACQUISITION , TRAINING_STAGE_LOG_PHASE , TRAINING_STAGE_WAIT_FOR_CDCD ,
  TRAINING_STAGE_TRAIN_ON_CDCD , TRAINING_STAGE_TRAIN_ON_CDCD_AND_TEST , TRAINING_STAGE_TEST_ONES , TRAINING_STAGE_PARKED
}
 

Functions

float v29_rx_carrier_frequency (v29_rx_state_t *s)
 
float v29_rx_symbol_timing_correction (v29_rx_state_t *s)
 
float v29_rx_signal_power (v29_rx_state_t *s)
 
void v29_rx_signal_cutoff (v29_rx_state_t *s, float cutoff)
 
int v29_rx_equalizer_state (v29_rx_state_t *s, complexf_t **coeffs)
 Get a snapshot of the current equalizer coefficients.
 
int v29_rx (v29_rx_state_t *s, const int16_t amp[], int len)
 Process a block of received V.29 modem audio samples.
 
int v29_rx_fillin (v29_rx_state_t *s, int len)
 Fake processing of a missing block of received V.29 modem audio samples.
 
void v29_rx_set_put_bit (v29_rx_state_t *s, put_bit_func_t put_bit, void *user_data)
 Change the put_bit function associated with a V.29 modem receive context.
 
void v29_rx_set_modem_status_handler (v29_rx_state_t *s, modem_status_func_t handler, void *user_data)
 Change the modem status report function associated with a V.29 modem receive context.
 
logging_state_tv29_rx_get_logging_state (v29_rx_state_t *s)
 Get the logging context associated with a V.29 modem receive context.
 
int v29_rx_restart (v29_rx_state_t *s, int bit_rate, bool old_train)
 Reinitialise an existing V.29 modem receive context.
 
v29_rx_state_tv29_rx_init (v29_rx_state_t *s, int bit_rate, put_bit_func_t put_bit, void *user_data)
 Initialise a V.29 modem receive context.
 
int v29_rx_release (v29_rx_state_t *s)
 Release a V.29 modem receive context.
 
int v29_rx_free (v29_rx_state_t *s)
 Free a V.29 modem receive context.
 
void v29_rx_set_qam_report_handler (v29_rx_state_t *s, qam_report_handler_t handler, void *user_data)
 

Macro Definition Documentation

◆ BAUD_RATE

#define BAUD_RATE   2400

The nominal baud or symbol rate

◆ CARRIER_NOMINAL_FREQ

#define CARRIER_NOMINAL_FREQ   1700.0f

The nominal frequency of the carrier, in Hertz

◆ EQUALIZER_DELTA

#define EQUALIZER_DELTA   0.21f

The adaption rate coefficient for the equalizer

◆ V29_TRAINING_SEG_2_LEN

#define V29_TRAINING_SEG_2_LEN   128

The length of training segment 2, in symbols

◆ V29_TRAINING_SEG_3_LEN

#define V29_TRAINING_SEG_3_LEN   384

The length of training segment 3, in symbols

◆ V29_TRAINING_SEG_4_LEN

#define V29_TRAINING_SEG_4_LEN   48

The length of training segment 4, in symbols

Function Documentation

◆ v29_rx()

int v29_rx ( v29_rx_state_t s,
const int16_t  amp[],
int  len 
)

Process a block of received V.29 modem audio samples.

Process a block of received V.29 modem audio samples.

Parameters
sThe modem context.
ampThe audio sample buffer.
lenThe number of samples in the buffer.
Returns
The number of samples unprocessed.

References v29_rx_state_s::agc_scaling, v29_rx_state_s::agc_scaling_save, v29_rx_state_s::carrier_phase, v29_rx_state_s::carrier_phase_rate, dds_advance(), dds_advancef(), dds_lookup_complexf(), dds_lookup_complexi16(), v29_rx_state_s::eq_put_step, complexi16_t::im, complexi16_t::re, v29_rx_state_s::rrc_filter, v29_rx_state_s::rrc_filter_step, v29_rx_state_s::symbol_sync_high, v29_rx_state_s::symbol_sync_low, and v29_rx_state_s::training_stage.

◆ v29_rx_carrier_frequency()

float v29_rx_carrier_frequency ( v29_rx_state_t s)

Get the current received carrier frequency.

Parameters
sThe modem context.
Returns
The frequency, in Hertz.

References v29_rx_state_s::carrier_phase_rate, and dds_frequencyf().

◆ v29_rx_equalizer_state()

int v29_rx_equalizer_state ( v29_rx_state_t s,
complexf_t **  coeffs 
)

Get a snapshot of the current equalizer coefficients.

Get a snapshot of the current equalizer coefficients.

Parameters
sThe modem context.
coeffsThe vector of complex coefficients.
Returns
The number of coefficients in the vector.

References v29_rx_state_s::eq_coeff.

◆ v29_rx_fillin()

int v29_rx_fillin ( v29_rx_state_t s,
int  len 
)

Fake processing of a missing block of received V.29 modem audio samples.

Fake processing of a missing block of received V.29 modem audio samples. (e.g due to packet loss).

Parameters
sThe modem context.
lenThe number of samples to fake.
Returns
The number of samples unprocessed.

References v29_rx_state_s::carrier_phase, v29_rx_state_s::carrier_phase_rate, dds_advance(), dds_advancef(), v29_rx_state_s::eq_put_step, v29_rx_state_s::logging, v29_rx_state_s::signal_present, span_log(), and v29_rx_state_s::training_stage.

◆ v29_rx_free()

int v29_rx_free ( v29_rx_state_t s)

Free a V.29 modem receive context.

Free a V.29 modem receive context.

Parameters
sThe modem context.
Returns
0 for OK

◆ v29_rx_get_logging_state()

logging_state_t * v29_rx_get_logging_state ( v29_rx_state_t s)

Get the logging context associated with a V.29 modem receive context.

Get the logging context associated with a V.29 modem receive context.

Parameters
sThe modem context.
Returns
A pointer to the logging context

References v29_rx_state_s::logging.

◆ v29_rx_init()

v29_rx_state_t * v29_rx_init ( v29_rx_state_t s,
int  bit_rate,
put_bit_func_t  put_bit,
void *  user_data 
)

Initialise a V.29 modem receive context.

Initialise a V.29 modem receive context.

Parameters
sThe modem context.
bit_rateThe bit rate of the modem. Valid values are 4800, 7200 and 9600.
put_bitThe callback routine used to put the received data.
user_dataAn opaque pointer passed to the put_bit routine.
Returns
A pointer to the modem context, or NULL if there was a problem.

References v29_rx_state_s::logging, v29_rx_state_s::put_bit, v29_rx_state_s::put_bit_user_data, v29_rx_restart(), and v29_rx_signal_cutoff().

◆ v29_rx_release()

int v29_rx_release ( v29_rx_state_t s)

Release a V.29 modem receive context.

Release a V.29 modem receive context.

Parameters
sThe modem context.
Returns
0 for OK

◆ v29_rx_restart()

◆ v29_rx_set_modem_status_handler()

void v29_rx_set_modem_status_handler ( v29_rx_state_t s,
modem_status_func_t  handler,
void *  user_data 
)

Change the modem status report function associated with a V.29 modem receive context.

Change the modem status report function associated with a V.29 modem receive context.

Parameters
sThe modem context.
handlerThe callback routine used to report modem status changes.
user_dataAn opaque pointer.

References v29_rx_state_s::status_handler, and v29_rx_state_s::status_user_data.

◆ v29_rx_set_put_bit()

void v29_rx_set_put_bit ( v29_rx_state_t s,
put_bit_func_t  put_bit,
void *  user_data 
)

Change the put_bit function associated with a V.29 modem receive context.

Change the put_bit function associated with a V.29 modem receive context.

Parameters
sThe modem context.
put_bitThe callback routine used to handle received bits.
user_dataAn opaque pointer.

References v29_rx_state_s::put_bit, and v29_rx_state_s::put_bit_user_data.

◆ v29_rx_set_qam_report_handler()

void v29_rx_set_qam_report_handler ( v29_rx_state_t s,
qam_report_handler_t  handler,
void *  user_data 
)

Set a handler routine to process QAM status reports

Parameters
sThe modem context.
handlerThe handler routine.
user_dataAn opaque pointer passed to the handler routine.

References v29_rx_state_s::qam_report, and v29_rx_state_s::qam_user_data.

◆ v29_rx_signal_cutoff()

void v29_rx_signal_cutoff ( v29_rx_state_t s,
float  cutoff 
)

Set the power level at which the carrier detection will cut in

Parameters
sThe modem context.
cutoffThe signal cutoff power, in dBm0.

References v29_rx_state_s::carrier_off_power, v29_rx_state_s::carrier_on_power, and power_meter_level_dbm0().

Referenced by v29_rx_init().

◆ v29_rx_signal_power()

float v29_rx_signal_power ( v29_rx_state_t s)

Get the current received signal power.

Parameters
sThe modem context.
Returns
The signal power, in dBm0.

References v29_rx_state_s::power, and power_meter_current_dbm0().

◆ v29_rx_symbol_timing_correction()

float v29_rx_symbol_timing_correction ( v29_rx_state_t s)

Get the current symbol timing correction since startup.

Parameters
sThe modem context.
Returns
The correction.

References v29_rx_state_s::total_baud_timing_correction.