Index: main/dsp.c =================================================================== --- main/dsp.c (revision 309081) +++ main/dsp.c (working copy) @@ -209,9 +209,9 @@ #define DTMF_GSIZE 102 /* How many successive hits needed to consider begin of a digit */ -#define DTMF_HITS_TO_BEGIN 2 +#define DTMF_HITS_TO_BEGIN 4 /* How many successive misses needed to consider end of a digit */ -#define DTMF_MISSES_TO_END 3 +#define DTMF_MISSES_TO_END 4 /*! * \brief The default silence threshold we will use if an alternate @@ -723,42 +723,42 @@ } } - if (s->td.dtmf.current_hit) { - /* We are in the middle of a digit already */ - if (hit != s->td.dtmf.current_hit) { - s->td.dtmf.misses++; - if (s->td.dtmf.misses == s->td.dtmf.misses_to_end) { - /* There were enough misses to consider digit ended */ - s->td.dtmf.current_hit = 0; + if (hit == s->td.dtmf.lasthit) { + if (s->td.dtmf.current_hit) { + /* We are in the middle of a digit already */ + if (hit) { + if (hit != s->td.dtmf.current_hit) { + /* Look for a start of a new digit. + This is because hits_to_begin may be smaller than misses_to_end + and we may find the beginning of new digit before we consider last one ended. */ + s->td.dtmf.current_hit = 0; + } else { + /* Current hit was same as last, so increment digit duration (of last digit) */ + s->digitlen[s->current_digits - 1] += DTMF_GSIZE; + } + } else { + /* No Digit */ + s->td.dtmf.misses++; + if (s->td.dtmf.misses == s->td.dtmf.misses_to_end) { + /* There were enough misses to consider digit ended */ + s->td.dtmf.current_hit = 0; + } } - } else { - s->td.dtmf.misses = 0; - /* Current hit was same as last, so increment digit duration (of last digit) */ - s->digitlen[s->current_digits - 1] += DTMF_GSIZE; - } - } - - /* Look for a start of a new digit no matter if we are already in the middle of some - digit or not. This is because hits_to_begin may be smaller than misses_to_end - and we may find begin of new digit before we consider last one ended. */ - if (hit) { - if (hit == s->td.dtmf.lasthit) { + } else if (hit) { + /* Detecting new digit */ s->td.dtmf.hits++; - } else { - s->td.dtmf.hits = 1; + if (s->td.dtmf.hits == s->td.dtmf.hits_to_begin) { + store_digit(s, hit); + s->td.dtmf.current_hit = hit; + } } - - if (s->td.dtmf.hits == s->td.dtmf.hits_to_begin && hit != s->td.dtmf.current_hit) { - store_digit(s, hit); - s->td.dtmf.current_hit = hit; - s->td.dtmf.misses = 0; - } } else { - s->td.dtmf.hits = 0; + s->td.dtmf.hits = 1; + s->td.dtmf.misses = 1; + s->td.dtmf.lasthit = hit; + ast_debug(1, "DTMF EDGE\n"); } - s->td.dtmf.lasthit = hit; - /* If we had a hit in this block, include it into mute fragment */ if (squelch && hit) { if (mute.end < sample - DTMF_GSIZE) { @@ -1405,6 +1405,7 @@ if (dsp->features & DSP_FEATURE_DIGIT_DETECT) { event = AST_FRAME_DTMF_BEGIN; event_digit = dsp->digit_state.digits[0]; + ast_debug(1, "DTMF BEG digit='%c' len=%d\n", event_digit, dsp->digit_state.digitlen[0]); } dsp->dtmf_began = 1; @@ -1414,6 +1415,7 @@ event = AST_FRAME_DTMF_END; event_digit = dsp->digit_state.digits[0]; event_len = dsp->digit_state.digitlen[0] * 1000 / SAMPLE_RATE; + ast_debug(1, "DTMF END digit='%c' len=%d\n", event_digit, dsp->digit_state.digitlen[0]); } memmove(&dsp->digit_state.digits[0], &dsp->digit_state.digits[1], dsp->digit_state.current_digits); memmove(&dsp->digit_state.digitlen[0], &dsp->digit_state.digitlen[1], dsp->digit_state.current_digits * sizeof(dsp->digit_state.digitlen[0]));