Sample rate: 16k
I m using <speex_echo_state_init_mc(jBufSize, jTotalSize, 2 , 2>
Also as suggested in the doc frame_size should be of 20 ms & filter_length is of 100-500ms
I tried using frame_size as 16000 * 20/1000 = 320 & filter_size as 16000 * 500/1000 = 32000
Also tried other values for fram_size & filter_lenght but no luck !
JNIEXPORT void JNICALL Java_com_speex_SpeexInterface_open
(JNIEnv *env, jobject jObj, jint jSampleRate, jint jBufSize, jint jTotalSize) {
//init
int sampleRate = jSampleRate;
st = speex_echo_state_init_mc(jBufSize, jTotalSize, 2 , 2);
den = speex_preprocess_state_init(jBufSize, sampleRate);
speex_echo_ctl(st, SPEEX_ECHO_SET_SAMPLING_RATE, &sampleRate);
speex_preprocess_ctl(den, SPEEX_PREPROCESS_SET_ECHO_STATE, st);
}
JNIEXPORT jshortArray JNICALL Java_com_speex_SpeexInterface_process
(JNIEnv * env, jobject jObj, jshortArray input_frame, jshortArray echo_frame) {
//create native shorts from java shorts
jshort *native_input_frame = env->GetShortArrayElements(input_frame, 0);
jshort *native_echo_frame = env->GetShortArrayElements(echo_frame, 0);
//allocate memory for output data
jint length = env->GetArrayLength(input_frame);
jshortArray temp = env->NewShortArray(length);
jshort *native_output_frame = env->GetShortArrayElements(temp, 0);
//call echo cancellation
speex_echo_cancellation(st, native_input_frame, native_echo_frame, native_output_frame);
//preprocess output frame
speex_preprocess_run(den, native_output_frame);
//convert native output to java layer output
jshortArray output_shorts = env->NewShortArray(length);
env->SetShortArrayRegion(output_shorts, 0, length, native_output_frame);
//cleanup and return
env->ReleaseShortArrayElements(input_frame, native_input_frame, 0);
env->ReleaseShortArrayElements(echo_frame, native_echo_frame, 0);
env->ReleaseShortArrayElements(temp, native_output_frame, 0);
return output_shorts;
}
Please help me where I making mistake !!