News for hackers. Stuff that matters.
Re:Android’s 10 Millisecond Problem explained by afandian on Thursday April 16, 2015 @07:22AM (#9387125)
Anyone with any insight about how Apple does this?
Re:Android’s 10 Millisecond Problem explained by miahi on Thursday April 16, 2015 @07:45AM (#9387234)
Probably by custom and known hardware. Let's say it takes 1000 working hours to produce a low latency driver/firmware; Apple only needs to do that for a few devices, but every Android manufacturer has different audio chips and most of them only care that audio works, not that it works well - so they do not invest that time for each device type. Having known hardware also works for the application developers, because they can optimize their code for the specific device (knowing that you always have a 40ms latency is way better than knowing that the latency is between 35 and 300ms).

Also, Apple is much more motivated to get the audio path right, having started with the iPods and selling a lot of music.

Re:Android’s 10 Millisecond Problem explained by madez on Thursday April 16, 2015 @08:05AM (#9387313)
The latency problems arise with ALSA (mostly hardware-independent) and AudioFlinger (totally hardware-independent).
Re:Android’s 10 Millisecond Problem explained by kllrnohj on Thursday April 16, 2015 @03:41PM (#9390320)
That's technically correct but an extremely inaccurate summary.

The reason ALSA and AudioFlinger add latency is to hide hardware-dependent differences as well as kernel-caused scheduling issues & policy decisions.

To achieve low-latency you need real-time scheduling, something Linux has with SCHED_FIFO but it's a bit kludgy, and getting the policy right on that is tricky (obviously you don't want a random app to be able to set a thread to SCHED_FIFO and preempt the entire system). So you have to restrict the CPU budge of a SCHED_FIFO thread, and you have to only allow apps to have a single SCHED_FIFO thread. But how much CPU time you give it needs to depend on the CPU's performance in combination with the audio buffer size that the underlying audio chip needs (and those chips also have different sample rates, is it 44.1khz or 48khz or etc...).

tl;dr: this is insanely hardware-dependent.

Re:Android’s 10 Millisecond Problem explained by szantog on Thursday April 16, 2015 @09:34AM (#9387784)
ALSA is super. The HAL connecting ALSA to AudioFlinger is the major problem, plus the audio stack's "push" philosophy.
Re:Android’s 10 Millisecond Problem explained by po on Thursday April 16, 2015 @09:27AM (#9387755)
Look at the architecture of the Core Audio API and compare it to the parent article:

https://developer.apple.com/library/mac/documentation/MusicA...

Besides the fact that you are writing in C/Objective C, most heavy lifting is being provided by Audio Units which are specifically designed with common datatypes to be chained, composed and executed in low-latency situations.

Furthermore, most common things you would need in your app like mixing, conversion, timing, etc are provided as highly optimized services by the system.

Re:Android’s 10 Millisecond Problem explained by JoeAltmaier on Thursday April 16, 2015 @10:44AM (#9388238)
Also CoreAudio drivers (HAL) calls back every 11ms to empty/fill a buffer. So it starts with lower latency?
Re:Android’s 10 Millisecond Problem explained by tim333 on Thursday April 16, 2015 @07:33AM (#9387181)
Some answers on quora. TLDR Apple have been working on audio a long time.

http://www.quora.com/Why-do-iPhones-have-better-professional...

Re:Android’s 10 Millisecond Problem explained by creshal on Thursday April 16, 2015 @08:22AM (#9387409)
Or, rather, actually care about audio. Google (/Motorola Mobility, when it was owned by it) doesn't even care if a phone ships with a broken headphone port and refuses to fix it.
Re:Android’s 10 Millisecond Problem explained by TillE on Thursday April 16, 2015 @09:54AM (#9387892)
Seriously, the absolute garbage headphone jacks on the two flagship Android phones I owned (Motorola Milestone and Galaxy Nexus) are the reason I now own an iPhone 6. I still mostly prefer Android as an OS, but at least Apple is willing to spend the extra 50 cents on a headphone jack that lasts for more than a couple weeks.
Re:Android’s 10 Millisecond Problem explained by pja on Thursday April 16, 2015 @07:29AM (#9387162)
Same way they do with anything else they care about: by controlling everything in the stack from the hardware up.
Re:Android’s 10 Millisecond Problem explained by raverbashing on Thursday April 16, 2015 @07:36AM (#9387201)
I don't see how this has to do with hardware rather than architectural decisions

AudioFlinger + Alsa take a lot of time, as seen per the graph

But Android seems to take the option of least effort and "works most of the time" (which they have their reasons to)

Re:Android’s 10 Millisecond Problem explained by mhax on Thursday April 16, 2015 @07:43AM (#9387224)
The hardware you intend run on will impact your architectural decisions.

Given the wide scope of hardware targeted by android, it's not that surprising that it performs less well than a system targeting a very limited set of devices.

Having said that, it performs 'well enough' for the vast majority of use cases.

Re:Android’s 10 Millisecond Problem explained by epochwolf on Thursday April 16, 2015 @07:40AM (#9387217)
By controlling the hardware, they need fewer drivers and they can skip one of the abstraction layers.
Re:Android’s 10 Millisecond Problem explained by __david__ on Thursday April 16, 2015 @12:51PM (#9389157)
That whole theory is blown by the fact that CoreAudio supports 3rd party audio hardware. There is a thriving market of soundcards and audio peripherals for the professional Mac OS X market. Those all run CoreAudio, which is exactly what iOS runs.
Re:Android’s 10 Millisecond Problem explained by madez on Thursday April 16, 2015 @07:52AM (#9387264)
> they need fewer drivers

This suggests that you can work focused on one driver and therefore save developer-time. However, the drivers on Android are made by a bigger workforce, which must be taken into account.

> they can skip one of the abstraction layers

The post explicitly states that the HAL ought to add no latency at all.

Re:Android’s 10 Millisecond Problem explained by vidarh on Thursday April 16, 2015 @09:54AM (#9387893)
Besides the point. When you know the hardware you can shave away the upper layers.

Consider e.g. AmigaOS.

AmigaOS let you obtain a pointer directly to the screen bitmap to update your window contents with no buffering or clipping. It could do that because originally all the hardware was the same, or close enough.

Then graphics cards came along, and you didn't necessarily have a way of writing directly to the bitmap. Suddenly you had to use WritePixel() and ReadPixel() and similar, which would obtain the screen pointer for the window, and obtain the display the screen is on, and find the driver corresponding to the screen, and call the appropriate driver function via a jump table.

Similarly, the AmigaOS had functions to e.g. install copper lists (the copper was a very primitive co-processor that could be used to do things like change the palette at specific scan lines), which also wouldn't work at all on graphics cards.

This is why knowing the hardware is part of a limited set matters: You can define your API to match the hardware very precisely, or even expose hardware features directly.

Re:Android’s 10 Millisecond Problem explained by coreyoconnor on Thursday April 16, 2015 @02:18PM (#9389781)
One aspect of CoreAudio that, IMO, contributes to low latency: CoreAudio provides the buffers to process to the AudioUnit. Not the other way around. This permits CoreAudio to chain AudioUnits while minimizing buffer use. In the ideal case where all AudioUnits support the same audio stream format they are all provided the same buffers to process. Which can get close to zero-copy, zero-allocation audio rendering.

I don't know enough about android to say that this is the key aspect tho. Perhaps the low level API of android is the same? I didn't find an easy reference in a quick search.

Re:Android’s 10 Millisecond Problem explained by easytiger on Thursday April 16, 2015 @07:38AM (#9387209)
By having their devices all roughly the same, it is easier to mitigate in app development than the variance in latency on android devices