Question

By "fastest," I mean lowest-latency.

The 2 methods of which I am aware are:

  1. use android.media.AudioTrack
  2. use OpenSL ES with NDK/C++

Of the two, which is faster? If there are other alternatives, please enlighten me.

Further details: Assume that my application will be playing sounds that are predisposed to the native hardware's format. E.G., if the native playback sample rate is 44.1KHz, I will feed it a 44.1K sound. If instead the native sample rate is 48KHz, I will feed it a 48KHz sound. No system mixer or re-sampler should be necessary.

Was it helpful?

Solution

Last time I checked the Android source code, the only two APIs that would use the low-latency path added in Jellybean were OpenSL ES and SoundPool (and maybe ToneGenerator as well, but I guess that's irrelevant here).

If you've got a bunch of static sounds, using a SoundPool would be the most convenient option. For real-time generated audio you'll have to use OpenSL ES.

For the list of conditions that need to be met for the low-latency path to be chosen, I refer you to the source code of libaudioflinger and libwilhelm. Short summary: Use the native sample rate, mono or stereo linear PCM, no effects.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top