tweaked test frames support
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 19 Jun 2015 02:23:31 +0000 (02:23 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 19 Jun 2015 02:23:31 +0000 (02:23 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2208 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/CMakeLists.txt
codec2-dev/src/freedv_api.c
codec2-dev/unittest/tcohpsk.c
codec2-dev/unittest/test_cohpsk_ch.c

index f74643f278faaa539dc14934f94dbb6d1ff1b73a..2745e11659eeee42c90b189fc6e877ddd4c1dc6f 100644 (file)
@@ -53,7 +53,7 @@ endif()
 
 # Set default C++ flags.
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O2")
 
 # -fPIC is implied on MinGW...
 if(NOT WIN32)
index 04726d873db4b3ddb9d492958f0398ab51d3c2be..9b8701627e0e6f9852f47ad0e809a9e904622e5e 100644 (file)
@@ -502,6 +502,7 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) {
                     }
                     codeword1 = golay23_decode(recd_codeword);
                     f->total_bit_errors += golay23_count_errors(recd_codeword, codeword1);
+                    f->total_bits       += 23;
 
                     //codeword1 = recd_codeword;
                     //fprintf(stderr, "received codeword1: 0x%x  decoded codeword1: 0x%x\n", recd_codeword, codeword1);
@@ -549,7 +550,7 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) {
                 else {
                     int   test_frame_sync, bit_errors, ntest_bits, k;
                     short error_pattern[fdmdv_error_pattern_size(f->fdmdv)];
-
+                    
                     for(k=0; k<2; k++) {
                         /* test frames, so lets sync up to the test frames and count any errors */
                         fdmdv_put_test_bits(f->fdmdv, &test_frame_sync, error_pattern, &bit_errors, &ntest_bits, &f->rx_bits[k*bits_per_fdmdv_frame]);
@@ -655,11 +656,15 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) {
                     f->total_bit_errors += bit_errors;
                     f->total_bits       += COHPSK_BITS_PER_FRAME;
                 }
+
+                for(i=0; i<f->n_speech_samples; i++)
+                    speech_out[i] = 0; 
+                nout = f->n_speech_samples;  
             }
             
         }
 
