Android Sound Synthesis and Latency

January 27th, 2012
music, phone, tech
Playing with people's iPhones I really enjoy music apps. Even though there's no real tactile feedback they're still really fun to play. When I got a computer with a responsive and accurate multitouch trackpad I wrote one for it. Now that I have a smartphone I wanted to write something similar: map regions of the screen into notes.

I started with libpd for Android, which is a port of libpd to Android, which is a library version of the audio engine from Pure Data. Learning enough Android programming to get this loading on my phone was a little annoying, as was figuring out how to modify the CircleOfFifths example app to play single notes, but I got something working. Unfortunately, the latency is terrible. I put down my finger, and there is a significant delay before sound comes out of the device. This isn't just my experience; round trip generate-speaker-mic-record latency with libpd on Android tends to be around half a second. Measuring mine with their tester I got 558ms.

While this is way high, I thought at first the problem might be with libpd and that by using the lowest level API directly I might get good performance. Unfortunately, it sounds like this is not the case: the best you can do on the best devices is about 50ms, which is still too slow. If you read the Android Audio mailing list, this is nearly all they talk about back to the third message on the list. There's a bug registered, and it's in the top 10.

It looks like the main problem is that most devices are not designed for it. To get 5ms latency at 44KHz you need to be able to get the buffer down to 256 [1] samples and keep it from emptying. Most Android devices have a minimum buffer size over ten times that. I don't think Google's going to be fixing this soon. This is sad. I want to make music live with my phone.


[1] Really 220 samples, but we like powers of two.

Referenced in:

Comment via: google plus, facebook, r/androiddev

Recent posts on blogs I like:

Weird People of History: Jenny from the Jane Abortion Collective

Direct action when abortion was illegal

via Thing of Things October 24, 2024

Inner dialogue, walking down the sidewalk

A discussion I have with myself a lot The post Inner dialogue, walking down the sidewalk appeared first on Otherwise.

via Otherwise October 10, 2024

Startup advice targeting low and middle income countries

This post was inspired by a week of working from Ambitious Impact’s office in London, and chatting with several of the startup charities there. While my experience is in the for-profit world, I think it’s applicable to entrepreneurs working on impact-driv…

via Home September 27, 2024

more     (via openring)