From 009d07f4baae7698aaa8d8a079117fbfac504375 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Thu, 11 Jun 2015 02:34:32 +0000 Subject: [PATCH] tweaks to API for freedv integration, not tested yet git-svn-id: https://svn.code.sf.net/p/freetel/code@2180 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/src/freedv_api.c | 81 ++++++++++++++++++++++++++++++++----- codec2-dev/src/freedv_api.h | 12 +++++- codec2-dev/src/varicode.c | 7 ++++ codec2-dev/src/varicode.h | 1 + 4 files changed, 89 insertions(+), 12 deletions(-) diff --git a/codec2-dev/src/freedv_api.c b/codec2-dev/src/freedv_api.c index 921d2f0d..1a21fb83 100644 --- a/codec2-dev/src/freedv_api.c +++ b/codec2-dev/src/freedv_api.c @@ -288,8 +288,8 @@ int freedv_nin(struct freedv *f) { int freedv_rx(struct freedv *f, short speech_out[], short demod_in[]) { -float rxdata[FDMDV_MAX_SAMPLES_PER_FRAME]; -int i; + float rxdata[FDMDV_MAX_SAMPLES_PER_FRAME]; + int i; for(i=0; inin; i++) rxdata[i] = (float)demod_in[i]/FDMDV_SCALE; @@ -299,10 +299,23 @@ int i; } -// float version +// float input samples version int freedv_floatrx(struct freedv *f, short speech_out[], float demod_in[]) { - COMP rx_fdm[FDMDV_MAX_SAMPLES_PER_FRAME]; + COMP rx_fdm[FDMDV_MAX_SAMPLES_PER_FRAME]; + int i; + + for(i=0; inin; i++) { + rx_fdm[i].real = demod_in[i]; + rx_fdm[i].imag = 0; + } + + return freedv_comprx(f, speech_out, rx_fdm); +} + +// complex input samples version + +int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) { int bits_per_codec_frame, bytes_per_codec_frame, bits_per_fdmdv_frame; int reliable_sync_bit, i, j, bit, byte, nin_prev, nout; int recd_codeword, codeword1, data_flag_index, n_ascii; @@ -313,13 +326,8 @@ int freedv_floatrx(struct freedv *f, short speech_out[], float demod_in[]) { bytes_per_codec_frame = (bits_per_codec_frame + 7) / 8; bits_per_fdmdv_frame = fdmdv_bits_per_frame(f->fdmdv); - for(i=0; inin; i++) { - rx_fdm[i].real = demod_in[i]; - rx_fdm[i].imag = 0; - } - nin_prev = f->nin; - fdmdv_demod(f->fdmdv, f->fdmdv_bits, &reliable_sync_bit, rx_fdm, &f->nin); + fdmdv_demod(f->fdmdv, f->fdmdv_bits, &reliable_sync_bit, demod_in, &f->nin); fdmdv_get_demod_stats(f->fdmdv, &f->fdmdv_stats); if (f->fdmdv_stats.sync) { @@ -405,10 +413,61 @@ int freedv_floatrx(struct freedv *f, short speech_out[], float demod_in[]) { /* if not in sync pass through analog samples */ /* this lets us "hear" whats going on, e.g. during tuning */ for(i=0; i. */ +#ifdef __cplusplus + extern "C" { +#endif + #ifndef __FREEDV__ #define FREEDV_MODE_1600 0 +#define FREEDV_MODE_700 1 #define FREEDV_NSAMPLES 320 #include "varicode.h" @@ -39,7 +44,7 @@ struct freedv { int mode; - void *codec2; + struct CODEC2 *codec2; struct FDMDV *fdmdv; struct FDMDV_STATS fdmdv_stats; @@ -75,5 +80,10 @@ void freedv_tx(struct freedv *f, short mod_out[], short speech_in[]); int freedv_nin(struct freedv *f); int freedv_rx(struct freedv *f, short speech_out[], short demod_in[]); int freedv_floatrx(struct freedv *f, short speech_out[], float demod_in[]); +int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]); + +#endif +#ifdef __cplusplus +} #endif diff --git a/codec2-dev/src/varicode.c b/codec2-dev/src/varicode.c index 26de09a6..21f7cce1 100644 --- a/codec2-dev/src/varicode.c +++ b/codec2-dev/src/varicode.c @@ -168,6 +168,13 @@ void varicode_decode_init(struct VARICODE_DEC *dec_states, int code_num) } +void varicode_set_code_num(struct VARICODE_DEC *dec_states, int code_num) +{ + assert((code_num == 1) || (code_num == 2)); + dec_states->code_num = code_num; +} + + /* Code 1 decode function, accepts one bit at a time */ static int decode_one_bit(struct VARICODE_DEC *s, char *single_ascii, short varicode_in, int long_code) diff --git a/codec2-dev/src/varicode.h b/codec2-dev/src/varicode.h index 4834a95c..625d1e7e 100644 --- a/codec2-dev/src/varicode.h +++ b/codec2-dev/src/varicode.h @@ -43,6 +43,7 @@ struct VARICODE_DEC { int varicode_encode(short varicode_out[], char ascii_in[], int max_out, int n_in, int code_num); void varicode_decode_init(struct VARICODE_DEC *dec_states, int code_num); int varicode_decode(struct VARICODE_DEC *dec_states, char ascii_out[], short varicode_in[], int max_out, int n_in); +void varicode_set_code_num(struct VARICODE_DEC *dec_states, int code_num); #ifdef __cplusplus } -- 2.25.1