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:

Starting With Chords

A lot of people play fiddle. Basically nobody starts by learning chords before learning melodies. But that's actually how I learned. I started with chords. One of the nice things about learning to play violin this way is that you can go busking even…

via Anna Wise's Blog Posts November 15, 2024

Stuffies

I have some stuffies and I just have a bunny. Bunny is a rabbit. Woof is a seal. My favorite stuffie is bun bun. I play with my stuffies. Sometimes I jump up with them and I roll them. I can just throw them in the air when I want to play bthululubp wi…

via Nora Wise's Blog Posts November 15, 2024

You Can Buy A Malaria Net

2024 election takes

via Thing of Things November 6, 2024

more     (via openring)