diff --git a/linphone/mediastreamer2/include/mediastreamer2/msvolume.h b/linphone/mediastreamer2/include/mediastreamer2/msvolume.h index 9599a810717aa6daadc48d37ffeb80c866d2a44c..7fc46cdcdbac6104fb2edd6b8eba599d6995956f 100644 --- a/linphone/mediastreamer2/include/mediastreamer2/msvolume.h +++ b/linphone/mediastreamer2/include/mediastreamer2/msvolume.h @@ -52,6 +52,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MS_VOLUME_ENABLE_NOISE_GATE MS_FILTER_METHOD(MS_VOLUME_ID,9,int) +#define MS_VOLUME_SET_NOISE_GATE_THRESHOLD MS_FILTER_METHOD(MS_VOLUME_ID,10,float) + extern MSFilterDesc ms_volume_desc; #endif diff --git a/linphone/mediastreamer2/src/msvolume.c b/linphone/mediastreamer2/src/msvolume.c index 3c59553a3fb0a388fde51d60e4cedbcd3588da72..ae642bde08a5ae0fcb1e81827cfe87f1be4b6069 100644 --- a/linphone/mediastreamer2/src/msvolume.c +++ b/linphone/mediastreamer2/src/msvolume.c @@ -52,6 +52,7 @@ typedef struct Volume{ int nsamples; int ng_cut_time; /*noise gate cut time, after last speech detected*/ int ng_noise_dur; + float ng_threshold; MSBufferizer *buffer; bool_t ea_active; bool_t agc_enabled; @@ -75,6 +76,7 @@ static void volume_init(MSFilter *f){ v->noise_gate_enabled=FALSE; v->ng_cut_time=100;/*milliseconds*/ v->ng_noise_dur=0; + v->ng_threshold=noise_thres; #ifdef HAVE_SPEEXDSP v->speex_pp=NULL; #endif @@ -155,7 +157,7 @@ static void volume_echo_avoider_process(Volume *v){ static void volume_noise_gate_process(Volume *v , float energy, mblk_t *om){ int nsamples=((om->b_wptr-om->b_rptr)/2); - if ((energy/max_e)<v->thres){ + if ((energy/max_e)<v->ng_threshold){ v->ng_noise_dur+=(nsamples*1000)/v->sample_rate; if (v->ng_noise_dur>v->ng_cut_time){ v->target_gain=0; @@ -229,6 +231,12 @@ static int volume_enable_noise_gate(MSFilter *f, void *arg){ return 0; } +static int volume_set_noise_gate_threshold(MSFilter *f, void *arg){ + Volume *v=(Volume*)f->data; + v->ng_threshold=*(float*)arg; + return 0; +} + static inline int16_t saturate(float val){ return (val>32767) ? 32767 : ( (val<-32767) ? -32767 : val); } @@ -337,6 +345,7 @@ static MSFilterMethod methods[]={ { MS_FILTER_SET_SAMPLE_RATE, volume_set_sample_rate }, { MS_VOLUME_ENABLE_AGC , volume_set_agc }, { MS_VOLUME_ENABLE_NOISE_GATE, volume_enable_noise_gate}, + { MS_VOLUME_SET_NOISE_GATE_THRESHOLD, volume_set_noise_gate_threshold}, { 0 , NULL } };