Android touch-to-sound latency 2

I repeated the previous experiment but using a midi controller instead of the touch screen. So, I hooked up a CME XKEY 25 to each android device (with the help of a USB OTG adapter) and put the mic close to the controller to pick up the sound of my finger hitting a key, then loaded the resulting recording in audacity and measured the time between the key press and the sound.

That gives better latency; compared with previous results:

Nexus 9 Nexus 6
touch screen 45ms 50ms
midi controller 20ms 35ms

That was again with "music synthesizer", one of the Android Apps that feels low latency. It would be interesting to measure the difference when using one of the apps that feels more laggy.

It'd also be interesting to compare to a hardware synthesizer, but the only one I have at home has fully weighted keys and probably doesn't sound till the key is somewhere in the middle of the stroke, so it's hard to know what exactly to measure.

Android touch-to-sound latency

I have two Android devices at home, a Nexus 9 tablet and a Nexus 6 phone, and have some synth apps installed on both. I was curious what the total delay is between the time I tap a key on the screen and the time the device produces a sound.

So, I used a 3.5mm-to-1/4" cable to plug the Nexus 9 into the first input of my Zoom H4n recorder, and plugged a mic into the other input. I started up the app "Music Synthesizer" and set it to a piano sound. Subjectively, that app and "Grand Piano Pro" are the only apps I've found with acceptable latencies. On others the latency has either been too high or two unpredictable for me to be able to tap out simple rhythms reliably.

I put the mic right next to the screen, started a recording, and tapped a key on the screen.

I loaded the resulting recording into audacity and looked for the onset of the two noises--the sound of my finger hitting the screen, recorded by the mic, was in the first (left) channel, and the piano sound was in the second (right) channel. I could measure the difference between them--about 45 milliseconds.

I repeated that with the Nexus 6 and got about 50 milliseconds.

