Android audio programming nightmare - soundpool, audiotrack arrghh?

可紊 提交于 2019-11-30 13:37:41

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

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.

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++

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!