[Home]

Summary:ASTERISK-10754: silence threshold put to configuration
Reporter:Philipp Skadorov (philipps)Labels:
Date Opened:2007-11-13 11:45:15.000-0600Date Closed:2008-02-18 00:32:00.000-0600
Priority:MajorRegression?No
Status:Closed/CompleteComponents:Applications/General
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) silence_threshold_120108.patch
( 1) silencethreshold_tabified.patch
( 2) silencethreshold.patch
( 3) silthreshold.patch
Description:Hi,
Below is the patch to get silence threshold from /etc/asterisk/dsp.conf file instead of having it hardcoded. It is assumed, that dsp.conf has the following contents:

[default]
silencethreshold=256


****** ADDITIONAL INFORMATION ******

The patch itself:

Index: apps/app_meetme.c
===================================================================
--- apps/app_meetme.c (revision 89243)
+++ apps/app_meetme.c (working copy)
@@ -1516,6 +1516,9 @@
  long time_left_ms = 0;
  struct timeval nexteventts = { 0, };
  int to;
+    int silencethreshold;
+
+    silencethreshold = ast_dsp_get_threshold_from_settings();
 
if (!(user = ast_calloc(1, sizeof(*user))))
return ret;
@@ -1709,7 +1712,7 @@
"%s/meetme/meetme-username-%s-%d", ast_config_AST_SPOOL_DIR,
conf->confno, user->user_no);
if (confflags & CONFFLAG_INTROUSERNOREVIEW)
- res = ast_play_and_record(chan, "vm-rec-name", user->namerecloc, 10, "sln", &duration, 128, 0, NULL);
+ res = ast_play_and_record(chan, "vm-rec-name", user->namerecloc, 10, "sln", &duration, silencethreshold, 0, NULL);
else
res = ast_record_review(chan, "vm-rec-name", user->namerecloc, 10, "sln", &duration, NULL);
if (res == -1)
Index: apps/app_minivm.c
===================================================================
--- apps/app_minivm.c (revision 89243)
+++ apps/app_minivm.c (working copy)
@@ -2291,6 +2291,8 @@
{
int error = 0;

+    global_silencethreshold = ast_dsp_get_threshold_from_settings();
+
while (var) {
/* Mail command */
if (!strcmp(var->name, "mailcmd")) {
Index: apps/app_voicemail.c
===================================================================
--- apps/app_voicemail.c (revision 89243)
+++ apps/app_voicemail.c (working copy)
@@ -8156,7 +8156,7 @@
}

/* Silence treshold */
- silencethreshold = 256;
+ silencethreshold = ast_dsp_get_threshold_from_settings();
if ((val = ast_variable_retrieve(cfg, "general", "silencethreshold")))
silencethreshold = atoi(val);

Index: apps/app_dial.c
===================================================================
--- apps/app_dial.c (revision 89243)
+++ apps/app_dial.c (working copy)
@@ -1093,6 +1093,7 @@
char callerid[60];
int res;
char *l;
+    int silencethreshold;

if (!ast_strlen_zero(chan->cid.cid_num)) {
l = ast_strdupa(chan->cid.cid_num);
@@ -1169,8 +1170,9 @@
  "At the tone, please say your name:"

*/
+            silencethreshold = ast_dsp_get_threshold_from_settings();
ast_answer(chan);
- res = ast_play_and_record(chan, "priv-recordintro", pa->privintro, 4, "gsm", &duration, 128, 2000, 0);  /* NOTE: I've reduced the total time to 4 sec */
+ res = ast_play_and_record(chan, "priv-recordintro", pa->privintro, 4, "gsm", &duration, silencethreshold, 2000, 0);  /* NOTE: I've reduced the total time to 4 sec */
/* don't think we'll need a lock removed, we took care of
  conflicts by naming the pa.privintro file */
if (res == -1) {
Index: apps/app_waitforsilence.c
===================================================================
--- apps/app_waitforsilence.c (revision 89243)
+++ apps/app_waitforsilence.c (working copy)
@@ -78,7 +78,7 @@
static int do_waiting(struct ast_channel *chan, int silencereqd, time_t waitstart, int timeout) {
struct ast_frame *f;
int dspsilence = 0;
- static int silencethreshold = 128;
+ int silencethreshold;
int rfmt = 0;
int res = 0;
struct ast_dsp *sildet; /* silence detector dsp */
@@ -96,6 +96,7 @@
ast_log(LOG_WARNING, "Unable to create silence detector :(\n");
return -1;
}
+    silencethreshold = ast_dsp_get_threshold_from_settings();
ast_dsp_set_threshold(sildet, silencethreshold);

/* Await silence... */
Index: apps/app_amd.c
===================================================================
--- apps/app_amd.c (revision 89243)
+++ apps/app_amd.c (working copy)
@@ -49,7 +49,7 @@
static char *descrip =
"  AMD([initialSilence],[greeting],[afterGreetingSilence],[totalAnalysisTime]\n"
"      ,[minimumWordLength],[betweenWordsSilence],[maximumNumberOfWords]\n"
-"      ,[silenceThreshold])\n"
+"      ,[silencethreshold])\n"
"  This application attempts to detect answering machines at the beginning\n"
"  of outbound calls.  Simply call this application after the call\n"
"  has been answered (outbound only, of course).\n"
@@ -68,7 +68,7 @@
"   consider the audio that follows as a new word.\n"
"- 'maximumNumberOfWords'is the maximum number of words in the greeting. \n"
"   If exceeded then MACHINE.\n"
-"- 'silenceThreshold' is the silence threshold.\n"
+"- 'silencethreshold' is the silence threshold.\n"
"This application sets the following channel variables upon completion:\n"
"    AMDSTATUS - This is the status of the answering machine detection.\n"
"                Possible values are:\n"
@@ -93,7 +93,6 @@
static int dfltBetweenWordsSilence  = 50;
static int dfltMaximumNumberOfWords = 3;
static int dfltSilenceThreshold     = 256;
-
static void isAnsweringMachine(struct ast_channel *chan, void *data)
{
int res = 0;
@@ -123,7 +122,7 @@
int minimumWordLength    = dfltMinimumWordLength;
int betweenWordsSilence  = dfltBetweenWordsSilence;
int maximumNumberOfWords = dfltMaximumNumberOfWords;
- int silenceThreshold     = dfltSilenceThreshold;
+ int silencethreshold;

AST_DECLARE_APP_ARGS(args,
    AST_APP_ARG(argInitialSilence);
@@ -138,6 +137,7 @@

ast_verb(3, "AMD: %s %s %s (Fmt: %d)\n", chan->name ,chan->cid.cid_ani, chan->cid.cid_rdnis, chan->readformat);

+    silencethreshold = ast_dsp_get_threshold_from_settings();
/* Lets parse the arguments. */
if (!ast_strlen_zero(parse)) {
/* Some arguments have been passed. Lets parse them and overwrite the defaults. */
@@ -157,16 +157,16 @@
if (!ast_strlen_zero(args.argMaximumNumberOfWords))
maximumNumberOfWords = atoi(args.argMaximumNumberOfWords);
if (!ast_strlen_zero(args.argSilenceThreshold))
- silenceThreshold = atoi(args.argSilenceThreshold);
+ silencethreshold = atoi(args.argSilenceThreshold);
} else {
ast_debug(1, "AMD using the default parameters.\n");
}

/* Now we're ready to roll! */
ast_verb(3, "AMD: initialSilence [%d] greeting [%d] afterGreetingSilence [%d] "
- "totalAnalysisTime [%d] minimumWordLength [%d] betweenWordsSilence [%d] maximumNumberOfWords [%d] silenceThreshold [%d] \n",
+ "totalAnalysisTime [%d] minimumWordLength [%d] betweenWordsSilence [%d] maximumNumberOfWords [%d] silencethreshold [%d] \n",
initialSilence, greeting, afterGreetingSilence, totalAnalysisTime,
- minimumWordLength, betweenWordsSilence, maximumNumberOfWords, silenceThreshold );
+ minimumWordLength, betweenWordsSilence, maximumNumberOfWords, silencethreshold );

/* Set read format to signed linear so we get signed linear frames in */
readFormat = chan->readformat;
@@ -186,7 +186,7 @@
}

/* Set silence threshold to specified value */
- ast_dsp_set_threshold(silenceDetector, silenceThreshold);
+ ast_dsp_set_threshold(silenceDetector, silencethreshold);

/* Now we go into a loop waiting for frames from the channel */
while ((res = ast_waitfor(chan, totalAnalysisTime)) > -1) {
@@ -365,7 +365,7 @@
ast_config_destroy(cfg);

ast_verb(3, "AMD defaults: initialSilence [%d] greeting [%d] afterGreetingSilence [%d] "
- "totalAnalysisTime [%d] minimumWordLength [%d] betweenWordsSilence [%d] maximumNumberOfWords [%d] silenceThreshold [%d] \n",
+ "totalAnalysisTime [%d] minimumWordLength [%d] betweenWordsSilence [%d] maximumNumberOfWords [%d] silencethreshold [%d] \n",
dfltInitialSilence, dfltGreeting, dfltAfterGreetingSilence, dfltTotalAnalysisTime,
dfltMinimumWordLength, dfltBetweenWordsSilence, dfltMaximumNumberOfWords, dfltSilenceThreshold );

Index: apps/app_record.c
===================================================================
--- apps/app_record.c (revision 89243)
+++ apps/app_record.c (working copy)
@@ -116,6 +116,7 @@
int rfmt = 0;
int ioflags;
int waitres;
+    int silencethreshold;
struct ast_silence_generator *silgen = NULL;
struct ast_flags flags = { 0, };
AST_DECLARE_APP_ARGS(args,
@@ -252,7 +253,8 @@
ast_log(LOG_WARNING, "Unable to create silence detector :(\n");
return -1;
}
- ast_dsp_set_threshold(sildet, 256);
+        silencethreshold = ast_dsp_get_threshold_from_settings();
+ ast_dsp_set_threshold(sildet, silencethreshold);
}

/* Create the directory if it does not exist. */
Index: apps/app_followme.c
===================================================================
--- apps/app_followme.c (revision 89243)
+++ apps/app_followme.c (working copy)
@@ -887,9 +887,13 @@
char *argstr;
char namerecloc[255];
int duration = 0;
+    int silencethreshold;
struct ast_channel *caller;
struct ast_channel *outbound;
static char toast[80];
+
+
+    silencethreshold = ast_dsp_get_threshold_from_settings();

AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(followmeid);
@@ -959,7 +963,7 @@
duration = 5;

if (ast_test_flag(&targs.followmeflags, FOLLOWMEFLAG_RECORDNAME))
- if (ast_play_and_record(chan, "vm-rec-name", namerecloc, 5, "sln", &duration, 128, 0, NULL) < 0)
+ if (ast_play_and_record(chan, "vm-rec-name", namerecloc, 5, "sln", &duration, silencethreshold, 0, NULL) < 0)
goto outrun;

if (!ast_fileexists(namerecloc, NULL, chan->language))
Index: include/asterisk/dsp.h
===================================================================
--- include/asterisk/dsp.h (revision 89243)
+++ include/asterisk/dsp.h (working copy)
@@ -108,4 +108,7 @@
/*! \brief Get tcount (Threshold counter) */
int ast_dsp_get_tcount(struct ast_dsp *dsp);

+/*! \brief Get silence threshold from dsp.conf*/
+int ast_dsp_get_threshold_from_settings(void);
+
#endif /* _ASTERISK_DSP_H */
Index: main/app.c
===================================================================
--- main/app.c (revision 89243)
+++ main/app.c (working copy)
@@ -1262,7 +1262,7 @@

int ast_record_review(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, const char *path)
{
- int silencethreshold = 128;
+ int silencethreshold;
int maxsilence = 0;
int res = 0;
int cmd = 0;
@@ -1280,6 +1280,8 @@

cmd = '3'; /* Want to start by recording */

+    silencethreshold = ast_dsp_get_threshold_from_settings();
+
while ((cmd >= 0) && (cmd != 't')) {
switch (cmd) {
case '1':
Index: main/dsp.c
===================================================================
--- main/dsp.c (revision 89243)
+++ main/dsp.c (working copy)
@@ -60,6 +60,7 @@
#include "asterisk/alaw.h"
#include "asterisk/utils.h"
#include "asterisk/options.h"
+#include "asterisk/config.h"

/*! Number of goertzels for progress detect */
enum gsamp_size {
@@ -181,6 +182,9 @@
#define BELL_MF_RELATIVE_PEAK 12.6    /* 11dB */
#endif

+/*config file for dsp settings*/
+#define CONFIG_FILE_NAME "dsp.conf"
+
#if !defined(BUSYDETECT_MARTIN) && !defined(BUSYDETECT) && !defined(BUSYDETECT_TONEONLY) && !defined(BUSYDETECT_COMPARE_TONE_AND_SILENCE)
#define BUSYDETECT_MARTIN
#endif
@@ -1765,3 +1769,34 @@
{
return dsp->tcount;
}
+
+int ast_dsp_get_threshold_from_settings()
+{
+    static int threshold = -1;
+    const int default_threshold = 256;
+
+    struct ast_flags config_flags = { 0 };
+    struct ast_config *cfg;
+    struct ast_variable *var;
+
+    if(-1 == threshold) {
+        threshold = default_threshold;
+        cfg = ast_config_load(CONFIG_FILE_NAME, config_flags);
+        if (!cfg) {
+            ast_log(LOG_WARNING, "No %s file :(\n", CONFIG_FILE_NAME);
+        }
+        else {
+            for (var = ast_variable_browse(cfg, "default"); var; var = var->next) {
+                if (!strcasecmp(var->name, "silencethreshold")){
+                    if(sscanf(var->value, "%d", &threshold) != 1) {
+                        ast_log(LOG_WARNING, "Error processing file %s :(\n", CONFIG_FILE_NAME);
+                        threshold = default_threshold;
+                    }
+                    break;
+                }
+            }
+        }
+    }
+    return threshold;
+}
+
Index: res/res_agi.c
===================================================================
--- res/res_agi.c (revision 89243)
+++ res/res_agi.c (working copy)
@@ -892,7 +892,9 @@
char *silencestr=NULL;
int rfmt=0;

+    int silencethreshold;

+
/* XXX EAGI FIXME XXX */

if (argc < 6)
@@ -932,7 +934,8 @@
ast_log(LOG_WARNING, "Unable to create silence detector :(\n");
return -1;
}
- ast_dsp_set_threshold(sildet, 256);
+        silencethreshold = ast_dsp_get_threshold_from_settings();
+ ast_dsp_set_threshold(sildet, silencethreshold);
}

/* backward compatibility, if no offset given, arg[6] would have been
Comments:By: Jason Parker (jparker) 2007-12-07 13:40:06.000-0600

Have you worked out your licensing issues?  Once that gets finished, you'll need to reupload the patch here.

By: Philipp Skadorov (philipps) 2007-12-07 15:15:05.000-0600

Qwell, the patch uploaded.

By: Jason Parker (jparker) 2007-12-07 15:24:14.000-0600

There are some major coding guidelines violations in this patch - specifically with spacing.  Please review that, and update the patch with tabs rather than spaces, where appropriate.

Also, I'm seeing many places where silence threshold was 128, and we're now setting the default to 256.  I'm not really sure what to do here - we may just have to choose one or the other.

Rather than creating a new config file with only one option, it would probably make more sense to find another config in which this option would fit.  That config would likely be asterisk.conf.

By: Philipp Skadorov (philipps) 2007-12-09 14:13:22.000-0600

Pls pick silencethreshold_tabified.patch with tabs rather then spaces, where appropriate.

By: Tilghman Lesher (tilghman) 2007-12-24 21:12:11.000-0600

I really don't think that parsing the file each time is really a good way to go.  I would prefer that you parse the file once at load (and perhaps additionally at reload) and save the value in a static variable, returning it when requested.

By: Philipp Skadorov (philipps) 2007-12-25 08:56:47.000-0600

Corydon76,
The setting is picked up from file once into a static variable, pls look at ast_dsp_get_threshold_from_settings .
However, the file is parsed the very first time the setting is requested.
Is it the settings policy to get everything from files at load/reload?



By: Tilghman Lesher (tilghman) 2007-12-25 09:32:40.000-0600

Ah, I see.  Then I'd only like one additional change:  at reload, set the variable back to -1, so that the file gets re-parsed.  Otherwise, any attempt to tweak the value requires a restart.

By: Philipp Skadorov (philipps) 2008-01-12 10:55:05.000-0600

Hi,
Added is silence_threshold_120108.patch that corresponds  to trunk/98514 revision.
It provides silence threshold setting reload from dsp.conf file.

By: jmls (jmls) 2008-02-17 12:55:57.000-0600

Corydon76, any further comments, or can this be merged ?

By: Tilghman Lesher (tilghman) 2008-02-18 00:32:00.000-0600

I'm closing this one out as the patch will be addressed in ASTERISK-10755