Wed Jan 8 2020 09:49:47

Asterisk developer's documentation


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 
46 #define DSP_FAXMODE_DETECT_CNG (1 << 0)
47 #define DSP_FAXMODE_DETECT_CED (1 << 1)
48 #define DSP_FAXMODE_DETECT_ALL (DSP_FAXMODE_DETECT_CNG | DSP_FAXMODE_DETECT_CED)
49 
50 #define DSP_TONE_STATE_SILENCE 0
51 #define DSP_TONE_STATE_RINGING 1
52 #define DSP_TONE_STATE_DIALTONE 2
53 #define DSP_TONE_STATE_TALKING 3
54 #define DSP_TONE_STATE_BUSY 4
55 #define DSP_TONE_STATE_SPECIAL1 5
56 #define DSP_TONE_STATE_SPECIAL2 6
57 #define DSP_TONE_STATE_SPECIAL3 7
58 #define DSP_TONE_STATE_HUNGUP 8
59 
60 struct ast_dsp;
61 
62 enum threshold {
63  /* Array offsets */
65  /* Always the last */
67 };
68 
69 struct ast_dsp *ast_dsp_new(void);
70 void ast_dsp_free(struct ast_dsp *dsp);
71 
72 /*! \brief Set threshold value for silence */
73 void ast_dsp_set_threshold(struct ast_dsp *dsp, int threshold);
74 
75 /*! \brief Set number of required cadences for busy */
76 void ast_dsp_set_busy_count(struct ast_dsp *dsp, int cadences);
77 
78 /*! \brief Set if silence and noice lengths must be compared for busy */
79 void ast_dsp_set_busy_compare(struct ast_dsp *dsp, int compare);
80 
81 /*! \brief Set expected lengths of the busy tones */
82 void ast_dsp_set_busy_pattern(struct ast_dsp *dsp, int tonelength, int quietlength, int fuzzy);
83 
84 /*! \brief Scans for progress indication in audio */
85 int ast_dsp_call_progress(struct ast_dsp *dsp, struct ast_frame *inf);
86 
87 /*! \brief Set zone for doing progress detection */
88 int ast_dsp_set_call_progress_zone(struct ast_dsp *dsp, char *zone);
89 
90 /*! \brief Return AST_FRAME_NULL frames when there is silence, AST_FRAME_BUSY on
91  busies, and call progress, all dependent upon which features are enabled */
92 struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp, struct ast_frame *inf);
93 
94 /*! \brief Return non-zero if this is silence. Updates "totalsilence" with the total
95  number of seconds of silence */
96 int ast_dsp_silence(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence);
97 
98 /*!
99  * \brief Return non-zero if this is noise. Updates "totalnoise" with the total
100  * number of seconds of noise
101  * \since 1.6.1
102  */
103 int ast_dsp_noise(struct ast_dsp *dsp, struct ast_frame *f, int *totalnoise);
104 
105 /*! \brief Return non-zero if historically this should be a busy, request that
106  ast_dsp_silence has already been called */
107 int ast_dsp_busydetect(struct ast_dsp *dsp);
108 
109 /*! \brief Return non-zero if DTMF hit was found */
110 int ast_dsp_digitdetect(struct ast_dsp *dsp, struct ast_frame *f);
111 
112 /*! \brief Reset total silence count */
113 void ast_dsp_reset(struct ast_dsp *dsp);
114 
115 /*! \brief Reset DTMF detector */
116 void ast_dsp_digitreset(struct ast_dsp *dsp);
117 
118 /*! \brief Select feature set */
119 void ast_dsp_set_features(struct ast_dsp *dsp, int features);
120 
121 /*! \brief Get pending DTMF/MF digits */
122 int ast_dsp_getdigits(struct ast_dsp *dsp, char *buf, int max);
123 
124 /*! \brief Set digit mode
125  * \version 1.6.1 renamed from ast_dsp_digitmode to ast_dsp_set_digitmode
126  */
127 int ast_dsp_set_digitmode(struct ast_dsp *dsp, int digitmode);
128 
129 /*! \brief Set fax mode */
130 int ast_dsp_set_faxmode(struct ast_dsp *dsp, int faxmode);
131 
132 /*!
133  * \brief Returns true if DSP code was muting any fragment of the last processed frame.
134  * Muting (squelching) happens when DSP code removes DTMF/MF/generic tones from the audio
135  * \since 1.6.1
136  */
137 int ast_dsp_was_muted(struct ast_dsp *dsp);
138 
139 /*! \brief Get tstate (Tone State) */
140 int ast_dsp_get_tstate(struct ast_dsp *dsp);
141 
142 /*! \brief Get tcount (Threshold counter) */
143 int ast_dsp_get_tcount(struct ast_dsp *dsp);
144 
145 /*!
146  * \brief Get silence threshold from dsp.conf
147  * \since 1.6.1
148  */
150 
151 /*!
152  * \brief Reloads dsp settings from dsp.conf
153  * \since 1.6.1
154  */
155 int ast_dsp_reload(void);
156 
157 /*!
158  * \brief Load dsp settings from dsp.conf
159  * \since 1.6.1
160  */
161 int ast_dsp_init(void);
162 
163 #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:1392
Main Channel structure associated with a channel.
Definition: channel.h:742
void ast_dsp_free(struct ast_dsp *dsp)
Definition: dsp.c:1650
int ast_dsp_get_tcount(struct ast_dsp *dsp)
Get tcount (Threshold counter)
Definition: dsp.c:1787
struct ast_dsp * ast_dsp_new(void)
Definition: dsp.c:1607
void ast_dsp_digitreset(struct ast_dsp *dsp)
Reset DTMF detector.
Definition: dsp.c:1694
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:1777
int ast_dsp_init(void)
Load dsp settings from dsp.conf.
Definition: dsp.c:1885
int ast_dsp_getdigits(struct ast_dsp *dsp, char *buf, int max)
Get pending DTMF/MF digits.
threshold
Definition: dsp.h:62
void ast_dsp_set_busy_count(struct ast_dsp *dsp, int cadences)
Set number of required cadences for busy.
Definition: dsp.c:1663
Definition: dsp.c:390
int ast_dsp_set_faxmode(struct ast_dsp *dsp, int faxmode)
Set fax mode.
Definition: dsp.c:1754
int ast_dsp_get_tstate(struct ast_dsp *dsp)
Get tstate (Tone State)
Definition: dsp.c:1782
void ast_dsp_set_busy_pattern(struct ast_dsp *dsp, int tonelength, int quietlength, int fuzzy)
Set expected lengths of the busy tones.
Definition: dsp.c:1682
void ast_dsp_set_threshold(struct ast_dsp *dsp, int threshold)
Set threshold value for silence.
Definition: dsp.c:1655
void ast_dsp_reset(struct ast_dsp *dsp)
Reset total silence count.
Definition: dsp.c:1725
void ast_dsp_set_busy_compare(struct ast_dsp *dsp, int compare)
Set if silence and noice lengths must be compared for busy.
Definition: dsp.c:1674
void ast_dsp_set_features(struct ast_dsp *dsp, int features)
Select feature set.
Definition: dsp.c:1642
static struct ast_format f[]
Definition: format_g726.c:181
int ast_dsp_silence(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence)
Return non-zero if this is silence. Updates &quot;totalsilence&quot; with the total number of seconds of silenc...
Definition: dsp.c:1355
static struct dahdi_ring_cadence cadences[NUM_CADENCE_MAX]
Definition: chan_dahdi.c:393
int ast_dsp_reload(void)
Reloads dsp settings from dsp.conf.
Definition: dsp.c:1890
static int compare(const char *text, const char *template)
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.
Definition: frame.h:142
int ast_dsp_call_progress(struct ast_dsp *dsp, struct ast_frame *inf)
Scans for progress indication in audio.
Definition: dsp.c:1174
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:1250
int ast_dsp_get_threshold_from_settings(enum threshold which)
Get silence threshold from dsp.conf.
Definition: dsp.c:1880
int ast_dsp_set_call_progress_zone(struct ast_dsp *dsp, char *zone)
Set zone for doing progress detection.
Definition: dsp.c:1763
int ast_dsp_set_digitmode(struct ast_dsp *dsp, int digitmode)
Set digit mode.
Definition: dsp.c:1739
int ast_dsp_noise(struct ast_dsp *dsp, struct ast_frame *f, int *totalnoise)
Return non-zero if this is noise. Updates &quot;totalnoise&quot; with the total number of seconds of noise...
Definition: dsp.c:1373