All guides

Engineering · 12 min read

Teaching a phone to hear your guitar over its own metronome.

VOX is a metronome app that tells you, note by note, whether you played early or late. It works over the phone's own speaker: the same phone plays the click and listens to you, with no headphones and no cable. This is how the listening works, what went wrong on the way, and how well it does today.

Two takes of the same sixteenth-note exercise at 60 bpm, phone on a stand, click on the phone's speaker. Each dot is one note: the center line is the click, the green band is ±30 ms, early above, late below. The first take ends at 100% on time; in the second, the gold dots in bar 1 are late. The phone listened through its own microphone; the soundtrack here is the direct guitar recording plus the app's click, so you can hear it clearly.

One speaker, one microphone.

To say a note was 12 ms late, you first need the moment it started, its onset, to within a few milliseconds. The timing windows in VOX run from ±10 ms to ±45 ms, so a detector that is 20 ms off is the difference between "in the pocket" and "late".

Most timing tools avoid the hard part. Headphones keep the click out of the microphone. A cable or a MIDI instrument skips the microphone entirely. I wanted it to work with a phone on a music stand and nothing else, because that's how most people practice.

That means the microphone hears the click and the instrument mixed together, and the click is usually the loudest thing in the room. On an iPhone, the speaker's clicks reach the microphone at about -1 dBFS, while guitar notes sit around -15 to -25 dBFS. And the notes that matter most land right on top of the click, because playing in time means playing with it.

Spectrogram of four seconds of a phone recording with sharp vertical click lines and guitar notes, above a plot of the model's click and note outputs with peaks at each click and each note
A test take from an iPhone 15 Pro: clean guitar at 90 bpm, phone on a stand. Top: what the microphone hears. Bottom: the live model's two outputs, every 10 ms, and what VOX reports. The notes at 6.1 and 6.8 s land 49 and 62 ms after their clicks; the one at 7.4 s lands 4 ms after. Over the whole 30-second take the model reported 73 of the 74 notes and all 46 clicks.

Why the usual detectors fail here.

Classic onset detection looks for sudden rises in energy or sudden changes in the spectrum. Bello and colleagues wrote the standard tutorial on it in 2005. A metronome click is a textbook sudden rise. The first version of VOX used a detector like that, and on an early version of my phone benchmark it found only 56% of the notes, while counting clicks as notes.

Neural detectors trained on music do much better on clean recordings. madmom's CNN detector, from Schlüter and Böck's work, found 91% of the notes on my phone takes, but it also reported 139 false notes per minute, mostly the click. It was trained on recordings without a click in the room, so it has no reason to ignore one.

Subtracting the click was my other early attempt. It helped, but on the same takes it found fewer notes than the model below. The speaker, the phone's audio processing and the room all change the click before it reaches the microphone, and the echo cancellation phones use for calls is tuned for voices: it removes the click and smears the sharp attacks that mark a note. The detector has to know what a click sounds like on this phone, in this room, and tell it apart from a note.

The model: two outputs, click and note.

The model is small: a few convolutional layers over a log-mel spectrogram, then a recurrent layer. It has under a million parameters and weighs about 3 MB in float32. It reads 16 kHz audio and makes two predictions every 10 ms: "a click starts here" and "a note starts here". A note played on the click fires both.

Teaching it to find clicks, and not only notes, was the turning point. A model that has to account for the click stops mistaking it for you. And the clicks it hears become the timing reference, which removes the need for calibration. More on that below.

A few engineering choices that paid off:

  • The spectrogram is part of the model. The STFT is a fixed convolution and the mel filterbank a fixed matrix inside the network, so the app hands it raw audio. iOS and Android can't drift apart on feature extraction, because there is none outside the model.
  • One set of weights, two runtimes. Core ML on iOS, LiteRT (TensorFlow Lite) on Android. Every export runs a parity test against the PyTorch original on a set of golden clips, down to identical detections.
  • CPU only on iOS. The float32 model crashed on the GPU through Core ML. It's small enough that the CPU keeps up easily, fed in 60 ms chunks.
  • Time in samples, everywhere. An early integration placed analysis windows by the system clock instead of by sample position. That moved notes by 15 to 75 ms, more than the windows we judge. Every time inside the engine is now a sample count.

Live, or after the take?

