20

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().

Rich
  • 36,270
  • 31
  • 115
  • 154

4 Answers4

6

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
  • 5,230
  • 2
  • 27
  • 27
6

Android 2.3 now supports native access to audio APIs (via OpenSL) for low latency applications.

However, not all hardware devices will have the a low latency audio feature profile. Thus applications requiring low latency audio shouuld filter devices not supporting it in the Android market by specifying the following in the manifest:

<uses-feature android:name="android.hardware.audio.low_latency"/>
dljava
  • 1,825
  • 17
  • 14
  • I have a phone with 2.2 now and a 1Ghz CPU, and I've seen a bunch of apps do a half decent job. After doing some research, I'm pretty sure they're decoding PCM data from audio files and writing it straight to an AudioTrack, and that's pretty low latency enough for a basic audio sequencer/player – Rich Dec 10 '10 at 15:03
  • @Rich: I have tried with 2.2 and a 1GHz phone and the minimum buffer size Audiotrack gives me is 1400 when in 8kHz, Mono. That's 175 ms. For my desired functionality, that's to slow. – AudioDroid Jun 07 '11 at 14:59
  • 7
    It's a marketing gimmick - to make someone think that are 'keeping up with apple. It should have been called 'medium latency'. I do not think there are too many use cases that can benefit from 50 ms latency. It's too slow for a proper audio respsonse, and an unnecessary requirement for anything else. – Jon Biz Nov 30 '11 at 20:05
  • If it's a gimmick, it's not a very successful one. Up until very recently, no devices at all supported that feature. – Ian Ni-Lewis Sep 24 '12 at 00:21
4

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
  • 74,184
  • 40
  • 190
  • 334
  • I am willing to try what you suggested here for low latency audio record/play. But I think I need more direction than current answer. Could you describe more what you did for WinPhone? – Tae-Sung Shin Dec 07 '11 at 22:57
1

Please see my answer to Android: sound API (deterministic, low latency).

The latency of an Android device depends less on the API and more on the hardware and drivers for that particular device. Enabling low latency playback consumes more power and increases the chances of audio glitches, so many OEMs will enlarge their playback buffers intentionally.

Community
  • 1
  • 1
Ian Ni-Lewis
  • 2,377
  • 20
  • 20