WebRTC AEC on Android

10.7k views Asked by At

I'm developing a SIP softphone app for Android, and facing the echo cancellation problem. I've tried to solve it using Speex with no success. So my next shot is WebRTC AEC (Acoustic Echo Cancellation), but I cannot find any documentation about how to use it.

In my app, the audio is managed with AudioTrack and AudioRecord classes in Java, but the sockets that sends and receive are in a C code (integrated with JNI). WebRTC is a mega-project, and I only want to integrate the AEC module.

Does someone know which files I have to include, which flags does the compiler need, which function calls to do, and so on? I have the CSipSimple code, which also uses the WebRTC (but for other uses too) and I can't find out the easy and proper way to include and use it.

Thanks.

3

There are 3 answers

0
Sam Dutton On

This doesn't answer your question, but if you can't find what you need on webrtc.org, try the discuss-webrtc group.

0
junglecat On

You'll need the following files:

aec/modules/audio_processing/aec/aec_core_sse2.c
aec/modules/audio_processing/aec/aec_core.c
aec/modules/audio_processing/aec/aec_rdft_sse2.c
aec/modules/audio_processing/aec/aec_rdft.c
aec/modules/audio_processing/aec/aec_resampler.c
aec/modules/audio_processing/aec/echo_cancellation.c
aec/modules/audio_processing/utility/ring_buffer.c
aec/modules/audio_processing/utility/delay_estimator.c
aec/modules/audio_processing/utility/delay_estimator_wrapper.c
aec/system_wrappers/source/cpu_features.cc
aec/common_audio/signal_processing/randomization_functions.c

Usage:

void * aec = 0;
int status = WebRtcAecm_Create(&aec);
status = WebRtcAecm_Init(aec, 8000 /* sample rate */);

// Buffer the far end frames
int status = WebRtcAecm_BufferFarend(
    aec, play_frm, 160
);

// Cancel echo
status = WebRtcAecm_Process(
    aec, (WebRtc_Word16 *)buf, (WebRtc_Word16 *)buf,
    tmp_frm, 160,
    echo_tail / tail_factor
);
3
Keo Malope On

Note: Version of android referenced below is 4.1 (JellyBean)

The response is probably too late. However, for anyone interested in answers to dbaustista's questions, consider following:

AEC is modeled by AudioEffect class. So, an AEC AudioEffect object needs to be added to the "effects-chain" of the RecordThread. I believe the implementation of AEC is built into the libaudioprocessing library. See additional notes below.

Library

/system/etc/audio_effects.conf
libraries {
...
   pre_processing {
     path /system/lib/soundfx/libaudiopreprocessing.so
   }
}

Interface

media/AudioEffect.h

Example

The example below shows you how to add an AudioEffect object to a PlaybackThread. Apply similar logic to the RecordThread i.e. Add the AEC object to the effects-chain of the RecordThread.

mediaframeworktest/functional/audio/MediaAudioEffectTest.java

      AudioTrack track = new AudioTrack(
                                  AudioManager.STREAM_MUSIC,
                                  44100,
                                  AudioFormat.CHANNEL_OUT_MONO,
                                  AudioFormat.ENCODING_PCM_16BIT,
                                  AudioTrack.getMinBufferSize(44100,
                                  AudioFormat.CHANNEL_OUT_MONO,
                                  AudioFormat.ENCODING_PCM_16BIT),
                                  AudioTrack.MODE_STREAM);
      assertNotNull(msg + ": could not create AudioTrack", track);
      AudioEffect effect = new AudioEffect(AudioEffect.EFFECT_TYPE_ENV_REVERB,
              AudioEffect.EFFECT_TYPE_NULL,
              0,
              0);

      track.attachAuxEffect(effect.getId());
      track.setAuxEffectSendLevel(1.0f);

AEC Config Options

TODO: add example configuration of AEC