Wednesday, February 3, 2010

No Low Level Audio in Android SDK

After a lengthy search of the Web, I've learned that low level audio support for Android is still in the works. As of now there is only a Java API for audio recording and playback, the lowest of which are the AudioRecord and AudioTrack classes. The AudioRecord class lets you get raw data from the microphone, and the AudioTrack class lets you stream raw PCM data for playback. The latency from Java to the hardware is unacceptable for many types of music, sound, and game applications. The lack of low level features like synchronous play is very painful for what I'm wanting to do.

There are a number of threads as well as an issue report addressing this problem. The current version of the Android NDK does not have an audio API. There are hints that the next NDK version will have some audio support, but who knows when that will be available. 

Without low level audio support and no synchronous play API, there seems to be only two options for playing two sounds synchronously: 1) play them at the same time and hope for the best, or 2) mix the sounds in the software before playing them. Option 2 sounds more reliable, but can it be done in real time? I may need to use the NDK to implement the mixing in C, which would involve sending the data through a JNI round trip.