From 418f54b9495f925e296f6fed75081b71ca1fc0a3 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Thu, 7 Mar 2013 07:23:02 +0000 Subject: [PATCH] 2000 bit/s mode seems to be transmitting OK git-svn-id: https://svn.code.sf.net/p/freetel/code@1196 01035d8c-6547-0410-b346-abe4f91aad63 --- fdmdv2/src/Makefile.linux | 5 +- fdmdv2/src/fdmdv2_main.cpp | 100 ++++++++++++++++++++++++++++++++++--- fdmdv2/src/fdmdv2_main.h | 1 + 3 files changed, 97 insertions(+), 9 deletions(-) diff --git a/fdmdv2/src/Makefile.linux b/fdmdv2/src/Makefile.linux index 57bf9930..ffe5efa8 100644 --- a/fdmdv2/src/Makefile.linux +++ b/fdmdv2/src/Makefile.linux @@ -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 diff --git a/fdmdv2/src/fdmdv2_main.cpp b/fdmdv2/src/fdmdv2_main.cpp index cba30486..b4aff0e9 100644 --- a/fdmdv2/src/fdmdv2_main.cpp +++ b/fdmdv2/src/fdmdv2_main.cpp @@ -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> (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> (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> (10-j)) & 0x1; + } + for(j=0; i> (10-j)) & 0x1; + } + assert(i <= 2*bits_per_fdmdv_frame); + } + /* modulate even and odd frames */ fdmdv_mod(g_pFDMDV, tx_fdm, bits, &sync_bit); diff --git a/fdmdv2/src/fdmdv2_main.h b/fdmdv2/src/fdmdv2_main.h index 5635c00a..69615189 100644 --- a/fdmdv2/src/fdmdv2_main.h +++ b/fdmdv2/src/fdmdv2_main.h @@ -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" -- 2.25.1