Changeset 241:4eec3ed19919 in mediastreamer2


Ignore:
Timestamp:
Feb 5, 2009 6:45:02 PM (4 years ago)
Author:
aymeric <aymeric@…>
Branch:
default
Message:

add half duplex simulation with VAD for noisy environment.

git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@244 3f6dc0c8-ddfe-455d-9043-3cd528dc4637

Location:
linphone/mediastreamer2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • linphone/mediastreamer2/include/mediastreamer2/msfilter.h

    r205 r241  
    389389#define MS_FILTER_ENABLE_AGC            MS_FILTER_BASE_METHOD(20,int) 
    390390#define MS_FILTER_SET_PLAYBACKDELAY MS_FILTER_BASE_METHOD(21,int) 
     391#define MS_FILTER_ENABLE_HALFDUPLEX MS_FILTER_BASE_METHOD(22,int) 
     392#define MS_FILTER_SET_VAD_PROB_START MS_FILTER_BASE_METHOD(23,int) 
     393#define MS_FILTER_SET_VAD_PROB_CONTINUE MS_FILTER_BASE_METHOD(24,int) 
     394 
    391395/** @} */ 
    392396 
  • linphone/mediastreamer2/src/msconf.c

    r205 r241  
    4545        bool_t has_contributed; 
    4646        bool_t is_used; 
     47 
     48        int is_speaking; 
     49 
    4750        int count; 
    4851        int missed; 
     
    6366        int enable_directmode; 
    6467        int enable_vad; 
     68 
     69        int enable_halfduplex; 
     70        int vad_prob_start; 
     71        int vad_prob_continue; 
     72 
    6573        int agc_level; 
    6674        int mix_mode; 
     
    7482 
    7583static void channel_init(ConfState *s, Channel *chan, int pos){ 
     84        memset(chan, 0, sizeof(Channel)); 
    7685        ms_bufferizer_init(&chan->buff); 
    7786#ifndef DISABLE_SPEEX 
     
    92101                        speex_preprocess_ctl(chan->speex_pp, SPEEX_PREPROCESS_SET_VAD, &val); 
    93102                } 
     103                else if (pos==0 && s->enable_halfduplex>0) 
     104                { 
     105                        val=1; 
     106                        speex_preprocess_ctl(chan->speex_pp, SPEEX_PREPROCESS_SET_VAD, &val); 
     107                        val = s->vad_prob_start; // xx% 
     108                        speex_preprocess_ctl(chan->speex_pp, SPEEX_PREPROCESS_SET_PROB_START, &val); 
     109                        val = s->vad_prob_continue; // xx% 
     110                        speex_preprocess_ctl(chan->speex_pp, SPEEX_PREPROCESS_SET_PROB_CONTINUE, &val); 
     111                } 
     112 
    94113                /* enable AGC only on local soundcard */ 
    95114                if (s->agc_level>0 && pos==0) 
     
    250269 
    251270                /* skip soundread and short buffer entry */ 
    252 #if 0 
    253                 if (i>0 
    254                         && ms_bufferizer_get_avail(&chan->buff)>=s->conf_gran*s->adaptative_msconf_buf) 
    255                 { 
    256                         while (ms_bufferizer_get_avail(&chan->buff)>=s->conf_gran*2) 
    257 #endif 
    258271                if (i>0  
    259272                        && ms_bufferizer_get_avail(&chan->buff)> s->conf_gran 
     
    283296                        } 
    284297 
    285                         for(j=0;j<s->conf_nsamples;++j){ 
    286                                 s->sum[j]+=chan->input[j]; 
    287                         } 
    288                         chan->has_contributed=TRUE; 
     298                        if (s->channels[0].is_speaking<=0) 
     299                        { 
     300                                for(j=0;j<s->conf_nsamples;++j){ 
     301                                        s->sum[j]+=chan->input[j]; 
     302                                } 
     303                                chan->has_contributed=TRUE; 
     304                        } 
    289305                        chan->stat_processed++; 
    290306                } 
     
    297313                                int vad; 
    298314                                vad = speex_preprocess(chan->speex_pp, (short*)chan->input, NULL); 
    299                         } 
    300       else if (chan->speex_pp!=NULL && s->enable_vad==TRUE) 
    301       { 
    302         speex_preprocess_estimate_update(chan->speex_pp, (short*)chan->input); 
    303       } 
    304 #endif 
    305  
    306                         for(j=0;j<s->conf_nsamples;++j){ 
    307                                 s->sum[j]+=chan->input[j]; 
    308                         } 
    309                         chan->has_contributed=TRUE; 
     315                                if (s->enable_halfduplex>0) 
     316                                { 
     317                                        if (vad>0) 
     318                                        { 
     319                                                /* speech detected */ 
     320                                                chan->is_speaking++; 
     321                                                if (chan->is_speaking>5) 
     322                                                        chan->is_speaking=5; 
     323                                        } 
     324                                        else 
     325                                        { 
     326                                                chan->is_speaking--; 
     327                                                if (chan->is_speaking<-5) 
     328                                                        chan->is_speaking=-5; 
     329                                        } 
     330                                if (chan->is_speaking<=0) 
     331                                        ms_message("silence on! (%i)", chan->is_speaking); 
     332                                else 
     333                                        ms_message("speech on! (%i)", chan->is_speaking); 
     334                                } 
     335                        } 
     336                        else if (chan->speex_pp!=NULL && s->enable_vad==TRUE) 
     337                        { 
     338                                speex_preprocess_estimate_update(chan->speex_pp, (short*)chan->input); 
     339                        } 
     340#endif 
     341 
     342                        if (i==0 
     343                                || s->channels[0].is_speaking<=0) 
     344                        { 
     345                                for(j=0;j<s->conf_nsamples;++j){ 
     346                                        s->sum[j]+=chan->input[j]; 
     347                                } 
     348                                chan->has_contributed=TRUE; 
     349                        } 
    310350                        chan->stat_processed++; 
    311351                } else { 
     
    445485        int i; 
    446486        ConfState *s=(ConfState*)f->data; 
    447         Channel *chan; 
    448         /*read from all inputs and put into bufferizers*/ 
    449         for (i=0;i<CONF_MAX_PINS;++i){ 
    450                 if (f->inputs[i]!=NULL){ 
    451                         chan=&s->channels[i]; 
    452                         ms_bufferizer_uninit(&chan->buff); 
    453                         ms_bufferizer_init(&chan->buff); 
    454                 } 
    455         } 
    456 } 
     487        for (i=0;i<CONF_MAX_PINS;i++) 
     488                channel_uninit(&s->channels[i]); 
     489    for (i=0;i<CONF_MAX_PINS;i++) 
     490                channel_init(s, &s->channels[i], i); 
     491} 
     492 
    457493static int msconf_set_sr(MSFilter *f, void *arg){ 
    458494        ConfState *s=(ConfState*)f->data; 
     
    479515        int i; 
    480516        s->agc_level = *(int*)arg; 
     517 
     518        for (i=0;i<CONF_MAX_PINS;i++) 
     519                channel_uninit(&s->channels[i]); 
     520    for (i=0;i<CONF_MAX_PINS;i++) 
     521                channel_init(s, &s->channels[i], i); 
     522        return 0; 
     523} 
     524 
     525static int msconf_enable_halfduplex(MSFilter *f, void *arg){ 
     526        ConfState *s=(ConfState*)f->data; 
     527        int i; 
     528        s->enable_halfduplex = *(int*)arg; 
     529 
     530        for (i=0;i<CONF_MAX_PINS;i++) 
     531                channel_uninit(&s->channels[i]); 
     532    for (i=0;i<CONF_MAX_PINS;i++) 
     533                channel_init(s, &s->channels[i], i); 
     534        return 0; 
     535} 
     536 
     537static int msconf_set_vad_prob_start(MSFilter *f, void *arg){ 
     538        ConfState *s=(ConfState*)f->data; 
     539        int i; 
     540        s->vad_prob_start = *(int*)arg; 
     541 
     542        for (i=0;i<CONF_MAX_PINS;i++) 
     543                channel_uninit(&s->channels[i]); 
     544    for (i=0;i<CONF_MAX_PINS;i++) 
     545                channel_init(s, &s->channels[i], i); 
     546        return 0; 
     547} 
     548 
     549static int msconf_set_vad_prob_continue(MSFilter *f, void *arg){ 
     550        ConfState *s=(ConfState*)f->data; 
     551        int i; 
     552        s->vad_prob_continue = *(int*)arg; 
    481553 
    482554        for (i=0;i<CONF_MAX_PINS;i++) 
     
    555627        {       MS_FILTER_GET_STAT_MISSED, msconf_get_stat_missed }, 
    556628        {       MS_FILTER_GET_STAT_OUTPUT, msconf_get_stat_processed }, 
     629 
     630        {       MS_FILTER_ENABLE_HALFDUPLEX, msconf_enable_halfduplex }, 
     631        {       MS_FILTER_SET_VAD_PROB_START, msconf_set_vad_prob_start }, 
     632        {       MS_FILTER_SET_VAD_PROB_CONTINUE, msconf_set_vad_prob_continue }, 
    557633        {       0                       , NULL} 
    558634}; 
Note: See TracChangeset for help on using the changeset viewer.