From b16b26d32627b18c714e4c6b27a80a14b7863dca Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sun, 21 Apr 2024 14:47:06 +0200 Subject: [PATCH] Add parameter to DTMF decode to change frequency margin There is no user for this yet. --- src/jolly/dsp.c | 2 +- src/libdtmf/dtmf_decode.c | 6 +++--- src/libdtmf/dtmf_decode.h | 6 ++++-- src/test/test_dtmf.c | 3 ++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/jolly/dsp.c b/src/jolly/dsp.c index 82d8012..baa3862 100644 --- a/src/jolly/dsp.c +++ b/src/jolly/dsp.c @@ -90,7 +90,7 @@ int dsp_init_sender(jolly_t *jolly, int nbfm, double squelch_db, int repeater) /* init dtmf audio processing. * each frequency may be +6 dB deviation, which means a total deviation of +12 dB is allowed for detection. * also we allow a minimum of -30 dB for each tone. */ - rc = dtmf_decode_init(&jolly->dtmf, jolly, jolly_receive_dtmf, 8000, db2level(6.0), db2level(-30.0)); + rc = dtmf_decode_init(&jolly->dtmf, jolly, jolly_receive_dtmf, 8000, db2level(6.0), db2level(-30.0), DTMF_FREQ_MARGIN_PERCENT_DEFAULT); if (rc < 0) { LOGP(DDSP, LOGL_ERROR, "Failed to init DTMF decoder!\n"); goto error; diff --git a/src/libdtmf/dtmf_decode.c b/src/libdtmf/dtmf_decode.c index b1c30aa..97aec6a 100644 --- a/src/libdtmf/dtmf_decode.c +++ b/src/libdtmf/dtmf_decode.c @@ -41,7 +41,7 @@ static const char dtmf_digit[] = " 123A456B789C*0#D"; -int dtmf_decode_init(dtmf_dec_t *dtmf, void *priv, void (*recv_digit)(void *priv, char digit, dtmf_meas_t *meas), int samplerate, double max_amplitude, double min_amplitude) +int dtmf_decode_init(dtmf_dec_t *dtmf, void *priv, void (*recv_digit)(void *priv, char digit, dtmf_meas_t *meas), int samplerate, double max_amplitude, double min_amplitude, double freq_margin) { int rc; @@ -49,7 +49,7 @@ int dtmf_decode_init(dtmf_dec_t *dtmf, void *priv, void (*recv_digit)(void *priv dtmf->priv = priv; dtmf->recv_digit = recv_digit; dtmf->samplerate = samplerate; - dtmf->freq_margin = 1.03; /* 1.8 .. 3.5 % */ + dtmf->freq_margin = freq_margin; dtmf->max_amplitude = max_amplitude; dtmf->min_amplitude = min_amplitude; dtmf->forward_twist = db2level(4.0); @@ -118,7 +118,7 @@ void dtmf_decode(dtmf_dec_t *dtmf, sample_t *samples, int length) int amplitude_ok, twist_ok; int i; - margin = dtmf->freq_margin; + margin = dtmf->freq_margin / 100.0 + 1.0; min_amplitude = dtmf->min_amplitude; max_amplitude = dtmf->max_amplitude; forward_twist = dtmf->forward_twist; diff --git a/src/libdtmf/dtmf_decode.h b/src/libdtmf/dtmf_decode.h index 9c162fe..ea2ff8e 100644 --- a/src/libdtmf/dtmf_decode.h +++ b/src/libdtmf/dtmf_decode.h @@ -1,6 +1,8 @@ #include "../libfm/fm.h" -typedef struct ftmf_meas { +#define DTMF_FREQ_MARGIN_PERCENT_DEFAULT 3 /* 1.8 .. 3.5 % */ + +typedef struct dtmf_meas { double frequency_low; double frequency_high; double amplitude_low; @@ -28,7 +30,7 @@ typedef struct dtmf_dec { dtmf_meas_t meas; /* measurements */ } dtmf_dec_t; -int dtmf_decode_init(dtmf_dec_t *dtmf, void *priv, void (*recv_digit)(void *priv, char digit, dtmf_meas_t *meas), int samplerate, double max_amplitude, double min_amplitude); +int dtmf_decode_init(dtmf_dec_t *dtmf, void *priv, void (*recv_digit)(void *priv, char digit, dtmf_meas_t *meas), int samplerate, double max_amplitude, double min_amplitude, double freq_margin); void dtmf_decode_exit(dtmf_dec_t *dtmf); void dtmf_decode_reset(dtmf_dec_t *dtmf); void dtmf_decode(dtmf_dec_t *dtmf, sample_t *samples, int length); diff --git a/src/test/test_dtmf.c b/src/test/test_dtmf.c index 5b92634..e35ec8e 100644 --- a/src/test/test_dtmf.c +++ b/src/test/test_dtmf.c @@ -65,7 +65,8 @@ int main(void) fm_init(0); - dtmf_decode_init(&dtmf_dec, NULL, recv_digit, SAMPLERATE, db2level(0), db2level(-30.0)); + /* decoder uses a strict frequency offset of 0.1 percent. */ + dtmf_decode_init(&dtmf_dec, NULL, recv_digit, SAMPLERATE, db2level(0), db2level(-30.0), 0.1); for (f = 0; f < 8; f++) { printf("Testing filter with frequency %.0f Hz:\n", test_frequency[f]);