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:

Jealousy In Polyamory Isn't A Big Problem And I'm Tired Of Being Gaslit By Big Self-Help

The nuance is in the post, guys

via Thing of Things July 18, 2024

Trust as a bottleneck to growing teams quickly

non-trust is reasonable • trust lets collaboration scale • symptoms of trust deficit • how to proactively build trust

via benkuhn.net July 13, 2024

Coaching kids as they learn to climb

Helping kids learn to climb things that are at the edge of their ability The post Coaching kids as they learn to climb appeared first on Otherwise.

via Otherwise July 10, 2024

more     (via openring)