A model that sees the whole take, past and future, is the most accurate. An early version of the app used one and showed its results after a delay. Players found the late corrections confusing: a dot that changes after you've moved on is worse than no dot.

So the app runs a live model. It reads the audio as it arrives, looks 0.17 s ahead, and reports each note about 0.2 s after it's played. At first, giving up the future cost a lot: with 0.2 s of look-ahead, my best model found 87% of the notes, against 92% with the whole take. The live model now learns from a slower whole-take model, and on the phone benchmark it has caught up:

ModelReports a noteNotes foundFalse per minF1
Live (in the app)~0.2 s after it92.1%9.892.5
Whole takeAfter the take92.1%8.293.0

Both at the same detection threshold (0.5), on the 33 phone test takes described below. The app runs a slightly lower threshold, which finds more notes (93.6%) for a few more false ones.

Context matters most for the click. Models that only saw 5-second windows made 1 to 4 false notes a minute on recordings of the click alone. With the whole take, none. A click is predictable, and the model leans on the ones it has already heard. The live model keeps its state for the whole session and makes about 0.4 false notes a minute on click-only recordings.

Data is the hard part.

Public research datasets have tens of thousands of well-labeled notes on guitar, drums and piano. GuitarSet and the Groove MIDI Dataset are two of the ones I used. None of them has a phone in the room playing a click. So most of the work went into data:

  • My own takes on numerous phones and devices, iPhone and Android: different rooms, positions, volumes and amps, clean and distorted, picked and strummed. Every one labeled by hand.
  • Click-only recordings. A script in the app plays silence, then the click at several volumes and tempos, so the model learns what each phone's click really sounds like after its speaker, its processing and the room.
  • Synthetic mixes of real phone clicks with note recordings, for more variety than anyone could record by hand.
  • A small set of extra fast-solo clips, because fast legato was the weakest spot.

The benchmarks are frozen: fixed sets of takes that never go into training, scored the same way for every model version.

The labeling tool: an overview waveform, a zoomed waveform and spectrogram with blue click markers and pink note markers, and a panel of keyboard shortcuts
The labeling tool, a local web page. Clicks are blue, notes are pink. The model's first guess comes pre-filled and flags what it's unsure of. I listen to each marker, down to 1/20 speed, drag it onto the attack, add or delete, and every correction is saved next to the guess, so the guesser's own error stays measurable.

Labeling needs rules, or the labels contradict each other. Some of mine:

  • Hammer-ons, pull-offs, taps, palm mutes and percussive chucks are notes.
  • A slide counts once, at the picked start. A bend is not a new note.
  • Strings strummed within about 30 ms of each other are one note.
  • The release noise when you change notes, often about 40 ms before the beat, is not an onset.

The public datasets needed checking too. GuitarSet's onsets sit about 9 ms late against its own audio, and one piano set had a different offset for each piece, as much as 26 ms. At this precision, unchecked labels teach the model to be late.

What went wrong.

The model that decided phones never have notes. An early version learned from click recordings made on phones and from clean note recordings made in studios. It found the shortcut: if it sounds like a phone speaker, there are no notes. On real phone takes it found 39 of 238 notes. The fix was making sure phone sound and notes always appear together in training.

Synthetic validation lied. In one training run, the checkpoint my synthetic validation set picked as best found 57 of 171 notes on real takes. Another checkpoint from the same run found 115. Since then every checkpoint is kept, and models are chosen on real recordings only.

A phone microphone is a processing pipeline. iPhones apply a soft limiter, so notes stacked on the click hit the ceiling. An Android phone's automatic gain drifted 26 dB over a single take, and with the operating system's voice filter on, the level swung by 58 dB. On a Pixel 7, turning the click down made its tail quieter but left its attack just as loud. One model version reported 134 false notes on a single Pixel 2 recording of loud, fast clicks.

False notes have causes. At one point I sorted every false note by what caused it: ringing and echo 27%, double hits 18%, noise just before a real note 16%, the click 15%, and isolated noises 23%. Each cause needed different recordings.

Timing without calibration.

To say "12 ms late", you need to know when the click actually left the speaker. The operating system reports an output latency, but it's an estimate. In one session iOS reported 92 ms and the measured delay was 83 ms. In another, a latency saved from an earlier session was 112 ms against 82 ms measured. Errors of 10 to 30 ms are the size of what we're trying to measure.