(Just to make sure the comparisons even made sense, I also tried just tapping the bare 3.5mm plug against the mic and looking at the result in Audacity, and the offset between the two signals was a tiny fraction of a millisecond, as I'd hope,)

I don't really know if those numbers are good or not. You can certainly hear that the finger-tap and the piano note aren't quite simultaneous. I guess the real test would be to try using them to play some real music. But there's plenty of other reasons why playing on a touch screen isn't very satisfying.

It might also be interesting to do the same experiment with a midi controller plugged into one of the Android devices. And might be interesting to compare to a hardware synth.

Linux audio: multitrack recording and latency

Linux is often like the disorganized toolbox in you find in somebody's garage. There's lots of useful tools in there somewhere, but first you're going to have dig around, untangle everything, and do a lot of google searches to figure out what it all is and how to use it.

The Linux situation for musicians is no exception.

Lately I've been attempting some simple multitrack recording. I have a portable recorder (Zoom H4n) that works as a 4-track recorder, but the interface (tiny screen, a few buttons and a selection wheel) is a little cramped. And even my simple projects run out of tracks quickly.

So, laptops are supposed to be able to do this, right?

To record, I've got to get audio into the laptop somehow. My options are:

  1. laptop audio jack: unlike my old laptops which had multiple audio jacks, this has one which doubles as input and output; it takes a headset with a TRRS jack like you'd use for mobile phones. The output is stereo but the input is only mono, I'd need some sort of adapter, and I have no idea what sort of inputs it'd handle well: mic, instrument, line level?
  2. The Zoom H4n: it's not just a recorder, it's also a USB audio interface, so you hoook it up to the laptop with USB, then plug mics or instruments into it.
  3. My Zoom B3 bass pedal: this also functions as a USB audio interface. But all I can record with it is bass guitar. (OK, electric guitar or other instruments might work too.)

So, I can transfer some tracks I'd already recorded with the H4n to audacity, plug the B3 into my laptop, plug headphones and bass into the B3, and hit audacity's "record" button. Audacity streams the existing tracks to the B3, so I can hear them over my headphones, and what I play on bass gets sent back to the laptop and audacity puts it in a new track.

Unfortunately, when I play back the result, the timing sounds all wrong--the bass lags noticeably behind the other instruments.

What's happened is that I was playing in pretty good time with what I heard in my headphones. But what I heard had already taken a little while to get from audacity to my ears. And what I played took a little while to make its way back. So, there was a delay. I shifted the track around a little, and with some trial and error got to make it sound OK. But, that's going to be a pain to do every time, so, what to do instead?

Googling around found me a page explaining how to measure and correct for latency with audacity.

I figured I'd first just test the laptop (leaving the B3 aside for now). I plugged my usual phone earbuds into the laptop's audio jack to create a loop, putting the earbuds right next to the mic and turning up volume pretty high. I made a click track in audacity, and hit record. Then I could zoom in on the two tracks and see that the original click track was offset by about 149ms from the recorded track that had been played over the earbuds and come back through their mic. Repeated tests showed anywhere between 145 and 154ms for that round-trip latency.

The page linked above explains how to tell audacity to automatically shift recorded tracks to compensate for a known latency, and it looked like a shift of 150ms would get me within 5ms of where it should be--and people apparently start hearing events as simultaneous when the events are within about 20ms of each other, so 5ms isn't bad. But, I was curious if I could do a little better, so I switched to jack instead--unlike the default audio system on my laptop (pulseaudio), jack is designed for predictable low latency.

This meant opening qjackctl, setting qjackctl->Setup->Device to the B3, starting jack, then starting audacity and making sure its audio device was set to jack. This time three tests got me exactly 33ms each time. Much better--jack makes a big difference!

I tried a similar test with the H4n, this time using a cable from its headphone jack to one of its inputs to create the loop. There was nasty feedback until I realized I needed to turn off the H4n's own monitoring--I didn't want it sending its input straight back through the headphone jack. Then I also needed to set qjackctl->setup->sample rate to 44100. With that done, I measured latencies ranging from 95ms to 271ms. Ugh! There's no way to automatically adjust for that. (Actually, the first three tests gave me 99ms, 97ms, and 95ms--which I could live with--but after more problems recording later I reran tests and found that quickly repeated tests often give similar latencies, but waiting and coming back can a few minutes later can give very different results, for some reason.) Googling around suggests the H4n just isn't a great USB audio interface if you care about latency.

The B3 got me much more consistent results, about 57-60ms.

But that only helps with the bass guitar, so I ordered a USB audio interface that claims good latency (Focusrite Scarlett 2i2). That's predictably getting me 48ms round trip latency.

For multitrack recording purposes, I care more about the variation in latency than the latency itself, so that's good enough for me. But, it might be interesting to see if I can get those numbers a little lower. Most of the remaining latency is probably happening in software running on my laptop, so some careful configuration there might help.

Also I should try learning Ardour, it looks potentially more useful than Audacity. And their approach to latency measurement and compensation looks more sophisticated. Another day!

Juggling Festival Crossword

I attempted to make a proper crossword puzzle for the 2013 Ann Arbor Juggling Arts Festival.

I did this once before a few years ago, mostly just trying to figure it out on my own from scratch. This time found a great book through interlibrary loan. That and a couple smartphone crossword-solver apps helped. But it still took a lot of trial and error, I still broke a couple rules, and it's still lame in spots.

Still, I like it, and if you're a juggler maybe you'll be amused by a few of the entries; print it out and give it a try:

music tools 4

A couple more, both very simple:

Everything so far

music tools 3

More fun with the Library's music toys!

And now I have a theremin checked out. It's a really nice instrument, and I appreciate the novelty value to making noise by waving my hands around in the air. But once that wears off I'm stuck thinking: OK, so I could make a lot of spooky wooo-eee-ooo sounds, or I could spend another 10 years practicing to actually get accurate pitch and rhythm with a fairly boring sound, but neither's too appealing. I tried running it through one of these delay things; that helps a bit.

music tools 2

A third ringtone, this one made with the Pocket Piano. Simple, but very ringtone-y!

I think my favorite so far is actually the Macpipes Electronic Bagpipes, but all I want to do with that is march around playing "Scotland the Brave", and you don't want to hear that.

numbers I wish I knew this time of year

Every time there's a discussion about local politics I realize how ignorant I am of the most basic facts:

- What's the city's annual budget?
- To a first approximation, can I ignore revenue sources other than property tax?
- I know how much a one-mill property tax costs a property owner ($1 per $1000 of half the property value; well, sort of). But how much revenue does each mill represent to whoever's doing the taxing? (And is the answer significantly different for the city, the school district, ? And remind me how many of those there are?)

Etc. etc.

I get the impression I have a lot of company in my ignorance. It's amazing we manage to get anything done.

music tools

The library recently added a collection of "music tools". I love my library!

It's fun to just bring them home and twiddle the knobs. I'd also like to make something with them. But I don't have much time. So, my goal is just to make a ring tone with each one. I figure a ring tone is short, doesn't have to sound like anything in particular, but could still be fun. So far:

  • first ringtone: made with the Wavedrum Mini. It's made up of several different sounds, but on a phone all you actually here is a big klang followed by a couple taps.
  • second ringtone: made with the Monotron. OK sort of simple but I thought it was funny for some reason.

Recorded either with a little external mike to my laptop, or with a Zoom H4n, then chose bits that work as loops and converted them to ogg format with Audacity.

Another year goes by

The baby is 16 months now, sleeps pretty well, crawls and pulls up, and is in general much more fun. I still don't have time for much else. But I keep reading: I'm taking another break from Proust partway through the last volume; rereading David Copperfield for the first time since I was a kid, and enjoying it immensely; read "Three Men in a Boat" while on vacation in Colorado a couple weeks ago, and was a little disappointed--mildly funny but not much more, to me; started "Huckleberry Finn", which I've never read, embarassingly!, and recognize the source of Heinlein's voice (so why do I find one charming and the other condescending and smug?); and more.

I should have more to talk about than that, but I'm tired.


Subscribe to RSS