views:

1146

answers:

2

What are my options for playing simultaneous audio on an Android device with the least amount of latency? Am I going to get anything half decent out of the canned SDK, or is that asking too much? The documentation claims that the SoundPool class is capable of playing multiple sounds simultaneously with relatively good performance, but after running some tests in the emulator and on a physical device it seems pretty weak. Is there maybe a trick to it, or do I have to go to a much lower level api for this kind of thing? I've tried using a single sound pool with multiple samples loaded, and I've tried multiple sound pools each managing a single sample. I'm preloading everything, so that when I attempt to play back I have no additional code being executed other than the call to SoundPool.play().

+2  A: 

I don't have any Android experience, but I've written similar things for Windows Mobile. The devices themselves are certainly capable of mixing multiple sounds in real-time with a low latency (under 25 ms), although by "multiple" I mean maybe 4 or 5 (and not 30 to 40). However, I was only able to achieve this satisfactorily by writing my own code that did the mixing internally and accessed the low-level audio playback API only for playing the final mixed output. The higher-level ways of playing sounds in the .Net Compact Framework are theoretically capable of polyphony, but in practice they work horribly (lots of glitches, stuttering and distortion).

I suspect that the Android audio SDK has the same problem, so you may have to write your own.

MusiGenesis
+1  A: 

A number of people are interested in low-latency audio on Andriod. Here are the threads I'm following on the topic:

  • A wave covering audio related topics from this year's I/O conference.
  • An Android issue about support for low latency audio in the NDK.

This post suggests that Android devices have ALSA drivers (capable of low-latency audio)--but it seems that low-latency functionality isn't exposed to apps via the NDK.

I have no direct experience with Android, but from what I've read, low-latency (less than <10ms or so) isn't a reality yet. Please post any experience to the contrary!

mattbh