mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-10-30 15:14:17 +00:00
Numerous little changes to spandsp that haven't been pushed to Freeswitch for a
while. The only big changes are a majorly rewritten V.42 and V.42bis which are now basically functional.
This commit is contained in:
1 parent
6f62f39139
commit
d30e82e226
68 files changed
+2513
-2114
No files matched your search
@@ -69,6 +69,12 @@ SPAN_DECLARE(const char *) signal_status_to_str(int status)
|
||||
return "Poor signal quality";
|
||||
case SIG_STATUS_MODEM_RETRAIN_OCCURRED:
|
||||
return "Modem retrain occurred";
|
||||
case SIG_STATUS_LINK_CONNECTED:
|
||||
return "Link connected";
|
||||
case SIG_STATUS_LINK_DISCONNECTED:
|
||||
return "Link disconnected";
|
||||
case SIG_STATUS_LINK_ERROR:
|
||||
return "Link error";
|
||||
}
|
||||
return "???";
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
/* This is a simple set of direct digital synthesis (DDS) functions to generate sine
|
||||
waves. This version uses a 128 entry sin/cos table to cover one quadrant. */
|
||||
|
||||
static const int16_t sine_table[DDS_STEPS] =
|
||||
static const int16_t sine_table[DDS_STEPS + 1] =
|
||||
{
|
||||
201,
|
||||
603,
|
||||
@@ -186,6 +186,7 @@ static const int16_t sine_table[DDS_STEPS] =
|
||||
32753,
|
||||
32762,
|
||||
32767,
|
||||
32767
|
||||
};
|
||||
|
||||
SPAN_DECLARE(int32_t) dds_phase_rate(float frequency)
|
||||
@@ -220,7 +221,7 @@ SPAN_DECLARE(int16_t) dds_lookup(uint32_t phase)
|
||||
phase >>= DDS_SHIFT;
|
||||
step = phase & (DDS_STEPS - 1);
|
||||
if ((phase & DDS_STEPS))
|
||||
step = (DDS_STEPS - 1) - step;
|
||||
step = DDS_STEPS - step;
|
||||
amp = sine_table[step];
|
||||
if ((phase & (2*DDS_STEPS)))
|
||||
amp = -amp;
|
||||
@@ -254,7 +255,7 @@ SPAN_DECLARE(int16_t) dds_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t s
|
||||
{
|
||||
int16_t amp;
|
||||
|
||||
amp = (int16_t) (((int32_t) dds_lookup(*phase_acc + phase)*(int32_t) scale) >> 15);
|
||||
amp = (int16_t) (((int32_t) dds_lookup(*phase_acc + phase)*scale) >> 15);
|
||||
*phase_acc += phase_rate;
|
||||
return amp;
|
||||
}
|
||||
@@ -280,8 +281,8 @@ SPAN_DECLARE(complexi_t) dds_complexi_mod(uint32_t *phase_acc, int32_t phase_rat
|
||||
{
|
||||
complexi_t amp;
|
||||
|
||||
amp = complex_seti(((int32_t) dds_lookup(*phase_acc + phase + (1 << 30))*(int32_t) scale) >> 15,
|
||||
((int32_t) dds_lookup(*phase_acc + phase)*(int32_t) scale) >> 15);
|
||||
amp = complex_seti(((int32_t) dds_lookup(*phase_acc + phase + (1 << 30))*scale) >> 15,
|
||||
((int32_t) dds_lookup(*phase_acc + phase)*scale) >> 15);
|
||||
*phase_acc += phase_rate;
|
||||
return amp;
|
||||
}
|
||||
@@ -307,8 +308,8 @@ SPAN_DECLARE(complexi16_t) dds_complexi16_mod(uint32_t *phase_acc, int32_t phase
|
||||
{
|
||||
complexi16_t amp;
|
||||
|
||||
amp = complex_seti16((int16_t) (((int32_t) dds_lookup(*phase_acc + phase + (1 << 30))*(int32_t) scale) >> 15),
|
||||
(int16_t) (((int32_t) dds_lookup(*phase_acc + phase)*(int32_t) scale) >> 15));
|
||||
amp = complex_seti16((int16_t) (((int32_t) dds_lookup(*phase_acc + phase + (1 << 30))*scale) >> 15),
|
||||
(int16_t) (((int32_t) dds_lookup(*phase_acc + phase)*scale) >> 15));
|
||||
*phase_acc += phase_rate;
|
||||
return amp;
|
||||
}
|
||||
@@ -334,8 +335,8 @@ SPAN_DECLARE(complexi32_t) dds_complexi32_mod(uint32_t *phase_acc, int32_t phase
|
||||
{
|
||||
complexi32_t amp;
|
||||
|
||||
amp = complex_seti32(((int32_t) dds_lookup(*phase_acc + phase + (1 << 30))*(int32_t) scale) >> 15,
|
||||
((int32_t) dds_lookup(*phase_acc + phase)*(int32_t) scale) >> 15);
|
||||
amp = complex_seti32(((int32_t) dds_lookup(*phase_acc + phase + (1 << 30))*scale) >> 15,
|
||||
((int32_t) dds_lookup(*phase_acc + phase)*scale) >> 15);
|
||||
*phase_acc += phase_rate;
|
||||
return amp;
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ SPAN_DECLARE(void) fsk_tx_set_get_bit(fsk_tx_state_t *s, get_bit_func_t get_bit,
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
SPAN_DECLARE(void) fsk_tx_set_modem_status_handler(fsk_tx_state_t *s, modem_tx_status_func_t handler, void *user_data)
|
||||
SPAN_DECLARE(void) fsk_tx_set_modem_status_handler(fsk_tx_state_t *s, modem_status_func_t handler, void *user_data)
|
||||
{
|
||||
s->status_handler = handler;
|
||||
s->status_user_data = user_data;
|
||||
@@ -248,7 +248,7 @@ SPAN_DECLARE(void) fsk_rx_set_put_bit(fsk_rx_state_t *s, put_bit_func_t put_bit,
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
SPAN_DECLARE(void) fsk_rx_set_modem_status_handler(fsk_rx_state_t *s, modem_tx_status_func_t handler, void *user_data)
|
||||
SPAN_DECLARE(void) fsk_rx_set_modem_status_handler(fsk_rx_state_t *s, modem_status_func_t handler, void *user_data)
|
||||
{
|
||||
s->status_handler = handler;
|
||||
s->status_user_data = user_data;
|
||||
|
||||
@@ -91,15 +91,16 @@ void gsm0610_preprocess(gsm0610_state_t *s, const int16_t amp[GSM0610_FRAME_LEN]
|
||||
/* 4.2.1 Downscaling of the input signal */
|
||||
SO = (amp[k] >> 1) & ~3;
|
||||
|
||||
assert(SO >= -0x4000); // downscaled by
|
||||
assert(SO <= 0x3FFC); // previous routine.
|
||||
/* This is supposed to have been downscaled by previous routine. */
|
||||
assert(SO >= -0x4000);
|
||||
assert(SO <= 0x3FFC);
|
||||
|
||||
/* 4.2.2 Offset compensation */
|
||||
|
||||
/* This part implements a high-pass filter and requires extended
|
||||
arithmetic precision for the recursive part of this filter.
|
||||
The input of this procedure is the array so[0...159] and the
|
||||
output the array sof[ 0...159 ].
|
||||
output the array sof[0...159].
|
||||
*/
|
||||
/* Compute the non-recursive part */
|
||||
s1 = SO - z1;
|
||||
|
||||
@@ -332,7 +332,7 @@ SPAN_DECLARE(void) hdlc_rx_set_frame_handler(hdlc_rx_state_t *s, hdlc_frame_hand
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
SPAN_DECLARE(void) hdlc_rx_set_status_handler(hdlc_rx_state_t *s, modem_rx_status_func_t handler, void *user_data)
|
||||
SPAN_DECLARE(void) hdlc_rx_set_status_handler(hdlc_rx_state_t *s, modem_status_func_t handler, void *user_data)
|
||||
{
|
||||
s->status_handler = handler;
|
||||
s->status_user_data = user_data;
|
||||
|
||||
@@ -146,12 +146,12 @@ static int image_resize_row(image_translate_state_t *s, uint8_t buf[], size_t le
|
||||
int input_length;
|
||||
double c1;
|
||||
double c2;
|
||||
double int_part;
|
||||
int x;
|
||||
#if defined(SPANDSP_USE_FIXED_POINT)
|
||||
int frac_row;
|
||||
int frac_col;
|
||||
#else
|
||||
double int_part;
|
||||
double frac_row;
|
||||
double frac_col;
|
||||
#endif
|
||||
|
||||
@@ -86,7 +86,7 @@ static __inline__ int32_t pow_ii(int32_t x, int32_t n)
|
||||
if (n == 0 || x == 1)
|
||||
return 1;
|
||||
if (x != -1)
|
||||
return (x == 0) ? 1/x : 0;
|
||||
return (x != 0) ? 1/x : 0;
|
||||
n = -n;
|
||||
}
|
||||
u = n;
|
||||
|
||||
@@ -165,10 +165,8 @@ SPAN_DECLARE(int) plc_fillin(plc_state_t *s, int16_t amp[], int len)
|
||||
float old_weight;
|
||||
float new_weight;
|
||||
float gain;
|
||||
//int16_t *orig_amp;
|
||||
int orig_len;
|
||||
|
||||
//orig_amp = amp;
|
||||
orig_len = len;
|
||||
if (s->missing_samples == 0)
|
||||
{
|
||||
|
||||
@@ -122,7 +122,7 @@ SPAN_DECLARE(float) power_meter_current_dbm0(power_meter_t *s)
|
||||
if (s->reading <= 0)
|
||||
return -96.329f + DBM0_MAX_POWER;
|
||||
/* This is based on A-law, but u-law is only 0.03dB different, so don't worry. */
|
||||
return log10f((float) s->reading/(32767.0f*32767.0f))*10.0f + DBM0_MAX_POWER;
|
||||
return 10.0f*log10f((float) s->reading/(32767.0f*32767.0f) + 1.0e-10f) + DBM0_MAX_POWER;
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
@@ -130,7 +130,7 @@ SPAN_DECLARE(float) power_meter_current_dbov(power_meter_t *s)
|
||||
{
|
||||
if (s->reading <= 0)
|
||||
return -96.329f;
|
||||
return log10f((float) s->reading/(32767.0f*32767.0f))*10.0f;
|
||||
return 10.0f*log10f((float) s->reading/(32767.0f*32767.0f) + 1.0e-10f);
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ SPAN_DECLARE(int) silence_gen_generated(silence_gen_state_t *s)
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
SPAN_DECLARE(void) silence_gen_status_handler(silence_gen_state_t *s, modem_tx_status_func_t handler, void *user_data)
|
||||
SPAN_DECLARE(void) silence_gen_status_handler(silence_gen_state_t *s, modem_status_func_t handler, void *user_data)
|
||||
{
|
||||
s->status_handler = handler;
|
||||
s->status_user_data = user_data;
|
||||
|
||||
@@ -49,8 +49,18 @@ static __inline__ int32_t arctan2(float y, float x)
|
||||
float abs_y;
|
||||
float angle;
|
||||
|
||||
if (x == 0.0f || y == 0.0f)
|
||||
return 0;
|
||||
if (y == 0.0f)
|
||||
{
|
||||
if (x < 0.0f)
|
||||
return 0x80000000;
|
||||
return 0x00000000;
|
||||
}
|
||||
if (x == 0.0f)
|
||||
{
|
||||
if (y < 0.0f)
|
||||
return 0xc0000000;
|
||||
return 0x40000000;
|
||||
}
|
||||
|
||||
abs_y = fabsf(y);
|
||||
|
||||
@@ -77,8 +87,18 @@ static __inline__ float arctan2f(float y, float x)
|
||||
float fx;
|
||||
float fy;
|
||||
|
||||
if (x == 0.0f || y == 0.0f)
|
||||
return 0;
|
||||
if (y == 0.0f)
|
||||
{
|
||||
if (x < 0.0f)
|
||||
return 3.1415926f;
|
||||
return 0.0f;
|
||||
}
|
||||
if (x == 0.0f)
|
||||
{
|
||||
if (y < 0.0f)
|
||||
return 3.1415926f*1.5f;
|
||||
return 3.1415926f*0.5f;
|
||||
}
|
||||
fx = fabsf(x);
|
||||
fy = fabsf(y);
|
||||
/* Deal with the octants */
|
||||
|
||||
@@ -80,7 +80,13 @@ enum
|
||||
/*! \brief Notification that a modem has detected signal quality degradation. */
|
||||
SIG_STATUS_POOR_SIGNAL_QUALITY = -12,
|
||||
/*! \brief Notification that a modem retrain has occurred. */
|
||||
SIG_STATUS_MODEM_RETRAIN_OCCURRED = -13
|
||||
SIG_STATUS_MODEM_RETRAIN_OCCURRED = -13,
|
||||
/*! \brief The link protocol (e.g. V.42) has connected. */
|
||||
SIG_STATUS_LINK_CONNECTED = -14,
|
||||
/*! \brief The link protocol (e.g. V.42) has disconnected. */
|
||||
SIG_STATUS_LINK_DISCONNECTED = -15,
|
||||
/*! \brief An error has occurred in the link protocol (e.g. V.42). */
|
||||
SIG_STATUS_LINK_ERROR = -16
|
||||
};
|
||||
|
||||
/*! Message put function for data pumps */
|
||||
@@ -101,11 +107,8 @@ typedef void (*put_bit_func_t)(void *user_data, int bit);
|
||||
/*! Bit get function for data pumps */
|
||||
typedef int (*get_bit_func_t)(void *user_data);
|
||||
|
||||
/*! Completion callback function for tx data pumps */
|
||||
typedef void (*modem_tx_status_func_t)(void *user_data, int status);
|
||||
|
||||
/*! Completion callback function for rx data pumps */
|
||||
typedef void (*modem_rx_status_func_t)(void *user_data, int status);
|
||||
/*! Status change callback function for data pumps */
|
||||
typedef void (*modem_status_func_t)(void *user_data, int status);
|
||||
|
||||
enum
|
||||
{
|
||||
|
||||
@@ -225,7 +225,7 @@ SPAN_DECLARE(uint32_t) bit_reverse_4bytes(uint32_t data);
|
||||
SPAN_DECLARE(uint64_t) bit_reverse_8bytes(uint64_t data);
|
||||
#endif
|
||||
|
||||
/*! \brief Bit reverse each bytes in a buffer.
|
||||
/*! \brief Bit reverse each byte in a buffer.
|
||||
\param to The buffer to place the reversed data in.
|
||||
\param from The buffer containing the data to be reversed.
|
||||
\param len The length of the data in the buffer. */
|
||||
|
||||
@@ -477,6 +477,12 @@ static __inline__ complexi32_t complex_conji32(const complexi32_t *x)
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
static __inline__ int32_t poweri16(const complexi16_t *x)
|
||||
{
|
||||
return (int32_t) x->re*x->re + (int32_t) x->im*x->im;
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
static __inline__ float powerf(const complexf_t *x)
|
||||
{
|
||||
return x->re*x->re + x->im*x->im;
|
||||
|
||||
@@ -175,7 +175,7 @@ SPAN_DECLARE(void) fsk_tx_set_get_bit(fsk_tx_state_t *s, get_bit_func_t get_bit,
|
||||
\param s The modem context.
|
||||
\param handler The callback routine used to report modem status changes.
|
||||
\param user_data An opaque pointer. */
|
||||
SPAN_DECLARE(void) fsk_tx_set_modem_status_handler(fsk_tx_state_t *s, modem_tx_status_func_t handler, void *user_data);
|
||||
SPAN_DECLARE(void) fsk_tx_set_modem_status_handler(fsk_tx_state_t *s, modem_status_func_t handler, void *user_data);
|
||||
|
||||
/*! Generate a block of FSK modem audio samples.
|
||||
\brief Generate a block of FSK modem audio samples.
|
||||
@@ -243,7 +243,7 @@ SPAN_DECLARE(void) fsk_rx_set_put_bit(fsk_rx_state_t *s, put_bit_func_t put_bit,
|
||||
\param s The modem context.
|
||||
\param handler The callback routine used to report modem status changes.
|
||||
\param user_data An opaque pointer. */
|
||||
SPAN_DECLARE(void) fsk_rx_set_modem_status_handler(fsk_rx_state_t *s, modem_rx_status_func_t handler, void *user_data);
|
||||
SPAN_DECLARE(void) fsk_rx_set_modem_status_handler(fsk_rx_state_t *s, modem_status_func_t handler, void *user_data);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ SPAN_DECLARE(void) hdlc_rx_set_frame_handler(hdlc_rx_state_t *s, hdlc_frame_hand
|
||||
\param handler The callback routine used to report status changes.
|
||||
\param user_data An opaque parameter for the callback routine.
|
||||
*/
|
||||
SPAN_DECLARE(void) hdlc_rx_set_status_handler(hdlc_rx_state_t *s, modem_rx_status_func_t handler, void *user_data);
|
||||
SPAN_DECLARE(void) hdlc_rx_set_status_handler(hdlc_rx_state_t *s, modem_status_func_t handler, void *user_data);
|
||||
|
||||
/*! Release an HDLC receiver context.
|
||||
\brief Release an HDLC receiver context.
|
||||
|
||||
@@ -39,7 +39,7 @@ struct fsk_tx_state_s
|
||||
void *get_bit_user_data;
|
||||
|
||||
/*! \brief The callback function used to report modem status changes. */
|
||||
modem_tx_status_func_t status_handler;
|
||||
modem_status_func_t status_handler;
|
||||
/*! \brief A user specified opaque pointer passed to the status function. */
|
||||
void *status_user_data;
|
||||
|
||||
@@ -66,7 +66,7 @@ struct fsk_rx_state_s
|
||||
void *put_bit_user_data;
|
||||
|
||||
/*! \brief The callback function used to report modem status changes. */
|
||||
modem_tx_status_func_t status_handler;
|
||||
modem_status_func_t status_handler;
|
||||
/*! \brief A user specified opaque pointer passed to the status function. */
|
||||
void *status_user_data;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ struct hdlc_rx_state_s
|
||||
/*! \brief An opaque parameter passed to the frame callback routine. */
|
||||
void *frame_user_data;
|
||||
/*! \brief The callback routine called to report status changes. */
|
||||
modem_rx_status_func_t status_handler;
|
||||
modem_status_func_t status_handler;
|
||||
/*! \brief An opaque parameter passed to the status callback routine. */
|
||||
void *status_user_data;
|
||||
/*! \brief TRUE if bad frames are to be reported. */
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
struct silence_gen_state_s
|
||||
{
|
||||
/*! \brief The callback function used to report status changes. */
|
||||
modem_tx_status_func_t status_handler;
|
||||
modem_status_func_t status_handler;
|
||||
/*! \brief A user specified opaque pointer passed to the status function. */
|
||||
void *status_user_data;
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ struct v17_rx_state_s
|
||||
void *put_bit_user_data;
|
||||
|
||||
/*! \brief The callback function used to report modem status changes. */
|
||||
modem_rx_status_func_t status_handler;
|
||||
modem_status_func_t status_handler;
|
||||
/*! \brief A user specified opaque pointer passed to the status function. */
|
||||
void *status_user_data;
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ struct v17_tx_state_s
|
||||
void *get_bit_user_data;
|
||||
|
||||
/*! \brief The callback function used to report modem status changes. */
|
||||
modem_tx_status_func_t status_handler;
|
||||
modem_status_func_t status_handler;
|
||||
/*! \brief A user specified opaque pointer passed to the status function. */
|
||||
void *status_user_data;
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ struct v22bis_state_s
|
||||
/*! \brief A user specified opaque pointer passed to the put_bit callback routine. */
|
||||
void *put_bit_user_data;
|
||||
/*! \brief The callback function used to report modem status changes. */
|
||||
modem_rx_status_func_t status_handler;
|
||||
modem_status_func_t status_handler;
|
||||
/*! \brief A user specified opaque pointer passed to the status function. */
|
||||
void *status_user_data;
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ struct v27ter_rx_state_s
|
||||
void *put_bit_user_data;
|
||||
|
||||
/*! \brief The callback function used to report modem status changes. */
|
||||
modem_rx_status_func_t status_handler;
|
||||
modem_status_func_t status_handler;
|
||||
/*! \brief A user specified opaque pointer passed to the status function. */
|
||||
void *status_user_data;
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ struct v27ter_tx_state_s
|
||||
void *get_bit_user_data;
|
||||
|
||||
/*! \brief The callback function used to report modem status changes. */
|
||||
modem_tx_status_func_t status_handler;
|
||||
modem_status_func_t status_handler;
|
||||
/*! \brief A user specified opaque pointer passed to the status function. */
|
||||
void *status_user_data;
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ struct v29_rx_state_s
|
||||
void *put_bit_user_data;
|
||||
|
||||
/*! \brief The callback function used to report modem status changes. */
|
||||
modem_rx_status_func_t status_handler;
|
||||
modem_status_func_t status_handler;
|
||||
/*! \brief A user specified opaque pointer passed to the status function. */
|
||||
void *status_user_data;
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ struct v29_tx_state_s
|
||||
void *get_bit_user_data;
|
||||
|
||||
/*! \brief The callback function used to report modem status changes. */
|
||||
modem_tx_status_func_t status_handler;
|
||||
modem_status_func_t status_handler;
|
||||
/*! \brief A user specified opaque pointer passed to the status function. */
|
||||
void *status_user_data;
|
||||
|
||||
@@ -68,7 +68,7 @@ struct v29_tx_state_s
|
||||
int rrc_filter_step;
|
||||
|
||||
/*! \brief The register for the data scrambler. */
|
||||
unsigned int scramble_reg;
|
||||
uint32_t scramble_reg;
|
||||
/*! \brief The register for the training scrambler. */
|
||||
uint8_t training_scramble_reg;
|
||||
/*! \brief TRUE if transmitting the training sequence, or shutting down transmission.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* Written by Steve Underwood <steveu@coppice.org>
|
||||
*
|
||||
* Copyright (C) 2003 Steve Underwood
|
||||
* Copyright (C) 2003, 2011 Steve Underwood
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -26,75 +26,94 @@
|
||||
#if !defined(_SPANDSP_PRIVATE_V42_H_)
|
||||
#define _SPANDSP_PRIVATE_V42_H_
|
||||
|
||||
/*! Max retries (9.2.2) */
|
||||
#define V42_DEFAULT_N_400 5
|
||||
/*! Default for max octets in an information field (9.2.3) */
|
||||
#define V42_DEFAULT_N_401 128
|
||||
/*! Maximum supported value for max octets in an information field */
|
||||
#define V42_MAX_N_401 128
|
||||
/*! Default window size (k) (9.2.4) */
|
||||
#define V42_DEFAULT_WINDOW_SIZE_K 15
|
||||
/*! Maximum supported window size (k) */
|
||||
#define V42_MAX_WINDOW_SIZE_K 15
|
||||
|
||||
/*! The number of info frames to allocate */
|
||||
#define V42_INFO_FRAMES (V42_MAX_WINDOW_SIZE_K + 1)
|
||||
/*! The number of control frames to allocate */
|
||||
#define V42_CTRL_FRAMES 8
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* V.42 LAP.M parameters */
|
||||
uint8_t v42_tx_window_size_k;
|
||||
uint8_t v42_rx_window_size_k;
|
||||
uint16_t v42_tx_n401;
|
||||
uint16_t v42_rx_n401;
|
||||
|
||||
/* V.42bis compressor parameters */
|
||||
uint8_t comp;
|
||||
int comp_dict_size;
|
||||
int comp_max_string;
|
||||
} v42_config_parameters_t;
|
||||
|
||||
typedef struct frame_s
|
||||
{
|
||||
int len;
|
||||
uint8_t buf[4 + V42_MAX_N_401];
|
||||
} v42_frame_t;
|
||||
|
||||
/*!
|
||||
LAP-M descriptor. This defines the working state for a single instance of LAP-M.
|
||||
*/
|
||||
struct lapm_state_s
|
||||
typedef struct
|
||||
{
|
||||
int handle;
|
||||
get_msg_func_t iframe_get;
|
||||
void *iframe_get_user_data;
|
||||
|
||||
put_msg_func_t iframe_put;
|
||||
void *iframe_put_user_data;
|
||||
|
||||
modem_status_func_t status_handler;
|
||||
void *status_user_data;
|
||||
|
||||
hdlc_rx_state_t hdlc_rx;
|
||||
hdlc_tx_state_t hdlc_tx;
|
||||
|
||||
v42_frame_handler_t iframe_receive;
|
||||
void *iframe_receive_user_data;
|
||||
|
||||
v42_status_func_t status_callback;
|
||||
void *status_callback_user_data;
|
||||
/*! Negotiated values for the window and maximum info sizes */
|
||||
uint8_t tx_window_size_k;
|
||||
uint8_t rx_window_size_k;
|
||||
uint16_t tx_n401;
|
||||
uint16_t rx_n401;
|
||||
|
||||
uint8_t cmd_addr;
|
||||
uint8_t rsp_addr;
|
||||
uint8_t vs;
|
||||
uint8_t va;
|
||||
uint8_t vr;
|
||||
int state;
|
||||
int tx_waiting;
|
||||
int debug;
|
||||
/*! TRUE if originator. FALSE if answerer */
|
||||
int we_are_originator;
|
||||
/*! Remote network type (unknown, answerer. originator) */
|
||||
int peer_is_originator;
|
||||
/*! Next N(S) for transmission */
|
||||
int next_tx_frame;
|
||||
/*! The last of our frames which the peer acknowledged */
|
||||
int last_frame_peer_acknowledged;
|
||||
/*! Next N(R) for reception */
|
||||
int next_expected_frame;
|
||||
/*! The last of the peer's frames which we acknowledged */
|
||||
int last_frame_we_acknowledged;
|
||||
/*! TRUE if we sent an I or S frame with the F-bit set */
|
||||
int solicit_f_bit;
|
||||
/*! Retransmission count */
|
||||
int retransmissions;
|
||||
/*! TRUE if peer is busy */
|
||||
int busy;
|
||||
int configuring;
|
||||
int local_busy;
|
||||
int far_busy;
|
||||
int rejected;
|
||||
int retry_count;
|
||||
|
||||
/*! Acknowledgement timer */
|
||||
int t401_timer;
|
||||
/*! Reply delay timer - optional */
|
||||
int t402_timer;
|
||||
/*! Inactivity timer - optional */
|
||||
int t403_timer;
|
||||
/*! Maximum number of octets in an information field */
|
||||
int n401;
|
||||
/*! Window size */
|
||||
int window_size_k;
|
||||
|
||||
lapm_frame_queue_t *txqueue;
|
||||
lapm_frame_queue_t *tx_next;
|
||||
lapm_frame_queue_t *tx_last;
|
||||
queue_state_t *tx_queue;
|
||||
|
||||
span_sched_state_t sched;
|
||||
/*! \brief Error and flow logging control */
|
||||
logging_state_t logging;
|
||||
};
|
||||
/* The control frame buffer, and its pointers */
|
||||
int ctrl_put;
|
||||
int ctrl_get;
|
||||
v42_frame_t ctrl_buf[V42_CTRL_FRAMES];
|
||||
|
||||
/*!
|
||||
V.42 descriptor. This defines the working state for a single instance of V.42.
|
||||
*/
|
||||
struct v42_state_s
|
||||
/* The info frame buffer, and its pointers */
|
||||
int info_put;
|
||||
int info_get;
|
||||
int info_acked;
|
||||
v42_frame_t info_buf[V42_INFO_FRAMES];
|
||||
|
||||
void (*packer_process)(v42_state_t *m, int bits);
|
||||
} lapm_state_t;
|
||||
|
||||
/*! V.42 support negotiation parameters */
|
||||
typedef struct
|
||||
{
|
||||
/*! TRUE if we are the calling party, otherwise FALSE */
|
||||
int calling_party;
|
||||
/*! TRUE if we should detect whether the far end is V.42 capable. FALSE if we go
|
||||
directly to protocol establishment */
|
||||
int detect;
|
||||
|
||||
/*! Stage in negotiating V.42 support */
|
||||
int rx_negotiation_step;
|
||||
int rxbits;
|
||||
@@ -104,11 +123,30 @@ struct v42_state_s
|
||||
int txbits;
|
||||
int txstream;
|
||||
int txadps;
|
||||
/*! The LAP.M context */
|
||||
} v42_negotiation_t;
|
||||
|
||||
/*!
|
||||
V.42 descriptor. This defines the working state for a single
|
||||
instance of a V.42 error corrector.
|
||||
*/
|
||||
struct v42_state_s
|
||||
{
|
||||
/*! TRUE if we are the calling party, otherwise FALSE. */
|
||||
int calling_party;
|
||||
/*! TRUE if we should detect whether the far end is V.42 capable. FALSE if we go
|
||||
directly to protocol establishment. */
|
||||
int detect;
|
||||
|
||||
/*! The bit rate, used to time events */
|
||||
int tx_bit_rate;
|
||||
|
||||
v42_config_parameters_t config;
|
||||
v42_negotiation_t neg;
|
||||
lapm_state_t lapm;
|
||||
|
||||
/*! V.42 support detection timer */
|
||||
int t400_timer;
|
||||
int bit_timer;
|
||||
void (*bit_timer_func)(v42_state_t *m);
|
||||
|
||||
/*! \brief Error and flow logging control */
|
||||
logging_state_t logging;
|
||||
};
|
||||
|
||||
@@ -28,100 +28,85 @@
|
||||
|
||||
/*!
|
||||
V.42bis dictionary node.
|
||||
Note that 0 is not a valid node to point to (0 is always a control code), so 0 is used
|
||||
as a "no such value" marker in this structure.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/*! \brief The prior code for each defined code. */
|
||||
uint16_t parent_code;
|
||||
/*! \brief The number of leaf nodes this node has */
|
||||
int16_t leaves;
|
||||
/*! \brief This leaf octet for each defined code. */
|
||||
/*! \brief The value of the octet represented by the current dictionary node */
|
||||
uint8_t node_octet;
|
||||
/*! \brief Bit map of the children which exist */
|
||||
uint32_t children[8];
|
||||
/*! \brief The parent of this node */
|
||||
uint16_t parent;
|
||||
/*! \brief The first child of this node */
|
||||
uint16_t child;
|
||||
/*! \brief The next node at the same depth */
|
||||
uint16_t next;
|
||||
} v42bis_dict_node_t;
|
||||
|
||||
/*!
|
||||
V.42bis compression. This defines the working state for a single instance
|
||||
of V.42bis compression.
|
||||
V.42bis compression or decompression. This defines the working state for a single instance
|
||||
of V.42bis compression or decompression.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/*! \brief Compression enabled. */
|
||||
int v42bis_parm_p0;
|
||||
/*! \brief Compression mode. */
|
||||
int compression_mode;
|
||||
/*! \brief Callback function to handle received frames. */
|
||||
v42bis_frame_handler_t handler;
|
||||
/*! \brief An opaque pointer passed in calls to frame_handler. */
|
||||
/*! \brief Callback function to handle output data. */
|
||||
put_msg_func_t handler;
|
||||
/*! \brief An opaque pointer passed in calls to the data handler. */
|
||||
void *user_data;
|
||||
/*! \brief The maximum frame length allowed */
|
||||
int max_len;
|
||||
/*! \brief The maximum amount to be passed to the data handler. */
|
||||
int max_output_len;
|
||||
|
||||
uint32_t string_code;
|
||||
uint32_t latest_code;
|
||||
/*! \brief TRUE if we are in transparent (i.e. uncompressable) mode */
|
||||
int transparent;
|
||||
/*! \brief Next empty dictionary entry */
|
||||
uint16_t v42bis_parm_c1;
|
||||
/*! \brief Current codeword size */
|
||||
uint16_t v42bis_parm_c2;
|
||||
/*! \brief Threshold for codeword size change */
|
||||
uint16_t v42bis_parm_c3;
|
||||
/*! \brief The current update point in the dictionary */
|
||||
uint16_t update_at;
|
||||
/*! \brief The last entry matched in the dictionary */
|
||||
uint16_t last_matched;
|
||||
/*! \brief The last entry added to the dictionary */
|
||||
uint16_t last_added;
|
||||
/*! \brief Total number of codewords in the dictionary */
|
||||
int v42bis_parm_n2;
|
||||
/*! \brief Maximum permitted string length */
|
||||
int v42bis_parm_n7;
|
||||
/*! \brief The dictionary */
|
||||
v42bis_dict_node_t dict[V42BIS_MAX_CODEWORDS];
|
||||
|
||||
/*! \brief The octet string in progress */
|
||||
uint8_t string[V42BIS_MAX_STRING_SIZE];
|
||||
/*! \brief The current length of the octet string in progress */
|
||||
int string_length;
|
||||
uint32_t output_bit_buffer;
|
||||
int output_bit_count;
|
||||
/*! \brief The amount of the octet string in progress which has already
|
||||
been flushed out of the buffer */
|
||||
int flushed_length;
|
||||
|
||||
/*! \brief Compression performance metric */
|
||||
uint16_t compression_performance;
|
||||
|
||||
/*! \brief Outgoing bit buffer (compression), or incoming bit buffer (decompression) */
|
||||
uint32_t bit_buffer;
|
||||
/*! \brief Outgoing bit count (compression), or incoming bit count (decompression) */
|
||||
int bit_count;
|
||||
|
||||
/*! \brief The output composition buffer */
|
||||
uint8_t output_buf[V42BIS_MAX_OUTPUT_LENGTH];
|
||||
/*! \brief The length of the contents of the output composition buffer */
|
||||
int output_octet_count;
|
||||
uint8_t output_buf[1024];
|
||||
v42bis_dict_node_t dict[V42BIS_MAX_CODEWORDS];
|
||||
/*! \brief TRUE if we are in transparent (i.e. uncompressable) mode */
|
||||
int transparent;
|
||||
int change_transparency;
|
||||
/*! \brief IIR filter state, used in assessing compressibility. */
|
||||
int compressibility_filter;
|
||||
int compressibility_persistence;
|
||||
|
||||
/*! \brief Next empty dictionary entry */
|
||||
uint32_t v42bis_parm_c1;
|
||||
/*! \brief Current codeword size */
|
||||
int v42bis_parm_c2;
|
||||
/*! \brief Threshold for codeword size change */
|
||||
uint32_t v42bis_parm_c3;
|
||||
|
||||
/*! \brief Mark that this is the first octet/code to be processed */
|
||||
int first;
|
||||
uint8_t escape_code;
|
||||
} v42bis_compress_state_t;
|
||||
|
||||
/*!
|
||||
V.42bis decompression. This defines the working state for a single instance
|
||||
of V.42bis decompression.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/*! \brief Callback function to handle decompressed data. */
|
||||
v42bis_data_handler_t handler;
|
||||
/*! \brief An opaque pointer passed in calls to data_handler. */
|
||||
void *user_data;
|
||||
/*! \brief The maximum decompressed data block length allowed */
|
||||
int max_len;
|
||||
|
||||
uint32_t old_code;
|
||||
uint32_t last_old_code;
|
||||
uint32_t input_bit_buffer;
|
||||
int input_bit_count;
|
||||
int octet;
|
||||
int last_length;
|
||||
int output_octet_count;
|
||||
uint8_t output_buf[1024];
|
||||
v42bis_dict_node_t dict[V42BIS_MAX_CODEWORDS];
|
||||
/*! \brief TRUE if we are in transparent (i.e. uncompressable) mode */
|
||||
int transparent;
|
||||
|
||||
int last_extra_octet;
|
||||
|
||||
/*! \brief Next empty dictionary entry */
|
||||
uint32_t v42bis_parm_c1;
|
||||
/*! \brief Current codeword size */
|
||||
int v42bis_parm_c2;
|
||||
/*! \brief Threshold for codeword size change */
|
||||
uint32_t v42bis_parm_c3;
|
||||
|
||||
/*! \brief Mark that this is the first octet/code to be processed */
|
||||
int first;
|
||||
/*! \brief The current value of the escape code */
|
||||
uint8_t escape_code;
|
||||
/*! \brief TRUE if we just hit an escape code, and are waiting for the following octet */
|
||||
int escaped;
|
||||
} v42bis_decompress_state_t;
|
||||
} v42bis_comp_state_t;
|
||||
|
||||
/*!
|
||||
V.42bis compression/decompression descriptor. This defines the working state for a
|
||||
@@ -129,20 +114,13 @@ typedef struct
|
||||
*/
|
||||
struct v42bis_state_s
|
||||
{
|
||||
/*! \brief V.42bis data compression directions. */
|
||||
int v42bis_parm_p0;
|
||||
|
||||
/*! \brief Compression state. */
|
||||
v42bis_compress_state_t compress;
|
||||
v42bis_comp_state_t compress;
|
||||
/*! \brief Decompression state. */
|
||||
v42bis_decompress_state_t decompress;
|
||||
|
||||
/*! \brief Maximum codeword size (bits) */
|
||||
int v42bis_parm_n1;
|
||||
/*! \brief Total number of codewords */
|
||||
uint32_t v42bis_parm_n2;
|
||||
/*! \brief Maximum string length */
|
||||
int v42bis_parm_n7;
|
||||
v42bis_comp_state_t decompress;
|
||||
|
||||
/*! \brief Error and flow logging control */
|
||||
logging_state_t logging;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -84,7 +84,7 @@ SPAN_DECLARE(int) silence_gen_generated(silence_gen_state_t *s);
|
||||
\param s The silence generator context.
|
||||
\param handler The callback routine used to report status changes.
|
||||
\param user_data An opaque pointer. */
|
||||
SPAN_DECLARE(void) silence_gen_status_handler(silence_gen_state_t *s, modem_tx_status_func_t handler, void *user_data);
|
||||
SPAN_DECLARE(void) silence_gen_status_handler(silence_gen_state_t *s, modem_status_func_t handler, void *user_data);
|
||||
|
||||
/*! Initialise a timed silence generator context.
|
||||
\brief Initialise a timed silence generator context.
|
||||
|
||||
@@ -261,7 +261,7 @@ enum
|
||||
T30_ERR_RX_GOTDCS, /*! DCS received while waiting for DTC */
|
||||
T30_ERR_RX_INVALCMD, /*! Unexpected command after page received */
|
||||
T30_ERR_RX_NOCARRIER, /*! Carrier lost during fax receive */
|
||||
T30_ERR_RX_NOEOL, /*! Timed out while waiting for EOL (end Of line) */
|
||||
T30_ERR_RX_NOEOL, /*! Timed out while waiting for EOL (end of line) */
|
||||
T30_ERR_RX_NOFAX, /*! Timed out while waiting for first line */
|
||||
T30_ERR_RX_T2EXPDCN, /*! Timer T2 expired while waiting for DCN */
|
||||
T30_ERR_RX_T2EXPD, /*! Timer T2 expired while waiting for phase D */
|
||||
|
||||
@@ -77,6 +77,27 @@ typedef int (span_tx_handler_t)(void *s, int16_t amp[], int max_len);
|
||||
#define TRUE (!FALSE)
|
||||
#endif
|
||||
|
||||
/* Fixed point constant macros */
|
||||
#define FP_Q_9_7(x) ((int16_t) (128.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
|
||||
#define FP_Q_8_8(x) ((int16_t) (256.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
|
||||
#define FP_Q_7_9(x) ((int16_t) (512.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
|
||||
#define FP_Q_6_10(x) ((int16_t) (1024.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
|
||||
#define FP_Q_5_11(x) ((int16_t) (2048.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
|
||||
#define FP_Q_4_12(x) ((int16_t) (4096.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
|
||||
#define FP_Q_3_13(x) ((int16_t) (8192.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
|
||||
#define FP_Q_2_14(x) ((int16_t) (16384.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
|
||||
#define FP_Q_1_15(x) ((int16_t) (32768.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
|
||||
|
||||
#define FP_Q_9_23(x) ((int32_t) (65536.0*128.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
|
||||
#define FP_Q_8_24(x) ((int32_t) (65536.0*256.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
|
||||
#define FP_Q_7_25(x) ((int32_t) (65536.0*512.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
|
||||
#define FP_Q_6_26(x) ((int32_t) (65536.0*1024.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
|
||||
#define FP_Q_5_27(x) ((int32_t) (65536.0*2048.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
|
||||
#define FP_Q_4_28(x) ((int32_t) (65536.0*4096.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
|
||||
#define FP_Q_3_29(x) ((int32_t) (65536.0*8192.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
|
||||
#define FP_Q_2_30(x) ((int32_t) (65536.0*16384.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
|
||||
#define FP_Q_1_31(x) ((int32_t) (65536.0*32768.0*x + ((x >= 0.0) ? 0.5 : -0.5)))
|
||||
|
||||
#if defined(__cplusplus)
|
||||
/* C++ doesn't seem to have sane rounding functions/macros yet */
|
||||
#if !defined(WIN32)
|
||||
|
||||
@@ -267,7 +267,7 @@ SPAN_DECLARE(void) v17_rx_set_put_bit(v17_rx_state_t *s, put_bit_func_t put_bit,
|
||||
\param s The modem context.
|
||||
\param handler The callback routine used to report modem status changes.
|
||||
\param user_data An opaque pointer. */
|
||||
SPAN_DECLARE(void) v17_rx_set_modem_status_handler(v17_rx_state_t *s, modem_rx_status_func_t handler, void *user_data);
|
||||
SPAN_DECLARE(void) v17_rx_set_modem_status_handler(v17_rx_state_t *s, modem_status_func_t handler, void *user_data);
|
||||
|
||||
/*! Process a block of received V.17 modem audio samples.
|
||||
\brief Process a block of received V.17 modem audio samples.
|
||||
|
||||
@@ -146,7 +146,7 @@ SPAN_DECLARE(void) v17_tx_set_get_bit(v17_tx_state_t *s, get_bit_func_t get_bit,
|
||||
\param s The modem context.
|
||||
\param handler The callback routine used to report modem status changes.
|
||||
\param user_data An opaque pointer. */
|
||||
SPAN_DECLARE(void) v17_tx_set_modem_status_handler(v17_tx_state_t *s, modem_tx_status_func_t handler, void *user_data);
|
||||
SPAN_DECLARE(void) v17_tx_set_modem_status_handler(v17_tx_state_t *s, modem_status_func_t handler, void *user_data);
|
||||
|
||||
/*! Generate a block of V.17 modem audio samples.
|
||||
\brief Generate a block of V.17 modem audio samples.
|
||||
|
||||
@@ -213,7 +213,7 @@ SPAN_DECLARE(void) v22bis_set_put_bit(v22bis_state_t *s, put_bit_func_t put_bit,
|
||||
\param s The modem context.
|
||||
\param handler The callback routine used to report modem status changes.
|
||||
\param user_data An opaque pointer. */
|
||||
SPAN_DECLARE(void) v22bis_set_modem_status_handler(v22bis_state_t *s, modem_rx_status_func_t handler, void *user_data);
|
||||
SPAN_DECLARE(void) v22bis_set_modem_status_handler(v22bis_state_t *s, modem_status_func_t handler, void *user_data);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ SPAN_DECLARE(void) v27ter_rx_set_put_bit(v27ter_rx_state_t *s, put_bit_func_t pu
|
||||
\param s The modem context.
|
||||
\param handler The callback routine used to report modem status changes.
|
||||
\param user_data An opaque pointer. */
|
||||
SPAN_DECLARE(void) v27ter_rx_set_modem_status_handler(v27ter_rx_state_t *s, modem_rx_status_func_t handler, void *user_data);
|
||||
SPAN_DECLARE(void) v27ter_rx_set_modem_status_handler(v27ter_rx_state_t *s, modem_status_func_t handler, void *user_data);
|
||||
|
||||
/*! Process a block of received V.27ter modem audio samples.
|
||||
\brief Process a block of received V.27ter modem audio samples.
|
||||
|
||||
@@ -127,7 +127,7 @@ SPAN_DECLARE(void) v27ter_tx_set_get_bit(v27ter_tx_state_t *s, get_bit_func_t ge
|
||||
\param s The modem context.
|
||||
\param handler The callback routine used to report modem status changes.
|
||||
\param user_data An opaque pointer. */
|
||||
SPAN_DECLARE(void) v27ter_tx_set_modem_status_handler(v27ter_tx_state_t *s, modem_tx_status_func_t handler, void *user_data);
|
||||
SPAN_DECLARE(void) v27ter_tx_set_modem_status_handler(v27ter_tx_state_t *s, modem_status_func_t handler, void *user_data);
|
||||
|
||||
/*! Generate a block of V.27ter modem audio samples.
|
||||
\brief Generate a block of V.27ter modem audio samples.
|
||||
|
||||
@@ -178,7 +178,7 @@ SPAN_DECLARE(void) v29_rx_set_put_bit(v29_rx_state_t *s, put_bit_func_t put_bit,
|
||||
\param s The modem context.
|
||||
\param handler The callback routine used to report modem status changes.
|
||||
\param user_data An opaque pointer. */
|
||||
SPAN_DECLARE(void) v29_rx_set_modem_status_handler(v29_rx_state_t *s, modem_rx_status_func_t handler, void *user_data);
|
||||
SPAN_DECLARE(void) v29_rx_set_modem_status_handler(v29_rx_state_t *s, modem_status_func_t handler, void *user_data);
|
||||
|
||||
/*! Process a block of received V.29 modem audio samples.
|
||||
\brief Process a block of received V.29 modem audio samples.
|
||||
|
||||
@@ -158,7 +158,7 @@ SPAN_DECLARE(void) v29_tx_set_get_bit(v29_tx_state_t *s, get_bit_func_t get_bit,
|
||||
\param s The modem context.
|
||||
\param handler The callback routine used to report modem status changes.
|
||||
\param user_data An opaque pointer. */
|
||||
SPAN_DECLARE(void) v29_tx_set_modem_status_handler(v29_tx_state_t *s, modem_tx_status_func_t handler, void *user_data);
|
||||
SPAN_DECLARE(void) v29_tx_set_modem_status_handler(v29_tx_state_t *s, modem_status_func_t handler, void *user_data);
|
||||
|
||||
/*! Generate a block of V.29 modem audio samples.
|
||||
\brief Generate a block of V.29 modem audio samples.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* Written by Steve Underwood <steveu@coppice.org>
|
||||
*
|
||||
* Copyright (C) 2003 Steve Underwood
|
||||
* Copyright (C) 2003, 2011 Steve Underwood
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -36,45 +36,8 @@ far modem supports V.42 is also defined.
|
||||
#if !defined(_SPANDSP_V42_H_)
|
||||
#define _SPANDSP_V42_H_
|
||||
|
||||
enum
|
||||
{
|
||||
LAPM_DETECT = 0,
|
||||
LAPM_ESTABLISH = 1,
|
||||
LAPM_DATA = 2,
|
||||
LAPM_RELEASE = 3,
|
||||
LAPM_SIGNAL = 4,
|
||||
LAPM_SETPARM = 5,
|
||||
LAPM_TEST = 6,
|
||||
LAPM_UNSUPPORTED = 7
|
||||
};
|
||||
|
||||
typedef void (*v42_status_func_t)(void *user_data, int status);
|
||||
typedef void (*v42_frame_handler_t)(void *user_data, const uint8_t *pkt, int len);
|
||||
|
||||
typedef struct lapm_frame_queue_s
|
||||
{
|
||||
struct lapm_frame_queue_s *next;
|
||||
int len;
|
||||
uint8_t frame[];
|
||||
} lapm_frame_queue_t;
|
||||
|
||||
/*!
|
||||
LAP-M descriptor. This defines the working state for a single instance of LAP-M.
|
||||
*/
|
||||
typedef struct lapm_state_s lapm_state_t;
|
||||
|
||||
/*!
|
||||
V.42 descriptor. This defines the working state for a single instance of V.42.
|
||||
*/
|
||||
typedef struct v42_state_s v42_state_t;
|
||||
|
||||
/*! Log the raw HDLC frames */
|
||||
#define LAPM_DEBUG_LAPM_RAW (1 << 0)
|
||||
/*! Log the interpreted frames */
|
||||
#define LAPM_DEBUG_LAPM_DUMP (1 << 1)
|
||||
/*! Log state machine changes */
|
||||
#define LAPM_DEBUG_LAPM_STATE (1 << 2)
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
@@ -82,58 +45,46 @@ extern "C"
|
||||
|
||||
SPAN_DECLARE(const char *) lapm_status_to_str(int status);
|
||||
|
||||
/*! Dump LAP.M frames in a raw and/or decoded forms
|
||||
\param frame The frame itself
|
||||
\param len The length of the frame, in octets
|
||||
\param showraw TRUE if the raw octets should be dumped
|
||||
\param txrx TRUE if tx, FALSE if rx. Used to highlight the packet's direction.
|
||||
*/
|
||||
SPAN_DECLARE(void) lapm_dump(lapm_state_t *s, const uint8_t *frame, int len, int showraw, int txrx);
|
||||
SPAN_DECLARE_NONSTD(void) lapm_receive(void *user_data, const uint8_t *frame, int len, int ok);
|
||||
|
||||
/*! Accept an HDLC packet
|
||||
*/
|
||||
SPAN_DECLARE_NONSTD(void) lapm_receive(void *user_data, const uint8_t *buf, int len, int ok);
|
||||
SPAN_DECLARE(void) v42_start(v42_state_t *s);
|
||||
|
||||
/*! Transmit a LAP.M frame
|
||||
*/
|
||||
SPAN_DECLARE(int) lapm_tx(lapm_state_t *s, const void *buf, int len);
|
||||
SPAN_DECLARE(void) v42_stop(v42_state_t *s);
|
||||
|
||||
/*! Transmit a LAP.M information frame
|
||||
/*! Set the busy status of the local end of a V.42 context.
|
||||
\param s The V.42 context.
|
||||
\param busy The new local end busy status.
|
||||
\return The previous local end busy status.
|
||||
*/
|
||||
SPAN_DECLARE(int) lapm_tx_iframe(lapm_state_t *s, const void *buf, int len, int cr);
|
||||
SPAN_DECLARE(int) v42_set_local_busy_status(v42_state_t *s, int busy);
|
||||
|
||||
/*! Send a break over a LAP.M connection
|
||||
/*! Get the busy status of the far end of a V.42 context.
|
||||
\param s The V.42 context.
|
||||
\return The far end busy status.
|
||||
*/
|
||||
SPAN_DECLARE(int) lapm_break(lapm_state_t *s, int enable);
|
||||
SPAN_DECLARE(int) v42_get_far_busy_status(v42_state_t *s);
|
||||
|
||||
/*! Initiate an orderly release of a LAP.M connection
|
||||
*/
|
||||
SPAN_DECLARE(int) lapm_release(lapm_state_t *s);
|
||||
|
||||
/*! Enable or disable loopback of a LAP.M connection
|
||||
*/
|
||||
SPAN_DECLARE(int) lapm_loopback(lapm_state_t *s, int enable);
|
||||
|
||||
/*! Assign or remove a callback routine used to deal with V.42 status changes.
|
||||
*/
|
||||
SPAN_DECLARE(void) v42_set_status_callback(v42_state_t *s, v42_status_func_t callback, void *user_data);
|
||||
|
||||
/*! Process a newly received bit for a V.42 context.
|
||||
*/
|
||||
SPAN_DECLARE(void) v42_rx_bit(void *user_data, int bit);
|
||||
|
||||
/*! Get the next transmit bit for a V.42 context.
|
||||
*/
|
||||
SPAN_DECLARE(int) v42_tx_bit(void *user_data);
|
||||
|
||||
SPAN_DECLARE(void) v42_set_status_callback(v42_state_t *s, modem_status_func_t callback, void *user_data);
|
||||
|
||||
/*! Initialise a V.42 context.
|
||||
\param s The V.42 context.
|
||||
\param calling_party TRUE if caller mode, else answerer mode.
|
||||
\param frame_handler A callback function to handle received frames of data.
|
||||
\param user_data An opaque pointer passed to the frame handler routine.
|
||||
\param detect TRUE to perform the V.42 detection, else go straight into LAP.M
|
||||
\param iframe_get A callback function to handle received frames of data.
|
||||
\param iframe_put A callback function to get frames of data for transmission.
|
||||
\param user_data An opaque pointer passed to the frame handler routines.
|
||||
\return ???
|
||||
*/
|
||||
SPAN_DECLARE(v42_state_t *) v42_init(v42_state_t *s, int calling_party, int detect, v42_frame_handler_t frame_handler, void *user_data);
|
||||
SPAN_DECLARE(v42_state_t *) v42_init(v42_state_t *s,
|
||||
int calling_party,
|
||||
int detect,
|
||||
get_msg_func_t iframe_get,
|
||||
put_msg_func_t iframe_put,
|
||||
void *user_data);
|
||||
|
||||
/*! Restart a V.42 context.
|
||||
\param s The V.42 context.
|
||||
@@ -143,12 +94,12 @@ SPAN_DECLARE(void) v42_restart(v42_state_t *s);
|
||||
/*! Release a V.42 context.
|
||||
\param s The V.42 context.
|
||||
\return 0 if OK */
|
||||
SPAN_DECLARE(int) v42_release(v42_state_t *s);
|
||||
SPAN_DECLARE(void) v42_release(v42_state_t *s);
|
||||
|
||||
/*! Free a V.42 context.
|
||||
\param s The V.42 context.
|
||||
\return 0 if OK */
|
||||
SPAN_DECLARE(int) v42_free(v42_state_t *s);
|
||||
SPAN_DECLARE(void) v42_free(v42_state_t *s);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* Written by Steve Underwood <steveu@coppice.org>
|
||||
*
|
||||
* Copyright (C) 2005 Steve Underwood
|
||||
* Copyright (C) 2005, 2011 Steve Underwood
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -39,7 +39,7 @@ conjunction with the error correction scheme defined in V.42.
|
||||
#define V42BIS_MIN_DICTIONARY_SIZE 512
|
||||
#define V42BIS_MAX_BITS 12
|
||||
#define V42BIS_MAX_CODEWORDS 4096 /* 2^V42BIS_MAX_BITS */
|
||||
#define V42BIS_TABLE_SIZE 5021 /* This should be a prime >(2^V42BIS_MAX_BITS) */
|
||||
#define V42BIS_MAX_OUTPUT_LENGTH 1024
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -56,9 +56,6 @@ enum
|
||||
V42BIS_COMPRESSION_MODE_NEVER
|
||||
};
|
||||
|
||||
typedef void (*v42bis_frame_handler_t)(void *user_data, const uint8_t *pkt, int len);
|
||||
typedef void (*v42bis_data_handler_t)(void *user_data, const uint8_t *buf, int len);
|
||||
|
||||
/*!
|
||||
V.42bis compression/decompression descriptor. This defines the working state for a
|
||||
single instance of V.42bis compress/decompression.
|
||||
@@ -75,7 +72,7 @@ extern "C"
|
||||
\param buf The data to be compressed.
|
||||
\param len The length of the data buffer.
|
||||
\return 0 */
|
||||
SPAN_DECLARE(int) v42bis_compress(v42bis_state_t *s, const uint8_t *buf, int len);
|
||||
SPAN_DECLARE(int) v42bis_compress(v42bis_state_t *s, const uint8_t buf[], int len);
|
||||
|
||||
/*! Flush out any data remaining in a compression buffer.
|
||||
\param s The V.42bis context.
|
||||
@@ -87,7 +84,7 @@ SPAN_DECLARE(int) v42bis_compress_flush(v42bis_state_t *s);
|
||||
\param buf The data to be decompressed.
|
||||
\param len The length of the data buffer.
|
||||
\return 0 */
|
||||
SPAN_DECLARE(int) v42bis_decompress(v42bis_state_t *s, const uint8_t *buf, int len);
|
||||
SPAN_DECLARE(int) v42bis_decompress(v42bis_state_t *s, const uint8_t buf[], int len);
|
||||
|
||||
/*! Flush out any data remaining in the decompression buffer.
|
||||
\param s The V.42bis context.
|
||||
@@ -107,23 +104,23 @@ SPAN_DECLARE(void) v42bis_compression_control(v42bis_state_t *s, int mode);
|
||||
\param negotiated_p0 The negotiated P0 parameter, from the V.42bis spec.
|
||||
\param negotiated_p1 The negotiated P1 parameter, from the V.42bis spec.
|
||||
\param negotiated_p2 The negotiated P2 parameter, from the V.42bis spec.
|
||||
\param frame_handler Frame callback handler.
|
||||
\param frame_user_data An opaque pointer passed to the frame callback handler.
|
||||
\param max_frame_len The maximum length that should be passed to the frame handler.
|
||||
\param data_handler data callback handler.
|
||||
\param data_user_data An opaque pointer passed to the data callback handler.
|
||||
\param max_data_len The maximum length that should be passed to the data handler.
|
||||
\param encode_handler Encode callback handler.
|
||||
\param encode_user_data An opaque pointer passed to the encode callback handler.
|
||||
\param max_encode_len The maximum length that should be passed to the encode handler.
|
||||
\param decode_handler Decode callback handler.
|
||||
\param decode_user_data An opaque pointer passed to the decode callback handler.
|
||||
\param max_decode_len The maximum length that should be passed to the decode handler.
|
||||
\return The V.42bis context. */
|
||||
SPAN_DECLARE(v42bis_state_t *) v42bis_init(v42bis_state_t *s,
|
||||
int negotiated_p0,
|
||||
int negotiated_p1,
|
||||
int negotiated_p2,
|
||||
v42bis_frame_handler_t frame_handler,
|
||||
void *frame_user_data,
|
||||
int max_frame_len,
|
||||
v42bis_data_handler_t data_handler,
|
||||
void *data_user_data,
|
||||
int max_data_len);
|
||||
put_msg_func_t encode_handler,
|
||||
void *encode_user_data,
|
||||
int max_encode_len,
|
||||
put_msg_func_t decode_handler,
|
||||
void *decode_user_data,
|
||||
int max_decode_len);
|
||||
|
||||
/*! Release a V.42bis context.
|
||||
\param s The V.42bis context.
|
||||
|
||||
@@ -114,11 +114,11 @@ static const int year_lengths[2] =
|
||||
|
||||
static int increment_overflow(int *number, int delta)
|
||||
{
|
||||
int number0;
|
||||
int last_number;
|
||||
|
||||
number0 = *number;
|
||||
last_number = *number;
|
||||
*number += delta;
|
||||
return (*number < number0) != (delta < 0);
|
||||
return (*number < last_number) != (delta < 0);
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
@@ -164,6 +164,10 @@ static struct tm *time_sub(const time_t * const timep, const long int offset, co
|
||||
int y;
|
||||
int hit;
|
||||
int i;
|
||||
int newy;
|
||||
time_t tdelta;
|
||||
int idelta;
|
||||
int leapdays;
|
||||
|
||||
corr = 0;
|
||||
hit = 0;
|
||||
@@ -198,11 +202,6 @@ static struct tm *time_sub(const time_t * const timep, const long int offset, co
|
||||
rem = *timep - tdays*SECS_PER_DAY;
|
||||
while (tdays < 0 || tdays >= year_lengths[isleap(y)])
|
||||
{
|
||||
int newy;
|
||||
time_t tdelta;
|
||||
int idelta;
|
||||
int leapdays;
|
||||
|
||||
tdelta = tdays / DAYS_PER_LEAP_YEAR;
|
||||
idelta = tdelta;
|
||||
if (tdelta - idelta >= 1 || idelta - tdelta >= 1)
|
||||
|
||||
@@ -1248,7 +1248,7 @@ SPAN_DECLARE(void) v17_rx_set_put_bit(v17_rx_state_t *s, put_bit_func_t put_bit,
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
SPAN_DECLARE(void) v17_rx_set_modem_status_handler(v17_rx_state_t *s, modem_tx_status_func_t handler, void *user_data)
|
||||
SPAN_DECLARE(void) v17_rx_set_modem_status_handler(v17_rx_state_t *s, modem_status_func_t handler, void *user_data)
|
||||
{
|
||||
s->status_handler = handler;
|
||||
s->status_user_data = user_data;
|
||||
|
||||
@@ -364,7 +364,7 @@ SPAN_DECLARE(void) v17_tx_set_get_bit(v17_tx_state_t *s, get_bit_func_t get_bit,
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
SPAN_DECLARE(void) v17_tx_set_modem_status_handler(v17_tx_state_t *s, modem_tx_status_func_t handler, void *user_data)
|
||||
SPAN_DECLARE(void) v17_tx_set_modem_status_handler(v17_tx_state_t *s, modem_status_func_t handler, void *user_data)
|
||||
{
|
||||
s->status_handler = handler;
|
||||
s->status_user_data = user_data;
|
||||
|
||||
@@ -552,7 +552,7 @@ SPAN_DECLARE(void) v22bis_set_put_bit(v22bis_state_t *s, put_bit_func_t put_bit,
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
SPAN_DECLARE(void) v22bis_set_modem_status_handler(v22bis_state_t *s, modem_tx_status_func_t handler, void *user_data)
|
||||
SPAN_DECLARE(void) v22bis_set_modem_status_handler(v22bis_state_t *s, modem_status_func_t handler, void *user_data)
|
||||
{
|
||||
s->status_handler = handler;
|
||||
s->status_user_data = user_data;
|
||||
|
||||
@@ -1019,7 +1019,7 @@ SPAN_DECLARE(void) v27ter_rx_set_put_bit(v27ter_rx_state_t *s, put_bit_func_t pu
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
SPAN_DECLARE(void) v27ter_rx_set_modem_status_handler(v27ter_rx_state_t *s, modem_tx_status_func_t handler, void *user_data)
|
||||
SPAN_DECLARE(void) v27ter_rx_set_modem_status_handler(v27ter_rx_state_t *s, modem_status_func_t handler, void *user_data)
|
||||
{
|
||||
s->status_handler = handler;
|
||||
s->status_user_data = user_data;
|
||||
|
||||
@@ -374,7 +374,7 @@ SPAN_DECLARE(void) v27ter_tx_set_get_bit(v27ter_tx_state_t *s, get_bit_func_t ge
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
SPAN_DECLARE(void) v27ter_tx_set_modem_status_handler(v27ter_tx_state_t *s, modem_tx_status_func_t handler, void *user_data)
|
||||
SPAN_DECLARE(void) v27ter_tx_set_modem_status_handler(v27ter_tx_state_t *s, modem_status_func_t handler, void *user_data)
|
||||
{
|
||||
s->status_handler = handler;
|
||||
s->status_user_data = user_data;
|
||||
|
||||
@@ -1052,7 +1052,7 @@ SPAN_DECLARE(void) v29_rx_set_put_bit(v29_rx_state_t *s, put_bit_func_t put_bit,
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
SPAN_DECLARE(void) v29_rx_set_modem_status_handler(v29_rx_state_t *s, modem_tx_status_func_t handler, void *user_data)
|
||||
SPAN_DECLARE(void) v29_rx_set_modem_status_handler(v29_rx_state_t *s, modem_status_func_t handler, void *user_data)
|
||||
{
|
||||
s->status_handler = handler;
|
||||
s->status_user_data = user_data;
|
||||
|
||||
@@ -316,7 +316,7 @@ SPAN_DECLARE(void) v29_tx_set_get_bit(v29_tx_state_t *s, get_bit_func_t get_bit,
|
||||
}
|
||||
/*- End of function --------------------------------------------------------*/
|
||||
|
||||
SPAN_DECLARE(void) v29_tx_set_modem_status_handler(v29_tx_state_t *s, modem_tx_status_func_t handler, void *user_data)
|
||||
SPAN_DECLARE(void) v29_tx_set_modem_status_handler(v29_tx_state_t *s, modem_status_func_t handler, void *user_data)
|
||||
{
|
||||
s->status_handler = handler;
|
||||
s->status_user_data = user_data;
|
||||
|
||||
+1209
-1071
File diff suppressed because it is too large.
Load diff
+558
-516
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user