Convenience Signal Processing routines. More...
#include "asterisk.h"
#include <math.h>
#include "asterisk/frame.h"
#include "asterisk/channel.h"
#include "asterisk/dsp.h"
#include "asterisk/ulaw.h"
#include "asterisk/alaw.h"
#include "asterisk/utils.h"
#include "asterisk/options.h"
#include "asterisk/config.h"
Go to the source code of this file.
Data Structures | |
struct | ast_dsp |
struct | digit_detect_state_t |
struct | dtmf_detect_state_t |
struct | fragment_t |
struct | goertzel_result_t |
struct | goertzel_state_t |
struct | mf_detect_state_t |
struct | progalias |
struct | progress |
struct | tone_detect_state_t |
Defines | |
#define | BELL_MF_RELATIVE_PEAK 12.6 |
#define | BELL_MF_THRESHOLD 1.6e9 |
#define | BELL_MF_TWIST 4.0 |
#define | CONFIG_FILE_NAME "dsp.conf" |
#define | DEFAULT_THRESHOLD 512 |
This value is the minimum threshold, calculated by averaging all of the samples within a frame, for which a frame is determined to either be silence (below the threshold) or noise (above the threshold). Please note that while the default threshold is an even exponent of 2, there is no requirement that it be so. The threshold will accept any value between 0 and 32767. | |
#define | DSP_HISTORY 15 |
#define | DTMF_2ND_HARMONIC_COL 63.1 |
#define | DTMF_2ND_HARMONIC_ROW (relax ? 1.7 : 2.5) |
#define | DTMF_GSIZE 102 |
#define | DTMF_HITS_TO_BEGIN 2 |
#define | DTMF_MISSES_TO_END 3 |
#define | DTMF_NORMAL_TWIST 6.3 |
#define | DTMF_RELATIVE_PEAK_COL 6.3 |
#define | DTMF_RELATIVE_PEAK_ROW 6.3 |
#define | DTMF_REVERSE_TWIST (relax ? 4.0 : 2.5) |
#define | DTMF_THRESHOLD 8.0e7 |
#define | DTMF_TO_TOTAL_ENERGY 42.0 |
#define | FAX_2ND_HARMONIC 2.0 |
#define | FAX_THRESHOLD 8.0e7 |
#define | FAX_TONE_CED_DB 16 |
#define | FAX_TONE_CED_DURATION 2600 |
#define | FAX_TONE_CED_FREQ 2100 |
#define | FAX_TONE_CNG_DB 16 |
#define | FAX_TONE_CNG_DURATION 500 |
#define | FAX_TONE_CNG_FREQ 1100 |
#define | MAX_DTMF_DIGITS 128 |
#define | MF_GSIZE 120 |
#define | SAMPLE_RATE 8000 |
#define | SAMPLES_IN_FRAME 160 |
#define | TONE_MIN_THRESH 1e8 |
#define | TONE_THRESH 10.0 |
Enumerations | |
enum | busy_detect { BUSY_PERCENT = 10, BUSY_PAT_PERCENT = 7, BUSY_THRESHOLD = 100, BUSY_MIN = 75, BUSY_MAX = 3100 } |
enum | freq_index { HZ_350 = 0, HZ_440, HZ_480, HZ_620, HZ_950, HZ_1400, HZ_1800, HZ_425 = 0, HZ_350UK = 0, HZ_400UK, HZ_440UK } |
enum | gsamp_size { GSAMP_SIZE_NA = 183, GSAMP_SIZE_CR = 188, GSAMP_SIZE_UK = 160 } |
enum | gsamp_thresh { THRESH_RING = 8, THRESH_TALK = 2, THRESH_BUSY = 4, THRESH_CONGESTION = 4, THRESH_HANGUP = 60, THRESH_RING2ANSWER = 300 } |
enum | prog_mode { PROG_MODE_NA = 0, PROG_MODE_CR, PROG_MODE_UK } |
Functions | |
static int | __ast_dsp_call_progress (struct ast_dsp *dsp, short *s, int len) |
static int | __ast_dsp_silence_noise (struct ast_dsp *dsp, short *s, int len, int *totalsilence, int *totalnoise) |
static int | _dsp_init (int reload) |
static void | ast_digit_detect_init (digit_detect_state_t *s, int mf) |
int | ast_dsp_busydetect (struct ast_dsp *dsp) |
Return non-zero if historically this should be a busy, request that ast_dsp_silence has already been called. | |
int | ast_dsp_call_progress (struct ast_dsp *dsp, struct ast_frame *inf) |
Scans for progress indication in audio. | |
void | ast_dsp_digitreset (struct ast_dsp *dsp) |
Reset DTMF detector. | |
void | ast_dsp_frame_freed (struct ast_frame *fr) |
Hint that a frame from a dsp was freed. | |
void | ast_dsp_free (struct ast_dsp *dsp) |
int | ast_dsp_get_tcount (struct ast_dsp *dsp) |
Get tcount (Threshold counter) | |
int | ast_dsp_get_threshold_from_settings (enum threshold which) |
Get silence threshold from dsp.conf. | |
int | ast_dsp_get_tstate (struct ast_dsp *dsp) |
Get tstate (Tone State) | |
int | ast_dsp_init (void) |
Load dsp settings from dsp.conf. | |
struct ast_dsp * | ast_dsp_new (void) |
int | ast_dsp_noise (struct ast_dsp *dsp, struct ast_frame *f, int *totalnoise) |
Return non-zero if this is noise. Updates "totalnoise" with the total number of seconds of noise. | |
struct ast_frame * | ast_dsp_process (struct ast_channel *chan, struct ast_dsp *dsp, struct ast_frame *af) |
Return AST_FRAME_NULL frames when there is silence, AST_FRAME_BUSY on busies, and call progress, all dependent upon which features are enabled. | |
static void | ast_dsp_prog_reset (struct ast_dsp *dsp) |
int | ast_dsp_reload (void) |
Reloads dsp settings from dsp.conf. | |
void | ast_dsp_reset (struct ast_dsp *dsp) |
Reset total silence count. | |
void | ast_dsp_set_busy_count (struct ast_dsp *dsp, int cadences) |
Set number of required cadences for busy. | |
void | ast_dsp_set_busy_pattern (struct ast_dsp *dsp, int tonelength, int quietlength) |
Set expected lengths of the busy tone. | |
int | ast_dsp_set_call_progress_zone (struct ast_dsp *dsp, char *zone) |
Set zone for doing progress detection. | |
int | ast_dsp_set_digitmode (struct ast_dsp *dsp, int digitmode) |
Set digit mode. | |
int | ast_dsp_set_faxmode (struct ast_dsp *dsp, int faxmode) |
Set fax mode. | |
void | ast_dsp_set_features (struct ast_dsp *dsp, int features) |
Select feature set. | |
void | ast_dsp_set_threshold (struct ast_dsp *dsp, int threshold) |
Set threshold value for silence. | |
int | ast_dsp_silence (struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence) |
Return non-zero if this is silence. Updates "totalsilence" with the total number of seconds of silence. | |
int | ast_dsp_was_muted (struct ast_dsp *dsp) |
Returns true if DSP code was muting any fragment of the last processed frame. Muting (squelching) happens when DSP code removes DTMF/MF/generic tones from the audio. | |
static void | ast_dtmf_detect_init (dtmf_detect_state_t *s) |
static void | ast_fax_detect_init (struct ast_dsp *s) |
static void | ast_mf_detect_init (mf_detect_state_t *s) |
static void | ast_tone_detect_init (tone_detect_state_t *s, int freq, int duration, int amp) |
static int | dtmf_detect (struct ast_dsp *dsp, digit_detect_state_t *s, int16_t amp[], int samples, int squelch, int relax) |
static void | goertzel_init (goertzel_state_t *s, float freq, int samples) |
static void | goertzel_reset (goertzel_state_t *s) |
static float | goertzel_result (goertzel_state_t *s) |
static void | goertzel_sample (goertzel_state_t *s, short sample) |
static void | goertzel_update (goertzel_state_t *s, short *samps, int count) |
static int | mf_detect (struct ast_dsp *dsp, digit_detect_state_t *s, int16_t amp[], int samples, int squelch, int relax) |
static void | mute_fragment (struct ast_dsp *dsp, fragment_t *fragment) |
static int | pair_there (float p1, float p2, float i1, float i2, float e) |
static void | store_digit (digit_detect_state_t *s, char digit) |
static int | tone_detect (struct ast_dsp *dsp, tone_detect_state_t *s, int16_t *amp, int samples) |
Variables | |
static struct progalias | aliases [] |
static char | bell_mf_positions [] = "1247C-358A--69*---0B----#" |
static const int | DEFAULT_SILENCE_THRESHOLD = 256 |
The default silence threshold we will use if an alternate configured value is not present or is invalid. | |
static float | dtmf_col [] |
static char | dtmf_positions [] = "*0#D" |
static float | dtmf_row [] |
static float | mf_tones [] |
static struct progress | modes [] |
static int | thresholds [THRESHOLD_MAX] |
Convenience Signal Processing routines.
Definition in file dsp.c.
#define BELL_MF_RELATIVE_PEAK 12.6 |
Definition at line 174 of file dsp.c.
Referenced by mf_detect().
#define BELL_MF_THRESHOLD 1.6e9 |
Definition at line 172 of file dsp.c.
Referenced by mf_detect().
#define BELL_MF_TWIST 4.0 |
Definition at line 173 of file dsp.c.
Referenced by mf_detect().
#define CONFIG_FILE_NAME "dsp.conf" |
Definition at line 222 of file dsp.c.
Referenced by _dsp_init().
#define DEFAULT_THRESHOLD 512 |
This value is the minimum threshold, calculated by averaging all of the samples within a frame, for which a frame is determined to either be silence (below the threshold) or noise (above the threshold). Please note that while the default threshold is an even exponent of 2, there is no requirement that it be so. The threshold will accept any value between 0 and 32767.
Definition at line 117 of file dsp.c.
Referenced by ast_dsp_new().
#define DSP_HISTORY 15 |
Remember last 15 units
Definition at line 128 of file dsp.c.
Referenced by __ast_dsp_silence_noise(), ast_dsp_busydetect(), ast_dsp_new(), and ast_dsp_set_busy_count().
#define DTMF_GSIZE 102 |
Definition at line 209 of file dsp.c.
Referenced by ast_dtmf_detect_init(), dtmf_detect(), and mf_detect().
#define DTMF_HITS_TO_BEGIN 2 |
Definition at line 212 of file dsp.c.
Referenced by ast_dtmf_detect_init().
#define DTMF_MISSES_TO_END 3 |
Definition at line 214 of file dsp.c.
Referenced by ast_dtmf_detect_init().
#define DTMF_NORMAL_TWIST 6.3 |
Definition at line 160 of file dsp.c.
Referenced by dtmf_detect().
#define DTMF_RELATIVE_PEAK_COL 6.3 |
Definition at line 167 of file dsp.c.
Referenced by dtmf_detect().
#define DTMF_RELATIVE_PEAK_ROW 6.3 |
Definition at line 166 of file dsp.c.
Referenced by dtmf_detect().
#define DTMF_REVERSE_TWIST (relax ? 4.0 : 2.5) |
Definition at line 164 of file dsp.c.
Referenced by dtmf_detect().
#define DTMF_THRESHOLD 8.0e7 |
Definition at line 157 of file dsp.c.
Referenced by dtmf_detect().
#define DTMF_TO_TOTAL_ENERGY 42.0 |
Definition at line 170 of file dsp.c.
Referenced by dtmf_detect().
#define FAX_TONE_CED_DB 16 |
Definition at line 193 of file dsp.c.
Referenced by ast_fax_detect_init().
#define FAX_TONE_CED_DURATION 2600 |
Definition at line 192 of file dsp.c.
Referenced by ast_fax_detect_init().
#define FAX_TONE_CED_FREQ 2100 |
Definition at line 191 of file dsp.c.
Referenced by ast_fax_detect_init().
#define FAX_TONE_CNG_DB 16 |
Definition at line 185 of file dsp.c.
Referenced by ast_fax_detect_init().
#define FAX_TONE_CNG_DURATION 500 |
Definition at line 184 of file dsp.c.
Referenced by ast_fax_detect_init().
#define FAX_TONE_CNG_FREQ 1100 |
Definition at line 183 of file dsp.c.
Referenced by ast_fax_detect_init().
#define MAX_DTMF_DIGITS 128 |
Definition at line 143 of file dsp.c.
Referenced by store_digit().
#define MF_GSIZE 120 |
Definition at line 206 of file dsp.c.
Referenced by mf_detect().
#define SAMPLE_RATE 8000 |
Definition at line 195 of file dsp.c.
Referenced by ast_dsp_process(), ast_tone_detect_init(), and goertzel_init().
#define SAMPLES_IN_FRAME 160 |
Definition at line 203 of file dsp.c.
Referenced by ast_tone_detect_init().
#define TONE_MIN_THRESH 1e8 |
How much tone there should be at least to attempt
Definition at line 131 of file dsp.c.
Referenced by __ast_dsp_call_progress(), and pair_there().
#define TONE_THRESH 10.0 |
How much louder the tone should be than channel energy
Definition at line 130 of file dsp.c.
Referenced by __ast_dsp_call_progress(), and pair_there().
enum busy_detect |
Definition at line 119 of file dsp.c.
{ 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 */ };
enum freq_index |
enum gsamp_size |
Number of goertzels for progress detect
GSAMP_SIZE_NA |
North America - 350, 440, 480, 620, 950, 1400, 1800 Hz |
GSAMP_SIZE_CR |
Costa Rica, Brazil - Only care about 425 Hz |
GSAMP_SIZE_UK |
UK disconnect goertzel feed - should trigger 400hz |
Definition at line 59 of file dsp.c.
{ 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 */ };
enum gsamp_thresh |
All THRESH_XXX values are in GSAMP_SIZE chunks (us = 22ms)
Definition at line 134 of file dsp.c.
{ 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) */ };
enum prog_mode |
Definition at line 65 of file dsp.c.
{ PROG_MODE_NA = 0, PROG_MODE_CR, PROG_MODE_UK };
static int __ast_dsp_call_progress | ( | struct ast_dsp * | dsp, |
short * | s, | ||
int | len | ||
) | [static] |
Definition at line 973 of file dsp.c.
References AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HANGUP, AST_CONTROL_RINGING, ast_debug, ast_log(), DSP_FEATURE_CALL_PROGRESS, DSP_PROGRESS_BUSY, DSP_PROGRESS_CONGESTION, DSP_PROGRESS_RINGING, DSP_PROGRESS_TALK, DSP_TONE_STATE_BUSY, DSP_TONE_STATE_DIALTONE, DSP_TONE_STATE_HUNGUP, DSP_TONE_STATE_RINGING, DSP_TONE_STATE_SILENCE, DSP_TONE_STATE_SPECIAL1, DSP_TONE_STATE_SPECIAL2, DSP_TONE_STATE_SPECIAL3, DSP_TONE_STATE_TALKING, ast_dsp::features, ast_dsp::freqcount, ast_dsp::freqs, ast_dsp::genergy, goertzel_result(), goertzel_sample(), ast_dsp::gsamp_size, ast_dsp::gsamps, HZ_1400, HZ_1800, HZ_350, HZ_350UK, HZ_400UK, HZ_425, HZ_440, HZ_440UK, HZ_480, HZ_620, HZ_950, len(), LOG_WARNING, pair_there(), pass, PROG_MODE_CR, PROG_MODE_NA, PROG_MODE_UK, ast_dsp::progmode, ast_dsp::ringtimeout, ast_dsp::tcount, THRESH_BUSY, THRESH_CONGESTION, THRESH_HANGUP, THRESH_RING, THRESH_RING2ANSWER, THRESH_TALK, TONE_MIN_THRESH, TONE_THRESH, ast_dsp::tstate, goertzel_state_t::v2, and goertzel_state_t::v3.
Referenced by ast_dsp_call_progress(), and ast_dsp_process().
{ int x; int y; int pass; int newstate = DSP_TONE_STATE_SILENCE; int res = 0; while (len) { /* Take the lesser of the number of samples we need and what we have */ pass = len; if (pass > dsp->gsamp_size - dsp->gsamps) { pass = dsp->gsamp_size - dsp->gsamps; } for (x = 0; x < pass; x++) { for (y = 0; y < dsp->freqcount; y++) { goertzel_sample(&dsp->freqs[y], s[x]); } dsp->genergy += s[x] * s[x]; } s += pass; dsp->gsamps += pass; len -= pass; if (dsp->gsamps == dsp->gsamp_size) { float hz[7]; for (y = 0; y < 7; y++) { hz[y] = goertzel_result(&dsp->freqs[y]); } switch (dsp->progmode) { case PROG_MODE_NA: if (pair_there(hz[HZ_480], hz[HZ_620], hz[HZ_350], hz[HZ_440], dsp->genergy)) { newstate = DSP_TONE_STATE_BUSY; } else if (pair_there(hz[HZ_440], hz[HZ_480], hz[HZ_350], hz[HZ_620], dsp->genergy)) { newstate = DSP_TONE_STATE_RINGING; } else if (pair_there(hz[HZ_350], hz[HZ_440], hz[HZ_480], hz[HZ_620], dsp->genergy)) { newstate = DSP_TONE_STATE_DIALTONE; } else if (hz[HZ_950] > TONE_MIN_THRESH * TONE_THRESH) { newstate = DSP_TONE_STATE_SPECIAL1; } else if (hz[HZ_1400] > TONE_MIN_THRESH * TONE_THRESH) { /* End of SPECIAL1 or middle of SPECIAL2 */ if (dsp->tstate == DSP_TONE_STATE_SPECIAL1 || dsp->tstate == DSP_TONE_STATE_SPECIAL2) { newstate = DSP_TONE_STATE_SPECIAL2; } } else if (hz[HZ_1800] > TONE_MIN_THRESH * TONE_THRESH) { /* End of SPECIAL2 or middle of SPECIAL3 */ if (dsp->tstate == DSP_TONE_STATE_SPECIAL2 || dsp->tstate == DSP_TONE_STATE_SPECIAL3) { newstate = DSP_TONE_STATE_SPECIAL3; } } else if (dsp->genergy > TONE_MIN_THRESH * TONE_THRESH) { newstate = DSP_TONE_STATE_TALKING; } else { newstate = DSP_TONE_STATE_SILENCE; } break; case PROG_MODE_CR: if (hz[HZ_425] > TONE_MIN_THRESH * TONE_THRESH) { newstate = DSP_TONE_STATE_RINGING; } else if (dsp->genergy > TONE_MIN_THRESH * TONE_THRESH) { newstate = DSP_TONE_STATE_TALKING; } else { newstate = DSP_TONE_STATE_SILENCE; } break; case PROG_MODE_UK: if (hz[HZ_400UK] > TONE_MIN_THRESH * TONE_THRESH) { newstate = DSP_TONE_STATE_HUNGUP; } else if (pair_there(hz[HZ_350UK], hz[HZ_440UK], hz[HZ_400UK], hz[HZ_400UK], dsp->genergy)) { newstate = DSP_TONE_STATE_DIALTONE; } break; default: ast_log(LOG_WARNING, "Can't process in unknown prog mode '%d'\n", dsp->progmode); } if (newstate == dsp->tstate) { dsp->tcount++; if (dsp->ringtimeout) { dsp->ringtimeout++; } switch (dsp->tstate) { case DSP_TONE_STATE_RINGING: if ((dsp->features & DSP_PROGRESS_RINGING) && (dsp->tcount == THRESH_RING)) { res = AST_CONTROL_RINGING; dsp->ringtimeout = 1; } break; case DSP_TONE_STATE_BUSY: if ((dsp->features & DSP_PROGRESS_BUSY) && (dsp->tcount == THRESH_BUSY)) { res = AST_CONTROL_BUSY; dsp->features &= ~DSP_FEATURE_CALL_PROGRESS; } break; case DSP_TONE_STATE_TALKING: if ((dsp->features & DSP_PROGRESS_TALK) && (dsp->tcount == THRESH_TALK)) { res = AST_CONTROL_ANSWER; dsp->features &= ~DSP_FEATURE_CALL_PROGRESS; } break; case DSP_TONE_STATE_SPECIAL3: if ((dsp->features & DSP_PROGRESS_CONGESTION) && (dsp->tcount == THRESH_CONGESTION)) { res = AST_CONTROL_CONGESTION; dsp->features &= ~DSP_FEATURE_CALL_PROGRESS; } break; case DSP_TONE_STATE_HUNGUP: if ((dsp->features & DSP_FEATURE_CALL_PROGRESS) && (dsp->tcount == THRESH_HANGUP)) { res = AST_CONTROL_HANGUP; dsp->features &= ~DSP_FEATURE_CALL_PROGRESS; } break; } if (dsp->ringtimeout == THRESH_RING2ANSWER) { ast_debug(1, "Consider call as answered because of timeout after last ring\n"); res = AST_CONTROL_ANSWER; dsp->features &= ~DSP_FEATURE_CALL_PROGRESS; } } else { ast_debug(5, "Stop state %d with duration %d\n", dsp->tstate, dsp->tcount); ast_debug(5, "Start state %d\n", newstate); dsp->tstate = newstate; dsp->tcount = 1; } /* Reset goertzel */ for (x = 0; x < 7; x++) { dsp->freqs[x].v2 = dsp->freqs[x].v3 = 0.0; } dsp->gsamps = 0; dsp->genergy = 0.0; } } return res; }
static int __ast_dsp_silence_noise | ( | struct ast_dsp * | dsp, |
short * | s, | ||
int | len, | ||
int * | totalsilence, | ||
int * | totalnoise | ||
) | [static] |
Definition at line 1124 of file dsp.c.
References BUSY_PERCENT, ast_dsp::busycount, ast_dsp::busymaybe, DSP_HISTORY, ast_dsp::historicnoise, ast_dsp::historicsilence, len(), ast_dsp::totalnoise, and ast_dsp::totalsilence.
Referenced by ast_dsp_noise(), ast_dsp_process(), and ast_dsp_silence().
{ int accum; int x; int res = 0; if (!len) { return 0; } accum = 0; for (x = 0; x < len; x++) { accum += abs(s[x]); } accum /= len; if (accum < dsp->threshold) { /* Silent */ dsp->totalsilence += len / 8; if (dsp->totalnoise) { /* Move and save history */ memmove(dsp->historicnoise + DSP_HISTORY - dsp->busycount, dsp->historicnoise + DSP_HISTORY - dsp->busycount + 1, dsp->busycount * sizeof(dsp->historicnoise[0])); dsp->historicnoise[DSP_HISTORY - 1] = dsp->totalnoise; /* we don't want to check for busydetect that frequently */ #if 0 dsp->busymaybe = 1; #endif } dsp->totalnoise = 0; res = 1; } else { /* Not silent */ dsp->totalnoise += len / 8; if (dsp->totalsilence) { int silence1 = dsp->historicsilence[DSP_HISTORY - 1]; int silence2 = dsp->historicsilence[DSP_HISTORY - 2]; /* Move and save history */ memmove(dsp->historicsilence + DSP_HISTORY - dsp->busycount, dsp->historicsilence + DSP_HISTORY - dsp->busycount + 1, dsp->busycount * sizeof(dsp->historicsilence[0])); 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 / 100 >= silence2) { dsp->busymaybe = 1; } else { dsp->busymaybe = 0; } } else { if (silence1 - silence1 * BUSY_PERCENT / 100 <= silence2) { dsp->busymaybe = 1; } else { dsp->busymaybe = 0; } } } dsp->totalsilence = 0; } if (totalsilence) { *totalsilence = dsp->totalsilence; } if (totalnoise) { *totalnoise = dsp->totalnoise; } return res; }
static int _dsp_init | ( | int | reload | ) | [static] |
Definition at line 1697 of file dsp.c.
References ast_config_destroy(), ast_config_load2(), ast_variable_retrieve(), ast_verb, CONFIG_FILE_NAME, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, CONFIG_STATUS_FILEUNCHANGED, DEFAULT_SILENCE_THRESHOLD, and THRESHOLD_SILENCE.
Referenced by ast_dsp_init(), and ast_dsp_reload().
{ struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; struct ast_config *cfg; 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; return 0; } if (cfg == CONFIG_STATUS_FILEUNCHANGED) { 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; } ast_config_destroy(cfg); } return 0; }
static void ast_digit_detect_init | ( | digit_detect_state_t * | s, |
int | mf | ||
) | [static] |
Definition at line 518 of file dsp.c.
References ast_dtmf_detect_init(), ast_mf_detect_init(), digit_detect_state_t::current_digits, digit_detect_state_t::detected_digits, digit_detect_state_t::digits, digit_detect_state_t::dtmf, digit_detect_state_t::lost_digits, digit_detect_state_t::mf, and digit_detect_state_t::td.
Referenced by ast_dsp_new(), and ast_dsp_set_digitmode().
{ s->current_digits = 0; s->detected_digits = 0; s->lost_digits = 0; s->digits[0] = '\0'; if (mf) { ast_mf_detect_init(&s->td.mf); } else { ast_dtmf_detect_init(&s->td.dtmf); } }
int ast_dsp_busydetect | ( | struct ast_dsp * | dsp | ) |
Return non-zero if historically this should be a busy, request that ast_dsp_silence has already been called.
Definition at line 1187 of file dsp.c.
References ast_debug, BUSY_MAX, BUSY_MIN, BUSY_PAT_PERCENT, BUSY_PERCENT, ast_dsp::busy_quietlength, ast_dsp::busy_tonelength, ast_dsp::busycount, ast_dsp::busymaybe, DSP_HISTORY, ast_dsp::historicnoise, and ast_dsp::historicsilence.
Referenced by ast_dsp_process().
{ int res = 0, x; #ifndef BUSYDETECT_TONEONLY int avgsilence = 0, hitsilence = 0; #endif int avgtone = 0, hittone = 0; if (!dsp->busymaybe) { return res; } for (x = DSP_HISTORY - dsp->busycount; x < DSP_HISTORY; x++) { #ifndef BUSYDETECT_TONEONLY avgsilence += dsp->historicsilence[x]; #endif avgtone += dsp->historicnoise[x]; } #ifndef BUSYDETECT_TONEONLY avgsilence /= dsp->busycount; #endif avgtone /= dsp->busycount; for (x = DSP_HISTORY - dsp->busycount; x < DSP_HISTORY; x++) { #ifndef BUSYDETECT_TONEONLY if (avgsilence > dsp->historicsilence[x]) { if (avgsilence - (avgsilence * BUSY_PERCENT / 100) <= dsp->historicsilence[x]) { hitsilence++; } } else { if (avgsilence + (avgsilence * BUSY_PERCENT / 100) >= dsp->historicsilence[x]) { hitsilence++; } } #endif if (avgtone > dsp->historicnoise[x]) { if (avgtone - (avgtone * BUSY_PERCENT / 100) <= dsp->historicnoise[x]) { hittone++; } } else { if (avgtone + (avgtone * BUSY_PERCENT / 100) >= dsp->historicnoise[x]) { hittone++; } } } #ifndef BUSYDETECT_TONEONLY if ((hittone >= dsp->busycount - 1) && (hitsilence >= dsp->busycount - 1) && (avgtone >= BUSY_MIN && avgtone <= BUSY_MAX) && (avgsilence >= BUSY_MIN && avgsilence <= BUSY_MAX)) { #else if ((hittone >= dsp->busycount - 1) && (avgtone >= BUSY_MIN && avgtone <= BUSY_MAX)) { #endif #ifdef BUSYDETECT_COMPARE_TONE_AND_SILENCE if (avgtone > avgsilence) { if (avgtone - avgtone*BUSY_PERCENT/100 <= avgsilence) { res = 1; } } else { 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)) { #ifdef BUSYDETECT_DEBUG ast_debug(5, "busy detector: avgtone of %d not close enough to desired %d\n", avgtone, dsp->busy_tonelength); #endif res = 0; } } #ifndef BUSYDETECT_TONEONLY /* 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)) { #ifdef BUSYDETECT_DEBUG ast_debug(5, "busy detector: avgsilence of %d not close enough to desired %d\n", avgsilence, dsp->busy_quietlength); #endif res = 0; } } #endif #if !defined(BUSYDETECT_TONEONLY) && defined(BUSYDETECT_DEBUG) if (res) { ast_debug(5, "ast_dsp_busydetect detected busy, avgtone: %d, avgsilence %d\n", avgtone, avgsilence); } else { ast_debug(5, "busy detector: FAILED with avgtone: %d, avgsilence %d\n", avgtone, avgsilence); } #endif return res; }
Scans for progress indication in audio.
Definition at line 1111 of file dsp.c.
References __ast_dsp_call_progress(), AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_log(), ast_frame::data, ast_frame::datalen, ast_frame::frametype, LOG_WARNING, ast_frame::ptr, and ast_frame::subclass.
{ if (inf->frametype != AST_FRAME_VOICE) { ast_log(LOG_WARNING, "Can't check call progress of non-voice frames\n"); return 0; } if (inf->subclass != AST_FORMAT_SLINEAR) { ast_log(LOG_WARNING, "Can only check call progress in signed-linear frames\n"); return 0; } return __ast_dsp_call_progress(dsp, inf->data.ptr, inf->datalen / 2); }
void ast_dsp_digitreset | ( | struct ast_dsp * | dsp | ) |
Reset DTMF detector.
Definition at line 1599 of file dsp.c.
References dtmf_detect_state_t::col_out, digit_detect_state_t::current_digits, dtmf_detect_state_t::current_hit, mf_detect_state_t::current_hit, dtmf_detect_state_t::current_sample, mf_detect_state_t::current_sample, ast_dsp::digit_state, ast_dsp::digitmode, digit_detect_state_t::digits, DSP_DIGITMODE_MF, digit_detect_state_t::dtmf, ast_dsp::dtmf_began, dtmf_detect_state_t::energy, goertzel_reset(), dtmf_detect_state_t::hits, mf_detect_state_t::hits, dtmf_detect_state_t::lasthit, digit_detect_state_t::mf, dtmf_detect_state_t::misses, dtmf_detect_state_t::row_out, s, digit_detect_state_t::td, and mf_detect_state_t::tone_out.
Referenced by ss_thread().
{ int i; dsp->dtmf_began = 0; if (dsp->digitmode & DSP_DIGITMODE_MF) { mf_detect_state_t *s = &dsp->digit_state.td.mf; /* Reinitialise the detector for the next block */ for (i = 0; i < 6; i++) { goertzel_reset(&s->tone_out[i]); } s->hits[4] = s->hits[3] = s->hits[2] = s->hits[1] = s->hits[0] = s->current_hit = 0; s->current_sample = 0; } else { dtmf_detect_state_t *s = &dsp->digit_state.td.dtmf; /* Reinitialise the detector for the next block */ for (i = 0; i < 4; i++) { goertzel_reset(&s->row_out[i]); goertzel_reset(&s->col_out[i]); } s->lasthit = s->current_hit = 0; s->energy = 0.0; s->current_sample = 0; s->hits = 0; s->misses = 0; } dsp->digit_state.digits[0] = '\0'; dsp->digit_state.current_digits = 0; }
void ast_dsp_frame_freed | ( | struct ast_frame * | fr | ) |
Hint that a frame from a dsp was freed.
This is called from ast_frame_free if AST_FRFLAG_FROM_DSP is set. This occurs because it is possible for the dsp to be freed while someone still holds a reference to the frame that is in that dsp. This has been known to happen when the dsp on a DAHDI channel detects a busy signal. The channel is hung up, and the application that read the frame to begin with still has a reference to the frame.
Definition at line 1744 of file dsp.c.
References ast_clear_flag, ast_dsp_free(), AST_FRFLAG_FROM_DSP, ast_dsp::destroy, and f.
Referenced by __frame_free().
{ struct ast_dsp *dsp; ast_clear_flag(fr, AST_FRFLAG_FROM_DSP); dsp = (struct ast_dsp *) (((char *) fr) - offsetof(struct ast_dsp, f)); if (!dsp->destroy) return; ast_dsp_free(dsp); }
void ast_dsp_free | ( | struct ast_dsp * | dsp | ) |
Definition at line 1561 of file dsp.c.
References ast_free, AST_FRFLAG_FROM_DSP, ast_test_flag, ast_dsp::destroy, and ast_dsp::f.
Referenced by __ast_play_and_record(), __oh323_destroy(), ast_dsp_frame_freed(), background_detect_exec(), cl_dequeue_chan(), cleanup_connection(), conf_run(), dahdi_hangup(), destroy_endpoint(), do_waiting(), handle_recordfile(), isAnsweringMachine(), mgcp_hangup(), record_exec(), sip_dtmfmode(), sip_hangup(), sip_rtp_read(), ss_thread(), and unload_module().
{ if (ast_test_flag(&dsp->f, AST_FRFLAG_FROM_DSP)) { /* If this flag is still set, that means that the dsp's destruction * been torn down, while we still have a frame out there being used. * When ast_frfree() gets called on that frame, this ast_trans_pvt * will get destroyed, too. */ dsp->destroy = 1; return; } ast_free(dsp); }
int ast_dsp_get_tcount | ( | struct ast_dsp * | dsp | ) |
Get tcount (Threshold counter)
Definition at line 1692 of file dsp.c.
References ast_dsp::tcount.
Referenced by dahdi_read().
{ return dsp->tcount; }
int ast_dsp_get_threshold_from_settings | ( | enum threshold | which | ) |
Get silence threshold from dsp.conf.
Definition at line 1729 of file dsp.c.
Referenced by app_exec(), ast_record_review(), conf_run(), do_waiting(), handle_recordfile(), load_config(), record_exec(), and setup_privacy_args().
{ return thresholds[which]; }
int ast_dsp_get_tstate | ( | struct ast_dsp * | dsp | ) |
Get tstate (Tone State)
Definition at line 1687 of file dsp.c.
References ast_dsp::tstate.
Referenced by dahdi_read().
{ return dsp->tstate; }
int ast_dsp_init | ( | void | ) |
Load dsp settings from dsp.conf.
Definition at line 1734 of file dsp.c.
References _dsp_init().
Referenced by main().
{ return _dsp_init(0); }
struct ast_dsp* ast_dsp_new | ( | void | ) | [read] |
Definition at line 1535 of file dsp.c.
References ast_calloc, ast_digit_detect_init(), ast_dsp_prog_reset(), ast_fax_detect_init(), ast_dsp::busycount, DEFAULT_THRESHOLD, ast_dsp::digit_state, ast_dsp::digitmode, ast_dsp::display_inband_dtmf_warning, DSP_DIGITMODE_DTMF, DSP_DIGITMODE_MF, DSP_FAXMODE_DETECT_CNG, DSP_FEATURE_SILENCE_SUPPRESS, DSP_HISTORY, ast_dsp::faxmode, ast_dsp::features, and ast_dsp::threshold.
Referenced by __ast_play_and_record(), __oh323_new(), background_detect_exec(), conf_run(), dahdi_new(), do_waiting(), handle_recordfile(), isAnsweringMachine(), mgcp_new(), misdn_set_opt_exec(), read_config(), record_exec(), sip_dtmfmode(), sip_new(), and store_config().
{ struct ast_dsp *dsp; if ((dsp = ast_calloc(1, sizeof(*dsp)))) { dsp->threshold = DEFAULT_THRESHOLD; dsp->features = DSP_FEATURE_SILENCE_SUPPRESS; dsp->busycount = DSP_HISTORY; dsp->digitmode = DSP_DIGITMODE_DTMF; dsp->faxmode = DSP_FAXMODE_DETECT_CNG; /* Initialize digit detector */ ast_digit_detect_init(&dsp->digit_state, dsp->digitmode & DSP_DIGITMODE_MF); dsp->display_inband_dtmf_warning = 1; /* Initialize initial DSP progress detect parameters */ ast_dsp_prog_reset(dsp); /* Initialize fax detector */ ast_fax_detect_init(dsp); } return dsp; }
Return non-zero if this is noise. Updates "totalnoise" with the total number of seconds of noise.
Definition at line 1300 of file dsp.c.
References __ast_dsp_silence_noise(), AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_log(), ast_frame::data, ast_frame::datalen, ast_frame::frametype, len(), LOG_WARNING, ast_frame::ptr, s, and ast_frame::subclass.
Referenced by do_waiting().
{ short *s; int len; if (f->frametype != AST_FRAME_VOICE) { ast_log(LOG_WARNING, "Can't calculate noise on a non-voice frame\n"); return 0; } if (f->subclass != AST_FORMAT_SLINEAR) { ast_log(LOG_WARNING, "Can only calculate noise on signed-linear frames :(\n"); return 0; } s = f->data.ptr; len = f->datalen/2; return __ast_dsp_silence_noise(dsp, s, len, NULL, totalnoise); }
struct ast_frame* ast_dsp_process | ( | struct ast_channel * | chan, |
struct ast_dsp * | dsp, | ||
struct ast_frame * | af | ||
) | [read] |
Return AST_FRAME_NULL frames when there is silence, AST_FRAME_BUSY on busies, and call progress, all dependent upon which features are enabled.
Definition at line 1319 of file dsp.c.
References __ast_dsp_call_progress(), __ast_dsp_silence_noise(), ast_channel::_softhangup, AST_ALAW, AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HANGUP, AST_CONTROL_RINGING, ast_debug, ast_dsp_busydetect(), AST_FORMAT_ALAW, AST_FORMAT_SLINEAR, AST_FORMAT_ULAW, AST_FRAME_CONTROL, AST_FRAME_DTMF, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_NULL, AST_FRAME_VOICE, AST_FRFLAG_FROM_DSP, ast_frfree, ast_getformatname(), AST_LIN2A, AST_LIN2MU, ast_log(), AST_MULAW, ast_queue_frame(), ast_set_flag, AST_SOFTHANGUP_DEV, ast_dsp::ced_tone_state, ast_dsp::cng_tone_state, digit_detect_state_t::current_digits, ast_frame::data, ast_frame::datalen, ast_dsp::digit_state, digit_detect_state_t::digitlen, ast_dsp::digitmode, digit_detect_state_t::digits, ast_dsp::display_inband_dtmf_warning, DSP_DIGITMODE_MF, DSP_DIGITMODE_NOQUELCH, DSP_DIGITMODE_RELAXDTMF, DSP_FAXMODE_DETECT_CED, DSP_FAXMODE_DETECT_CNG, DSP_FEATURE_BUSY_DETECT, DSP_FEATURE_CALL_PROGRESS, DSP_FEATURE_DIGIT_DETECT, DSP_FEATURE_FAX_DETECT, DSP_FEATURE_SILENCE_SUPPRESS, DSP_FEATURE_WAITDIALTONE, ast_dsp::dtmf_began, dtmf_detect(), fragment_t::end, ast_dsp::f, ast_dsp::faxmode, ast_dsp::features, ast_frame::frametype, ast_dsp::historicnoise, ast_dsp::historicsilence, ast_frame::len, len(), LOG_WARNING, mf_detect(), ast_dsp::mute_data, ast_dsp::mute_fragments, ast_channel::name, ast_frame::ptr, SAMPLE_RATE, ast_frame::src, fragment_t::start, ast_frame::subclass, and tone_detect().
Referenced by dahdi_read(), mgcp_rtp_read(), oh323_rtp_read(), process_ast_dsp(), sip_rtp_read(), and usbradio_read().
{ int silence; int res; int digit = 0, fax_digit = 0; int x; short *shortdata; unsigned char *odata; int len; struct ast_frame *outf = NULL; if (!af) { return NULL; } if (af->frametype != AST_FRAME_VOICE) { return af; } odata = af->data.ptr; len = af->datalen; /* Make sure we have short data */ switch (af->subclass) { case AST_FORMAT_SLINEAR: shortdata = af->data.ptr; len = af->datalen / 2; break; case AST_FORMAT_ULAW: shortdata = alloca(af->datalen * 2); for (x = 0;x < len; x++) { shortdata[x] = AST_MULAW(odata[x]); } break; case AST_FORMAT_ALAW: shortdata = alloca(af->datalen * 2); for (x = 0; x < len; x++) { shortdata[x] = AST_ALAW(odata[x]); } break; default: /*Display warning only once. Otherwise you would get hundreds of warnings every second */ if (dsp->display_inband_dtmf_warning) ast_log(LOG_WARNING, "Inband DTMF is not supported on codec %s. Use RFC2833\n", ast_getformatname(af->subclass)); dsp->display_inband_dtmf_warning = 0; return af; } /* Initially we do not want to mute anything */ dsp->mute_fragments = 0; /* Need to run the silence detection stuff for silence suppression and busy detection */ if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) || (dsp->features & DSP_FEATURE_BUSY_DETECT)) { res = __ast_dsp_silence_noise(dsp, shortdata, len, &silence, NULL); } if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) && silence) { memset(&dsp->f, 0, sizeof(dsp->f)); dsp->f.frametype = AST_FRAME_NULL; ast_frfree(af); ast_set_flag(&dsp->f, AST_FRFLAG_FROM_DSP); return &dsp->f; } if ((dsp->features & DSP_FEATURE_BUSY_DETECT) && ast_dsp_busydetect(dsp)) { chan->_softhangup |= AST_SOFTHANGUP_DEV; memset(&dsp->f, 0, sizeof(dsp->f)); dsp->f.frametype = AST_FRAME_CONTROL; dsp->f.subclass = AST_CONTROL_BUSY; ast_frfree(af); ast_debug(1, "Requesting Hangup because the busy tone was detected on channel %s\n", chan->name); ast_set_flag(&dsp->f, AST_FRFLAG_FROM_DSP); return &dsp->f; } if ((dsp->features & DSP_FEATURE_FAX_DETECT)) { if ((dsp->faxmode & DSP_FAXMODE_DETECT_CNG) && tone_detect(dsp, &dsp->cng_tone_state, shortdata, len)) { fax_digit = 'f'; } if ((dsp->faxmode & DSP_FAXMODE_DETECT_CED) && tone_detect(dsp, &dsp->ced_tone_state, shortdata, len)) { fax_digit = 'e'; } } if (dsp->features & (DSP_FEATURE_DIGIT_DETECT | DSP_FEATURE_BUSY_DETECT)) { 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 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; char event_digit = 0; if (!dsp->dtmf_began) { /* We have not reported DTMF_BEGIN for anything yet */ if (dsp->features & DSP_FEATURE_DIGIT_DETECT) { event = AST_FRAME_DTMF_BEGIN; event_digit = dsp->digit_state.digits[0]; } dsp->dtmf_began = 1; } else if (dsp->digit_state.current_digits > 1 || digit != dsp->digit_state.digits[0]) { /* Digit changed. This means digit we have reported with DTMF_BEGIN ended */ if (dsp->features & DSP_FEATURE_DIGIT_DETECT) { event = AST_FRAME_DTMF_END; event_digit = dsp->digit_state.digits[0]; event_len = dsp->digit_state.digitlen[0] * 1000 / SAMPLE_RATE; } 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])); dsp->digit_state.current_digits--; dsp->dtmf_began = 0; if (dsp->features & DSP_FEATURE_BUSY_DETECT) { /* Reset Busy Detector as we have some confirmed activity */ memset(dsp->historicsilence, 0, sizeof(dsp->historicsilence)); memset(dsp->historicnoise, 0, sizeof(dsp->historicnoise)); ast_debug(1, "DTMF Detected - Reset busydetector\n"); } } if (event) { memset(&dsp->f, 0, sizeof(dsp->f)); dsp->f.frametype = event; dsp->f.subclass = event_digit; dsp->f.len = event_len; outf = &dsp->f; goto done; } } } if (fax_digit) { /* Fax was detected - digit is either 'f' or 'e' */ memset(&dsp->f, 0, sizeof(dsp->f)); dsp->f.frametype = AST_FRAME_DTMF; dsp->f.subclass = fax_digit; outf = &dsp->f; goto done; } if ((dsp->features & DSP_FEATURE_CALL_PROGRESS)) { res = __ast_dsp_call_progress(dsp, shortdata, len); if (res) { switch (res) { case AST_CONTROL_ANSWER: case AST_CONTROL_BUSY: case AST_CONTROL_RINGING: case AST_CONTROL_CONGESTION: case AST_CONTROL_HANGUP: memset(&dsp->f, 0, sizeof(dsp->f)); dsp->f.frametype = AST_FRAME_CONTROL; dsp->f.subclass = res; dsp->f.src = "dsp_progress"; 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); } } } else if ((dsp->features & DSP_FEATURE_WAITDIALTONE)) { res = __ast_dsp_call_progress(dsp, shortdata, len); } done: /* Mute fragment of the frame */ for (x = 0; x < dsp->mute_fragments; x++) { memset(shortdata + dsp->mute_data[x].start, 0, sizeof(int16_t) * (dsp->mute_data[x].end - dsp->mute_data[x].start)); } switch (af->subclass) { case AST_FORMAT_SLINEAR: break; case AST_FORMAT_ULAW: for (x = 0; x < len; x++) { odata[x] = AST_LIN2MU((unsigned short) shortdata[x]); } break; case AST_FORMAT_ALAW: for (x = 0; x < len; x++) { odata[x] = AST_LIN2A((unsigned short) shortdata[x]); } break; } if (outf) { if (chan) { ast_queue_frame(chan, af); } ast_frfree(af); ast_set_flag(outf, AST_FRFLAG_FROM_DSP); return outf; } else { return af; } }
static void ast_dsp_prog_reset | ( | struct ast_dsp * | dsp | ) | [static] |
Definition at line 1518 of file dsp.c.
References ARRAY_LEN, ast_dsp::freqcount, ast_dsp::freqs, progress::freqs, goertzel_init(), ast_dsp::gsamp_size, ast_dsp::gsamps, modes, ast_dsp::progmode, ast_dsp::ringtimeout, and progress::size.
Referenced by ast_dsp_new(), and ast_dsp_set_call_progress_zone().
{ int max = 0; int x; dsp->gsamp_size = modes[dsp->progmode].size; dsp->gsamps = 0; for (x = 0; x < ARRAY_LEN(modes[dsp->progmode].freqs); x++) { if (modes[dsp->progmode].freqs[x]) { goertzel_init(&dsp->freqs[x], (float)modes[dsp->progmode].freqs[x], dsp->gsamp_size); max = x + 1; } } dsp->freqcount = max; dsp->ringtimeout= 0; }
int ast_dsp_reload | ( | void | ) |
Reloads dsp settings from dsp.conf.
Definition at line 1739 of file dsp.c.
References _dsp_init().
{ return _dsp_init(1); }
void ast_dsp_reset | ( | struct ast_dsp * | dsp | ) |
Reset total silence count.
Definition at line 1630 of file dsp.c.
References ast_dsp::freqs, ast_dsp::gsamps, ast_dsp::historicnoise, ast_dsp::historicsilence, ast_dsp::ringtimeout, ast_dsp::totalsilence, goertzel_state_t::v2, and goertzel_state_t::v3.
{ int x; dsp->totalsilence = 0; dsp->gsamps = 0; for (x = 0; x < 4; x++) { dsp->freqs[x].v2 = dsp->freqs[x].v3 = 0.0; } memset(dsp->historicsilence, 0, sizeof(dsp->historicsilence)); memset(dsp->historicnoise, 0, sizeof(dsp->historicnoise)); dsp->ringtimeout= 0; }
void ast_dsp_set_busy_count | ( | struct ast_dsp * | dsp, |
int | cadences | ||
) |
Set number of required cadences for busy.
Definition at line 1581 of file dsp.c.
References ast_dsp::busycount, cadences, and DSP_HISTORY.
Referenced by dahdi_new().
{ if (cadences < 4) { cadences = 4; } if (cadences > DSP_HISTORY) { cadences = DSP_HISTORY; } dsp->busycount = cadences; }
void ast_dsp_set_busy_pattern | ( | struct ast_dsp * | dsp, |
int | tonelength, | ||
int | quietlength | ||
) |
Set expected lengths of the busy tone.
Definition at line 1592 of file dsp.c.
References ast_debug, ast_dsp::busy_quietlength, and ast_dsp::busy_tonelength.
Referenced by dahdi_new().
{ dsp->busy_tonelength = tonelength; dsp->busy_quietlength = quietlength; ast_debug(1, "dsp busy pattern set to %d,%d\n", tonelength, quietlength); }
int ast_dsp_set_call_progress_zone | ( | struct ast_dsp * | dsp, |
char * | zone | ||
) |
Set zone for doing progress detection.
Definition at line 1668 of file dsp.c.
References aliases, ARRAY_LEN, ast_dsp_prog_reset(), progalias::mode, name, and ast_dsp::progmode.
Referenced by dahdi_new().
int ast_dsp_set_digitmode | ( | struct ast_dsp * | dsp, |
int | digitmode | ||
) |
Set digit mode.
Definition at line 1644 of file dsp.c.
References ast_digit_detect_init(), ast_dsp::digit_state, ast_dsp::digitmode, DSP_DIGITMODE_DTMF, DSP_DIGITMODE_MF, DSP_DIGITMODE_MUTECONF, and DSP_DIGITMODE_MUTEMAX.
Referenced by dahdi_hangup(), dahdi_new(), dahdi_setoption(), mgcp_new(), mkintf(), sip_new(), ss_thread(), and store_config().
{ int new; int old; old = dsp->digitmode & (DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX); new = digitmode & (DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_MUTEMAX); if (old != new) { /* Must initialize structures if switching from MF to DTMF or vice-versa */ ast_digit_detect_init(&dsp->digit_state, new & DSP_DIGITMODE_MF); } dsp->digitmode = digitmode; return 0; }
int ast_dsp_set_faxmode | ( | struct ast_dsp * | dsp, |
int | faxmode | ||
) |
Set fax mode.
Definition at line 1659 of file dsp.c.
References ast_fax_detect_init(), and ast_dsp::faxmode.
{ if (dsp->faxmode != faxmode) { ast_fax_detect_init(dsp); } dsp->faxmode = faxmode; return 0; }
void ast_dsp_set_features | ( | struct ast_dsp * | dsp, |
int | features | ||
) |
Select feature set.
Definition at line 1556 of file dsp.c.
References ast_dsp::features.
Referenced by __oh323_new(), dahdi_new(), dahdi_read(), disable_dtmf_detect(), enable_dtmf_detect(), mgcp_new(), misdn_set_opt_exec(), read_config(), sip_dtmfmode(), sip_new(), sip_rtp_read(), and store_config().
{ dsp->features = features; }
void ast_dsp_set_threshold | ( | struct ast_dsp * | dsp, |
int | threshold | ||
) |
Set threshold value for silence.
Definition at line 1576 of file dsp.c.
References ast_dsp::threshold.
Referenced by __ast_play_and_record(), do_waiting(), handle_recordfile(), isAnsweringMachine(), and record_exec().
Return non-zero if this is silence. Updates "totalsilence" with the total number of seconds of silence.
Definition at line 1282 of file dsp.c.
References __ast_dsp_silence_noise(), AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_log(), ast_frame::data, ast_frame::datalen, ast_frame::frametype, len(), LOG_WARNING, ast_frame::ptr, s, and ast_frame::subclass.
Referenced by __ast_play_and_record(), background_detect_exec(), conf_run(), do_waiting(), handle_recordfile(), isAnsweringMachine(), and record_exec().
{ short *s; int len; if (f->frametype != AST_FRAME_VOICE) { ast_log(LOG_WARNING, "Can't calculate silence on a non-voice frame\n"); return 0; } if (f->subclass != AST_FORMAT_SLINEAR) { ast_log(LOG_WARNING, "Can only calculate silence on signed-linear frames :(\n"); return 0; } s = f->data.ptr; len = f->datalen/2; return __ast_dsp_silence_noise(dsp, s, len, totalsilence, NULL); }
int ast_dsp_was_muted | ( | struct ast_dsp * | dsp | ) |
Returns true if DSP code was muting any fragment of the last processed frame. Muting (squelching) happens when DSP code removes DTMF/MF/generic tones from the audio.
Definition at line 1682 of file dsp.c.
References ast_dsp::mute_fragments.
Referenced by dahdi_read().
{ return (dsp->mute_fragments > 0); }
static void ast_dtmf_detect_init | ( | dtmf_detect_state_t * | s | ) | [static] |
Definition at line 488 of file dsp.c.
References dtmf_detect_state_t::col_out, dtmf_detect_state_t::current_hit, dtmf_detect_state_t::current_sample, DTMF_GSIZE, DTMF_HITS_TO_BEGIN, DTMF_MISSES_TO_END, dtmf_detect_state_t::energy, goertzel_init(), dtmf_detect_state_t::hits, dtmf_detect_state_t::hits_to_begin, dtmf_detect_state_t::lasthit, dtmf_detect_state_t::misses, dtmf_detect_state_t::misses_to_end, and dtmf_detect_state_t::row_out.
Referenced by ast_digit_detect_init().
{ int i; s->lasthit = 0; s->current_hit = 0; for (i = 0; i < 4; i++) { goertzel_init(&s->row_out[i], dtmf_row[i], DTMF_GSIZE); goertzel_init(&s->col_out[i], dtmf_col[i], DTMF_GSIZE); s->energy = 0.0; } s->current_sample = 0; s->hits = 0; s->misses = 0; s->hits_to_begin = DTMF_HITS_TO_BEGIN; s->misses_to_end = DTMF_MISSES_TO_END; }
static void ast_fax_detect_init | ( | struct ast_dsp * | s | ) | [static] |
Definition at line 482 of file dsp.c.
References ast_tone_detect_init(), ast_dsp::ced_tone_state, ast_dsp::cng_tone_state, FAX_TONE_CED_DB, FAX_TONE_CED_DURATION, FAX_TONE_CED_FREQ, FAX_TONE_CNG_DB, FAX_TONE_CNG_DURATION, and FAX_TONE_CNG_FREQ.
Referenced by ast_dsp_new(), and ast_dsp_set_faxmode().
static void ast_mf_detect_init | ( | mf_detect_state_t * | s | ) | [static] |
Definition at line 507 of file dsp.c.
References mf_detect_state_t::current_hit, mf_detect_state_t::current_sample, goertzel_init(), mf_detect_state_t::hits, and mf_detect_state_t::tone_out.
Referenced by ast_digit_detect_init().
{ int i; s->hits[0] = s->hits[1] = s->hits[2] = s->hits[3] = s->hits[4] = 0; for (i = 0; i < 6; i++) { goertzel_init (&s->tone_out[i], mf_tones[i], 160); } s->current_sample = 0; s->current_hit = 0; }
static void ast_tone_detect_init | ( | tone_detect_state_t * | s, |
int | freq, | ||
int | duration, | ||
int | amp | ||
) | [static] |
Definition at line 422 of file dsp.c.
References ast_debug, tone_detect_state_t::block_size, tone_detect_state_t::energy, tone_detect_state_t::freq, goertzel_init(), tone_detect_state_t::hit_count, tone_detect_state_t::hits_required, tone_detect_state_t::last_hit, SAMPLE_RATE, SAMPLES_IN_FRAME, tone_detect_state_t::samples_pending, tone_detect_state_t::squelch, tone_detect_state_t::threshold, and tone_detect_state_t::tone.
Referenced by ast_fax_detect_init().
{ int duration_samples; float x; int periods_in_block; s->freq = freq; /* Desired tone duration in samples */ duration_samples = duration * SAMPLE_RATE / 1000; /* We want to allow 10% deviation of tone duration */ duration_samples = duration_samples * 9 / 10; /* 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 */ s->block_size = SAMPLES_IN_FRAME; periods_in_block = s->block_size * freq / 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) 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; /* tone_detect is currently only used to detect fax tones and we do not need suqlching the fax tones */ s->squelch = 0; /* Account for the first and the last block to be incomplete and thus no tone will be detected in them */ s->hits_required = (duration_samples - (s->block_size - 1)) / s->block_size; goertzel_init(&s->tone, freq, s->block_size); s->samples_pending = s->block_size; s->hit_count = 0; s->last_hit = 0; s->energy = 0.0; /* We want tone energy to be amp decibels above the rest of the signal (the noise). According to Parseval's theorem the energy computed in time domain equals to energy computed in frequency domain. So subtracting energy in the frequency domain (Goertzel result) from the energy in the time domain we will get energy of the remaining signal (without the tone we are detecting). We will be checking that 10*log(Ew / (Et - Ew)) > amp Calculate threshold so that we will be actually checking Ew > Et * threshold */ x = pow(10.0, amp / 10.0); s->threshold = x / (x + 1); ast_debug(1, "Setup tone %d Hz, %d ms, block_size=%d, hits_required=%d\n", freq, duration, s->block_size, s->hits_required); }
static int dtmf_detect | ( | struct ast_dsp * | dsp, |
digit_detect_state_t * | s, | ||
int16_t | amp[], | ||
int | samples, | ||
int | squelch, | ||
int | relax | ||
) | [static] |
Definition at line 649 of file dsp.c.
References dtmf_detect_state_t::col_out, digit_detect_state_t::current_digits, dtmf_detect_state_t::current_hit, dtmf_detect_state_t::current_sample, digit_detect_state_t::digitlen, digit_detect_state_t::dtmf, DTMF_GSIZE, DTMF_NORMAL_TWIST, DTMF_RELATIVE_PEAK_COL, DTMF_RELATIVE_PEAK_ROW, DTMF_REVERSE_TWIST, DTMF_THRESHOLD, DTMF_TO_TOTAL_ENERGY, fragment_t::end, dtmf_detect_state_t::energy, goertzel_reset(), goertzel_result(), goertzel_sample(), dtmf_detect_state_t::hits, dtmf_detect_state_t::hits_to_begin, dtmf_detect_state_t::lasthit, dtmf_detect_state_t::misses, dtmf_detect_state_t::misses_to_end, mute_fragment(), dtmf_detect_state_t::mute_samples, dtmf_detect_state_t::row_out, ast_frame::samples, fragment_t::start, store_digit(), and digit_detect_state_t::td.
Referenced by ast_dsp_process().
{ float row_energy[4]; float col_energy[4]; float famp; int i; int j; int sample; int best_row; int best_col; int hit; int limit; fragment_t mute = {0, 0}; if (squelch && s->td.dtmf.mute_samples > 0) { mute.end = (s->td.dtmf.mute_samples < samples) ? s->td.dtmf.mute_samples : samples; s->td.dtmf.mute_samples -= mute.end; } hit = 0; for (sample = 0; sample < samples; sample = limit) { /* DTMF_GSIZE is optimised to meet the DTMF specs. */ if ((samples - sample) >= (DTMF_GSIZE - s->td.dtmf.current_sample)) { limit = sample + (DTMF_GSIZE - s->td.dtmf.current_sample); } else { limit = samples; } /* The following unrolled loop takes only 35% (rough estimate) of the time of a rolled loop on the machine on which it was developed */ for (j = sample; j < limit; j++) { famp = amp[j]; s->td.dtmf.energy += famp*famp; /* With GCC 2.95, the following unrolled code seems to take about 35% (rough estimate) as long as a neat little 0-3 loop */ goertzel_sample(s->td.dtmf.row_out, amp[j]); goertzel_sample(s->td.dtmf.col_out, amp[j]); goertzel_sample(s->td.dtmf.row_out + 1, amp[j]); goertzel_sample(s->td.dtmf.col_out + 1, amp[j]); goertzel_sample(s->td.dtmf.row_out + 2, amp[j]); goertzel_sample(s->td.dtmf.col_out + 2, amp[j]); goertzel_sample(s->td.dtmf.row_out + 3, amp[j]); goertzel_sample(s->td.dtmf.col_out + 3, amp[j]); } s->td.dtmf.current_sample += (limit - sample); if (s->td.dtmf.current_sample < DTMF_GSIZE) { continue; } /* We are at the end of a DTMF detection block */ /* Find the peak row and the peak column */ row_energy[0] = goertzel_result (&s->td.dtmf.row_out[0]); col_energy[0] = goertzel_result (&s->td.dtmf.col_out[0]); for (best_row = best_col = 0, i = 1; i < 4; i++) { row_energy[i] = goertzel_result (&s->td.dtmf.row_out[i]); if (row_energy[i] > row_energy[best_row]) { best_row = i; } col_energy[i] = goertzel_result (&s->td.dtmf.col_out[i]); if (col_energy[i] > col_energy[best_col]) { best_col = i; } } hit = 0; /* Basic signal level test and the twist test */ if (row_energy[best_row] >= DTMF_THRESHOLD && col_energy[best_col] >= DTMF_THRESHOLD && col_energy[best_col] < row_energy[best_row] * DTMF_REVERSE_TWIST && col_energy[best_col] * DTMF_NORMAL_TWIST > row_energy[best_row]) { /* Relative peak test */ for (i = 0; i < 4; i++) { if ((i != best_col && col_energy[i] * DTMF_RELATIVE_PEAK_COL > col_energy[best_col]) || (i != best_row && row_energy[i] * DTMF_RELATIVE_PEAK_ROW > row_energy[best_row])) { break; } } /* ... and fraction of total energy test */ if (i >= 4 && (row_energy[best_row] + col_energy[best_col]) > DTMF_TO_TOTAL_ENERGY * s->td.dtmf.energy) { /* Got a hit */ hit = dtmf_positions[(best_row << 2) + best_col]; } } 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; } } 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) { s->td.dtmf.hits++; } else { s->td.dtmf.hits = 1; } 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.lasthit = hit; /* If we had a hit in this block, include it into mute fragment */ if (squelch && hit) { if (mute.end < sample - DTMF_GSIZE) { /* There is a gap between fragments */ mute_fragment(dsp, &mute); mute.start = (sample > DTMF_GSIZE) ? (sample - DTMF_GSIZE) : 0; } mute.end = limit + DTMF_GSIZE; } /* Reinitialise the detector for the next block */ for (i = 0; i < 4; i++) { goertzel_reset(&s->td.dtmf.row_out[i]); goertzel_reset(&s->td.dtmf.col_out[i]); } s->td.dtmf.energy = 0.0; s->td.dtmf.current_sample = 0; } if (squelch && mute.end) { if (mute.end > samples) { s->td.dtmf.mute_samples = mute.end - samples; mute.end = samples; } mute_fragment(dsp, &mute); } return (s->td.dtmf.current_hit); /* return the debounced hit */ }
static void goertzel_init | ( | goertzel_state_t * | s, |
float | freq, | ||
int | samples | ||
) | [inline, static] |
Definition at line 349 of file dsp.c.
References goertzel_state_t::chunky, cos, goertzel_state_t::fac, SAMPLE_RATE, goertzel_state_t::samples, goertzel_state_t::v2, and goertzel_state_t::v3.
Referenced by ast_dsp_prog_reset(), ast_dtmf_detect_init(), ast_mf_detect_init(), and ast_tone_detect_init().
static void goertzel_reset | ( | goertzel_state_t * | s | ) | [inline, static] |
Definition at line 356 of file dsp.c.
References goertzel_state_t::chunky, goertzel_state_t::v2, and goertzel_state_t::v3.
Referenced by ast_dsp_digitreset(), dtmf_detect(), mf_detect(), and tone_detect().
static float goertzel_result | ( | goertzel_state_t * | s | ) | [inline, static] |
Definition at line 340 of file dsp.c.
References goertzel_state_t::chunky, goertzel_state_t::fac, goertzel_result_t::power, goertzel_state_t::v2, goertzel_state_t::v3, and goertzel_result_t::value.
Referenced by __ast_dsp_call_progress(), dtmf_detect(), mf_detect(), and tone_detect().
static void goertzel_sample | ( | goertzel_state_t * | s, |
short | sample | ||
) | [inline, static] |
Definition at line 313 of file dsp.c.
References goertzel_state_t::chunky, goertzel_state_t::fac, goertzel_state_t::v2, and goertzel_state_t::v3.
Referenced by __ast_dsp_call_progress(), dtmf_detect(), goertzel_update(), mf_detect(), and tone_detect().
static void goertzel_update | ( | goertzel_state_t * | s, |
short * | samps, | ||
int | count | ||
) | [inline, static] |
Definition at line 330 of file dsp.c.
References goertzel_sample().
{ int i; for (i = 0; i < count; i++) { goertzel_sample(s, samps[i]); } }
static int mf_detect | ( | struct ast_dsp * | dsp, |
digit_detect_state_t * | s, | ||
int16_t | amp[], | ||
int | samples, | ||
int | squelch, | ||
int | relax | ||
) | [static] |
Definition at line 800 of file dsp.c.
References BELL_MF_RELATIVE_PEAK, BELL_MF_THRESHOLD, BELL_MF_TWIST, mf_detect_state_t::current_hit, mf_detect_state_t::current_sample, DTMF_GSIZE, fragment_t::end, goertzel_reset(), goertzel_result(), goertzel_sample(), mf_detect_state_t::hits, digit_detect_state_t::mf, MF_GSIZE, mute_fragment(), mf_detect_state_t::mute_samples, ast_frame::samples, fragment_t::start, store_digit(), digit_detect_state_t::td, and mf_detect_state_t::tone_out.
Referenced by ast_dsp_process().
{ float energy[6]; int best; int second_best; float famp; int i; int j; int sample; int hit; int limit; fragment_t mute = {0, 0}; if (squelch && s->td.mf.mute_samples > 0) { mute.end = (s->td.mf.mute_samples < samples) ? s->td.mf.mute_samples : samples; s->td.mf.mute_samples -= mute.end; } hit = 0; for (sample = 0; sample < samples; sample = limit) { /* 80 is optimised to meet the MF specs. */ /* XXX So then why is MF_GSIZE defined as 120? */ if ((samples - sample) >= (MF_GSIZE - s->td.mf.current_sample)) { limit = sample + (MF_GSIZE - s->td.mf.current_sample); } else { limit = samples; } /* The following unrolled loop takes only 35% (rough estimate) of the time of a rolled loop on the machine on which it was developed */ for (j = sample; j < limit; j++) { famp = amp[j]; /* With GCC 2.95, the following unrolled code seems to take about 35% (rough estimate) as long as a neat little 0-3 loop */ goertzel_sample(s->td.mf.tone_out, amp[j]); goertzel_sample(s->td.mf.tone_out + 1, amp[j]); goertzel_sample(s->td.mf.tone_out + 2, amp[j]); goertzel_sample(s->td.mf.tone_out + 3, amp[j]); goertzel_sample(s->td.mf.tone_out + 4, amp[j]); goertzel_sample(s->td.mf.tone_out + 5, amp[j]); } s->td.mf.current_sample += (limit - sample); if (s->td.mf.current_sample < MF_GSIZE) { continue; } /* We're at the end of an MF detection block. */ /* Find the two highest energies. The spec says to look for two tones and two tones only. Taking this literally -ie only two tones pass the minimum threshold - doesn't work well. The sinc function mess, due to rectangular windowing ensure that! Find the two highest energies and ensure they are considerably stronger than any of the others. */ energy[0] = goertzel_result(&s->td.mf.tone_out[0]); energy[1] = goertzel_result(&s->td.mf.tone_out[1]); if (energy[0] > energy[1]) { best = 0; second_best = 1; } else { best = 1; second_best = 0; } /*endif*/ for (i = 2; i < 6; i++) { energy[i] = goertzel_result(&s->td.mf.tone_out[i]); if (energy[i] >= energy[best]) { second_best = best; best = i; } else if (energy[i] >= energy[second_best]) { second_best = i; } } /* 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]) { /* Relative peak test */ hit = -1; for (i = 0; i < 6; i++) { if (i != best && i != second_best) { if (energy[i]*BELL_MF_RELATIVE_PEAK >= energy[second_best]) { /* The best two are not clearly the best */ hit = 0; break; } } } } if (hit) { /* Get the values into ascending order */ if (second_best < best) { i = best; best = second_best; second_best = i; } best = best * 5 + second_best - 1; hit = bell_mf_positions[best]; /* Look for two successive similar results */ /* The logic in the next test is: For KP we need 4 successive identical clean detects, with two blocks of something different preceeding it. For anything else we need two successive identical clean detects, with two blocks of something different preceeding it. */ if (hit == s->td.mf.hits[4] && hit == s->td.mf.hits[3] && ((hit != '*' && hit != s->td.mf.hits[2] && hit != s->td.mf.hits[1])|| (hit == '*' && hit == s->td.mf.hits[2] && hit != s->td.mf.hits[1] && hit != s->td.mf.hits[0]))) { store_digit(s, hit); } } if (hit != s->td.mf.hits[4] && hit != s->td.mf.hits[3]) { /* Two successive block without a hit terminate current digit */ s->td.mf.current_hit = 0; } s->td.mf.hits[0] = s->td.mf.hits[1]; s->td.mf.hits[1] = s->td.mf.hits[2]; s->td.mf.hits[2] = s->td.mf.hits[3]; s->td.mf.hits[3] = s->td.mf.hits[4]; s->td.mf.hits[4] = hit; /* If we had a hit in this block, include it into mute fragment */ if (squelch && hit) { if (mute.end < sample - MF_GSIZE) { /* There is a gap between fragments */ mute_fragment(dsp, &mute); mute.start = (sample > MF_GSIZE) ? (sample - MF_GSIZE) : 0; } mute.end = limit + DTMF_GSIZE; } /* Reinitialise the detector for the next block */ for (i = 0; i < 6; i++) goertzel_reset(&s->td.mf.tone_out[i]); s->td.mf.current_sample = 0; } if (squelch && mute.end) { if (mute.end > samples) { s->td.mf.mute_samples = mute.end - samples; mute.end = samples; } mute_fragment(dsp, &mute); } return (s->td.mf.current_hit); /* return the debounced hit */ }
static void mute_fragment | ( | struct ast_dsp * | dsp, |
fragment_t * | fragment | ||
) | [static] |
Definition at line 412 of file dsp.c.
References ARRAY_LEN, ast_log(), LOG_ERROR, ast_dsp::mute_data, and ast_dsp::mute_fragments.
Referenced by dtmf_detect(), mf_detect(), and tone_detect().
{ if (dsp->mute_fragments >= ARRAY_LEN(dsp->mute_data)) { ast_log(LOG_ERROR, "Too many fragments to mute. Ignoring\n"); return; } dsp->mute_data[dsp->mute_fragments++] = *fragment; }
static int pair_there | ( | float | p1, |
float | p2, | ||
float | i1, | ||
float | i2, | ||
float | e | ||
) | [inline, static] |
Definition at line 950 of file dsp.c.
References TONE_MIN_THRESH, and TONE_THRESH.
Referenced by __ast_dsp_call_progress().
{ /* See if p1 and p2 are there, relative to i1 and i2 and total energy */ /* Make sure absolute levels are high enough */ if ((p1 < TONE_MIN_THRESH) || (p2 < TONE_MIN_THRESH)) { return 0; } /* Amplify ignored stuff */ i2 *= TONE_THRESH; i1 *= TONE_THRESH; e *= TONE_THRESH; /* Check first tone */ if ((p1 < i1) || (p1 < i2) || (p1 < e)) { return 0; } /* And second */ if ((p2 < i1) || (p2 < i2) || (p2 < e)) { return 0; } /* Guess it's there... */ return 1; }
static void store_digit | ( | digit_detect_state_t * | s, |
char | digit | ||
) | [static] |
Definition at line 636 of file dsp.c.
References ast_log(), digit_detect_state_t::current_digits, digit_detect_state_t::detected_digits, digit_detect_state_t::digitlen, digit_detect_state_t::digits, LOG_WARNING, digit_detect_state_t::lost_digits, and MAX_DTMF_DIGITS.
Referenced by dtmf_detect(), and mf_detect().
{ s->detected_digits++; if (s->current_digits < MAX_DTMF_DIGITS) { s->digitlen[s->current_digits] = 0; s->digits[s->current_digits++] = digit; s->digits[s->current_digits] = '\0'; } else { ast_log(LOG_WARNING, "Digit lost due to full buffer\n"); s->lost_digits++; } }
static int tone_detect | ( | struct ast_dsp * | dsp, |
tone_detect_state_t * | s, | ||
int16_t * | amp, | ||
int | samples | ||
) | [static] |
Definition at line 532 of file dsp.c.
References ast_debug, tone_detect_state_t::block_size, fragment_t::end, tone_detect_state_t::energy, tone_detect_state_t::freq, goertzel_reset(), goertzel_result(), goertzel_sample(), tone_detect_state_t::hit_count, tone_detect_state_t::hits_required, tone_detect_state_t::last_hit, mute_fragment(), tone_detect_state_t::mute_samples, ast_frame::ptr, ast_frame::samples, tone_detect_state_t::samples_pending, tone_detect_state_t::squelch, fragment_t::start, tone_detect_state_t::threshold, and tone_detect_state_t::tone.
Referenced by ast_dsp_process().
{ float tone_energy; int i; int hit = 0; int limit; int res = 0; int16_t *ptr; int start, end; fragment_t mute = {0, 0}; if (s->squelch && s->mute_samples > 0) { mute.end = (s->mute_samples < samples) ? s->mute_samples : samples; s->mute_samples -= mute.end; } for (start = 0; start < samples; start = end) { /* Process in blocks. */ limit = samples - start; if (limit > s->samples_pending) { limit = s->samples_pending; } end = start + limit; for (i = limit, ptr = amp ; i > 0; i--, ptr++) { /* signed 32 bit int should be enough to suqare any possible signed 16 bit value */ s->energy += (int32_t) *ptr * (int32_t) *ptr; goertzel_sample(&s->tone, *ptr); } s->samples_pending -= limit; if (s->samples_pending) { /* Finished incomplete (last) block */ break; } tone_energy = goertzel_result(&s->tone); /* Scale to make comparable */ tone_energy *= 2.0; s->energy *= s->block_size; ast_debug(10, "tone %d, Ew=%.2E, Et=%.2E, s/n=%10.2f\n", s->freq, tone_energy, s->energy, tone_energy / (s->energy - tone_energy)); hit = 0; if (tone_energy > s->energy * s->threshold) { ast_debug(10, "Hit! count=%d\n", s->hit_count); hit = 1; } if (s->hit_count) { s->hit_count++; } if (hit == s->last_hit) { if (!hit) { /* Two successive misses. Tone ended */ s->hit_count = 0; } else if (!s->hit_count) { s->hit_count++; } } if (s->hit_count == s->hits_required) { ast_debug(1, "%d Hz done detected\n", s->freq); res = 1; } s->last_hit = hit; /* If we had a hit in this block, include it into mute fragment */ if (s->squelch && hit) { if (mute.end < start - s->block_size) { /* There is a gap between fragments */ mute_fragment(dsp, &mute); mute.start = (start > s->block_size) ? (start - s->block_size) : 0; } mute.end = end + s->block_size; } /* Reinitialise the detector for the next block */ /* Reset for the next block */ goertzel_reset(&s->tone); /* Advance to the next block */ s->energy = 0.0; s->samples_pending = s->block_size; amp += limit; } if (s->squelch && mute.end) { if (mute.end > samples) { s->mute_samples = mute.end - samples; mute.end = samples; } mute_fragment(dsp, &mute); } return res; }
Referenced by ast_dsp_set_call_progress_zone(), and find_alias().
char bell_mf_positions[] = "1247C-358A--69*---0B----#" [static] |
const int DEFAULT_SILENCE_THRESHOLD = 256 [static] |
The default silence threshold we will use if an alternate configured value is not present or is invalid.
Definition at line 220 of file dsp.c.
Referenced by _dsp_init().
float dtmf_col[] [static] |
char dtmf_positions[] = "*0#D" [static] |
float dtmf_row[] [static] |
float mf_tones[] [static] |
Referenced by ast_dsp_prog_reset(), and setrem().
int thresholds[THRESHOLD_MAX] [static] |