[Asterisk-cvs] asterisk dsp.c,1.46,1.47
markster
markster
Sun Aug 7 20:05:07 CDT 2005
Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv2987
Modified Files:
dsp.c
Log Message:
Merge steve's busy detect stuff (bug #4830)
Index: dsp.c
===================================================================
RCS file: /usr/cvsroot/asterisk/dsp.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- dsp.c 25 Jul 2005 21:57:14 -0000 1.46
+++ dsp.c 8 Aug 2005 00:08:48 -0000 1.47
@@ -93,7 +93,8 @@
#define DEFAULT_THRESHOLD 512
-#define BUSY_PERCENT 10 /* The percentage diffrence between the two last silence periods */
+#define BUSY_PERCENT 10 /* The percentage difference between the two last silence periods */
+#define BUSY_PAT_PERCENT 7 /* The percentage difference between measured and actual pattern */
#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 +305,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 +1157,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 +1171,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 +1181,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 +1198,7 @@
*totalsilence = dsp->totalsilence;
return res;
}
+
#ifdef BUSYDETECT_MARTIN
int ast_dsp_busydetect(struct ast_dsp *dsp)
{
@@ -1216,18 +1222,18 @@
for (x=DSP_HISTORY - dsp->busycount;x<DSP_HISTORY;x++) {
#ifndef BUSYDETECT_TONEONLY
if (avgsilence > 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 +1249,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_PAT_PERCENT/100)) {
#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_PAT_PERCENT/100)) {
+#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_DEBUG, "ast_dsp_busydetect detected busy, avgtone: %d, avgsilence %d\n", avgtone, avgsilence);
#endif
return res;
}
@@ -1576,6 +1602,13 @@
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_DEBUG, "dsp busy pattern set to %d,%d\n", tonelength, quietlength);
+}
+
void ast_dsp_digitreset(struct ast_dsp *dsp)
{
int i;
More information about the svn-commits
mailing list