dsp.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  * \brief Convenient Signal Processing routines
00021  */
00022 
00023 #ifndef _ASTERISK_DSP_H
00024 #define _ASTERISK_DSP_H
00025 
00026 #define DSP_FEATURE_SILENCE_SUPPRESS   (1 << 0)
00027 #define DSP_FEATURE_BUSY_DETECT     (1 << 1)
00028 #define DSP_FEATURE_DIGIT_DETECT (1 << 3)
00029 #define DSP_FEATURE_FAX_DETECT      (1 << 4)
00030 
00031 #define  DSP_DIGITMODE_DTMF         0           /*!< Detect DTMF digits */
00032 #define DSP_DIGITMODE_MF         1           /*!< Detect MF digits */
00033 
00034 #define DSP_DIGITMODE_NOQUELCH      (1 << 8)    /*!< Do not quelch DTMF from in-band */
00035 #define DSP_DIGITMODE_MUTECONF      (1 << 9)    /*!< Mute conference */
00036 #define DSP_DIGITMODE_MUTEMAX    (1 << 10)      /*!< Delay audio by a frame to try to extra quelch */
00037 #define DSP_DIGITMODE_RELAXDTMF     (1 << 11)      /*!< "Radio" mode (relaxed DTMF) */
00038 
00039 #define DSP_PROGRESS_TALK     (1 << 16)      /*!< Enable talk detection */
00040 #define DSP_PROGRESS_RINGING     (1 << 17)      /*!< Enable calling tone detection */
00041 #define DSP_PROGRESS_BUSY     (1 << 18)      /*!< Enable busy tone detection */
00042 #define DSP_PROGRESS_CONGESTION     (1 << 19)      /*!< Enable congestion tone detection */
00043 #define DSP_FEATURE_CALL_PROGRESS   (DSP_PROGRESS_TALK | DSP_PROGRESS_RINGING | DSP_PROGRESS_BUSY | DSP_PROGRESS_CONGESTION)
00044 #define DSP_FEATURE_WAITDIALTONE (1 << 20)      /*!< Enable dial tone detection */
00045 
00046 #define DSP_FAXMODE_DETECT_CNG      (1 << 0)
00047 #define DSP_FAXMODE_DETECT_CED      (1 << 1)
00048 #define DSP_FAXMODE_DETECT_SQUELCH  (1 << 2)
00049 #define DSP_FAXMODE_DETECT_ALL   (DSP_FAXMODE_DETECT_CNG | DSP_FAXMODE_DETECT_CED)
00050 
00051 #define DSP_TONE_STATE_SILENCE  0
00052 #define DSP_TONE_STATE_RINGING  1
00053 #define DSP_TONE_STATE_DIALTONE 2
00054 #define DSP_TONE_STATE_TALKING  3
00055 #define DSP_TONE_STATE_BUSY     4
00056 #define DSP_TONE_STATE_SPECIAL1  5
00057 #define DSP_TONE_STATE_SPECIAL2 6
00058 #define DSP_TONE_STATE_SPECIAL3 7
00059 #define DSP_TONE_STATE_HUNGUP    8
00060 
00061 struct ast_dsp;
00062 
00063 struct ast_dsp_busy_pattern {
00064    /*! Number of elements. */
00065    int length;
00066    /*! Pattern elements in on/off time durations. */
00067    int pattern[4];
00068 };
00069 
00070 enum threshold {
00071    /* Array offsets */
00072    THRESHOLD_SILENCE = 0,
00073    /* Always the last */
00074    THRESHOLD_MAX = 1,
00075 };
00076 
00077 /*! \brief Allocates a new dsp with a specific internal sample rate used
00078  * during processing. */
00079 struct ast_dsp *ast_dsp_new_with_rate(unsigned int sample_rate);
00080 
00081 /*! \brief Allocates a new dsp, assumes 8khz for internal sample rate */
00082 struct ast_dsp *ast_dsp_new(void);
00083 
00084 void ast_dsp_free(struct ast_dsp *dsp);
00085 
00086 /*! \brief Retrieve the sample rate this DSP structure was
00087  * created with */
00088 unsigned int ast_dsp_get_sample_rate(const struct ast_dsp *dsp);
00089 
00090 /*! \brief Set threshold value for silence */
00091 void ast_dsp_set_threshold(struct ast_dsp *dsp, int threshold);
00092 
00093 /*! \brief Set number of required cadences for busy */
00094 void ast_dsp_set_busy_count(struct ast_dsp *dsp, int cadences);
00095 
00096 /*! \brief Set expected lengths of the busy tone */
00097 void ast_dsp_set_busy_pattern(struct ast_dsp *dsp, const struct ast_dsp_busy_pattern *cadence);
00098 
00099 /*! \brief Scans for progress indication in audio */
00100 int ast_dsp_call_progress(struct ast_dsp *dsp, struct ast_frame *inf);
00101 
00102 /*! \brief Set zone for doing progress detection */
00103 int ast_dsp_set_call_progress_zone(struct ast_dsp *dsp, char *zone);
00104 
00105 /*! \brief Return AST_FRAME_NULL frames when there is silence, AST_FRAME_BUSY on
00106    busies, and call progress, all dependent upon which features are enabled */
00107 struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp, struct ast_frame *inf);
00108 
00109 /*! \brief Return non-zero if this is silence.  Updates "totalsilence" with the total
00110    number of seconds of silence  */
00111 int ast_dsp_silence(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence);
00112 
00113 /*! \brief Return non-zero if this is silence.  Updates "totalsilence" with the total
00114    number of seconds of silence. Returns the average energy of the samples in the frame
00115    in frames_energy variable. */
00116 int ast_dsp_silence_with_energy(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence, int *frames_energy);
00117 
00118 /*!
00119  * \brief Return non-zero if this is noise.  Updates "totalnoise" with the total
00120  * number of seconds of noise
00121  * \since 1.6.1
00122  */
00123 int ast_dsp_noise(struct ast_dsp *dsp, struct ast_frame *f, int *totalnoise);
00124 
00125 /*! \brief Return non-zero if historically this should be a busy, request that
00126   ast_dsp_silence has already been called */
00127 int ast_dsp_busydetect(struct ast_dsp *dsp);
00128 
00129 /*! \brief Return non-zero if DTMF hit was found */
00130 int ast_dsp_digitdetect(struct ast_dsp *dsp, struct ast_frame *f);
00131 
00132 /*! \brief Reset total silence count */
00133 void ast_dsp_reset(struct ast_dsp *dsp);
00134 
00135 /*! \brief Reset DTMF detector */
00136 void ast_dsp_digitreset(struct ast_dsp *dsp);
00137 
00138 /*! \brief Select feature set */
00139 void ast_dsp_set_features(struct ast_dsp *dsp, int features);
00140 
00141 /*! \brief Get features */
00142 int ast_dsp_get_features(struct ast_dsp *dsp);
00143 
00144 /*! \brief Get pending DTMF/MF digits */
00145 int ast_dsp_getdigits(struct ast_dsp *dsp, char *buf, int max);
00146 
00147 /*! \brief Set digit mode
00148  * \version 1.6.1 renamed from ast_dsp_digitmode to ast_dsp_set_digitmode
00149  */
00150 int ast_dsp_set_digitmode(struct ast_dsp *dsp, int digitmode);
00151 
00152 /*! \brief Set fax mode */
00153 int ast_dsp_set_faxmode(struct ast_dsp *dsp, int faxmode);
00154 
00155 /*!
00156  * \brief Returns true if DSP code was muting any fragment of the last processed frame.
00157  * Muting (squelching) happens when DSP code removes DTMF/MF/generic tones from the audio
00158  * \since 1.6.1
00159  */
00160 int ast_dsp_was_muted(struct ast_dsp *dsp);
00161 
00162 /*! \brief Get tstate (Tone State) */
00163 int ast_dsp_get_tstate(struct ast_dsp *dsp);
00164 
00165 /*! \brief Get tcount (Threshold counter) */
00166 int ast_dsp_get_tcount(struct ast_dsp *dsp);
00167 
00168 /*!
00169  * \brief Get silence threshold from dsp.conf
00170  * \since 1.6.1
00171  */
00172 int ast_dsp_get_threshold_from_settings(enum threshold which);
00173 
00174 /*!
00175  * \brief Reloads dsp settings from dsp.conf
00176  * \since 1.6.1
00177  */
00178 int ast_dsp_reload(void);
00179 
00180 /*!
00181  * \brief Load dsp settings from dsp.conf
00182  * \since 1.6.1
00183  */
00184 int ast_dsp_init(void);
00185 
00186 #endif /* _ASTERISK_DSP_H */

Generated on Thu Apr 16 06:27:33 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6