2000 bit/s mode seems to be transmitting OK
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 7 Mar 2013 07:23:02 +0000 (07:23 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 7 Mar 2013 07:23:02 +0000 (07:23 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1196 01035d8c-6547-0410-b346-abe4f91aad63

fdmdv2/src/Makefile.linux
fdmdv2/src/fdmdv2_main.cpp
fdmdv2/src/fdmdv2_main.h

index 57bf9930b298ec587bc183bda29e096cb52a3718..ffe5efa825b4d0b850e9242a1a53bd683f4c25ff 100644 (file)
@@ -65,9 +65,10 @@ dlg_audiooptions.o \
 dlg_comports.o \
 dlg_filter.o \
 varicode.o \
-sox_biquad.o
+sox_biquad.o \
+codec2-dev/src/golay23.c
 
-HDRS = ../version.h dlg_about.h dlg_audiooptions.h dlg_comports.h dlg_filter.h fdmdv2_main.h fdmdv2_defines.h fdmdv2_plot.h fdmdv2_plot_scalar.h fdmdv2_plot_waterfall_linux.h fdmdv2_plot_scatter.h fdmdv2_plot_spectrum.h fdmdv2_pa_wrapper.h topFrame.h varicode.h
+HDRS = ../version.h dlg_about.h dlg_audiooptions.h dlg_comports.h dlg_filter.h fdmdv2_main.h fdmdv2_defines.h fdmdv2_plot.h fdmdv2_plot_scalar.h fdmdv2_plot_waterfall_linux.h fdmdv2_plot_scatter.h fdmdv2_plot_spectrum.h fdmdv2_pa_wrapper.h topFrame.h varicode.h codec2-dev/src/golay23.h
 
 all: $(WXWIDGETS)/.built $(PORTAUDIO)/.built $(CODEC2)/.built $(SOX)/.built $(CTB)/.built freedv
 
index cba30486d0a5b83578995f69742a90d22c708501..b4aff0e950c55658ccf4c7e10934dc105e6c674c 100644 (file)
@@ -58,7 +58,7 @@ struct FIFO         *g_rxDataOutFifo;
 
 // tx/rx processing states
 int                 g_nRxIn = FDMDV_NOM_SAMPLES_PER_FRAME;
-int                 g_CodecBits[MAX_BITS_PER_CODEC_FRAME];
+int                 g_CodecBits[2*MAX_BITS_PER_FDMDV_FRAME];
 int                 g_State;
 paCallBackData     *g_rxUserdata;
 
@@ -407,7 +407,7 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent)
     varicode_decode_init(&g_varicode_dec_states);
 
     sox_biquad_start();
-
+    golay23_init();
 }
 
 //-------------------------------------------------------------------------
