Index: dsp.c =================================================================== RCS file: /usr/cvsroot/asterisk/dsp.c,v retrieving revision 1.46 diff -u -r1.46 dsp.c --- dsp.c 25 Jul 2005 21:57:14 -0000 1.46 +++ dsp.c 27 Jul 2005 17:26:47 -0000 @@ -93,7 +93,7 @@ #define DEFAULT_THRESHOLD 512 -#define BUSY_PERCENT 10 /* The percentage diffrence between the two last silence periods */ +#define BUSY_PERCENT 15 /* The percentage diffrence between the two last silence periods */ #define BUSY_THRESHOLD 100 /* Max number of ms difference between max and min times in busy */ #define BUSY_MIN 75 /* Busy must be at least 80 ms in half-cadence */ #define BUSY_MAX 1100 /* Busy can't be longer than 1100 ms in half-cadence */ @@ -304,6 +304,8 @@ int features; int busymaybe; int busycount; + int busy_tonelength; + int busy_quietlength; int historicnoise[DSP_HISTORY]; int historicsilence[DSP_HISTORY]; goertzel_state_t freqs[7]; @@ -1154,6 +1156,7 @@ accum += abs(s[x]); accum /= len; if (accum < dsp->threshold) { + /* Silent */ dsp->totalsilence += len/8; if (dsp->totalnoise) { /* Move and save history */ @@ -1167,6 +1170,7 @@ dsp->totalnoise = 0; res = 1; } else { + /* Not silent */ dsp->totalnoise += len/8; if (dsp->totalsilence) { int silence1 = dsp->historicsilence[DSP_HISTORY - 1]; @@ -1176,12 +1180,12 @@ dsp->historicsilence[DSP_HISTORY - 1] = dsp->totalsilence; /* check if the previous sample differs only by BUSY_PERCENT from the one before it */ if (silence1 < silence2) { - if (silence1 + silence1/BUSY_PERCENT >= silence2) + if (silence1 + silence1*BUSY_PERCENT/100 >= silence2) dsp->busymaybe = 1; else dsp->busymaybe = 0; } else { - if (silence1 - silence1/BUSY_PERCENT <= silence2) + if (silence1 - silence1*BUSY_PERCENT/100 <= silence2) dsp->busymaybe = 1; else dsp->busymaybe = 0; @@ -1193,6 +1197,7 @@ *totalsilence = dsp->totalsilence; return res; } + #ifdef BUSYDETECT_MARTIN int ast_dsp_busydetect(struct ast_dsp *dsp) { @@ -1216,18 +1221,18 @@ for (x=DSP_HISTORY - dsp->busycount;x dsp->historicsilence[x]) { - if (avgsilence - (avgsilence / BUSY_PERCENT) <= dsp->historicsilence[x]) + if (avgsilence - (avgsilence*BUSY_PERCENT/100) <= dsp->historicsilence[x]) hitsilence++; } else { - if (avgsilence + (avgsilence / BUSY_PERCENT) >= dsp->historicsilence[x]) + if (avgsilence + (avgsilence*BUSY_PERCENT/100) >= dsp->historicsilence[x]) hitsilence++; } #endif if (avgtone > dsp->historicnoise[x]) { - if (avgtone - (avgtone / BUSY_PERCENT) <= dsp->historicnoise[x]) + if (avgtone - (avgtone*BUSY_PERCENT/100) <= dsp->historicnoise[x]) hittone++; } else { - if (avgtone + (avgtone / BUSY_PERCENT) >= dsp->historicnoise[x]) + if (avgtone + (avgtone*BUSY_PERCENT/100) >= dsp->historicnoise[x]) hittone++; } } @@ -1243,19 +1248,39 @@ #error You cant use BUSYDETECT_TONEONLY together with BUSYDETECT_COMPARE_TONE_AND_SILENCE #endif if (avgtone > avgsilence) { - if (avgtone - avgtone/(BUSY_PERCENT*2) <= avgsilence) + if (avgtone - avgtone*BUSY_PERCENT/100 <= avgsilence) res = 1; } else { - if (avgtone + avgtone/(BUSY_PERCENT*2) >= avgsilence) + if (avgtone + avgtone*BUSY_PERCENT/100 >= avgsilence) res = 1; } #else res = 1; #endif } + /* If we know the expected busy tone length, check we are in the range */ + if (res && (dsp->busy_tonelength > 0)) { + if (abs(avgtone - dsp->busy_tonelength) > (dsp->busy_tonelength*BUSY_PERCENT/200)) { +#if 0 + ast_log(LOG_NOTICE, "busy detector: avgtone of %d not close enough to desired %d\n", + avgtone, dsp->busy_tonelength); +#endif + res = 0; + } + } + /* If we know the expected busy tone silent-period length, check we are in the range */ + if (res && (dsp->busy_quietlength > 0)) { + if (abs(avgsilence - dsp->busy_quietlength) > (dsp->busy_quietlength*BUSY_PERCENT/200)) { #if 0 + ast_log(LOG_NOTICE, "busy detector: avgsilence of %d not close enough to desired %d\n", + avgsilence, dsp->busy_quietlength); +#endif + res = 0; + } + } +#if 1 if (res) - ast_log(LOG_NOTICE, "detected busy, avgtone: %d, avgsilence %d\n", avgtone, avgsilence); + ast_log(LOG_NOTICE, "ast_dsp_busydetect detected busy, avgtone: %d, avgsilence %d\n", avgtone, avgsilence); #endif return res; } @@ -1574,6 +1599,13 @@ if (cadences > DSP_HISTORY) cadences = DSP_HISTORY; dsp->busycount = cadences; +} + +void ast_dsp_set_busy_pattern(struct ast_dsp *dsp, int tonelength, int quietlength) +{ + dsp->busy_tonelength = tonelength; + dsp->busy_quietlength = quietlength; + ast_log(LOG_NOTICE, "dsp busy pattern set to %d,%d\n", tonelength, quietlength); } void ast_dsp_digitreset(struct ast_dsp *dsp) Index: channels/chan_zap.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_zap.c,v retrieving revision 1.482 diff -u -r1.482 chan_zap.c --- channels/chan_zap.c 25 Jul 2005 22:16:35 -0000 1.482 +++ channels/chan_zap.c 27 Jul 2005 17:27:20 -0000 @@ -234,6 +235,8 @@ static int busydetect = 0; static int busycount = 3; +static int busy_tonelength = 0; +static int busy_quietlength = 0; static int callprogress = 0; @@ -611,6 +614,8 @@ int echotraining; char echorest[20]; int busycount; + int busy_tonelength; + int busy_quietlength; int callprogress; struct timeval flashtime; /* Last flash-hook time */ struct ast_dsp *dsp; @@ -4824,6 +4829,7 @@ ast_dsp_set_call_progress_zone(i->dsp, progzone); if (i->busydetect && CANBUSYDETECT(i)) { ast_dsp_set_busy_count(i->dsp, i->busycount); + ast_dsp_set_busy_pattern(i->dsp, i->busy_tonelength, i->busy_quietlength); } } } @@ -6871,6 +6877,8 @@ tmp->echocanbridged = echocanbridged; tmp->busydetect = busydetect; tmp->busycount = busycount; + tmp->busy_tonelength = busy_tonelength; + tmp->busy_quietlength = busy_quietlength; tmp->callprogress = callprogress; tmp->cancallforward = cancallforward; tmp->dtmfrelax = relaxdtmf; @@ -10054,6 +10062,10 @@ busydetect = ast_true(v->value); } else if (!strcasecmp(v->name, "busycount")) { busycount = atoi(v->value); + } else if (!strcasecmp(v->name, "busypattern")) { + if (sscanf(v->value, "%d,%d", &busy_tonelength, &busy_quietlength) != 2) { + ast_log(LOG_ERROR, "busypattern= expects busypattern=tonelength,quietlength\n"); + } } else if (!strcasecmp(v->name, "callprogress")) { if (ast_true(v->value)) callprogress |= 1; Index: configs/zapata.conf.sample =================================================================== RCS file: /usr/cvsroot/asterisk/configs/zapata.conf.sample,v retrieving revision 1.49 diff -u -r1.49 zapata.conf.sample --- configs/zapata.conf.sample 19 Jul 2005 13:30:37 -0000 1.49 +++ configs/zapata.conf.sample 27 Jul 2005 17:27:21 -0000 @@ -366,17 +366,35 @@ ; ; On trunk interfaces (FXS) and E&M interfaces (E&M, Wink, Feature Group D ; etc, it can be useful to perform busy detection either in an effort to -; detect hangup or for detecting busies +; detect hangup or for detecting busies. This enables listening for +; the beep-beep busy pattern. ; ;busydetect=yes ; ; If busydetect is enabled, is also possible to specify how many -; busy tones to wait before hanging up. The default is 4, but +; busy tones to wait for before hanging up. The default is 4, but ; better results can be achieved if set to 6 or even 8. Mind that ; higher the number, more time is needed to hangup a channel, but ; lower is probability to get random hangups ; -;busycount=4 +;busycount=4 +; +; If busydetect is enabled, is also possible to specify the +; cadence of your busy signal. In many countries it is 500mec +; on, 500msec off. +; Without busypattern specified, we'll accept any regular +; sound-silence pattern than repeats busycount times as a busy +; signal. +; If you specify busypattern then we'll further check the length +; of the sound (tone) and silence, which will further reduce the +; chance of a false positive. +; +;busypattern=500,500 +; +; NOTE: In the Asterisk Makefile you'll find further options to tweak +; the busy detector. If your country has a busy tone with the same +; lengh tone and silence (as many countries do), consider defining +; the -DBUSYDETECT_COMPARE_TONE_AND_SILENCE option. ; ; Use a polarity reversal to mark when a outgoing call is answered by the ; remote party. Index: include/asterisk/dsp.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/dsp.h,v retrieving revision 1.7 diff -u -r1.7 dsp.h --- include/asterisk/dsp.h 28 Jun 2005 14:36:56 -0000 1.7 +++ include/asterisk/dsp.h 27 Jul 2005 17:27:22 -0000 @@ -53,6 +53,9 @@ /* Set number of required cadences for busy */ void ast_dsp_set_busy_count(struct ast_dsp *dsp, int cadences); +/* Set expected lengths of the busy tone */ +void ast_dsp_set_busy_pattern(struct ast_dsp *dsp, int tonelength, int quietlength); + /* Scans for progress indication in audio */ int ast_dsp_call_progress(struct ast_dsp *dsp, struct ast_frame *inf);