From f72c53757d4ce30c37ecefda825f21f42c60b05e Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sun, 29 Jan 2017 07:27:08 +0100 Subject: [PATCH] B-Netz, NMT: Improved check for minimum required sample rate --- src/bnetz/dsp.c | 8 ++++++-- src/nmt/dsp.c | 10 +++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/bnetz/dsp.c b/src/bnetz/dsp.c index 70b4649..3d1e127 100644 --- a/src/bnetz/dsp.c +++ b/src/bnetz/dsp.c @@ -83,8 +83,12 @@ int dsp_init_sender(bnetz_t *bnetz) sample_t *spl; int i; - if ((bnetz->sender.samplerate % 1000)) { - PDEBUG(DDSP, DEBUG_ERROR, "Samples rate must be a multiple of 1000 bits per second.\n"); + if ((bnetz->sender.samplerate % (int)(1.0 / (double)BIT_DURATION))) { + PDEBUG(DDSP, DEBUG_ERROR, "Samples rate must be a multiple of %d bits per second.\n", (int)(1.0 / (double)BIT_DURATION)); + return -EINVAL; + } + if ((bnetz->sender.samplerate % (int)(1.0 / (double)FILTER_STEP))) { + PDEBUG(DDSP, DEBUG_ERROR, "Samples rate must be a multiple of %d bits per second.\n", (int)(1.0 / (double)FILTER_STEP)); return -EINVAL; } diff --git a/src/nmt/dsp.c b/src/nmt/dsp.c index 3d7dd52..65dc8ae 100644 --- a/src/nmt/dsp.c +++ b/src/nmt/dsp.c @@ -120,8 +120,8 @@ int dsp_init_sender(nmt_t *nmt) /* attack (3ms) and recovery time (13.5ms) according to NMT specs */ init_compandor(&nmt->cstate, 8000, 3.0, 13.5, COMPANDOR_0DB); - /* this should not happen. it is implied by previous check */ - if (nmt->supervisory && nmt->sender.samplerate < 12000) { + /* a symbol rate of 1200 Hz, times check interval of FILTER_STEPS */ + if (nmt->sender.samplerate < (double)BIT_RATE / (double)FILTER_STEPS) { PDEBUG(DDSP, DEBUG_ERROR, "Sample rate must be at least 12000 Hz to process FSK+supervisory signal.\n"); return -EINVAL; } @@ -313,7 +313,7 @@ static inline void fsk_decode_step(nmt_t *nmt, int pos) spl = nmt->fsk_filter_spl; /* count time in bits */ - nmt->rx_bits_count += 0.1; + nmt->rx_bits_count += FILTER_STEPS; level = audio_level(spl, max); /* limit level to prevent division by zero */ @@ -462,8 +462,8 @@ void sender_receive(sender_t *sender, sample_t *samples, int length) } /* if 1/10th of a bit duration is reached, decode buffer */ step += bps; - if (step >= 0.1) { - step -= 0.1; + if (step >= FILTER_STEPS) { + step -= FILTER_STEPS; fsk_decode_step(nmt, pos); } }