Echo cancellation is method in telephony/VOIP to improve voice quality by preventing echo from being created or removing it after it is already present.

What is Acoustic echo?

Echo is a sound or sounds caused by the reflection of sound waves from a surface back to the listener. This happens in telephony/VOIP application, when a speaker phone/loud speaker is used, the microphone receives the voice signal from speaker. This results in acoustic echo for the person speaking in the far end.

AEC Implementation in Android

The Android framework supports audio effects such as Acoustic Echo Cancellation (AEC), Noise Suppression (NS) and Automatic Gain Control (AGC). To use this effects in Android, device vendor should implement this support in their audio HAL. These effects for audio source is applied based on the /system/etc/audio_effects.conf file. If user wants to add any specific effects for their device, then create a vendor specific configuration file in /system/vendor/etc/audio_effects.conf with the required effects turned on. Below is example audio_effects.conf file to enable AEC effects in Android.

libraries {
  pre_processing {
    path /system/lib/soundfx/libaudiopreprocessing.so
  }
}
effects {
  aec {
    library pre_processing
    uuid bb392ec0-8d4d-11e0-a896-0002a5d5c51b
  }
}

pre_processing {
  voice_communication {
      aec {
      }
  }
}

Note:

This effects work only, if hardware vendors of the device supported those effects in their Audio HAL.

AEC Architecture in Android using webRTC

The Android platform provides audio effects on supported devices in the audiofx package, which is available for developers to access. Below is the AEC architecture overview in Android using webRTC.

Overview

Application framework and JNI

The application framework includes the app code, which uses the android.media APIs to interact with audio hardware. For example, media player application, voice recorder application, SIP call application etc are the applications which are going to use audio hardware. The JNI code associated with android.media calls lower level native code (audio HAL) to access audio hardware.

Media server

The media server contains audio services, which are the actual code that interacts with your HAL implementations. The media server is located in

  • /AOSP/frameworks/av/services/audioflinger

Audio HAL

The HAL defines the standard interface that audio services call into and contains implementation for all audio hardware to function correctly. Audio HAL will be provided by device vendor. Audio HAL needs to AEC support. This involves enabling AEC session when requested by application frmaework, once AEC session enabled, processing the RX and TX audio data with the help of external AEC engine. Here it is webRTC.

Audio effects and audio utils

This audio utils forward the data to prepossessing library to apply the corresponding AEC effect. The audio efects and audio utils are located in the below path.

  • /AOSP/system/media/audio_utils

Preprocessing library

Preprocessing library is responsible for below purposes.

  • Initialise the webRTC AEC engine, when AEC session requested by HAL
  • Audio signal up-sampling and down-sampling, if needed.
  • Forward the input(reference) signal to AEC engine.
  • Give the processed audio signal (after AEC effects applied) signal back to audio HAL.

The audio preprocessing codes are located in

  • /AOSP/frameworks/av/media/libeffects/preprocessing/

WebRTC

WebRTC is a free, open project, and its supports audio processing effects such as AEC,Noise Reduction (NR) etc. WebRTC’s Acoustic Echo Canceller is a software based signal processing component that removes the acoustic echo in real time. This library expects receive audio which is going to be played in speaker and transmit audio which is recorded via microphone and gives output of microphone by removing the acoustic echo . The WebRTC applies AEC algorithms to remove echo from the given signal.