mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-03 03:20:57 +00:00
res_tonedetect: Tone detection module
dsp.c contains arbitrary tone detection functionality which is currently only used for fax tone recognition. This change makes this functionality publicly accessible so that other modules can take advantage of this. Additionally, a WaitForTone and TONE_DETECT app and function are included to allow users to do their own tone detection operations in the dialplan. ASTERISK-29546 Change-Id: Ie38c395000f4fd4d04e942e8658e177f8f499b26
This commit is contained in:
committed by
George Joseph
parent
448962d056
commit
7df69633cf
41
main/dsp.c
41
main/dsp.c
@@ -425,6 +425,7 @@ struct ast_dsp {
|
||||
int tcount;
|
||||
int digitmode;
|
||||
int faxmode;
|
||||
int freqmode;
|
||||
int dtmf_began;
|
||||
int display_inband_dtmf_warning;
|
||||
float genergy;
|
||||
@@ -476,7 +477,7 @@ static void ast_tone_detect_init(tone_detect_state_t *s, int freq, int duration,
|
||||
/* Now calculate final block size. It will contain integer number of periods */
|
||||
s->block_size = periods_in_block * sample_rate / freq;
|
||||
|
||||
/* tone_detect is currently only used to detect fax tones and we
|
||||
/* tone_detect is generally only used to detect fax tones and we
|
||||
do not need squelching the fax tones */
|
||||
s->squelch = 0;
|
||||
|
||||
@@ -518,6 +519,15 @@ static void ast_fax_detect_init(struct ast_dsp *s)
|
||||
|
||||
}
|
||||
|
||||
static void ast_freq_detect_init(struct ast_dsp *s, int freq, int dur, int db, int squelch)
|
||||
{
|
||||
/* we can conveniently just use one of the two fax tone states */
|
||||
ast_tone_detect_init(&s->cng_tone_state, freq, dur, db, s->sample_rate);
|
||||
if (s->freqmode & squelch) {
|
||||
s->cng_tone_state.squelch = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void ast_dtmf_detect_init(dtmf_detect_state_t *s, unsigned int sample_rate)
|
||||
{
|
||||
int i;
|
||||
@@ -1485,7 +1495,7 @@ struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp,
|
||||
{
|
||||
int silence;
|
||||
int res;
|
||||
int digit = 0, fax_digit = 0;
|
||||
int digit = 0, fax_digit = 0, custom_freq_digit = 0;
|
||||
int x;
|
||||
short *shortdata;
|
||||
unsigned char *odata;
|
||||
@@ -1558,6 +1568,12 @@ struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp,
|
||||
}
|
||||
}
|
||||
|
||||
if ((dsp->features & DSP_FEATURE_FREQ_DETECT)) {
|
||||
if ((dsp->freqmode) && tone_detect(dsp, &dsp->cng_tone_state, shortdata, len)) {
|
||||
custom_freq_digit = 'q';
|
||||
}
|
||||
}
|
||||
|
||||
if (dsp->features & (DSP_FEATURE_DIGIT_DETECT | DSP_FEATURE_BUSY_DETECT)) {
|
||||
if (dsp->digitmode & DSP_DIGITMODE_MF) {
|
||||
digit = mf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF));
|
||||
@@ -1619,6 +1635,16 @@ struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp,
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (custom_freq_digit) {
|
||||
/* Custom frequency was detected - digit is 'q' */
|
||||
|
||||
memset(&dsp->f, 0, sizeof(dsp->f));
|
||||
dsp->f.frametype = AST_FRAME_DTMF;
|
||||
dsp->f.subclass.integer = custom_freq_digit;
|
||||
outf = &dsp->f;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if ((dsp->features & DSP_FEATURE_CALL_PROGRESS)) {
|
||||
res = __ast_dsp_call_progress(dsp, shortdata, len);
|
||||
if (res) {
|
||||
@@ -1830,6 +1856,17 @@ int ast_dsp_set_digitmode(struct ast_dsp *dsp, int digitmode)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ast_dsp_set_freqmode(struct ast_dsp *dsp, int freq, int dur, int db, int squelch)
|
||||
{
|
||||
if (freq > 0) {
|
||||
dsp->freqmode = 1;
|
||||
ast_freq_detect_init(dsp, freq, dur, db, squelch);
|
||||
} else {
|
||||
dsp->freqmode = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ast_dsp_set_faxmode(struct ast_dsp *dsp, int faxmode)
|
||||
{
|
||||
if (dsp->faxmode != faxmode) {
|
||||
|
Reference in New Issue
Block a user