Commit 6a5c222c authored by jehan's avatar jehan

add ec bypass mode

parent 11a2eced
......@@ -100,4 +100,11 @@ typedef enum _MSPlayerState MSPlayerState;
#define MS_ECHO_CANCELLER_SET_TAIL_LENGTH \
MS_FILTER_METHOD(MSFilterEchoCancellerInterface,2,int)
/** put filter in bypass mode */
#define MS_ECHO_CANCELLER_SET_BYPASS_MODE \
MS_FILTER_METHOD(MSFilterEchoCancellerInterface,3,bool_t)
/** get filter bypass mode */
#define MS_ECHO_CANCELLER_GET_BYPASS_MODE \
MS_FILTER_METHOD(MSFilterEchoCancellerInterface,4,bool_t)
#endif
......@@ -271,22 +271,10 @@ int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char
return -1;
}
if (stream->el_type!=ELInactive || stream->use_gc || stream->use_ng){
stream->volsend=ms_filter_new(MS_VOLUME_ID);
stream->volrecv=ms_filter_new(MS_VOLUME_ID);
if (stream->el_type!=ELInactive){
if (stream->el_type==ELControlFull) {
/* also reduce speaker gain when no signal - same parameters as std. noise gate */
int tmp=1;
ms_filter_call_method(stream->volrecv,MS_VOLUME_ENABLE_NOISE_GATE,&tmp);
}
ms_filter_call_method(stream->volsend,MS_VOLUME_SET_PEER,stream->volrecv);
}
if (stream->use_ng){
int tmp=1;
ms_filter_call_method(stream->volsend,MS_VOLUME_ENABLE_NOISE_GATE,&tmp);
}
}
stream->volsend=ms_filter_new(MS_VOLUME_ID);
stream->volrecv=ms_filter_new(MS_VOLUME_ID);
audio_stream_enable_echo_limiter(stream,stream->el_type);
audio_stream_enable_noise_gate(stream,stream->use_ng);
if (stream->use_agc){
int tmp=1;
......@@ -501,6 +489,13 @@ void audio_stream_set_echo_canceller_params(AudioStream *st, int tail_len_ms, in
void audio_stream_enable_echo_limiter(AudioStream *stream, EchoLimiterType type){
stream->el_type=type;
if (stream->volsend){
bool_t enable_noise_gate = stream->el_type==ELControlFull;
ms_filter_call_method(stream->volrecv,MS_VOLUME_ENABLE_NOISE_GATE,&enable_noise_gate);
ms_filter_call_method(stream->volsend,MS_VOLUME_SET_PEER,type!=ELInactive?stream->volrecv:NULL);
} else {
ms_warning("cannot set echo limiter to mode [%i] because no volume send",type);
}
}
void audio_stream_enable_gain_control(AudioStream *stream, bool_t val){
......@@ -513,6 +508,13 @@ void audio_stream_enable_automatic_gain_control(AudioStream *stream, bool_t val)
void audio_stream_enable_noise_gate(AudioStream *stream, bool_t val){
stream->use_ng=val;
if (stream->volsend){
ms_filter_call_method(stream->volsend,MS_VOLUME_ENABLE_NOISE_GATE,&val);
} else {
ms_warning("cannot set noise gate mode to [%i] because no volume send",val);
}
}
void audio_stream_set_mic_gain(AudioStream *stream, float gain){
......
......@@ -204,7 +204,7 @@ static float volume_echo_avoider_process(Volume *v, mblk_t *om) {
v->target_gain = v->static_gain;
}
//if (!(++counter % 20))
ms_message("volume_echo_avoider_process(): mic_en=%f, peer_e=%f, target_g=%f, gain=%f, spk_peak=%f",
ms_debug("volume_echo_avoider_process(): mic_en=%f, peer_e=%f, target_g=%f, gain=%f, spk_peak=%f",
v->energy, peer_e, v->target_gain, v->gain, v->lt_speaker_en);
return v->target_gain;
}
......
......@@ -56,6 +56,7 @@ typedef struct SpeexECState{
#endif
bool_t using_silence;
bool_t echostarted;
bool_t bypass_mode;
}SpeexECState;
static void speex_ec_init(MSFilter *f){
......@@ -72,6 +73,7 @@ static void speex_ec_init(MSFilter *f){
s->den = NULL;
s->using_silence=FALSE;
s->echostarted=FALSE;
s->bypass_mode=FALSE;
#ifdef EC_DUMP
{
......@@ -124,6 +126,7 @@ static void speex_ec_preprocess(MSFilter *f){
/* inputs[0]= reference signal (sent to soundcard)
* inputs[1]= near speech & echo signal (read from soundcard)
* outputs[0]= far end speech
* outputs[1]= near end speech, echo removed - towards far end
*/
static void speex_ec_process(MSFilter *f){
......@@ -133,6 +136,16 @@ static void speex_ec_process(MSFilter *f){
uint8_t *ref,*echo;
int size;
if (s->bypass_mode) {
while((refm=ms_queue_get(f->inputs[0]))!=NULL){
ms_queue_put(f->outputs[0],refm);
}
while((refm=ms_queue_get(f->inputs[1]))!=NULL){
ms_queue_put(f->outputs[1],refm);
}
return;
}
if (f->inputs[1]!=NULL){
int maxsize;
ms_bufferizer_put_from_queue (&s->echo,f->inputs[1]);
......@@ -254,13 +267,25 @@ static int speex_ec_set_tail_length(MSFilter *f, void *arg){
s->tail_length_ms=*(int*)arg;
return 0;
}
static int speex_ec_set_bypass_mode(MSFilter *f, void *arg) {
SpeexECState *s=(SpeexECState*)f->data;
s->bypass_mode=*(bool_t*)arg;
ms_message("set EC bypass mode to [%i]",s->bypass_mode);
return 0;
}
static int speex_ec_get_bypass_mode(MSFilter *f, void *arg) {
SpeexECState *s=(SpeexECState*)f->data;
*(bool_t*)arg=s->bypass_mode;
return 0;
}
static MSFilterMethod speex_ec_methods[]={
{ MS_FILTER_SET_SAMPLE_RATE, speex_ec_set_sr },
{ MS_ECHO_CANCELLER_SET_TAIL_LENGTH , speex_ec_set_tail_length },
{ MS_ECHO_CANCELLER_SET_DELAY , speex_ec_set_delay },
{ MS_ECHO_CANCELLER_SET_FRAMESIZE , speex_ec_set_framesize },
{ MS_ECHO_CANCELLER_SET_BYPASS_MODE , speex_ec_set_bypass_mode },
{ MS_ECHO_CANCELLER_GET_BYPASS_MODE , speex_ec_get_bypass_mode },
};
#ifdef _MSC_VER
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment