123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- #ifndef __SILENCEDET_H__
- #define __SILENCEDET_H__
- #pragma once
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * @brief Adaptive Silence Detector
- */
- typedef struct silence_det_t silence_det_t;
- /**
- * Create voice activity detector with default settings. The default settings
- * are set to adaptive silence detection with the default threshold.
- *
- * @param pool Pool for allocating the structure.
- * @param clock_rate Clock rate.
- * @param samples_per_frame Number of samples per frame. The clock_rate and
- * samples_per_frame is only used to calculate the
- * frame time, from which some timing parameters
- * are calculated from.
- * @param p_sd Pointer to receive the silence detector instance.
- *
- * @return 0 on success.
- */
- int silence_det_create(unsigned clock_rate,unsigned samples_per_frame,silence_det_t **p_sd );
- void silence_det_destory(silence_det_t *sd);
- /**
- * Set the sd to operate in fixed threshold mode. With fixed threshold mode,
- * the threshold will not be changed adaptively.
- *
- * @param sd The silence detector
- * @param threshold The silence threshold, or -1 to use default
- * threshold.
- *
- * @return 0 on success.
- */
- int silence_det_set_fixed( silence_det_t *sd,int threshold );
- /**
- * Set the sd to operate in adaptive mode. This is the default mode
- * when the silence detector is created.
- *
- * @param sd The silence detector
- * @param threshold Initial threshold to be set, or -1 to use default
- * threshold.
- *
- * @return 0 on success.
- */
- int silence_det_set_adaptive(silence_det_t *sd,int threshold);
- /**
- * Set other silence detector parameters.
- *
- * @param sd The silence detector
- * @param before_silence Minimum duration of silence (in msec) before
- * silence is reported. If -1 is specified, then
- * the default value will be used. The default is
- * 400 msec.
- * @param recalc_time1 The interval (in msec) to recalculate threshold
- * in non-silence condition when adaptive silence
- * detection is set. If -1 is specified, then the
- * default value will be used. The default is 4000
- * (msec).
- * @param recalc_time2 The interval (in msec) to recalculate threshold
- * in silence condition when adaptive silence detection
- * is set. If -1 is specified, then the default value
- * will be used. The default value is 2000 (msec).
- *
- * @return 0 on success.
- */
- int silence_det_set_params( silence_det_t *sd,int before_silence,int recalc_time1,int recalc_time2);
- /**
- * Disable the silence detector.
- *
- * @param sd The silence detector
- *
- * @return 0 on success.
- */
- int silence_det_disable( silence_det_t *sd );
- /**
- * Perform voice activity detection on the given input samples. This
- * function uses #calc_avg_signal() and #silence_det_apply()
- * for its calculation.
- *
- * @param sd The silence detector instance.
- * @param samples Pointer to 16-bit PCM input samples.
- * @param count Number of samples in the input.
- * @param p_level Optional pointer to receive average signal level
- * of the input samples.
- *
- * @return Non zero if signal is silence.
- */
- int silence_det_detect( silence_det_t *sd,
- const short samples[],
- size_t count,
- int *p_level);
- /**
- * Calculate average signal level for the given samples.
- *
- * @param samples Pointer to 16-bit PCM samples.
- * @param count Number of samples in the input.
- *
- * @return The average signal level, which simply is total level
- * divided by number of samples.
- */
- int calc_avg_signal( const short samples[],size_t count );
- /**
- * Perform voice activity detection, given the specified average signal
- * level.
- *
- * @param sd The silence detector instance.
- * @param level Signal level.
- *
- * @return Non zero if signal is silence.
- */
- int silence_det_apply( silence_det_t *sd,unsigned int level);
- #ifdef __cplusplus
- } // extern "C" {
- #endif
- #endif //__SILENCEDET_H__
|