Android Audio Latency Workarounds
Asked Answered
J

3

8

So anybody worth their salt in the android development community knows about issue 3434 relating to low latency audio in Android. For those who don't, you can educate yourself here. http://code.google.com/p/android/issues/detail?id=3434

I'm looking for any sort of temporary workaround for my personal project. I've heard tell of exposing private interfaces to the NDK by rolling your own build of android and modifying the NDK.

All I need is a way to access the low level alsa drivers which are already packaged with the standard 2.2 build. I'd like to have the ability to send PCM directly to the audio hardware on my device. I don't care that the resulting app won't be distributable over the marketplace, and likely won't run with any other device than mine.

Anybody have any useful ideas?

-Griff

EDIT: I should mention, I know AudioTrack provides this functionality, but I'd like much lower latency -- AudioTrack sits around 300ms, I'd like somewhere around 20-30 ms.

Jaworski answered 17/11, 2010 at 0:18 Comment(0)
U
7

Griff, that's just the problem, NDK wil not improve the known latency issue (that's even documented). The hardware abstraction layer in native code is currently adding to the latency, so it's not just about access to the low level drivers (btw you shouldn't rely on alsa drivers being there anyway).

Unworldly answered 27/3, 2011 at 22:16 Comment(3)
Gah. I was hoping that wouldn't be the case. I actually had a chance to talk to the Android guys at GDC 2011, and apparently it isn't entirely a hardware issue, but instead an architecture issue that is not easy to resolve.Jaworski
See @Ian Ni-Lewis's comment - things are getting better with 4.1Multicolored
I predict that there will be no architectural resolution, as Google is unconcerned with actual performance of these data-mining devices that pose as smart phones.Impinge
L
1

Android: sound API (deterministic, low latency) covers the tradeoffs pretty well. TL;DR: NDK gives you a minor benefit because the threads can run at higher priority, but this benefit is meaningless pre-Jellybean because the entire audio system is tuned for Java.

The Galaxy Nexus running 4.1 can get fairly close to 30ms of output latency.

Lisabethlisan answered 13/9, 2012 at 17:59 Comment(1)
Great, so a specific hardware device will work but only slightly better; this is becoming a zero-sum game.Impinge
H
0

The latency situation on Android has changed significantly sine the original post. Now most flagship Android phones can achieve good low latency.

The AAudio API allows an app to write into an MMAP buffer that is read by the hardware. So that provides the lowest possible path. That is better than writing to ALSA directly.

There is a new checklist for enabling low latency on Android at: https://developer.android.com/games/sdk/oboe/low-latency-audio#oboe

Hagiocracy answered 6/2 at 1:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.