Asterisk - The Open Source Telephony Project GIT-master-80b953f
Loading...
Searching...
No Matches
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#define DSP_DIGITMODE_R2_FORWARD (1 << 2) /*!< Detect R2 forward signaling */
34#define DSP_DIGITMODE_R2_BACKWARD (1 << 3) /*!< Detect R2 backward signaling */
35
36#define DSP_DIGITMODE_NOQUELCH (1 << 8) /*!< Do not quelch DTMF from in-band */
37#define DSP_DIGITMODE_MUTECONF (1 << 9) /*!< Mute conference */
38#define DSP_DIGITMODE_MUTEMAX (1 << 10) /*!< Delay audio by a frame to try to extra quelch */
39#define DSP_DIGITMODE_RELAXDTMF (1 << 11) /*!< "Radio" mode (relaxed DTMF) */
40
41#define DSP_PROGRESS_TALK (1 << 16) /*!< Enable talk detection */
42#define DSP_PROGRESS_RINGING (1 << 17) /*!< Enable calling tone detection */
43#define DSP_PROGRESS_BUSY (1 << 18) /*!< Enable busy tone detection */
44#define DSP_PROGRESS_CONGESTION (1 << 19) /*!< Enable congestion tone detection */
45#define DSP_FEATURE_CALL_PROGRESS (DSP_PROGRESS_TALK | DSP_PROGRESS_RINGING | DSP_PROGRESS_BUSY | DSP_PROGRESS_CONGESTION)
46#define DSP_FEATURE_WAITDIALTONE (1 << 20) /*!< Enable dial tone detection */
47#define DSP_FEATURE_FREQ_DETECT (1 << 21) /*!< Enable arbitrary tone detection */
48
49#define DSP_FAXMODE_DETECT_CNG (1 << 0)
50#define DSP_FAXMODE_DETECT_CED (1 << 1)
51#define DSP_FAXMODE_DETECT_SQUELCH (1 << 2)
52#define DSP_FAXMODE_DETECT_ALL (DSP_FAXMODE_DETECT_CNG | DSP_FAXMODE_DETECT_CED)
53
54#define DSP_TONE_STATE_SILENCE 0
55#define DSP_TONE_STATE_RINGING 1
56#define DSP_TONE_STATE_DIALTONE 2
57#define DSP_TONE_STATE_TALKING 3
58#define DSP_TONE_STATE_BUSY 4
59#define DSP_TONE_STATE_SPECIAL1 5
60#define DSP_TONE_STATE_SPECIAL2 6
61#define DSP_TONE_STATE_SPECIAL3 7
62#define DSP_TONE_STATE_HUNGUP 8
63
64struct ast_dsp;
65
67 /*! Number of elements. */
68 int length;
69 /*! Pattern elements in on/off time durations. */
70 int pattern[4];
71};
72
74 /* Array offsets */
76 /* Always the last */
78};
79
80/*! \brief Allocates a new dsp with a specific internal sample rate used
81 * during processing. */
82struct ast_dsp *ast_dsp_new_with_rate(unsigned int sample_rate);
83
84/*! \brief Allocates a new dsp, assumes 8khz for internal sample rate */
85struct ast_dsp *ast_dsp_new(void);
86
87void ast_dsp_free(struct ast_dsp *dsp);
88
89/*! \brief Retrieve the sample rate this DSP structure was
90 * created with */
91unsigned int ast_dsp_get_sample_rate(const struct ast_dsp *dsp);
92
93/*! \brief Set the minimum average magnitude threshold to determine talking by the DSP. */
94void ast_dsp_set_threshold(struct ast_dsp *dsp, int threshold);
95
96/*! \brief Set number of required cadences for busy */
97void ast_dsp_set_busy_count(struct ast_dsp *dsp, int cadences);
98
99/*! \brief Set expected lengths of the busy tone */
100void ast_dsp_set_busy_pattern(struct ast_dsp *dsp, const struct ast_dsp_busy_pattern *cadence);
101
102/*! \brief Scans for progress indication in audio */
103int ast_dsp_call_progress(struct ast_dsp *dsp, struct ast_frame *inf);
104
105/*! \brief Set zone for doing progress detection */
106int ast_dsp_set_call_progress_zone(struct ast_dsp *dsp, char *zone);
107
108/*! \brief Return AST_FRAME_NULL frames when there is silence, AST_FRAME_BUSY on
109 busies, and call progress, all dependent upon which features are enabled */
110struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp, struct ast_frame *inf);
111
112/*!
113 * \brief Process the audio frame for silence.
114 *
115 * \param dsp DSP processing audio media.
116 * \param f Audio frame to process.
117 * \param totalsilence Variable to set to the total accumulated silence in ms
118 * seen by the DSP since the last noise.
119 *
120 * \return Non-zero if the frame is silence.
121 */
122int ast_dsp_silence(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence);
123
124/*!
125 * \brief Process the audio frame for silence.
126 *
127 * \param dsp DSP processing audio media.
128 * \param f Audio frame to process.
129 * \param totalsilence Variable to set to the total accumulated silence in ms
130 * seen by the DSP since the last noise.
131 * \param frames_energy Variable to set to the average energy of the samples in the frame.
132 *
133 * \return Non-zero if the frame is silence.
134 */
135int ast_dsp_silence_with_energy(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence, int *frames_energy);
136
137/*!
138 * \brief Process the audio frame for noise.
139 * \since 1.6.1
140 *
141 * \param dsp DSP processing audio media.
142 * \param f Audio frame to process.
143 * \param totalnoise Variable to set to the total accumulated noise in ms
144 * seen by the DSP since the last silence.
145 *
146 * \return Non-zero if the frame is silence.
147 */
148int ast_dsp_noise(struct ast_dsp *dsp, struct ast_frame *f, int *totalnoise);
149
150/*! \brief Return non-zero if historically this should be a busy, request that
151 ast_dsp_silence has already been called */
152int ast_dsp_busydetect(struct ast_dsp *dsp);
153
154/*! \brief Return non-zero if DTMF hit was found */
155int ast_dsp_digitdetect(struct ast_dsp *dsp, struct ast_frame *f);
156
157/*! \brief Reset total silence count */
158void ast_dsp_reset(struct ast_dsp *dsp);
159
160/*! \brief Reset DTMF detector */
161void ast_dsp_digitreset(struct ast_dsp *dsp);
162
163/*! \brief Select feature set */
164void ast_dsp_set_features(struct ast_dsp *dsp, int features);
165
166/*! \brief Get features */
167int ast_dsp_get_features(struct ast_dsp *dsp);
168
169/*! \brief Get pending DTMF/MF digits */
170int ast_dsp_getdigits(struct ast_dsp *dsp, char *buf, int max);
171
172/*! \brief Set digit mode
173 * \version 1.6.1 renamed from ast_dsp_digitmode to ast_dsp_set_digitmode
174 */
175int ast_dsp_set_digitmode(struct ast_dsp *dsp, int digitmode);
176
177/*! \brief Set arbitrary frequency detection mode */
178int ast_dsp_set_freqmode(struct ast_dsp *dsp, int freq, int dur, int db, int squelch);
179
180/*! \brief Set fax mode */
181int ast_dsp_set_faxmode(struct ast_dsp *dsp, int faxmode);
182
183/*!
184 * \brief Returns true if DSP code was muting any fragment of the last processed frame.
185 * Muting (squelching) happens when DSP code removes DTMF/MF/generic tones from the audio
186 * \since 1.6.1
187 */
188int ast_dsp_was_muted(struct ast_dsp *dsp);
189
190/*! \brief Get tstate (Tone State) */
191int ast_dsp_get_tstate(struct ast_dsp *dsp);
192
193/*! \brief Get tcount (Threshold counter) */
194int ast_dsp_get_tcount(struct ast_dsp *dsp);
195
196/*!
197 * \brief Get silence threshold from dsp.conf
198 * \since 1.6.1
199 */
201
202#endif /* _ASTERISK_DSP_H */
static struct dahdi_ring_cadence cadences[NUM_CADENCE_MAX]
Definition chan_dahdi.c:820
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:1973
void ast_dsp_free(struct ast_dsp *dsp)
Definition dsp.c:1968
int ast_dsp_get_tcount(struct ast_dsp *dsp)
Get tcount (Threshold counter)
Definition dsp.c:2103
threshold
Definition dsp.h:73
@ THRESHOLD_SILENCE
Definition dsp.h:75
@ THRESHOLD_MAX
Definition dsp.h:77
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:1672
void ast_dsp_digitreset(struct ast_dsp *dsp)
Reset DTMF detector.
Definition dsp.c:1995
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:1948
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:1667
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:1403
void ast_dsp_reset(struct ast_dsp *dsp)
Reset total silence count.
Definition dsp.c:2028
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:1989
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:1915
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:1683
int ast_dsp_get_features(struct ast_dsp *dsp)
Get features.
Definition dsp.c:1962
int ast_dsp_set_digitmode(struct ast_dsp *dsp, int digitmode)
Set digit mode.
Definition dsp.c:2044
int ast_dsp_get_threshold_from_settings(enum threshold which)
Get silence threshold from dsp.conf.
Definition dsp.c:2196
int ast_dsp_noise(struct ast_dsp *dsp, struct ast_frame *f, int *totalnoise)
Process the audio frame for noise.
Definition dsp.c:1677
int ast_dsp_get_tstate(struct ast_dsp *dsp)
Get tstate (Tone State)
Definition dsp.c:2098
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:2093
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:1483
int ast_dsp_set_faxmode(struct ast_dsp *dsp, int faxmode)
Set fax mode.
Definition dsp.c:2070
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:2059
void ast_dsp_set_busy_count(struct ast_dsp *dsp, int cadences)
Set number of required cadences for busy.
Definition dsp.c:1978
void ast_dsp_set_features(struct ast_dsp *dsp, int features)
Select feature set.
Definition dsp.c:1953
struct ast_dsp * ast_dsp_new(void)
Allocates a new dsp, assumes 8khz for internal sample rate.
Definition dsp.c:1943
int ast_dsp_set_call_progress_zone(struct ast_dsp *dsp, char *zone)
Set zone for doing progress detection.
Definition dsp.c:2079
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:70
Definition dsp.c:421
unsigned int sample_rate
Definition dsp.c:449
Data structure associated with a single frame of data.