1
/* $Id: silencedet.h 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#ifndef __PJMEDIA_SILENCE_DET_H__
21
#define __PJMEDIA_SILENCE_DET_H__
26
* @brief Adaptive silence detector.
28
#include <pjmedia/types.h>
32
* @defgroup PJMEDIA_SILENCEDET Adaptive Silence Detection
33
* @ingroup PJMEDIA_FRAME_OP
34
* @brief Adaptive Silence Detector
43
* Opaque declaration for silence detector.
45
typedef struct pjmedia_silence_det pjmedia_silence_det;
50
* Create voice activity detector with default settings. The default settings
51
* are set to adaptive silence detection with the default threshold.
53
* @param pool Pool for allocating the structure.
54
* @param clock_rate Clock rate.
55
* @param samples_per_frame Number of samples per frame. The clock_rate and
56
* samples_per_frame is only used to calculate the
57
* frame time, from which some timing parameters
58
* are calculated from.
59
* @param p_sd Pointer to receive the silence detector instance.
61
* @return PJ_SUCCESS on success.
63
PJ_DECL(pj_status_t) pjmedia_silence_det_create( pj_pool_t *pool,
65
unsigned samples_per_frame,
66
pjmedia_silence_det **p_sd );
70
* Set silence detector name to identify the particular silence detector
71
* instance in the log.
73
* @param sd The silence detector.
76
* @return PJ_SUCCESS on success.
78
PJ_DECL(pj_status_t) pjmedia_silence_det_set_name(pjmedia_silence_det *sd,
83
* Set the sd to operate in fixed threshold mode. With fixed threshold mode,
84
* the threshold will not be changed adaptively.
86
* @param sd The silence detector
87
* @param threshold The silence threshold, or -1 to use default
90
* @return PJ_SUCCESS on success.
92
PJ_DECL(pj_status_t) pjmedia_silence_det_set_fixed( pjmedia_silence_det *sd,
96
* Set the sd to operate in adaptive mode. This is the default mode
97
* when the silence detector is created.
99
* @param sd The silence detector
100
* @param threshold Initial threshold to be set, or -1 to use default
103
* @return PJ_SUCCESS on success.
105
PJ_DECL(pj_status_t) pjmedia_silence_det_set_adaptive(pjmedia_silence_det *sd,
109
* Set other silence detector parameters.
111
* @param sd The silence detector
112
* @param before_silence Minimum duration of silence (in msec) before
113
* silence is reported. If -1 is specified, then
114
* the default value will be used. The default is
116
* @param recalc_time1 The interval (in msec) to recalculate threshold
117
* in non-silence condition when adaptive silence
118
* detection is set. If -1 is specified, then the
119
* default value will be used. The default is 4000
121
* @param recalc_time2 The interval (in msec) to recalculate threshold
122
* in silence condition when adaptive silence detection
123
* is set. If -1 is specified, then the default value
124
* will be used. The default value is 2000 (msec).
126
* @return PJ_SUCCESS on success.
128
PJ_DECL(pj_status_t) pjmedia_silence_det_set_params( pjmedia_silence_det *sd,
135
* Disable the silence detector.
137
* @param sd The silence detector
139
* @return PJ_SUCCESS on success.
141
PJ_DECL(pj_status_t) pjmedia_silence_det_disable( pjmedia_silence_det *sd );
145
* Perform voice activity detection on the given input samples. This
146
* function uses #pjmedia_calc_avg_signal() and #pjmedia_silence_det_apply()
147
* for its calculation.
149
* @param sd The silence detector instance.
150
* @param samples Pointer to 16-bit PCM input samples.
151
* @param count Number of samples in the input.
152
* @param p_level Optional pointer to receive average signal level
153
* of the input samples.
155
* @return Non zero if signal is silence.
157
PJ_DECL(pj_bool_t) pjmedia_silence_det_detect( pjmedia_silence_det *sd,
158
const pj_int16_t samples[],
160
pj_int32_t *p_level);
164
* Calculate average signal level for the given samples.
166
* @param samples Pointer to 16-bit PCM samples.
167
* @param count Number of samples in the input.
169
* @return The average signal level, which simply is total level
170
* divided by number of samples.
172
PJ_DECL(pj_int32_t) pjmedia_calc_avg_signal( const pj_int16_t samples[],
178
* Perform voice activity detection, given the specified average signal
181
* @param sd The silence detector instance.
182
* @param level Signal level.
184
* @return Non zero if signal is silence.
186
PJ_DECL(pj_bool_t) pjmedia_silence_det_apply( pjmedia_silence_det *sd,
199
#endif /* __PJMEDIA_SILENCE_DET_H__ */