From f5267863086c1ed020b0e7c35b1e79c9bf9f2d04 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Wed, 24 Jun 2015 03:21:56 +0000 Subject: [PATCH] sorted out squelch, now moved to the freedv api git-svn-id: https://svn.code.sf.net/p/freetel/code@2214 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/src/cohpsk.c | 2 +- codec2-dev/src/freedv_api.c | 15 +++++++++++---- codec2-dev/src/freedv_api.h | 2 +- codec2-dev/src/freedv_rx.c | 5 +++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/codec2-dev/src/cohpsk.c b/codec2-dev/src/cohpsk.c index 293af6a9..69755127 100644 --- a/codec2-dev/src/cohpsk.c +++ b/codec2-dev/src/cohpsk.c @@ -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; cmode = 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; in_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; in_speech_samples; i++) + speech_out[i] = 0; + } speech_out += codec2_samples_per_frame(f->codec2); } nout = f->n_speech_samples; diff --git a/codec2-dev/src/freedv_api.h b/codec2-dev/src/freedv_api.h index d4aa1875..c8c3b819 100644 --- a/codec2-dev/src/freedv_api.h +++ b/codec2-dev/src/freedv_api.h @@ -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; diff --git a/codec2-dev/src/freedv_rx.c b/codec2-dev/src/freedv_rx.c index 3aac5caf..d9496696 100644 --- a/codec2-dev/src/freedv_rx.c +++ b/codec2-dev/src/freedv_rx.c @@ -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); -- 2.25.1