2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
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.
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.
20 * \brief Convenient Signal Processing routines
23 #ifndef _ASTERISK_DSP_H
24 #define _ASTERISK_DSP_H
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)
31 #define DSP_DIGITMODE_DTMF 0 /*!< Detect DTMF digits */
32 #define DSP_DIGITMODE_MF 1 /*!< Detect MF digits */
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) */
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)
45 #define DSP_FAXMODE_DETECT_CNG (1 << 0)
46 #define DSP_FAXMODE_DETECT_CED (1 << 1)
47 #define DSP_FAXMODE_DETECT_ALL (DSP_FAXMODE_DETECT_CNG | DSP_FAXMODE_DETECT_CED)
49 #define DSP_TONE_STATE_SILENCE 0
50 #define DSP_TONE_STATE_RINGING 1
51 #define DSP_TONE_STATE_DIALTONE 2
52 #define DSP_TONE_STATE_TALKING 3
53 #define DSP_TONE_STATE_BUSY 4
54 #define DSP_TONE_STATE_SPECIAL1 5
55 #define DSP_TONE_STATE_SPECIAL2 6
56 #define DSP_TONE_STATE_SPECIAL3 7
57 #define DSP_TONE_STATE_HUNGUP 8
63 THRESHOLD_SILENCE = 0,
68 struct ast_dsp *ast_dsp_new(void);
69 void ast_dsp_free(struct ast_dsp *dsp);
71 /*! \brief Set threshold value for silence */
72 void ast_dsp_set_threshold(struct ast_dsp *dsp, int threshold);
74 /*! \brief Set number of required cadences for busy */
75 void ast_dsp_set_busy_count(struct ast_dsp *dsp, int cadences);
77 /*! \brief Set expected lengths of the busy tone */
78 void ast_dsp_set_busy_pattern(struct ast_dsp *dsp, int tonelength, int quietlength);
80 /*! \brief Scans for progress indication in audio */
81 int ast_dsp_call_progress(struct ast_dsp *dsp, struct ast_frame *inf);
83 /*! \brief Set zone for doing progress detection */
84 int ast_dsp_set_call_progress_zone(struct ast_dsp *dsp, char *zone);
86 /*! \brief Return AST_FRAME_NULL frames when there is silence, AST_FRAME_BUSY on
87 busies, and call progress, all dependent upon which features are enabled */
88 struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp, struct ast_frame *inf);
90 /*! \brief Return non-zero if this is silence. Updates "totalsilence" with the total
91 number of seconds of silence */
92 int ast_dsp_silence(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence);
94 /*! \brief Return non-zero if this is noise. Updates "totalnoise" with the total
95 number of seconds of noise */
96 int ast_dsp_noise(struct ast_dsp *dsp, struct ast_frame *f, int *totalnoise);
98 /*! \brief Return non-zero if historically this should be a busy, request that
99 ast_dsp_silence has already been called */
100 int ast_dsp_busydetect(struct ast_dsp *dsp);
102 /*! \brief Return non-zero if DTMF hit was found */
103 int ast_dsp_digitdetect(struct ast_dsp *dsp, struct ast_frame *f);
105 /*! \brief Reset total silence count */
106 void ast_dsp_reset(struct ast_dsp *dsp);
108 /*! \brief Reset DTMF detector */
109 void ast_dsp_digitreset(struct ast_dsp *dsp);
111 /*! \brief Select feature set */
112 void ast_dsp_set_features(struct ast_dsp *dsp, int features);
114 /*! \brief Get pending DTMF/MF digits */
115 int ast_dsp_getdigits(struct ast_dsp *dsp, char *buf, int max);
117 /*! \brief Set digit mode */
118 int ast_dsp_set_digitmode(struct ast_dsp *dsp, int digitmode);
120 /*! \brief Set fax mode */
121 int ast_dsp_set_faxmode(struct ast_dsp *dsp, int faxmode);
123 /*! \brief Returns true if DSP code was muting any fragment of the last processed frame.
124 Muting (squelching) happens when DSP code removes DTMF/MF/generic tones from the audio */
125 int ast_dsp_was_muted(struct ast_dsp *dsp);
127 /*! \brief Get tstate (Tone State) */
128 int ast_dsp_get_tstate(struct ast_dsp *dsp);
130 /*! \brief Get tcount (Threshold counter) */
131 int ast_dsp_get_tcount(struct ast_dsp *dsp);
133 /*! \brief Get silence threshold from dsp.conf*/
134 int ast_dsp_get_threshold_from_settings(enum threshold which);
136 /* \brief Reloads dsp settings from dsp.conf*/
137 int ast_dsp_reload(void);
139 int ast_dsp_init(void);
141 #endif /* _ASTERISK_DSP_H */