::  Posts  ::  RSS  ::  ◂◂RSS  ::  Contact

Android Sound Synthesis and Latency

January 27th, 2012
music, phone, tech  [html]

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.

Comment via: google plus, facebook, r/androiddev

Recent posts on blogs I like:

High-Speed Rail in Small, Dense Countries

Four years ago I brought up the concept of the small, dense country to argue in favor of full electrification in Israel, Belgium, and the Netherlands. Right now I am going to dredge up this concept again, in the context of intercity trains. In a geographi…

via Pedestrian Observations October 12, 2019

What do executives do, anyway?

An executive with 8,000 indirect reports and 2000 hours of work in a year can afford to spend, at most, 15 minutes per year per person in their reporting hierarchy... even if they work on nothing else. That job seems impossible. How can anyone make any im…

via apenwarr September 29, 2019

Taxing investment income is complicated

How should a state tax investment income if it wants to maximize its citizens’ welfare? This sounds like a simple question but I find it surprisingly hard to think about. Here are some of the positions I’ve moved through over the last few years: Taxing in…

via The sideways view September 22, 2019

more     (via openring)

More Posts:

  ::  Posts  ::  RSS  ::  ◂◂RSS  ::  Contact