So VOX doesn't time notes against the clock. The model hears the click too, in the same audio as your note, and each note is timed against the click as it was heard. Speaker delay, microphone delay and buffering shift both by the same amount and cancel out. There is no calibration step, and moving to another phone or room just works.

How well it works.

The phone benchmark is 33 test takes: 32 minutes and 4,472 hand-labeled notes, recorded over the speaker with the click playing, on iPhone and Android, none of them used in training. At the app's settings, the live model:

  • finds 93.6% of the notes, and 96.6% of those within 25 ms of the label;
  • makes 11.7 false notes per minute while you play, and 0.4 per minute when only the click plays;
  • finds 96% of notes at normal spacing (120 to 200 ms apart) and 88% in fast runs (under 120 ms apart).
Bar chart of notes found per kind of test take, from 100% on a clean Pixel 7 take down to 80.9% on a hard Pixel 7 take, with 89.9% for an amp across the room and 91% for strumming
Every group is a set of test takes. False notes per minute are counted while playing. The hard Pixel 7 take has uncertain labels.

Against two well-known open models: madmom's CNN onset detector and Spotify's Basic Pitch. Every number below is on recordings none of the three trained on, scored the way mir_eval does by default: a note counts as found within 50 ms of its label. "Within 20 ms" is the share of all labeled notes found that close. F1 combines found and false notes, 100 being perfect.

ModelFoundFalse / minWithin 20 msF1
Phone takes, click on the speaker (4,472 notes)
VOX (live)92.1%9.887%92.5
madmom90.9%13966%62.4
Basic Pitch55.0%39.642%59.9
Fast solos, isolated guitar and piano stems (859 notes)
VOX (live)85.4%43.882%89.0
madmom73.5%69.267%79.9
Basic Pitch----
Guitar, public research sets (23,936 notes)
VOX (live)93.0%24.491%88.9
madmom97.6%59.877%82.3
Basic Pitch85.0%27.179%83.8
Drums, public research sets (31,955 notes)
VOX (live)94.3%31.793%92.7
madmom76.5%34.257%82.0
Basic Pitch5.7%5.74%10.5
Piano, public research sets (45,126 notes)
VOX (live)82.5%9.981%89.0
madmom82.4%33.379%85.8
Basic Pitch76.5%41.171%81.2
Bowed strings, public research set (1,932 notes)
VOX (live)69.7%93.756%63.6
madmom73.8%13456%60.3
Basic Pitch56.5%80.339%56.8

VOX: the live model in the app, at the standard threshold (0.5). madmom and Basic Pitch at their defaults. Basic Pitch was not run on the fast solos. All three run on the same audio; VOX decides 0.2 s after each note, the other two see the whole recording.

The phone row isn't a fair fight: madmom and Basic Pitch were built for finished recordings, not for a click in the room. madmom finds almost as many notes as VOX there, but it also marks the click, 139 times a minute. That gap is why VOX needed its own model.

On the public sets, where the comparison is fair, the picture is mixed in the details. madmom finds more of the notes on guitar (97.6%) and on bowed strings, with more false notes: 60 a minute on guitar against VOX's 24. Basic Pitch is built for pitched notes, so drums sit outside its job.

Timing is where the difference is clearest. Measured on the notes each detector found, VOX's typical offset from the label is about 3 ms or less on every set, with an average error of 4 to 6 ms (12 ms on bowed strings). madmom places notes 9 to 17 ms early on average and Basic Pitch has little bias but a wider spread, with average errors of 8 to 17 ms. For a timing app, a detector that is consistently 15 ms early would call a player in the pocket early.

Where it's still weak: fast legato solos (85% found on excerpts of famous fast solos, with 44 false notes per minute), classical piano from research recordings (82% found), and bowed strings, where every detector I tried scores around 60.

What's next.

More phones, more instruments, and fast legato. The model is the part of VOX I spend the most time on, and every new kind of take I record teaches me something about phones.

VOX is free on iPhone and Android. ECO, the live timing view in the video, has a free 3-minute try, then it's part of Pro.

Further reading

VOX

Your next practice
starts with one word.

Download on the App Store Get it on Google Play