JNIEXPORT jint JNICALL Java_com_jabber_audio_encoder_AudioWebrtcAecm_yy_1webrtc_1aecm_1initiate (JNIEnv *env, jobject obj, jint samp_freq){ __android_log_print(ANDROID_LOG_ERROR ,TAG ,"in audioWebrtcAecm initiate function "); int ret ; void* AECM_instance; if ((ret = WebRtcAecm_Create(&AECM_instance) )) { __android_log_print(ANDROID_LOG_ERROR ,TAG ,"WebRtcAecm_Create failed with error code = %d", ret); return ret; } if ((ret = WebRtcAecm_Init(AECM_instance, samp_freq) )) { __android_log_print(ANDROID_LOG_ERROR ,TAG ,"WebRtcAecm_Init failed with error code = %d", ret); return ret; } #if 0 //config AecmConfig aecm_config; aecm_config.cngMode = AECM_TRUE; aecm_config.echoMode = 3; if(( ret = WebRtcAecm_set_config(AECM_instance, aecm_config) )){ __android_log_print(ANDROID_LOG_ERROR ,TAG ,"WebRtcAecm_set_config failed with error code = %d", ret); return ret; } #endif return (jint)((int *)AECM_instance ); }
int main(void){ void *aecInst; if(-1 == WebRtcAecm_Create(&aecInst)){ perror("WebRtcAec_Create:"); exit(1); } if(-1 == WebRtcAecm_Init(aecInst,8000)){ perror("WebRtcAec_Init:"); exit(1); } WebRtcAecm_Free(aecInst); printf("hello webRTC\n"); return 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; }
void KotiAEC_init(int16_t frame_size, int32_t sample_freq, AEC_CORE aec_core, int speex_filter_length, int16_t agc_mode, int16_t compression_gain_db, uint8_t limiter_enable, float snd_amplification) { int32_t speex_agc = 0; float speex_agc_level = 24000, speex_agc_level_tmp = 3000; int32_t speex_noise_suppress = -15; aec_core_used = aec_core; output_sound_amplification = snd_amplification; switch(aec_core) { #ifdef WEBRTC_AEC_CORE_ENABLED case WEBRTC_AEC: if(webrtc_aec_pty.webrtc_aec == NULL) { webrtc_aec_pty.frame_size = frame_size; webrtc_aec_pty.sample_freq = sample_freq; webrtc_aec_pty.sndcard_sample_freq = sample_freq; webrtc_aec_pty.sndcard_delay_ms = ((float)speex_filter_length/sample_freq) * 1000; if( WebRtcAec_Create(&webrtc_aec_pty.webrtc_aec) == 0) WebRtcAec_Init(webrtc_aec_pty.webrtc_aec, webrtc_aec_pty.sample_freq, webrtc_aec_pty.sndcard_sample_freq); if( WebRtcNsx_Create((NsxHandle**)&webrtc_aec_pty.webrtc_ns) == 0) { WebRtcNsx_Init((NsxHandle*)webrtc_aec_pty.webrtc_ns, webrtc_aec_pty.sample_freq); WebRtcNsx_set_policy((NsxHandle*)webrtc_aec_pty.webrtc_ns, 1); } if( WebRtcAgc_Create(&webrtc_aec_pty.webrtc_agc) == 0) { WebRtcAgc_Init(webrtc_aec_pty.webrtc_agc, 0, 255, agc_mode/*kAgcModeFixedDigital*/, webrtc_aec_pty.sample_freq); WebRtcAgc_config_t conf = {0, compression_gain_db, limiter_enable}; WebRtcAgc_set_config(webrtc_aec_pty.webrtc_agc, conf); } } else { WebRtcAec_Init(webrtc_aec_pty.webrtc_aec, webrtc_aec_pty.sample_freq, webrtc_aec_pty.sndcard_sample_freq); } break; case WEBRTC_AECM: if(webrtc_aecm_pty.webrtc_aec == NULL) { webrtc_aecm_pty.frame_size = frame_size; webrtc_aecm_pty.sample_freq = sample_freq; webrtc_aecm_pty.sndcard_sample_freq = sample_freq; webrtc_aecm_pty.sndcard_delay_ms = ((float)speex_filter_length/sample_freq) * 1000; // webrtc_aecm_pty.sndcard_delay_ms = speex_filter_length/frame_size; if( WebRtcAecm_Create(&webrtc_aecm_pty.webrtc_aec) == 0) WebRtcAecm_Init(webrtc_aecm_pty.webrtc_aec, webrtc_aecm_pty.sample_freq); if( WebRtcNsx_Create((NsxHandle**)&webrtc_aecm_pty.webrtc_ns) == 0) { WebRtcNsx_Init((NsxHandle*)webrtc_aecm_pty.webrtc_ns, webrtc_aecm_pty.sample_freq); WebRtcNsx_set_policy((NsxHandle*)webrtc_aecm_pty.webrtc_ns, 1); } if( WebRtcAgc_Create(&webrtc_aecm_pty.webrtc_agc) == 0) { WebRtcAgc_Init(webrtc_aecm_pty.webrtc_agc, 0, 255, agc_mode/*kAgcModeFixedDigital*/, webrtc_aecm_pty.sample_freq); WebRtcAgc_config_t conf = {0, compression_gain_db, limiter_enable}; WebRtcAgc_set_config(webrtc_aecm_pty.webrtc_agc, conf); } } break; #endif case SPEEX_AEC: default: #ifdef OLD_SPEEX_AEC if(speex_aec_pty.speex_echo_state == NULL && speex_aec_pty.speex_preprocess_state == NULL) { speex_aec_pty.frame_size = frame_size; speex_aec_pty.sample_freq = sample_freq; speex_aec_pty.filter_length = speex_filter_length; if(speex_aec_pty.filter_length < frame_size) speex_aec_pty.filter_length = frame_size*FILTER_LENGTH_MULTIPLE_OF_FRAME_SIZE; speex_aec_pty.speex_echo_state = speex_echo_state_init(frame_size, speex_aec_pty.filter_length); speex_aec_pty.speex_preprocess_state = speex_preprocess_state_init(frame_size, sample_freq); speex_echo_ctl((SpeexEchoState*)speex_aec_pty.speex_echo_state, SPEEX_ECHO_SET_SAMPLING_RATE, &speex_aec_pty.sample_freq); speex_aec_pty.nosie = (int32_t*) malloc( (frame_size+1) * sizeof(int32_t) ); } #else if(speex_aec_pty.speex_echo_state == NULL && speex_aec_pty.speex_preprocess_state == NULL) { speex_aec_pty.frame_size = frame_size; speex_aec_pty.sample_freq = sample_freq; speex_aec_pty.filter_length = speex_filter_length; if(speex_aec_pty.filter_length < frame_size) speex_aec_pty.filter_length = frame_size*FILTER_LENGTH_MULTIPLE_OF_FRAME_SIZE; speex_aec_pty.speex_echo_state = speex_echo_state_init(frame_size, speex_aec_pty.filter_length); speex_aec_pty.speex_preprocess_state = speex_preprocess_state_init(frame_size, sample_freq); speex_echo_ctl((SpeexEchoState*)speex_aec_pty.speex_echo_state, SPEEX_ECHO_SET_SAMPLING_RATE, &speex_aec_pty.sample_freq); speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_SET_ECHO_STATE, speex_aec_pty.speex_echo_state); speex_aec_pty.nosie = (int32_t*) malloc( (frame_size+1) * sizeof(int32_t) ); speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_SET_AGC, &speex_agc); speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_SET_AGC_LEVEL, &speex_agc_level); speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS, &speex_noise_suppress); speex_aec_pty.speex_preprocess_state_tmp = speex_preprocess_state_init(frame_size, sample_freq); speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state_tmp, SPEEX_PREPROCESS_SET_AGC, &speex_agc); speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state_tmp, SPEEX_PREPROCESS_SET_AGC_LEVEL, &speex_agc_level_tmp); speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state_tmp, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS, &speex_noise_suppress); // int32_t speex_vad = 1; // int32_t speex_vad_prob_start = 80; // int32_t speex_vad_prob_continue = 65; // speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_SET_VAD, &speex_vad); // speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_SET_PROB_START, // &speex_vad_prob_start); // speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_SET_PROB_CONTINUE, // &speex_vad_prob_continue); // int32_t tmp = -1; float tmp1 = 0.0f; // speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_GET_DENOISE, &tmp); // printf("SPEEX_PREPROCESS_GET_DENOISE: %d\n", tmp); // speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_GET_NOISE_SUPPRESS, &tmp); // printf("SPEEX_PREPROCESS_GET_NOISE_SUPPRESS: %d\n", tmp); // speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_GET_AGC, &tmp); // printf("SPEEX_PREPROCESS_GET_AGC: %d\n", tmp); // speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_GET_VAD, &tmp); // printf("SPEEX_PREPROCESS_GET_VAD: %d\n", tmp); // speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_GET_PROB_START, &tmp); // printf("SPEEX_PREPROCESS_GET_PROB_START: %d\n", tmp); // speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_GET_PROB_CONTINUE, &tmp); // printf("SPEEX_PREPROCESS_GET_PROB_CONTINUE: %d\n", tmp); // speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_GET_AGC_LEVEL, &tmp1); // printf("SPEEX_PREPROCESS_GET_AGC_LEVEL: %f\n", tmp1); // speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_GET_AGC_DECREMENT, &tmp); // printf("SPEEX_PREPROCESS_GET_AGC_DECREMENT: %d\n", tmp); // speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_GET_AGC_INCREMENT, &tmp); // printf("SPEEX_PREPROCESS_GET_AGC_INCREMENT: %d\n", tmp); // speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_GET_AGC_MAX_GAIN, &tmp); // printf("SPEEX_PREPROCESS_GET_AGC_MAX_GAIN: %d\n", tmp); // speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_GET_AGC_GAIN, &tmp); // printf("SPEEX_PREPROCESS_GET_AGC_GAIN: %d\n", tmp); // speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_GET_AGC_TARGET, &tmp); // printf("SPEEX_PREPROCESS_GET_AGC_TARGET: %d\n", tmp); // speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_GET_AGC_LOUDNESS, &tmp); // printf("SPEEX_PREPROCESS_GET_AGC_LOUDNESS: %d\n", tmp); // speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_GET_ECHO_SUPPRESS, &tmp); // printf("SPEEX_PREPROCESS_GET_ECHO_SUPPRESS: %d\n", tmp); // speex_preprocess_ctl((SpeexPreprocessState*)speex_aec_pty.speex_preprocess_state, SPEEX_PREPROCESS_GET_ECHO_SUPPRESS_ACTIVE, &tmp); // printf("SPEEX_PREPROCESS_GET_ECHO_SUPPRESS_ACTIVE: %d\n", tmp); } #endif break; } }