Example #1
0
static void speex_ec_preprocess(MSFilter *f) {
    SpeexECState *s=(SpeexECState*)f->data;
    int delay_samples=0;
    mblk_t *m;

    s->echostarted=FALSE;
    s->filterlength=(s->tail_length_ms*s->samplerate)/1000;
    s->framesize=adjust_framesize(s->framesize_at_8000,s->samplerate);
    delay_samples=s->delay_ms*s->samplerate/1000;
    ms_message("Initializing speex echo canceler with framesize=%i, filterlength=%i, delay_samples=%i",
               s->framesize,s->filterlength,delay_samples);

    s->ecstate=speex_echo_state_init(s->framesize,s->filterlength);
    s->den = speex_preprocess_state_init(s->framesize, s->samplerate);
    speex_echo_ctl(s->ecstate, SPEEX_ECHO_SET_SAMPLING_RATE, &s->samplerate);
    speex_preprocess_ctl(s->den, SPEEX_PREPROCESS_SET_ECHO_STATE, s->ecstate);
    /* fill with zeroes for the time of the delay*/
    m=allocb(delay_samples*2,0);
    m->b_wptr+=delay_samples*2;
    ms_bufferizer_put (&s->delayed_ref,m);
    s->min_ref_samples=-1;
    s->nominal_ref_samples=delay_samples;
    ms_audio_flow_controller_init(&s->afc);
    s->flow_control_time = f->ticker->time;
#ifdef SPEEX_ECHO_GET_BLOB
    apply_config(s);
#else
    if (s->state_str) ms_warning("This version of speex doesn't support echo canceller restoration state. Rebuild speex and mediatreamer2 if you want to use this feature.");
#endif
}
Example #2
0
static void webrtc_aec_preprocess(MSFilter *f)
{
	WebRTCAECState *s = (WebRTCAECState *) f->data;
	AecmConfig config;
	int delay_samples = 0;
	mblk_t *m;
	int error_code;

	s->echostarted = FALSE;
	delay_samples = s->delay_ms * s->samplerate / 1000;
	s->framesize=(framesize*s->samplerate)/8000;
	ms_message("Initializing WebRTC echo canceler with framesize=%i, delay_ms=%i, delay_samples=%i", s->framesize, s->delay_ms, delay_samples);

	if ((s->aecmInst = WebRtcAecm_Create()) == NULL) {
		s->bypass_mode = TRUE;
		ms_error("WebRtcAecm_Create(): error, entering bypass mode");
		return;
	}
	if ((error_code = WebRtcAecm_Init(s->aecmInst, s->samplerate)) < 0) {
		if (error_code == AECM_BAD_PARAMETER_ERROR) {
			ms_error("WebRtcAecm_Init(): WebRTC echo canceller does not support %d samplerate", s->samplerate);
		}
		s->bypass_mode = TRUE;
		ms_error("Entering bypass mode");
		return;
	}
	config.cngMode = TRUE;
	config.echoMode = 3;
	if (WebRtcAecm_set_config(s->aecmInst, config)!=0){
		ms_error("WebRtcAecm_set_config(): failed.");
	}

	/* fill with zeroes for the time of the delay*/
	m = allocb(delay_samples * 2, 0);
	m->b_wptr += delay_samples * 2;
	ms_bufferizer_put(&s->delayed_ref, m);
	s->min_ref_samples = -1;
	s->nominal_ref_samples = delay_samples;
	ms_audio_flow_controller_init(&s->afc);
	s->flow_control_time = f->ticker->time;
}