Reputation: 439
My Android app uses aaudio
to open audio stream, StreamBuilder
calls:
AudioStreamBuilder_setSessionId(builder, AAUDIO_SESSION_ID_ALLOCATE);
And after opening the stream:
AAudioStream_getSessionId(st->recorderStream)
produces a sessionId
such as 35329.
The app then calls AcousticEchoCanceler.create(sessionId)
with the produced sessionId
, but the call fails with these kind of error messages:
AudioEffect E set(): AudioFlinger could not create effect 7b491460-8d4d-11e0-bd61-0002a5d5c51b / ec7178ec-e5e1-4432-a3f4-4657e6795210, status: -19
AudioEffects-JNI E
AudioEffect initCheck failed -3
AudioEffect-JAVA E Error code -3 when initializing AudioEffect.
AcousticEchoCanceler W not enough memory
I have checked with ActivityManager.MemoryInfo()
and there is lots of memory available so it is hard to believe that memory would be the issue. Also, AcousticEchoCanceler.isAvailable()
returns true.
Any idea why creating of AcousticEchoCanceler
fails?
Upvotes: 1
Views: 50
Reputation: 1084
The issue likely stems from a mismatch between the session ID generated by AAudio and what the AcousticEchoCanceler
expects. AAudio’s session IDs aren’t always compatible with Android’s effect system, as effects like AEC are typically designed to work with AudioTrack
or AudioRecord
session IDs. You might want to try generating a session ID using AudioManager.generateAudioSessionId()
instead and pass that to the AcousticEchoCanceler
. Also, confirm that your app has the RECORD_AUDIO
permission and that no other app or effect is using AEC simultaneously. Finally, test on different devices, as some may not support AEC with AAudio streams.
Here’s an example of creating a valid session ID using in java AudioManager
:
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
int sessionId = audioManager.generateAudioSessionId();
if (sessionId == AudioManager.ERROR) {
Log.e("Audio", "Failed to generate a session ID");
} else {
AcousticEchoCanceler aec = AcousticEchoCanceler.create(sessionId);
if (aec != null) {
Log.d("Audio", "AcousticEchoCanceler successfully created");
} else {
Log.e("Audio", "Failed to create AcousticEchoCanceler");
}
}
Upvotes: 0