Asterisk - The Open Source Telephony Project  18.5.0
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 <[email protected]>
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 
62 struct ast_dsp;
63 
65  /*! Number of elements. */
66  int length;
67  /*! Pattern elements in on/off time durations. */
68  int pattern[4];
69 };
70 
71 enum threshold {
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. */
80 struct ast_dsp *ast_dsp_new_with_rate(unsigned int sample_rate);
81 
82 /*! \brief Allocates a new dsp, assumes 8khz for internal sample rate */
83 struct ast_dsp *ast_dsp_new(void);
84 
85 void ast_dsp_free(struct ast_dsp *dsp);
86 
87 /*! \brief Retrieve the sample rate this DSP structure was
88  * created with */
89 unsigned 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. */
92 void ast_dsp_set_threshold(struct ast_dsp *dsp, int threshold);
93 
94 /*! \brief Set number of required cadences for busy */
95 void ast_dsp_set_busy_count(struct ast_dsp *dsp, int cadences);
96 
97 /*! \brief Set expected lengths of the busy tone */
98 void 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 */
101 int ast_dsp_call_progress(struct ast_dsp *dsp, struct ast_frame *inf);
102 
103 /*! \brief Set zone for doing progress detection */
104 int 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 */
108 struct 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  */
120 int 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  */
133 int 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  */
146 int 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 */
150 int ast_dsp_busydetect(struct ast_dsp *dsp);
151 
152 /*! \brief Return non-zero if DTMF hit was found */
153 int ast_dsp_digitdetect(struct ast_dsp *dsp, struct ast_frame *f);
154 
155 /*! \brief Reset total silence count */
156 void ast_dsp_reset(struct ast_dsp *dsp);
157 
158 /*! \brief Reset DTMF detector */
159 void ast_dsp_digitreset(struct ast_dsp *dsp);
160 
161 /*! \brief Select feature set */
162 void ast_dsp_set_features(struct ast_dsp *dsp, int features);
163 
164 /*! \brief Get features */
165 int ast_dsp_get_features(struct ast_dsp *dsp);
166 
167 /*! \brief Get pending DTMF/MF digits */
168 int 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  */
173 int ast_dsp_set_digitmode(struct ast_dsp *dsp, int digitmode);
174 
175 /*! \brief Set arbitrary frequency detection mode */
176 int ast_dsp_set_freqmode(struct ast_dsp *dsp, int freq1, int dur, int db, int squelch);
177 
178 /*! \brief Set fax mode */
179 int 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  */
186 int ast_dsp_was_muted(struct ast_dsp *dsp);
187 
188 /*! \brief Get tstate (Tone State) */
189 int ast_dsp_get_tstate(struct ast_dsp *dsp);
190 
191 /*! \brief Get tcount (Threshold counter) */
192 int 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 */
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:1494
Main Channel structure associated with a channel.
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:1478
void ast_dsp_free(struct ast_dsp *dsp)
Definition: dsp.c:1770
int ast_dsp_get_tcount(struct ast_dsp *dsp)
Get tcount (Threshold counter)
Definition: dsp.c:1903
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
int pattern[4]
Definition: dsp.h:68
static sqlite3 * db
struct ast_dsp * ast_dsp_new(void)
Allocates a new dsp, assumes 8khz for internal sample rate.
Definition: dsp.c:1745
void ast_dsp_digitreset(struct ast_dsp *dsp)
Reset DTMF detector.
Definition: dsp.c:1797
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:1893
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:1717
int ast_dsp_getdigits(struct ast_dsp *dsp, char *buf, int max)
Get pending DTMF/MF digits.
threshold
Definition: dsp.h:71
void ast_dsp_set_busy_count(struct ast_dsp *dsp, int cadences)
Set number of required cadences for busy.
Definition: dsp.c:1780
int ast_dsp_get_features(struct ast_dsp *dsp)
Get features.
Definition: dsp.c:1764
Definition: dsp.c:405
int ast_dsp_set_faxmode(struct ast_dsp *dsp, int faxmode)
Set fax mode.
Definition: dsp.c:1870
int ast_dsp_get_tstate(struct ast_dsp *dsp)
Get tstate (Tone State)
Definition: dsp.c:1898
unsigned int sample_rate
Definition: dsp.c:433
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:1775
void ast_dsp_reset(struct ast_dsp *dsp)
Reset total silence count.
Definition: dsp.c:1830
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:1791
void ast_dsp_set_features(struct ast_dsp *dsp, int features)
Select feature set.
Definition: dsp.c:1755
int ast_dsp_silence(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence)
Process the audio frame for silence.
Definition: dsp.c:1483
static struct dahdi_ring_cadence cadences[NUM_CADENCE_MAX]
Definition: chan_dahdi.c:569
int ast_dsp_digitdetect(struct ast_dsp *dsp, struct ast_frame *f)
Return non-zero if DTMF hit was found.
Data structure associated with a single frame of data.
int ast_dsp_call_progress(struct ast_dsp *dsp, struct ast_frame *inf)
Scans for progress indication in audio.
Definition: dsp.c:1216
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:1750
int ast_dsp_set_freqmode(struct ast_dsp *dsp, int freq1, int dur, int db, int squelch)
Set arbitrary frequency detection mode.
Definition: dsp.c:1859
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:1295
int ast_dsp_get_threshold_from_settings(enum threshold which)
Get silence threshold from dsp.conf.
Definition: dsp.c:1996
int ast_dsp_set_call_progress_zone(struct ast_dsp *dsp, char *zone)
Set zone for doing progress detection.
Definition: dsp.c:1879
int ast_dsp_set_digitmode(struct ast_dsp *dsp, int digitmode)
Set digit mode.
Definition: dsp.c:1844
int ast_dsp_noise(struct ast_dsp *dsp, struct ast_frame *f, int *totalnoise)
Process the audio frame for noise.
Definition: dsp.c:1488
#define max(a, b)
Definition: f2c.h:198