Asterisk - The Open Source Telephony Project
21.4.1
|
Convenience Signal Processing routines. More...
#include "asterisk.h"
#include <math.h>
#include "asterisk/module.h"
#include "asterisk/frame.h"
#include "asterisk/format_cache.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"
#include "asterisk/test.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 |
Macros | |
#define | BELL_MF_RELATIVE_PEAK 12.6 /* 11dB */ |
#define | BELL_MF_THRESHOLD 1.6e9 |
#define | BELL_MF_TWIST 4.0 /* 6dB */ |
#define | CONFIG_FILE_NAME "dsp.conf" |
#define | DEF_DTMF_HITS_TO_BEGIN 2 |
#define | DEF_DTMF_MISSES_TO_END 3 |
#define | DEF_DTMF_NORMAL_TWIST 6.31 /* 8.0dB */ |
#define | DEF_DTMF_REVERSE_TWIST 2.51 /* 4.01dB */ |
#define | DEF_RELAX_DTMF_NORMAL_TWIST 6.31 /* 8.0dB */ |
#define | DEF_RELAX_DTMF_REVERSE_TWIST 3.98 /* 6.0dB */ |
#define | DEFAULT_SAMPLE_RATE 8000 |
#define | DEFAULT_THRESHOLD 512 |
Default minimum average magnitude threshold to determine talking/noise by the DSP. More... | |
#define | DSP_HISTORY 15 |
#define | DTMF_GSIZE 102 |
#define | DTMF_MATRIX_SIZE 4 |
#define | DTMF_RELATIVE_PEAK_COL 6.3 /* 8dB */ |
#define | DTMF_RELATIVE_PEAK_ROW 6.3 /* 8dB */ |
#define | DTMF_THRESHOLD 8.0e7 |
#define | DTMF_TO_TOTAL_ENERGY 42.0 |
#define | FAX_TONE_CED_DB 16 |
#define | FAX_TONE_CED_DURATION 2600 /* ms */ |
#define | FAX_TONE_CED_FREQ 2100 |
#define | FAX_TONE_CNG_DB 16 |
#define | FAX_TONE_CNG_DURATION 500 /* ms */ |
#define | FAX_TONE_CNG_FREQ 1100 |
#define | FREQ_ARRAY_SIZE 7 |
#define | MAX_DTMF_DIGITS 128 |
#define | MF_GSIZE 120 |
#define | TONE_MIN_THRESH 1e8 |
#define | TONE_THRESH 10.0 |
#define | TONE_THRESHOLD 7.8e7 |
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 struct ast_dsp * | __ast_dsp_new (unsigned int sample_rate) |
static int | __ast_dsp_silence_noise (struct ast_dsp *dsp, short *s, int len, int *totalsilence, int *totalnoise, int *frames_energy) |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | _dsp_init (int reload) |
static void | ast_digit_detect_init (digit_detect_state_t *s, int mf, unsigned int sample_rate) |
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_free (struct ast_dsp *dsp) |
int | ast_dsp_get_features (struct ast_dsp *dsp) |
Get features. | |
unsigned int | ast_dsp_get_sample_rate (const struct ast_dsp *dsp) |
Retrieve the sample rate this DSP structure was created with. | |
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. More... | |
int | ast_dsp_get_tstate (struct ast_dsp *dsp) |
Get tstate (Tone State) | |
struct ast_dsp * | ast_dsp_new (void) |
Allocates a new dsp, assumes 8khz for internal sample rate. | |
struct ast_dsp * | ast_dsp_new_with_rate (unsigned int sample_rate) |
Allocates a new dsp with a specific internal sample rate used during processing. | |
int | ast_dsp_noise (struct ast_dsp *dsp, struct ast_frame *f, int *totalnoise) |
Process the audio frame for noise. More... | |
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) |
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, const struct ast_dsp_busy_pattern *cadence) |
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. More... | |
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. | |
int | ast_dsp_set_freqmode (struct ast_dsp *dsp, int freq, int dur, int db, int squelch) |
Set arbitrary frequency detection mode. | |
void | ast_dsp_set_threshold (struct ast_dsp *dsp, int threshold) |
Set the minimum average magnitude threshold to determine talking by the DSP. | |
int | ast_dsp_silence (struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence) |
Process the audio frame for silence. More... | |
static int | ast_dsp_silence_noise_with_energy (struct ast_dsp *dsp, struct ast_frame *f, int *total, int *frames_energy, int noise) |
int | ast_dsp_silence_with_energy (struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence, int *frames_energy) |
Process the audio frame for silence. More... | |
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. More... | |
static void | ast_dtmf_detect_init (dtmf_detect_state_t *s, unsigned int sample_rate) |
static void | ast_fax_detect_init (struct ast_dsp *s) |
static void | ast_freq_detect_init (struct ast_dsp *s, int freq, int dur, int db, int squelch) |
static void | ast_mf_detect_init (mf_detect_state_t *s, unsigned int sample_rate) |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
static void | ast_tone_detect_init (tone_detect_state_t *s, int freq, int duration, int amp, unsigned int sample_rate) |
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, unsigned int sample_rate) |
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 int | load_module (void) |
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 int | reload_module (void) |
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) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "DSP" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "da6642af068ee5e6490c5b1d2cc1d238" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload_module, .load_pri = AST_MODPRI_CORE, .requires = "extconfig", } |
static struct progalias | aliases [] |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static const 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 const float | dtmf_col [] |
static int | dtmf_hits_to_begin |
static int | dtmf_misses_to_end |
static float | dtmf_normal_twist |
static const char | dtmf_positions [] = "123A" "456B" "789C" "*0#D" |
static float | dtmf_reverse_twist |
static const float | dtmf_row [] |
static const float | mf_tones [] |
static struct progress | modes [] |
static float | relax_dtmf_normal_twist |
static float | relax_dtmf_reverse_twist |
static int | thresholds [THRESHOLD_MAX] |
Convenience Signal Processing routines.
Definition in file dsp.c.
#define DEFAULT_THRESHOLD 512 |
Default minimum average magnitude threshold to determine talking/noise by the DSP.
The magnitude calculated for this threshold is determined by averaging the absolute value of all samples within a frame.
This value is the threshold for which a frame's average magnitude is determined to either be silence (below the threshold) or noise/talking (at or 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 work for any value between 1 and 2^15.
#define DSP_HISTORY 15 |
Remember last 15 units
Definition at line 151 of file dsp.c.
Referenced by ast_dsp_busydetect(), and ast_dsp_set_busy_count().
#define TONE_MIN_THRESH 1e8 |
#define TONE_THRESH 10.0 |
enum busy_detect |
enum freq_index |
enum gsamp_size |
Number of goertzels for progress detect
enum gsamp_thresh |
All THRESH_XXX values are in GSAMP_SIZE chunks (us = 22ms)
int ast_dsp_get_threshold_from_settings | ( | enum threshold | which | ) |
Get silence threshold from dsp.conf.
Definition at line 2009 of file dsp.c.
Referenced by ast_record_review(), load_config(), and setup_privacy_args().
Process the audio frame for noise.
dsp | DSP processing audio media. |
f | Audio frame to process. |
totalnoise | Variable to set to the total accumulated noise in ms seen by the DSP since the last silence. |
int ast_dsp_set_digitmode | ( | struct ast_dsp * | dsp, |
int | digitmode | ||
) |
Set digit mode.
Definition at line 1857 of file dsp.c.
References DSP_DIGITMODE_DTMF, DSP_DIGITMODE_MF, DSP_DIGITMODE_MUTECONF, and DSP_DIGITMODE_MUTEMAX.
Referenced by dahdi_setoption(), mbl_load_device(), mkintf(), and read_mf_digits().
Process the audio frame for silence.
dsp | DSP processing audio media. |
f | Audio frame to process. |
totalsilence | Variable to set to the total accumulated silence in ms seen by the DSP since the last noise. |
Definition at line 1488 of file dsp.c.
Referenced by __ast_play_and_record().
int ast_dsp_silence_with_energy | ( | struct ast_dsp * | dsp, |
struct ast_frame * | f, | ||
int * | totalsilence, | ||
int * | frames_energy | ||
) |
Process the audio frame for silence.
dsp | DSP processing audio media. |
f | Audio frame to process. |
totalsilence | Variable to set to the total accumulated silence in ms seen by the DSP since the last noise. |
frames_energy | Variable to set to the average energy of the samples in the frame. |
int ast_dsp_was_muted | ( | struct ast_dsp * | dsp | ) |
|
static |
|
static |
|
static |
|
static |