insert_errors_SOURCES = insert_errors.c
insert_errors_LDFLAGS = $(LIBS)
-fec_enc_SOURCES = fec_enc.c
+fec_enc_SOURCES = fec_enc.c golay23.c
fec_enc_LDADD = $(lib_LTLIBRARIES)
fec_enc_LDFLAGS = $(LIBS)
-fec_dec_SOURCES = fec_dec.c
+fec_dec_SOURCES = fec_dec.c golay23.c
fec_dec_LDADD = $(lib_LTLIBRARIES)
fec_dec_LDFLAGS = $(LIBS)
fdmdv.$(OBJEXT) kiss_fft.$(OBJEXT)
fdmdv_put_test_bits_OBJECTS = $(am_fdmdv_put_test_bits_OBJECTS)
fdmdv_put_test_bits_LDADD = $(LDADD)
-am_fec_dec_OBJECTS = fec_dec.$(OBJEXT)
+am_fec_dec_OBJECTS = fec_dec.$(OBJEXT) golay23.$(OBJEXT)
fec_dec_OBJECTS = $(am_fec_dec_OBJECTS)
fec_dec_DEPENDENCIES = $(am__DEPENDENCIES_1)
-am_fec_enc_OBJECTS = fec_enc.$(OBJEXT)
+am_fec_enc_OBJECTS = fec_enc.$(OBJEXT) golay23.$(OBJEXT)
fec_enc_OBJECTS = $(am_fec_enc_OBJECTS)
fec_enc_DEPENDENCIES = $(am__DEPENDENCIES_1)
generate_codebook_SOURCES = generate_codebook.c
fdmdv_interleave_LDFLAGS = $(LIBS)
insert_errors_SOURCES = insert_errors.c
insert_errors_LDFLAGS = $(LIBS)
-fec_enc_SOURCES = fec_enc.c
+fec_enc_SOURCES = fec_enc.c golay23.c
fec_enc_LDADD = $(lib_LTLIBRARIES)
fec_enc_LDFLAGS = $(LIBS)
-fec_dec_SOURCES = fec_dec.c
+fec_dec_SOURCES = fec_dec.c golay23.c
fec_dec_LDADD = $(lib_LTLIBRARIES)
fec_dec_LDFLAGS = $(LIBS)
all: all-am
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fec_enc.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generate_codebook.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/genlspdtcb.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/golay23.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/insert_errors.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/kiss_fft.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-codebook.Plo@am__quote@
#include "codec2.h"
#include "codec2_fdmdv.h"
+#include "golay23.h"
#include <assert.h>
#include <stdio.h>
int *unpacked_output_bits;
int mode, Nc, bit, byte;
int i;
+ int recd_codeword, codeword1, codeword2;
if (argc < 3) {
printf("%s InputFromModemWithFECFile OutputToCodec2File\n", argv[0]);
unpacked_output_bits = (int*)malloc(bits_per_output_frame*sizeof(int));
assert(unpacked_output_bits != NULL);
- fprintf(stderr, "input bits: %d input_bytes: %d output_bits: %d output_bytes: %d\n",
- bits_per_input_frame, bytes_per_input_frame, bits_per_output_frame, bytes_per_output_frame);
+ // fprintf(stderr, "input bits: %d input_bytes: %d output_bits: %d output_bytes: %d\n",
+ // bits_per_input_frame, bytes_per_input_frame, bits_per_output_frame, bytes_per_output_frame);
/* main loop */
+ golay23_init();
+
while(fread(packed_input_bits, sizeof(char), bytes_per_input_frame, fin) == (size_t)bytes_per_input_frame) {
/* unpack bits, MSB first */
}
assert(byte == bytes_per_input_frame);
- for(i=0; i<bits_per_output_frame; i++)
+ #ifdef TEST
+ /* Some test bit errors (not comprehesnive) */
+ unpacked_input_bits[0] = (unpacked_input_bits[0] ^ 1) & 0x1;
+ unpacked_input_bits[23] = (unpacked_input_bits[23] ^ 1) & 0x1;
+ #endif
+
+ /* 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);
+ }
+
+ /* unprotected bits */
+
+ for(i=24; i<bits_per_output_frame; i++)
unpacked_output_bits[i] = unpacked_input_bits[i];
/* pack bits, MSB first */
#include "codec2.h"
#include "codec2_fdmdv.h"
+#include "golay23.h"
#include <assert.h>
#include <stdio.h>
unsigned char *packed_output_bits;
int *unpacked_output_bits;
int mode, Nc, bit, byte;
- int i;
+ int i,j;
+ int data, codeword1, codeword2;
if (argc < 3) {
printf("%s InputFromCodecFile OutputToModemWithFECFile\n", argv[0]);
unpacked_output_bits = (int*)malloc(bits_per_output_frame*sizeof(int));
assert(unpacked_output_bits != NULL);
- fprintf(stderr, "input bits: %d input_bytes: %d output_bits: %d output_bytes: %d\n",
- bits_per_input_frame, bytes_per_input_frame, bits_per_output_frame, bytes_per_output_frame);
+ //fprintf(stderr, "input bits: %d input_bytes: %d output_bits: %d output_bytes: %d\n",
+ // bits_per_input_frame, bytes_per_input_frame, bits_per_output_frame, bytes_per_output_frame);
/* main loop */
+ golay23_init();
+
while(fread(packed_input_bits, sizeof(char), bytes_per_input_frame, fin) == (size_t)bytes_per_input_frame) {
/* unpack bits, MSB first */
}
assert(byte == bytes_per_input_frame);
+ /* add FEC ----------------------------------*/
+
+ /* 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 |= unpacked_input_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 |= unpacked_input_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=0; i<bits_per_input_frame; i++)
unpacked_output_bits[i] = unpacked_input_bits[i];
- for(i=bits_per_input_frame; i<bits_per_output_frame; i++)
- unpacked_output_bits[i] = 1;
+ for(j=0; i<bits_per_input_frame+11; i++,j++) {
+ unpacked_output_bits[i] = (codeword1 >> (10-j)) & 0x1;
+ }
+ for(j=0; i<bits_per_input_frame+11+11; i++,j++) {
+ unpacked_output_bits[i] = (codeword2 >> (10-j)) & 0x1;
+ }
/* pack bits, MSB first */
* a[] = auxiliary array to generate correctable error patterns
*/
+static int inited = 0;
+
static int encoding_table[4096], decoding_table[2048];
static int position[23] = { 0x00000001, 0x00000002, 0x00000004, 0x00000008,
0x00000010, 0x00000020, 0x00000040, 0x00000080,
decoding_table[get_syndrome(temp)] = temp;
}
+ inited = 1;
}
/*---------------------------------------------------------------------------*\
\*---------------------------------------------------------------------------*/
int golay23_encode(int data) {
+ assert(inited);
+
//printf("data: 0x%x\n", data);
assert(data <= 0xfff);
return encoding_table[data];
\*---------------------------------------------------------------------------*/
int golay23_decode(int received_codeword) {
+ assert(inited);
+
return received_codeword ^= decoding_table[get_syndrome(received_codeword)];
}