From: drowe67 Date: Mon, 10 Aug 2015 10:25:33 +0000 (+0000) Subject: freedv API and test programs modified for 700B, works OK X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=a3361b48e0d3f2c3528c4c61b56bd0048b0dfa81;p=freetel-svn-tracking.git freedv API and test programs modified for 700B, works OK git-svn-id: https://svn.code.sf.net/p/freetel/code@2268 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/src/freedv_api.c b/codec2-dev/src/freedv_api.c index b6bc2d28..06058604 100644 --- a/codec2-dev/src/freedv_api.c +++ b/codec2-dev/src/freedv_api.c @@ -6,12 +6,7 @@ Library of API functions that implement FreeDV "modes", useful for embedding FreeDV in other programs. - - TODO: - [X] speex tx/rx works - [X] txt messages - [X] optional test tx framemode - + \*---------------------------------------------------------------------------*/ /* @@ -73,7 +68,7 @@ struct freedv *freedv_open(int mode) { struct freedv *f; int Nc, codec2_mode, nbit, nbyte; - if ((mode != FREEDV_MODE_1600) && (mode != FREEDV_MODE_700)) + if ((mode != FREEDV_MODE_1600) && (mode != FREEDV_MODE_700) && (mode != FREEDV_MODE_700B)) return NULL; f = (struct freedv*)malloc(sizeof(struct freedv)); @@ -112,10 +107,13 @@ struct freedv *freedv_open(int mode) { f->sz_error_pattern = fdmdv_error_pattern_size(f->fdmdv); } - if (mode == FREEDV_MODE_700) { + if ((mode == FREEDV_MODE_700) || (mode == FREEDV_MODE_700B)) { f->snr_squelch_thresh = 0.0; f->squelch_en = 0; - codec2_mode = CODEC2_MODE_700; + if (mode == FREEDV_MODE_700) + codec2_mode = CODEC2_MODE_700; + else + codec2_mode = CODEC2_MODE_700B; f->cohpsk = cohpsk_create(); f->nin = COHPSK_NOM_SAMPLES_PER_FRAME; f->n_nom_modem_samples = COHPSK_NOM_SAMPLES_PER_FRAME; @@ -138,7 +136,7 @@ struct freedv *freedv_open(int mode) { return NULL; if (mode == FREEDV_MODE_1600) f->n_speech_samples = codec2_samples_per_frame(f->codec2); - if (mode == FREEDV_MODE_700) + if ((mode == FREEDV_MODE_700) || (mode == FREEDV_MODE_700B)) f->n_speech_samples = 2*codec2_samples_per_frame(f->codec2); f->prev_rx_bits = (float*)malloc(sizeof(float)*2*codec2_bits_per_frame(f->codec2)); if (f->prev_rx_bits == NULL) @@ -149,7 +147,7 @@ struct freedv *freedv_open(int mode) { f->packed_codec_bits = (unsigned char*)malloc(nbyte*sizeof(char)); if (mode == FREEDV_MODE_1600) f->codec_bits = (int*)malloc(nbit*sizeof(int)); - if (mode == FREEDV_MODE_700) + if ((mode == FREEDV_MODE_700) || (mode == FREEDV_MODE_700B)) f->codec_bits = (int*)malloc(COHPSK_BITS_PER_FRAME*sizeof(int)); if ((f->packed_codec_bits == NULL) || (f->codec_bits == NULL)) @@ -241,10 +239,10 @@ void freedv_comptx(struct freedv *f, COMP mod_out[], short speech_in[]) { assert(f != NULL); int bit, byte, i, j, k; int bits_per_codec_frame, bits_per_modem_frame; - int data, codeword1, data_flag_index; + int data, codeword1, data_flag_index, nspare; COMP tx_fdm[f->n_nom_modem_samples]; - assert((f->mode == FREEDV_MODE_1600) || (f->mode == FREEDV_MODE_700)); + assert((f->mode == FREEDV_MODE_1600) || (f->mode == FREEDV_MODE_700) || (f->mode == FREEDV_MODE_700B)); if (f->mode == FREEDV_MODE_1600) { bits_per_codec_frame = codec2_bits_per_frame(f->codec2); @@ -337,7 +335,7 @@ void freedv_comptx(struct freedv *f, COMP mod_out[], short speech_in[]) { } - if (f->mode == FREEDV_MODE_700) { + if ((f->mode == FREEDV_MODE_700) || (f->mode == FREEDV_MODE_700B)) { bits_per_codec_frame = codec2_bits_per_frame(f->codec2); bits_per_modem_frame = COHPSK_BITS_PER_FRAME; @@ -357,12 +355,17 @@ void freedv_comptx(struct freedv *f, COMP mod_out[], short speech_in[]) { } } - // spare bits in frame that codec defines. Use these 2 + // spare bits in frame that codec defines. Use these spare // bits/frame to send txt messages + if (f->mode == FREEDV_MODE_700) + nspare = 2; + else + nspare = 1; // Just one spare bit for FREEDV_MODE_700B + data_flag_index = codec2_get_spare_bit_index(f->codec2); - for(k=0; k<2; k++) { + for(k=0; knvaricode_bits) { f->codec_bits[j+data_flag_index+k] = f->tx_varicode_bits[f->varicode_bit_index++]; //fprintf(stderr, "%d %d\n", j+data_flag_index+k, f->codec_bits[j+data_flag_index+k]); @@ -480,7 +483,7 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) { assert(f != NULL); int bits_per_codec_frame, bytes_per_codec_frame, bits_per_fdmdv_frame; int i, j, bit, byte, nin_prev, nout, k; - int recd_codeword, codeword1, data_flag_index, n_ascii; + int recd_codeword, codeword1, data_flag_index, n_ascii, nspare; short abit[1]; char ascii_out; int reliable_sync_bit; @@ -650,7 +653,7 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) { } - if (f->mode == FREEDV_MODE_700) { + if ((f->mode == FREEDV_MODE_700) || (f->mode == FREEDV_MODE_700B)) { float rx_bits[COHPSK_BITS_PER_FRAME]; int sync; @@ -677,9 +680,14 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) { for (j=0; jmode == FREEDV_MODE_700) + nspare = 2; + else + nspare = 1; + + for(k=0; kvaricode_dec_states, &ascii_out, abit, 1, 1); diff --git a/codec2-dev/src/freedv_api.h b/codec2-dev/src/freedv_api.h index a6684f13..7f1825c0 100644 --- a/codec2-dev/src/freedv_api.h +++ b/codec2-dev/src/freedv_api.h @@ -39,6 +39,7 @@ #define FREEDV_MODE_1600 0 #define FREEDV_MODE_700 1 +#define FREEDV_MODE_700B 2 struct freedv; diff --git a/codec2-dev/src/freedv_rx.c b/codec2-dev/src/freedv_rx.c index 28a920ee..bcf3f981 100644 --- a/codec2-dev/src/freedv_rx.c +++ b/codec2-dev/src/freedv_rx.c @@ -48,7 +48,7 @@ struct my_callback_state { void my_put_next_rx_char(void *callback_state, char c) { struct my_callback_state* pstate = (struct my_callback_state*)callback_state; if (pstate->ftxt != NULL) { - fprintf(pstate->ftxt, "%c", c); + fprintf(pstate->ftxt, "%c\n", c); } } @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) { int n_max_modem_samples; if (argc < 4) { - printf("usage: %s 1600|700 InputModemSpeechFile OutputSpeechRawFile [--test_frames]\n", argv[0]); + printf("usage: %s 1600|700|700B InputModemSpeechFile OutputSpeechRawFile [--test_frames]\n", argv[0]); printf("e.g %s 1600 hts1a_fdmdv.raw hts1a_out.raw txtLogFile\n", argv[0]); exit(1); } @@ -78,6 +78,8 @@ int main(int argc, char *argv[]) { mode = FREEDV_MODE_1600; if (!strcmp(argv[1],"700")) mode = FREEDV_MODE_700; + if (!strcmp(argv[1],"700B")) + mode = FREEDV_MODE_700B; assert(mode != -1); if (strcmp(argv[2], "-") == 0) fin = stdin; diff --git a/codec2-dev/src/freedv_tx.c b/codec2-dev/src/freedv_tx.c index a3279229..ee3f07f5 100644 --- a/codec2-dev/src/freedv_tx.c +++ b/codec2-dev/src/freedv_tx.c @@ -60,7 +60,7 @@ int main(int argc, char *argv[]) { int n_nom_modem_samples; if (argc < 4) { - printf("usage: %s 1600|700 InputRawSpeechFile OutputModemRawFile [--testframes]\n", argv[0]); + printf("usage: %s 1600|700|700B InputRawSpeechFile OutputModemRawFile [--testframes]\n", argv[0]); printf("e.g %s 1600 hts1a.raw hts1a_fdmdv.raw\n", argv[0]); exit(1); } @@ -70,6 +70,8 @@ int main(int argc, char *argv[]) { mode = FREEDV_MODE_1600; if (!strcmp(argv[1],"700")) mode = FREEDV_MODE_700; + if (!strcmp(argv[1],"700B")) + mode = FREEDV_MODE_700B; assert(mode != -1); if (strcmp(argv[2], "-") == 0) fin = stdin;