freedv API and test programs modified for 700B, works OK
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 10 Aug 2015 10:25:33 +0000 (10:25 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 10 Aug 2015 10:25:33 +0000 (10:25 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2268 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/freedv_api.c
codec2-dev/src/freedv_api.h
codec2-dev/src/freedv_rx.c
codec2-dev/src/freedv_tx.c

index b6bc2d289ff6455d3bdb364c40ba44a0fadcb1e2..0605860461ced1ebb2775ed72074a097e313edaf 100644 (file)
@@ -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; k<nspare; k++) {
                 if (f->nvaricode_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; j<COHPSK_BITS_PER_FRAME; j+=bits_per_codec_frame) {
                 
-                    /* extract txt msg data bits */
+                    /* extract txt msg data bit(s) */
                 
-                    for(k=0; k<2; k++)  {
+                    if (f->mode == FREEDV_MODE_700)
+                        nspare = 2;
+                    else
+                        nspare = 1;
+
+                    for(k=0; k<nspare; k++)  {
                         abit[0] = rx_bits[data_flag_index+j+k] < 0.0;
                     
                         n_ascii = varicode_decode(&f->varicode_dec_states, &ascii_out, abit, 1, 1);
index a6684f131a9178a3892236fc42c6192e074c0ed5..7f1825c073c74526351b1ef4f5b8fc809f3728f0 100644 (file)
@@ -39,6 +39,7 @@
 
 #define FREEDV_MODE_1600        0
 #define FREEDV_MODE_700         1
+#define FREEDV_MODE_700B        2
 
 struct freedv;
 
index 28a920ee37a2111b594250b6580173c03c2322ea..bcf3f981eb1c5852bd146ff81aa247a58152350b 100644 (file)
@@ -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;
index a327922989f197f9f92afca63c5cd4cd46d9a0f1..ee3f07f5c6f9e06c2e5f8da9df8cfc4356654b06 100644 (file)
@@ -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;