@@ -2467,7 +2467,47 @@ void per_frame_rx_processing(
                     // second half of frame of codec bits
                     memcpy(&codec_bits[bits_per_fdmdv_frame], rx_bits, bits_per_fdmdv_frame *sizeof(int));
 
-                    // extract data bit
+                    // FEC Decoding  --------------------------------------------------------------
+
+                    if (g_mode == MODE_2000) {
+                        /* decode first codeword */
+
+                        recd_codeword = 0;
+                        for(i=0; i<12; i++) {
+                            recd_codeword <<= 1;
+                            recd_codeword |= unpacked_input_bits[i];
+                        }
+                        for(i=bits_per_output_frame; i<bits_per_output_frame+11; i++) {
+                            recd_codeword <<= 1;
+                            recd_codeword |= unpacked_input_bits[i];
+                        }
+                        codeword1 = golay23_decode(recd_codeword);
+                        //fprintf(stderr, "received codeword1: 0x%x  decoded codeword1: 0x%x\n", recd_codeword, codeword1);
+
+                        for(i=0; i<12; i++) {
+                            unpacked_output_bits[i] = codeword1 >> (22-i);
+                        }
+
+                        /* decode second codeword */
+
+                        recd_codeword = 0;
+                        for(i=12; i<24; i++) {
+                            recd_codeword <<= 1;
+                            recd_codeword |= unpacked_input_bits[i];
+                        }
+                        for(i=bits_per_output_frame+11; i<bits_per_output_frame+11+11; i++) {
+                            recd_codeword <<= 1;
+                            recd_codeword |= unpacked_input_bits[i];
+                        }
+                        codeword2 = golay23_decode(recd_codeword);
+                        //fprintf(stderr, "received codeword2: 0x%x  decoded codeword2: 0x%x\n", recd_codeword, codeword2);
+
+                        for(i=0; i<12; i++) {
+                            unpacked_output_bits[12+i] = codeword2 >> (22-i);
+                        }
+                   }
+
+                   // extract data bit ------------------------------------------------------------
 
                     data_flag_index = codec2_get_spare_bit_index(c2);
                     printf("data_flag_index: %d\n", data_flag_index);
@@ -2525,11 +2565,11 @@ void per_frame_tx_processing(
                                         )
 {
     unsigned char  packed_bits[MAX_BYTES_PER_CODEC_FRAME];
-    int            bits[MAX_BITS_PER_CODEC_FRAME];
+    int            bits[2*MAX_BITS_PER_FDMDV_FRAME];
     COMP           tx_fdm[2*FDMDV_NOM_SAMPLES_PER_FRAME];
     COMP           tx_fdm_offset[2*FDMDV_NOM_SAMPLES_PER_FRAME];
     int            sync_bit;
-    int            i, bit, byte, data_flag_index;
+    int            i, j, bit, byte, data_flag_index;
     short          abit;
     int            bits_per_fdmdv_frame, bits_per_codec_frame, bytes_per_codec_frame;
 
@@ -2556,8 +2596,10 @@ void per_frame_tx_processing(
     }
     assert(byte == bytes_per_codec_frame);
 
-    // voice/data flag is a spare bit in 1400 bit/s frame that
-    // codec defines.  Use this 1 bit/frame to send call sign data
+    /* add data bit  ----------------------------------*/
+
+    // spare bit in 1400 bit/s frame that codec defines.  Use this 1
+    // bit/frame to send call sign data
 
     data_flag_index = codec2_get_spare_bit_index(c2);
     assert(data_flag_index != -1); // not supported for all rates
@@ -2567,6 +2609,50 @@ void per_frame_tx_processing(
     else
         bits[data_flag_index] = 0;
 
+    /* add FEC  ---------------------------------------*/
+
+    if (g_mode == MODE_2000) {
+        int data, codeword1, codeword2;
+
+        /* Protect first 24 bits with (23,12) Golay Code.  The first
+           24 bits are the most sensitive, as they contain the
+           pitch/energy VQ and voicing bits. This uses 56 + 11 + 11 =
+           78 bits, so we have two spare in 80 bit frame sent to
+           modem. */
+
+        /* first codeword */
+
+        data = 0;
+        for(i=0; i<12; i++) {
+            data <<= 1;
+            data |= bits[i];
+        }
+        codeword1 = golay23_encode(data);
+        //fprintf(stderr, "data1: 0x%x codeword1: 0x%x\n", data, codeword1);
+
+        /* second codeword */
+
+        data = 0;
+        for(i=12; i<24; i++) {
+            data <<= 1;
+            data |= bits[i];
+        }
+        codeword2 = golay23_encode(data);
+        //fprintf(stderr, "data: 0x%x codeword2: 0x%x\n", data, codeword2);
+
+        /* now pack output frame with parity bits at end to make them
+           as far apart as possible from the data the protect.  Parity
+           bits are LSB of the Golay codeword */
+
+        for(i=bits_per_codec_frame,j=0; i<bits_per_codec_frame+11; i++,j++) {
+            bits[i] = (codeword1 >> (10-j)) & 0x1;
+        }
+        for(j=0; i<bits_per_codec_frame+11+11; i++,j++) {
+            bits[i] = (codeword2 >> (10-j)) & 0x1;
+        }
+        assert(i <= 2*bits_per_fdmdv_frame);
+    }
+
     /* modulate even and odd frames */
 
     fdmdv_mod(g_pFDMDV, tx_fdm, bits, &sync_bit);
index 5635c00a4ff9a9a89fc01fbedbc4003e24aee486..696151897f91fd69425d1fcc49dd974ea148d07a 100644 (file)
@@ -54,6 +54,7 @@
 #include "codec2.h"
 #include "codec2_fdmdv.h"
 #include "codec2_fifo.h"
+#include "golay23.h"
 
 #include "ctb-0.16/ctb.h"
 #include "ctb-0.16/portscan.h"