|
|
|
@ -59,7 +59,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
enum gsamp_size {
|
|
|
|
|
GSAMP_SIZE_NA = 183, /*!< North America - 350, 440, 480, 620, 950, 1400, 1800 Hz */
|
|
|
|
|
GSAMP_SIZE_CR = 188, /*!< Costa Rica, Brazil - Only care about 425 Hz */
|
|
|
|
|
GSAMP_SIZE_UK = 160 /*!< UK disconnect goertzel feed - should trigger 400hz */
|
|
|
|
|
GSAMP_SIZE_UK = 160 /*!< UK disconnect goertzel feed - should trigger 400hz */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum prog_mode {
|
|
|
|
@ -103,8 +103,8 @@ static struct progress {
|
|
|
|
|
int freqs[7];
|
|
|
|
|
} modes[] = {
|
|
|
|
|
{ GSAMP_SIZE_NA, { 350, 440, 480, 620, 950, 1400, 1800 } }, /*!< North America */
|
|
|
|
|
{ GSAMP_SIZE_CR, { 425 } }, /*!< Costa Rica, Brazil */
|
|
|
|
|
{ GSAMP_SIZE_UK, { 350, 400, 440 } }, /*!< UK */
|
|
|
|
|
{ GSAMP_SIZE_CR, { 425 } }, /*!< Costa Rica, Brazil */
|
|
|
|
|
{ GSAMP_SIZE_UK, { 350, 400, 440 } }, /*!< UK */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*!\brief This value is the minimum threshold, calculated by averaging all
|
|
|
|
@ -117,26 +117,26 @@ static struct progress {
|
|
|
|
|
#define DEFAULT_THRESHOLD 512
|
|
|
|
|
|
|
|
|
|
enum busy_detect {
|
|
|
|
|
BUSY_PERCENT = 10, /*!< The percentage difference between the two last silence periods */
|
|
|
|
|
BUSY_PERCENT = 10, /*!< The percentage difference between the two last silence periods */
|
|
|
|
|
BUSY_PAT_PERCENT = 7, /*!< The percentage difference between measured and actual pattern */
|
|
|
|
|
BUSY_THRESHOLD = 100, /*!< Max number of ms difference between max and min times in busy */
|
|
|
|
|
BUSY_MIN = 75, /*!< Busy must be at least 80 ms in half-cadence */
|
|
|
|
|
BUSY_MAX =3100 /*!< Busy can't be longer than 3100 ms in half-cadence */
|
|
|
|
|
BUSY_MIN = 75, /*!< Busy must be at least 80 ms in half-cadence */
|
|
|
|
|
BUSY_MAX =3100 /*!< Busy can't be longer than 3100 ms in half-cadence */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*! Remember last 15 units */
|
|
|
|
|
#define DSP_HISTORY 15
|
|
|
|
|
#define DSP_HISTORY 15
|
|
|
|
|
|
|
|
|
|
#define TONE_THRESH 10.0 /*!< How much louder the tone should be than channel energy */
|
|
|
|
|
#define TONE_MIN_THRESH 1e8 /*!< How much tone there should be at least to attempt */
|
|
|
|
|
#define TONE_MIN_THRESH 1e8 /*!< How much tone there should be at least to attempt */
|
|
|
|
|
|
|
|
|
|
/*! All THRESH_XXX values are in GSAMP_SIZE chunks (us = 22ms) */
|
|
|
|
|
enum gsamp_thresh {
|
|
|
|
|
THRESH_RING = 8, /*!< Need at least 150ms ring to accept */
|
|
|
|
|
THRESH_TALK = 2, /*!< Talk detection does not work continuously */
|
|
|
|
|
THRESH_BUSY = 4, /*!< Need at least 80ms to accept */
|
|
|
|
|
THRESH_CONGESTION = 4, /*!< Need at least 80ms to accept */
|
|
|
|
|
THRESH_HANGUP = 60, /*!< Need at least 1300ms to accept hangup */
|
|
|
|
|
THRESH_RING = 8, /*!< Need at least 150ms ring to accept */
|
|
|
|
|
THRESH_TALK = 2, /*!< Talk detection does not work continuously */
|
|
|
|
|
THRESH_BUSY = 4, /*!< Need at least 80ms to accept */
|
|
|
|
|
THRESH_CONGESTION = 4, /*!< Need at least 80ms to accept */
|
|
|
|
|
THRESH_HANGUP = 60, /*!< Need at least 1300ms to accept hangup */
|
|
|
|
|
THRESH_RING2ANSWER = 300 /*!< Timeout from start of ring to answer (about 6600 ms) */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -433,7 +433,7 @@ static void ast_tone_detect_init(tone_detect_state_t *s, int freq, int duration,
|
|
|
|
|
|
|
|
|
|
/* If we want to remove tone, it is important to have block size not
|
|
|
|
|
to exceed frame size. Otherwise by the moment tone is detected it is too late
|
|
|
|
|
to squelch it from previous frames. Block size is 20ms at the given sample rate.*/
|
|
|
|
|
to squelch it from previous frames. Block size is 20ms at the given sample rate.*/
|
|
|
|
|
s->block_size = (20 * sample_rate) / 1000;
|
|
|
|
|
|
|
|
|
|
periods_in_block = s->block_size * freq / sample_rate;
|
|
|
|
@ -441,8 +441,9 @@ static void ast_tone_detect_init(tone_detect_state_t *s, int freq, int duration,
|
|
|
|
|
/* Make sure we will have at least 5 periods at target frequency for analisys.
|
|
|
|
|
This may make block larger than expected packet and will make squelching impossible
|
|
|
|
|
but at least we will be detecting the tone */
|
|
|
|
|
if (periods_in_block < 5)
|
|
|
|
|
if (periods_in_block < 5) {
|
|
|
|
|
periods_in_block = 5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now calculate final block size. It will contain integer number of periods */
|
|
|
|
|
s->block_size = periods_in_block * sample_rate / freq;
|
|
|
|
@ -493,8 +494,9 @@ static void ast_v21_detect_init(v21_detect_state_t *s, unsigned int sample_rate)
|
|
|
|
|
/* Make sure we will have at least 5 periods at target frequency for analisys.
|
|
|
|
|
This may make block larger than expected packet and will make squelching impossible
|
|
|
|
|
but at least we will be detecting the tone */
|
|
|
|
|
if (periods_in_block < 5)
|
|
|
|
|
if (periods_in_block < 5) {
|
|
|
|
|
periods_in_block = 5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now calculate final block size. It will contain integer number of periods */
|
|
|
|
|
s->block_size = periods_in_block * sample_rate / 1850;
|
|
|
|
@ -1001,8 +1003,8 @@ static int mf_detect(struct ast_dsp *dsp, digit_detect_state_t *s, int16_t amp[]
|
|
|
|
|
/* Basic signal level and twist tests */
|
|
|
|
|
hit = 0;
|
|
|
|
|
if (energy[best] >= BELL_MF_THRESHOLD && energy[second_best] >= BELL_MF_THRESHOLD
|
|
|
|
|
&& energy[best] < energy[second_best]*BELL_MF_TWIST
|
|
|
|
|
&& energy[best] * BELL_MF_TWIST > energy[second_best]) {
|
|
|
|
|
&& energy[best] < energy[second_best]*BELL_MF_TWIST
|
|
|
|
|
&& energy[best] * BELL_MF_TWIST > energy[second_best]) {
|
|
|
|
|
/* Relative peak test */
|
|
|
|
|
hit = -1;
|
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
@ -1061,8 +1063,9 @@ static int mf_detect(struct ast_dsp *dsp, digit_detect_state_t *s, int16_t amp[]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Reinitialise the detector for the next block */
|
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
|
goertzel_reset(&s->td.mf.tone_out[i]);
|
|
|
|
|
}
|
|
|
|
|
s->td.mf.current_sample = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1603,10 +1606,11 @@ struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dsp->features & (DSP_FEATURE_DIGIT_DETECT | DSP_FEATURE_BUSY_DETECT)) {
|
|
|
|
|
if (dsp->digitmode & DSP_DIGITMODE_MF)
|
|
|
|
|
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));
|
|
|
|
|
else
|
|
|
|
|
} else {
|
|
|
|
|
digit = dtmf_detect(dsp, &dsp->digit_state, shortdata, len, (dsp->digitmode & DSP_DIGITMODE_NOQUELCH) == 0, (dsp->digitmode & DSP_DIGITMODE_RELAXDTMF));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dsp->digit_state.current_digits) {
|
|
|
|
|
int event = 0, event_len = 0;
|
|
|
|
@ -1675,8 +1679,9 @@ struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp,
|
|
|
|
|
dsp->f.frametype = AST_FRAME_CONTROL;
|
|
|
|
|
dsp->f.subclass.integer = res;
|
|
|
|
|
dsp->f.src = "dsp_progress";
|
|
|
|
|
if (chan)
|
|
|
|
|
if (chan) {
|
|
|
|
|
ast_queue_frame(chan, &dsp->f);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ast_log(LOG_WARNING, "Don't know how to represent call progress message %d\n", res);
|
|
|
|
@ -1907,33 +1912,34 @@ int ast_dsp_get_tcount(struct ast_dsp *dsp)
|
|
|
|
|
|
|
|
|
|
static int _dsp_init(int reload)
|
|
|
|
|
{
|
|
|
|
|
struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
|
|
|
|
|
struct ast_config *cfg;
|
|
|
|
|
struct ast_variable *v;
|
|
|
|
|
struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
|
|
|
|
|
int cfg_threshold;
|
|
|
|
|
|
|
|
|
|
cfg = ast_config_load2(CONFIG_FILE_NAME, "dsp", config_flags);
|
|
|
|
|
if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
|
|
|
|
|
ast_verb(5, "Can't find dsp config file %s. Assuming default silencethreshold of %d.\n", CONFIG_FILE_NAME, DEFAULT_SILENCE_THRESHOLD);
|
|
|
|
|
thresholds[THRESHOLD_SILENCE] = DEFAULT_SILENCE_THRESHOLD;
|
|
|
|
|
if ((cfg = ast_config_load2(CONFIG_FILE_NAME, "dsp", config_flags)) == CONFIG_STATUS_FILEUNCHANGED) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
|
|
|
|
|
thresholds[THRESHOLD_SILENCE] = DEFAULT_SILENCE_THRESHOLD;
|
|
|
|
|
|
|
|
|
|
if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cfg) {
|
|
|
|
|
const char *value;
|
|
|
|
|
|
|
|
|
|
value = ast_variable_retrieve(cfg, "default", "silencethreshold");
|
|
|
|
|
if (value && sscanf(value, "%30d", &thresholds[THRESHOLD_SILENCE]) != 1) {
|
|
|
|
|
ast_verb(5, "%s: '%s' is not a valid silencethreshold value\n", CONFIG_FILE_NAME, value);
|
|
|
|
|
thresholds[THRESHOLD_SILENCE] = DEFAULT_SILENCE_THRESHOLD;
|
|
|
|
|
} else if (!value) {
|
|
|
|
|
thresholds[THRESHOLD_SILENCE] = DEFAULT_SILENCE_THRESHOLD;
|
|
|
|
|
for (v = ast_variable_browse(cfg, "default"); v; v = v->next) {
|
|
|
|
|
if (!strcasecmp(v->name, "silencethreshold")) {
|
|
|
|
|
if (sscanf(v->value, "%30d", &cfg_threshold) < 1) {
|
|
|
|
|
ast_log(LOG_WARNING, "Unable to convert '%s' to a numeric value.\n", v->value);
|
|
|
|
|
} else if (cfg_threshold < 0) {
|
|
|
|
|
ast_log(LOG_WARNING, "Invalid silence threshold '%d' specified, using default\n", cfg_threshold);
|
|
|
|
|
} else {
|
|
|
|
|
thresholds[THRESHOLD_SILENCE] = cfg_threshold;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ast_config_destroy(cfg);
|
|
|
|
|
}
|
|
|
|
|
ast_config_destroy(cfg);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1951,4 +1957,3 @@ int ast_dsp_reload(void)
|
|
|
|
|
{
|
|
|
|
|
return _dsp_init(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|