Skip to content Skip to sidebar Skip to footer

Android Audio Programming Nightmare - Soundpool, Audiotrack Arrghh?

I've built a simple music sequencer Android app that plays multiple audio files. Originally I was using SoundPool to play mp3 files and it worked perfectly on 2.3.4 with an old HTC

Solution 1:

Like user harikris suggests, I would highly recommend you move all your audio playback and processing code to Android NDK using the OpenSL ES library for the best performance.

As I understand, the AudioTrack API is built on top of OpenSL ES Buffer Queue Audio Player. So you could probably improve performance by working directly with the NDK, writing C code that is called from your Java/Android layer to work with the sound.

The native-audio example mentioned above contains code that will show you how to play a sound file directly from a URI. In my experience, the results from this method are better than AudioTrack in Static Mode.

Soundpool is generally reserved for very short sounds that can be played from memory and its not a scalable solution for your sequencer especially if you introduce large files.

Here are some links that have helped me out with my applications: -General Information on OpenSL ES for Android: http://mobilepearls.com/labs/native-android-api/opensles/

-An Android audio blog with some great example code: http://audioprograming.wordpress.com

Edit: The old mobile pearl link appears to be down. Here's a working one:http://mobilepearls.com/labs/native-android-api/ndk/docs/opensles/index.html


Solution 2:

In the High Performance Audio session at Google I/O 2013 (introduced by Ian Ni-Lewis who commented on the original post. I'm surprised he didn't pick up on this), they talk about the Nexus 4. In the video of the presentation, jump to 27:25.

Unlike many other devices that use a native 44.1kHz sample rate, the Nexus 4 uses 48kHz. If you are submitting data at 44.1kHz, it will have to go through the resampler which is on the slow path. Another difference is that the buffer size on the Nexus 4 is 240 frames which can cause a regular jitter in your callback. This is all explained in the linked video.


Solution 3:

I would recommend you do all your audio capture and time sensitive processing in native code and use JNI to interact between the SDK and NDK components.

You can find native-audio project example code in the Android NDK distro that show you how to do audio in C/C++


Post a Comment for "Android Audio Programming Nightmare - Soundpool, Audiotrack Arrghh?"