Asterisk - The Open Source Telephony Project GIT-master-f36a736
dsp.h
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2005, Digium, Inc.
5 *
6 * Mark Spencer <markster@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*! \file
20 * \brief Convenient Signal Processing routines
21 */
22
23#ifndef _ASTERISK_DSP_H
24#define _ASTERISK_DSP_H
25
26#define DSP_FEATURE_SILENCE_SUPPRESS (1 << 0)
27#define DSP_FEATURE_BUSY_DETECT (1 << 1)
28#define DSP_FEATURE_DIGIT_DETECT (1 << 3)
29#define DSP_FEATURE_FAX_DETECT (1 << 4)
30
31#define DSP_DIGITMODE_DTMF 0 /*!< Detect DTMF digits */
32#define DSP_DIGITMODE_MF 1 /*!< Detect MF digits */
33
34#define DSP_DIGITMODE_NOQUELCH (1 << 8) /*!< Do not quelch DTMF from in-band */
35#define DSP_DIGITMODE_MUTECONF (1 << 9) /*!< Mute conference */
36#define DSP_DIGITMODE_MUTEMAX (1 << 10) /*!< Delay audio by a frame to try to extra quelch */
37#define DSP_DIGITMODE_RELAXDTMF (1 << 11) /*!< "Radio" mode (relaxed DTMF) */
38
39#define DSP_PROGRESS_TALK (1 << 16) /*!< Enable talk detection */
40#define DSP_PROGRESS_RINGING (1 << 17) /*!< Enable calling tone detection */
41#define DSP_PROGRESS_BUSY (1 << 18) /*!< Enable busy tone detection */
42#define DSP_PROGRESS_CONGESTION (1 << 19) /*!< Enable congestion tone detection */
43#define DSP_FEATURE_CALL_PROGRESS (DSP_PROGRESS_TALK | DSP_PROGRESS_RINGING | DSP_PROGRESS_BUSY | DSP_PROGRESS_CONGESTION)
44#define DSP_FEATURE_WAITDIALTONE (1 << 20) /*!< Enable dial tone detection */
45#define DSP_FEATURE_FREQ_DETECT (1 << 21) /*!< Enable arbitrary tone detection */
46
47#define DSP_FAXMODE_DETECT_CNG (1 << 0)
48#define DSP_FAXMODE_DETECT_CED (1 << 1)
49#define DSP_FAXMODE_DETECT_SQUELCH (1 << 2)
50#define DSP_FAXMODE_DETECT_ALL (DSP_FAXMODE_DETECT_CNG | DSP_FAXMODE_DETECT_CED)
51
52#define DSP_TONE_STATE_SILENCE 0
53#define DSP_TONE_STATE_RINGING 1
54#define DSP_TONE_STATE_DIALTONE 2
55#define DSP_TONE_STATE_TALKING 3
56#define DSP_TONE_STATE_BUSY 4
57#define DSP_TONE_STATE_SPECIAL1 5
58#define DSP_TONE_STATE_SPECIAL2 6
59#define DSP_TONE_STATE_SPECIAL3 7
60#define DSP_TONE_STATE_HUNGUP 8
61
62struct ast_dsp;
63
65 /*! Number of elements. */
66 int length;
67 /*! Pattern elements in on/off time durations. */
68 int pattern[4];
69};
70
72 /* Array offsets */
74 /* Always the last */
76};
77
78/*! \brief Allocates a new dsp with a specific internal sample rate used
79 * during processing. */
80struct ast_dsp *ast_dsp_new_with_rate(unsigned int sample_rate);
81
82/*! \brief Allocates a new dsp, assumes 8khz for internal sample rate */
83struct ast_dsp *ast_dsp_new(void);
84
85void ast_dsp_free(struct ast_dsp *dsp);
86
87/*! \brief Retrieve the sample rate this DSP structure was
88 * created with */
89unsigned int ast_dsp_get_sample_rate(const struct ast_dsp *dsp);
90
91/*! \brief Set the minimum average magnitude threshold to determine talking by the DSP. */
92void ast_dsp_set_threshold(struct ast_dsp *dsp, int threshold);
93
94/*! \brief Set number of required cadences for busy */
95void ast_dsp_set_busy_count(struct ast_dsp *dsp, int cadences);
96
97/*! \brief Set expected lengths of the busy tone */
98void ast_dsp_set_busy_pattern(struct ast_dsp *dsp, const struct ast_dsp_busy_pattern *cadence);
99
100/*! \brief Scans for progress indication in audio */
101int ast_dsp_call_progress(struct ast_dsp *dsp, struct ast_frame *inf);
102
103/*! \brief Set zone for doing progress detection */
104int ast_dsp_set_call_progress_zone(struct ast_dsp *dsp, char *zone);
105
106/*! \brief Return AST_FRAME_NULL frames when there is silence, AST_FRAME_BUSY on
107 busies, and call progress, all dependent upon which features are enabled */
108struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp, struct ast_frame *inf);
109
110/*!
111 * \brief Process the audio frame for silence.
112 *
113 * \param dsp DSP processing audio media.
114 * \param f Audio frame to process.
115 * \param totalsilence Variable to set to the total accumulated silence in ms
116 * seen by the DSP since the last noise.
117 *
118 * \return Non-zero if the frame is silence.
119 */
120int ast_dsp_silence(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence);
121
122/*!
123 * \brief Process the audio frame for silence.
124 *
125 * \param dsp DSP processing audio media.
126 * \param f Audio frame to process.
127 * \param totalsilence Variable to set to the total accumulated silence in ms
128 * seen by the DSP since the last noise.
129 * \param frames_energy Variable to set to the average energy of the samples in the frame.
130 *
131 * \return Non-zero if the frame is silence.
132 */
133int ast_dsp_silence_with_energy(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence, int *frames_energy);
134
135/*!
136 * \brief Process the audio frame for noise.
137 * \since 1.6.1
138 *
139 * \param dsp DSP processing audio media.
140 * \param f Audio frame to process.
141 * \param totalnoise Variable to set to the total accumulated noise in ms
142 * seen by the DSP since the last silence.
143 *
144 * \return Non-zero if the frame is silence.
145 */
146int ast_dsp_noise(struct ast_dsp *dsp, struct ast_frame *f, int *totalnoise);
147
148/*! \brief Return non-zero if historically this should be a busy, request that
149 ast_dsp_silence has already been called */
150int ast_dsp_busydetect(struct ast_dsp *dsp);
151
152/*! \brief Return non-zero if DTMF hit was found */
153int ast_dsp_digitdetect(struct ast_dsp *dsp, struct ast_frame *f);
154
155/*! \brief Reset total silence count */
156void ast_dsp_reset(struct ast_dsp *dsp);
157
158/*! \brief Reset DTMF detector */
159void ast_dsp_digitreset(struct ast_dsp *dsp);
160
161/*! \brief Select feature set */
162void ast_dsp_set_features(struct ast_dsp *dsp, int features);
163
164/*! \brief Get features */
165int ast_dsp_get_features(struct ast_dsp *dsp);
166
167/*! \brief Get pending DTMF/MF digits */
168int ast_dsp_getdigits(struct ast_dsp *dsp, char *buf, int max);
169
170/*! \brief Set digit mode
171 * \version 1.6.1 renamed from ast_dsp_digitmode to ast_dsp_set_digitmode
172 */
173int ast_dsp_set_digitmode(struct ast_dsp *dsp, int digitmode);
174
175/*! \brief Set arbitrary frequency detection mode */
176int ast_dsp_set_freqmode(struct ast_dsp *dsp, int freq, int dur, int db, int squelch);
177
178/*! \brief Set fax mode */
179int ast_dsp_set_faxmode(struct ast_dsp *dsp, int faxmode);
180
181/*!
182 * \brief Returns true if DSP code was muting any fragment of the last processed frame.
183 * Muting (squelching) happens when DSP code removes DTMF/MF/generic tones from the audio
184 * \since 1.6.1
185 */
186int ast_dsp_was_muted(struct ast_dsp *dsp);
187
188/*! \brief Get tstate (Tone State) */
189int ast_dsp_get_tstate(struct ast_dsp *dsp);
190
191/*! \brief Get tcount (Threshold counter) */
192int ast_dsp_get_tcount(struct ast_dsp *dsp);
193
194/*!
195 * \brief Get silence threshold from dsp.conf
196 * \since 1.6.1
197 */
199
200#endif /* _ASTERISK_DSP_H */
static sqlite3 * db
static struct dahdi_ring_cadence cadences[NUM_CADENCE_MAX]
Definition: chan_dahdi.c:690
void ast_dsp_set_threshold(struct ast_dsp *dsp, int threshold)
Set the minimum average magnitude threshold to determine talking by the DSP.
Definition: dsp.c:1788
void ast_dsp_free(struct ast_dsp *dsp)
Definition: dsp.c:1783
int ast_dsp_get_tcount(struct ast_dsp *dsp)
Get tcount (Threshold counter)
Definition: dsp.c:1916
threshold
Definition: dsp.h:71
@ THRESHOLD_SILENCE
Definition: dsp.h:73
@ THRESHOLD_MAX
Definition: dsp.h:75
int ast_dsp_getdigits(struct ast_dsp *dsp, char *buf, int max)
Get pending DTMF/MF digits.
int ast_dsp_silence(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence)
Process the audio frame for silence.
Definition: dsp.c:1488
void ast_dsp_digitreset(struct ast_dsp *dsp)
Reset DTMF detector.
Definition: dsp.c:1810
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.
Definition: dsp.c:1763
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.
Definition: dsp.c:1483
int ast_dsp_digitdetect(struct ast_dsp *dsp, struct ast_frame *f)
Return non-zero if DTMF hit was found.
int ast_dsp_call_progress(struct ast_dsp *dsp, struct ast_frame *inf)
Scans for progress indication in audio.
Definition: dsp.c:1219
void ast_dsp_reset(struct ast_dsp *dsp)
Reset total silence count.
Definition: dsp.c:1843
void ast_dsp_set_busy_pattern(struct ast_dsp *dsp, const struct ast_dsp_busy_pattern *cadence)
Set expected lengths of the busy tone.
Definition: dsp.c:1804
unsigned int ast_dsp_get_sample_rate(const struct ast_dsp *dsp)
Retrieve the sample rate this DSP structure was created with.
Definition: dsp.c:1730
struct ast_frame * ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp, struct ast_frame *inf)
Return AST_FRAME_NULL frames when there is silence, AST_FRAME_BUSY on busies, and call progress,...
Definition: dsp.c:1499
int ast_dsp_get_features(struct ast_dsp *dsp)
Get features.
Definition: dsp.c:1777
int ast_dsp_set_digitmode(struct ast_dsp *dsp, int digitmode)
Set digit mode.
Definition: dsp.c:1857
int ast_dsp_get_threshold_from_settings(enum threshold which)
Get silence threshold from dsp.conf.
Definition: dsp.c:2009
int ast_dsp_noise(struct ast_dsp *dsp, struct ast_frame *f, int *totalnoise)
Process the audio frame for noise.
Definition: dsp.c:1493
int ast_dsp_get_tstate(struct ast_dsp *dsp)
Get tstate (Tone State)
Definition: dsp.c:1911
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) hap...
Definition: dsp.c:1906
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 ...
Definition: dsp.c:1299
int ast_dsp_set_faxmode(struct ast_dsp *dsp, int faxmode)
Set fax mode.
Definition: dsp.c:1883
int ast_dsp_set_freqmode(struct ast_dsp *dsp, int freq, int dur, int db, int squelch)
Set arbitrary frequency detection mode.
Definition: dsp.c:1872
void ast_dsp_set_busy_count(struct ast_dsp *dsp, int cadences)
Set number of required cadences for busy.
Definition: dsp.c:1793
void ast_dsp_set_features(struct ast_dsp *dsp, int features)
Select feature set.
Definition: dsp.c:1768
struct ast_dsp * ast_dsp_new(void)
Allocates a new dsp, assumes 8khz for internal sample rate.
Definition: dsp.c:1758
int ast_dsp_set_call_progress_zone(struct ast_dsp *dsp, char *zone)
Set zone for doing progress detection.
Definition: dsp.c:1892
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define max(a, b)
Definition: f2c.h:198
Main Channel structure associated with a channel.
int pattern[4]
Definition: dsp.h:68
Definition: dsp.c:407
unsigned int sample_rate
Definition: dsp.c:435
Data structure associated with a single frame of data.