DTMF: Now allows to give duration and pause for digit

Also the dtmf encoder will return less samples, if the digit(+pause)
ends, so that the caller call set the next digit to play seamlessly.

A reset function allows to clear the decoder states, to prevent glitches
when re-attaching to an interrupted stream.
This commit is contained in:
Andreas Eversberg
2022-09-29 20:02:50 +02:00
parent a756ba8fd9
commit b60c844b4f
9 changed files with 74 additions and 44 deletions

View File

@@ -356,16 +356,20 @@ void sender_receive(sender_t *sender, sample_t *samples, int length, double __at
if ((nmt->dsp_mode == DSP_MODE_AUDIO || nmt->dsp_mode == DSP_MODE_DTMF)
&& nmt->trans && nmt->trans->callref) {
int count;
int len, count;
count = samplerate_downsample(&nmt->sender.srstate, samples, length);
len = samplerate_downsample(&nmt->sender.srstate, samples, length);
if (nmt->compandor)
expand_audio(&nmt->cstate, samples, count);
if (nmt->dsp_mode == DSP_MODE_DTMF)
dtmf_encode(&nmt->dtmf, samples, count);
expand_audio(&nmt->cstate, samples, len);
if (nmt->dsp_mode == DSP_MODE_DTMF) {
/* encode and fill with silence after finish */
count = dtmf_encode(&nmt->dtmf, samples, len);
if (count < len)
memset(samples + count, 0, sizeof(*samples) * (len - count));
}
spl = nmt->sender.rxbuf;
pos = nmt->sender.rxbuf_pos;
for (i = 0; i < count; i++) {
for (i = 0; i < len; i++) {
spl[pos++] = samples[i];
if (pos == 160) {
call_up_audio(nmt->trans->callref, spl, 160);

View File

@@ -58,6 +58,7 @@ static int sms_ref = 0;
#define RINGING_TO 60.0 /* how long may the phone ring */
#define SUPERVISORY_TO1 3.0 /* 3 sec to detect after setup */
#define SUPERVISORY_TO2 20.0 /* 20 sec lost until abort */
#define DTMF_DURATION 0.1 /* 100ms */
/* Counters */
#define PAGE_TRIES 3 /* How many time do we try to page the phone */
@@ -1519,7 +1520,7 @@ static void rx_active(nmt_t *nmt, frame_t *frame)
break;
}
digit = nmt_value2digit(frame->digit);
dtmf_encode_set_tone(&nmt->dtmf, digit);
dtmf_encode_set_tone(&nmt->dtmf, digit, DTMF_DURATION, 0.0);
PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received (odd) digit %c.\n", digit);
nmt->mft_num++;
break;
@@ -1542,7 +1543,7 @@ static void rx_active(nmt_t *nmt, frame_t *frame)
break;
}
digit = nmt_value2digit(frame->digit);
dtmf_encode_set_tone(&nmt->dtmf, digit);
dtmf_encode_set_tone(&nmt->dtmf, digit, DTMF_DURATION, 0.0);
PDEBUG_CHAN(DNMT, DEBUG_INFO, "Received (even) digit %c.\n", digit);
nmt->mft_num++;
break;