Why Java AudioEffect not working with Oboe?

284 Views Asked by At

Android version: 10
Android device: OnePlus 6

I have tried to apply Java AudioEffect using sessionID from AudioManager getting help from this LINK but I always get NullPointerException when using AcousticEchoCanceler.create(sessionId) but when I pass the sessionId of Java AudioRecord getAudioSessionId() it works.

My Code is:

val audioManager: AudioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
val sessionId = audioManager.generateAudioSessionId()

C code is

recordingBuilder.setSessionId(static_cast<oboe::SessionId>(sessionId));
oboe::Result recordStreamResult = recordingBuilder.openStream(&recordStream);

I have tried this code on OnePlus 6 and Motorola One Macro.

1

There are 1 best solutions below

0
On

I have resolved the issue of: Why my AcousticEchoCanceler.create(sessionId) returned null even though it was available.

Here is the code

  val audioManager: AudioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
  val sessionId = audioManager.generateAudioSessionId()
  //This is the line that enables AEC, when MODE is set
  audioManager.mode = AudioManager.MODE_IN_COMMUNICATION 

When mode is explicitly set to MODE_IN_COMMUNICATION then AcousticEchoCancelation start working. From here you can enable or disable it.

val isAecAvailable = AcousticEchoCanceler.isAvailable()
val acousticEchoCanceler = AcousticEchoCanceler.create(sessionId)
acousticEchoCanceler.enabled = true //THIS ENABLED THE AEC

if (acousticEchoCanceler != null)
    Log.e(TAG, "AEC STATUS:  ${acousticEchoCanceler.enabled}")
else
Log.e(TAG, "AEC  IS NULL")

Currently, I am using Oboe version: 1.5 stable