4

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.

dbautista
  • 121
  • 1
  • 1
  • 5

3 Answers3

10

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
);
junglecat
  • 643
  • 1
  • 10
  • 19
0

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

Sam Dutton
  • 14,775
  • 6
  • 54
  • 64
0

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

Keo Malope
  • 1,015
  • 12
  • 19
  • I never got Speex Echo Cancellation working very well (lot's of noise). See my answer on how to include the AEC from WebRTC. – junglecat Feb 04 '13 at 18:13
  • Thanks. Side note: SSE2 is for x86 architectures. If working on ARM based platform, you'd have to use aec"m" source files. Better still, you could link against the already integrated "libaudiopreprocessing" – Keo Malope Feb 12 '13 at 22:37
  • i am using some thing like this AudioSource audioSource = factory.createAudioSource(new MediaConstraints()); localMS.addTrack(factory.createAudioTrack("ARDAMSa0", audioSource)); i have created audiosource using Peerconnectionfactory and added that in mediastream track. So how can i use your code in that scenario ? – umerk44 Apr 20 '15 at 11:01