sorted out squelch, now moved to the freedv api
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 24 Jun 2015 03:21:56 +0000 (03:21 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 24 Jun 2015 03:21:56 +0000 (03:21 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2214 01035d8c-6547-0410-b346-abe4f91aad63

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

index 293af6a988cdcf3f0c44ff431e65546ec665fff0..69755127fd4f6bdb37f7b6db2edfbe37d80a1178 100644 (file)
@@ -1126,7 +1126,7 @@ void cohpsk_get_demod_stats(struct COHPSK *coh, struct MODEM_STATS *stats)
     stats->rx_timing = coh->rx_timing;
     stats->clock_offset = 0.0; /* TODO - implement clock offset estimation */
 
-    assert(stats->nr <= MODEM_STATS_NR_MAX);
+    assert(NSYMROW <= MODEM_STATS_NR_MAX);
     stats->nr = NSYMROW;
     for(c=0; c<COHPSK_NC*ND; c++) {
         for (r=0; r<NSYMROW; r++) {
index 9c90b53eacb815c72ed09e8fb70596e75fbaf04b..cf919c0c9a6580b42be1bade58517912ac60e1aa 100644 (file)
@@ -72,7 +72,8 @@ struct freedv *freedv_open(int mode) {
     
     f->mode = mode;
     f->test_frames = 0;
-    
+    f->snr_squelch_thresh = 2.0;
+   
     if (mode == FREEDV_MODE_1600) {
         Nc = 16;
         f->tx_sync_bit = 0;
@@ -80,7 +81,6 @@ struct freedv *freedv_open(int mode) {
         f->fdmdv = fdmdv_create(Nc);
         if (f->fdmdv == NULL)
             return NULL;
-        f->snr_thresh = 2.0;
         golay23_init();
         f->nin = FDMDV_NOM_SAMPLES_PER_FRAME;
         f->n_nom_modem_samples = 2*FDMDV_NOM_SAMPLES_PER_FRAME;
@@ -469,6 +469,7 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) {
 
     bits_per_codec_frame  = codec2_bits_per_frame(f->codec2);
     bytes_per_codec_frame = (bits_per_codec_frame + 7) / 8;
+    nout = f->n_speech_samples;
 
     if (f->mode == FREEDV_MODE_1600) {
         int reliable_sync_bit;
@@ -581,7 +582,7 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) {
 
                 /* squelch if beneath SNR threshold or test frames enabled */
 
-                if ((f->stats.snr_est < f->snr_thresh) || f->test_frames) {
+                if ((f->stats.snr_est < f->snr_squelch_thresh) || f->test_frames) {
                     for(i=0; i<f->n_speech_samples; i++)
                         speech_out[i] = 0;
                 }
@@ -608,7 +609,8 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) {
         nin_prev = f->nin;
        cohpsk_demod(f->cohpsk, rx_bits, &sync, demod_in, &f->nin);
         f->sync = sync;
-        f->snr_est = 2.0;
+        cohpsk_get_demod_stats(f->cohpsk, &f->stats);
+        f->snr_est = f->stats.snr_est;
 
        if (sync) {
 
@@ -642,6 +644,11 @@ int freedv_comprx(struct freedv *f, short speech_out[], COMP demod_in[]) {
                     }
 
                     codec2_decode(f->codec2, speech_out, f->packed_codec_bits);
+
+                    if (f->stats.snr_est < f->snr_squelch_thresh) {
+                        for(i=0; i<f->n_speech_samples; i++)
+                            speech_out[i] = 0; 
+                    }
                     speech_out += codec2_samples_per_frame(f->codec2);
                 }
                 nout = f->n_speech_samples;
index d4aa18755c810c12c4c1b2ef22fc327fc4eb0f9a..c8c3b819f3e1bb5e9ca2aa0e98203696ea9a57a6 100644 (file)
@@ -74,7 +74,7 @@ struct freedv {
 
     int                  sync;
     float                snr_est;
-    float                snr_thresh;
+    float                snr_squelch_thresh;
     int                  nin;
 
     struct VARICODE_DEC  varicode_dec_states;
index 3aac5caf9892ac36962e050cfc2fbbd275ae1cc5..d949669666405b1c628ff099c1fbcc46c1d4d237 100644 (file)
@@ -101,7 +101,7 @@ int main(int argc, char *argv[]) {
     freedv->callback_state = (void*)&my_cb_state;
     freedv->freedv_put_next_rx_char = &my_put_next_rx_char;
 
-    freedv->snr_thresh = -100.0;
+    freedv->snr_squelch_thresh = -100.0;
 
     /* Note we need to work out how many samples demod needs on each
        call (nin).  This is used to adjust for differences in the tx and rx
@@ -111,7 +111,8 @@ int main(int argc, char *argv[]) {
     nin = freedv_nin(freedv);
     while(fread(demod_in, sizeof(short), nin, fin) == nin) {
         frame++;
-        cohpsk_set_frame(freedv->cohpsk, frame);
+        if (mode == FREEDV_MODE_700)
+            cohpsk_set_frame(freedv->cohpsk, frame);
 
         nout = freedv_rx(freedv, speech_out, demod_in);
         nin = freedv_nin(freedv);