-        if ((sync == 0) || f->test_frames) {
+        if (sync == 0) {
             float t,a,b,s;
             int   t1,t2;
 
index 83dbc93ba510156e2bcb4f0c8501db74aef95308..6459946ed519dc464f0c24ff6c763343063ee58e 100644 (file)
@@ -39,7 +39,6 @@
 #include "codec2_cohpsk.h"
 #include "cohpsk_defs.h"
 #include "cohpsk_internal.h"
-#include "test_bits_coh.h"
 #include "octave.h"
 #include "comp_prim.h"
 #include "noise_samples.h"
@@ -82,7 +81,6 @@ int main(int argc, char *argv[])
                                           
     FILE          *fout;
     int            f, r, c, log_r, log_data_r, noise_r, ff_log_r, i;
-    int           *ptest_bits_coh, *ptest_bits_coh_end;
     double         foff;
     COMP           foff_rect, phase_ch;
 
@@ -124,10 +122,6 @@ int main(int argc, char *argv[])
     /* init stuff */
 
     log_r = log_data_r = noise_r = log_bits = ff_log_r = f_est_samples = 0;
-    ptest_bits_coh = (int*)test_bits_coh;
-    ptest_bits_coh_end = (int*)test_bits_coh + sizeof(test_bits_coh)/sizeof(int);
-    memcpy(tx_bits, test_bits_coh, sizeof(int)*COHPSK_BITS_PER_FRAME);
-
     phase_ch.real = 1.0; phase_ch.imag = 0.0; 
     foff = FOFF;
      
@@ -147,12 +141,7 @@ int main(int argc, char *argv[])
                                  Mod
        \*---------------------------------------------------------*/
 
-        memcpy(tx_bits, ptest_bits_coh, sizeof(int)*COHPSK_BITS_PER_FRAME);
-        ptest_bits_coh += COHPSK_BITS_PER_FRAME;
-        if (ptest_bits_coh >= ptest_bits_coh_end) {
-            ptest_bits_coh = (int*)test_bits_coh;
-        }
-
+        cohpsk_get_test_bits(coh, tx_bits);
        bits_to_qpsk_symbols(tx_symb, (int*)tx_bits, COHPSK_BITS_PER_FRAME);
 
         for(r=0; r<NSYMROWPILOT; r++) {
index 08e0939854e694bed48f895b0d2193fe2cb4ea97..6ce2da6f476732ee6d614753728e445d2d37991e 100644 (file)
@@ -33,7 +33,6 @@
 #include <math.h>
 
 #include "codec2_cohpsk.h"
-#include "test_bits_coh.h"
 #include "octave.h"
 #include "comp_prim.h"
 #include "noise_samples.h"
@@ -68,18 +67,16 @@ int main(int argc, char *argv[])
     COMP           tx_fdm[COHPSK_NOM_SAMPLES_PER_FRAME];
     COMP           ch_fdm[COHPSK_NOM_SAMPLES_PER_FRAME];
     COMP           ch_buf[CH_BUF_SZ];
-    int            rx_bits[COHPSK_BITS_PER_FRAME];
     float          rx_bits_sd[COHPSK_BITS_PER_FRAME];
     float         *rx_amp_log;
     float         *rx_phi_log;
     COMP          *rx_symb_log;
                                             
     int            f, r, i;
-    int           *ptest_bits_coh, *ptest_bits_coh_end, *ptest_bits_coh_rx;
     COMP           phase_ch;
     int            noise_r, noise_end;
-    int            errors;
-    int            state, next_state, nerrors, nbits, reliable_sync_bit;
+    int            bit_errors;
+    int            state, nerrors, nbits, reliable_sync_bit;
     float          EsNo, variance;
     COMP           scaled_noise;
     float          EsNodB, foff_hz;
@@ -89,12 +86,9 @@ int main(int argc, char *argv[])
     FILE          *ffading, *fout;
     int            ch_buf_n;
     float          tx_pwr, rx_pwr, noise_pwr;
-    int            error_positions_hist[COHPSK_BITS_PER_FRAME];
+    short          error_pattern[COHPSK_BITS_PER_FRAME];
     int            log_data_r, c, j, tmp;
-
-    for(i=0; i<COHPSK_BITS_PER_FRAME; i++)
-        error_positions_hist[i] = 0;
-
+             
     EsNodB = ES_NO_DB;
     foff_hz =  FOFF_HZ;
     fading_en = 0;
@@ -122,9 +116,6 @@ int main(int argc, char *argv[])
     rx_symb_log = (COMP *)malloc(sizeof(COMP)*frames*NSYMROW*COHPSK_NC*ND);
     assert(rx_symb_log != NULL);
 
-    ptest_bits_coh = ptest_bits_coh_rx = (int*)test_bits_coh;
-    ptest_bits_coh_end = (int*)test_bits_coh + sizeof(test_bits_coh)/sizeof(int);
-    
     phase_ch.real = 1.0; phase_ch.imag = 0.0; 
     noise_r = 0; 
     noise_end = sizeof(noise)/sizeof(COMP);
@@ -173,13 +164,7 @@ int main(int argc, char *argv[])
                                  Mod
        \*---------------------------------------------------------*/
 
-        memcpy(tx_bits, ptest_bits_coh, sizeof(int)*COHPSK_BITS_PER_FRAME);
-        ptest_bits_coh += COHPSK_BITS_PER_FRAME;
-        if (ptest_bits_coh >= ptest_bits_coh_end) {
-            ptest_bits_coh = (int*)test_bits_coh;
-            //fprintf(stderr, "  [%d] tx test bits wrap\n", f);            
-        }
-
+        cohpsk_get_test_bits(coh, tx_bits);
        cohpsk_mod(coh, tx_fdm, tx_bits);
         cohpsk_clip(tx_fdm);
         
@@ -251,9 +236,7 @@ int main(int argc, char *argv[])
         coh->frame = f;
         tmp = nin_frame;
        cohpsk_demod(coh, rx_bits_sd, &reliable_sync_bit, ch_buf, &tmp);
-        for(i=0; i<COHPSK_BITS_PER_FRAME; i++)
-            rx_bits[i] = rx_bits_sd[i] > 0.0;
-        
+
         ch_buf_n -= nin_frame;
         //printf("nin_frame: %d tmp: %d ch_buf_n: %d\n", nin_frame, tmp, ch_buf_n);
         assert(ch_buf_n >= 0);
@@ -261,40 +244,11 @@ int main(int argc, char *argv[])
             memcpy(ch_buf, &ch_buf[nin_frame], sizeof(COMP)*ch_buf_n);
         nin_frame = tmp;
 
-        //fprintf(stderr, "  [%d] nin_frame: %d\n", f, nin_frame);            
-        errors = 0;
-        for(i=0; i<COHPSK_BITS_PER_FRAME; i++) {
-            errors += (rx_bits[i] & 0x1) ^ ptest_bits_coh_rx[i];
-            if (state == 1) {
-                if ((rx_bits[i] & 0x1) ^ ptest_bits_coh_rx[i])
-                    error_positions_hist[i]++;
-            }
-        }
-        
-        /* state logic to sync up to test data */
-
-        next_state = state;
-        
-        if (state == 0) {
-            if (reliable_sync_bit && (errors < 4)) {
-                next_state = 1;
-                ptest_bits_coh_rx += COHPSK_BITS_PER_FRAME;
-                nerrors = errors;
-                nbits = COHPSK_BITS_PER_FRAME;
-                //fprintf(stderr, "  [%d] test data sync nerrors: %d\n", f, nerrors);            
-            }
-        }
-
-        if (state == 1) {
-            nerrors += errors;
-            nbits   += COHPSK_BITS_PER_FRAME;
-            //fprintf(stderr, "  [%d] test data sync errors: %d\n", f, errors);            
-            ptest_bits_coh_rx += COHPSK_BITS_PER_FRAME;
-            if (ptest_bits_coh_rx >= ptest_bits_coh_end) {
-                ptest_bits_coh_rx = (int*)test_bits_coh;
-                //fprintf(stderr, "  [%d] rx test bits wrap\n", f);                         
-            }
+        cohpsk_put_test_bits(coh, &state, error_pattern, &bit_errors, rx_bits_sd);
+        nerrors += bit_errors;
+        nbits   += COHPSK_BITS_PER_FRAME;
 
+        if (state) {
             for(r=0; r<NSYMROW; r++, log_data_r++) {
                 for(c=0; c<COHPSK_NC*ND; c++) {
                     rx_amp_log[log_data_r*COHPSK_NC*ND+c] = coh->amp_[r][c]; 
@@ -304,7 +258,6 @@ int main(int argc, char *argv[])
             }
         }
         
-        state = next_state;
     }
             
     printf("%4.3f %d %d\n", (float)nerrors/nbits, nbits, nerrors);
@@ -319,9 +272,6 @@ int main(int argc, char *argv[])
     }
     cohpsk_destroy(coh);
         
-    //for(i=0; i<COHPSK_BITS_PER_FRAME; i++)
-    //        printf("%d %d\n", i, error_positions_hist[i]);
-
     fout = fopen("test_cohpsk_ch_out.txt","wt");
     octave_save_complex(fout, "ch_symb_log_c", (COMP*)coh->ch_symb_log, coh->ch_symb_log_r, COHPSK_NC*ND, COHPSK_NC*ND);  
     octave_save_float(fout, "rx_amp_log_c", (float*)rx_amp_log, log_data_r, COHPSK_NC*ND, COHPSK_NC*ND);