Echo Cancellation from OpenSL ES

829 views
Skip to first unread message

Gary Bak

unread,
Mar 11, 2015, 7:43:46 PM3/11/15
to andro...@googlegroups.com
Hello,

It seems in Lollipop on Nexus devices I now have to enable the echo cancellation by creating an instance of the AcousticEchoCanceller in the SDK.  In addition, I need to set the audio source to VOICE_COMMUNICATION and stream type to STREAM_VOICE_CALL in order for the echo cancellation to be enabled.  This is within our Java driver.

AcousticEchoCanceler.create(audioRecord.getAudioSessionId());


How can I enable echo cancellation from within OpenSL ES?  From reading the docs and searches, the Echo Cancellation api is not exposed from the C library, and there is no API to receive the Record ID to callback into JNI to create the AcousticEchoCanceller within the Java SDK.  Is there any good way to do this?

TIA
Gary

Naaman Sittsamer

unread,
Mar 12, 2015, 3:00:55 AM3/12/15
to andro...@googlegroups.com
Hi Gary,
For using stream type STREAM_VOICE_CALL for the active source you can use this code:

SLAndroidConfigurationItf playerConfig;
  res = (*sles_player_)->GetInterface(sles_player_,
 SL_IID_ANDROIDCONFIGURATION, &playerConfig);
  if (res != SL_RESULT_SUCCESS) {
 WEBRTC_OPENSL_TRACE(kTraceError, kTraceAudioDevice, id_,
 "  failed to get SL_IID_ANDROIDCONFIGURATION");
 return -1;
  }
  int32_t streamType = SL_ANDROID_STREAM_VOICE;
  res = (*playerConfig)->SetConfiguration(playerConfig,
 SL_ANDROID_KEY_STREAM_TYPE, &streamType, sizeof(int32_t));
  if (res != SL_RESULT_SUCCESS) {
 WEBRTC_OPENSL_TRACE(kTraceError, kTraceAudioDevice, id_,
 "  failed to set SL_ANDROID_STREAM_VOICE");
 return -1;
  }


works for me...

Naaman

Reply all
Reply to author
Forward
0 new messages