How an Online Tuner Works

A tuner on a web page seems simple: play a note and see a needle move. Underneath, it has to turn a stream of microphone samples into a single frequency, name the nearest note, and report the error in cents, all in a fraction of a second. This is how that works in the Mewzick tuner.

From sound to numbers

A microphone converts air pressure into a voltage, and your device samples it tens of thousands of times a second, typically 44,100 or 48,000 times. The browser’s Web Audio API hands those samples to the page in short buffers. To find the pitch we need a window long enough to contain several cycles of the lowest note we care about. A bass E at 41 Hz has a period of about 24 milliseconds, so a window of a few tens of milliseconds covers only a couple of cycles, and low notes need longer windows than high ones.

Finding the pitch

The tuner uses the McLeod Pitch Method. The idea is to compare the sound with a copy of itself shifted in time. A repeating waveform lines up with itself again after exactly one period, so the shift at which it matches best is the period, and the frequency is the sample rate divided by that shift. This is called autocorrelation. The McLeod method uses a normalized form of it (the normalized square difference function), which makes the match score a number from roughly 0 to 1 that is independent of volume. That score doubles as a clarity measure: a clean, steady note has a clear peak, while noise or a chord doesn’t, and the tuner can decline to show a note when the clarity is low rather than flicker through wrong guesses.

Why octave errors happen

A plucked string produces a fundamental frequency plus a series of overtones. If the overtone is louder than the fundamental, a naive method locks onto it and reports a note an octave or a fifth too high. The same issue occurs in reverse: a waveform that repeats every two cycles can look like a match at twice the true period. The McLeod method picks the first strong peak, rather than the highest one, and that favors the true period. Low strings played through a weak phone microphone are still the hardest case. See tuning a bass for how that shows up in practice.

From frequency to a note and cents

Western tuning divides each octave into twelve equal semitones, so every semitone is a frequency ratio of the twelfth root of two. With A4 set to 440 Hz, the note number is 69 + 12 × log₂(f / 440), where 69 is the MIDI number of A4. The nearest whole number is the note, and the leftover fraction times 100 is the error in cents. A cent is one hundredth of a semitone, a difference most listeners cannot hear on a single note. Changing the reference pitch, say to 432 Hz, simply moves every target.

Smoothing the display

Raw readings jitter, especially as a note decays or when you first pluck, because the attack has a brief unstable pitch. The tuner follows a note once it has locked on, folds sudden octave or twelfth jumps back onto the fundamental, smooths the result so the needle moves steadily, and only believes a new note after several consistent readings. This adds a little lag by design. Without it the display would be too jumpy to use.

What limits accuracy

  • The microphone: low-end roll-off, automatic gain, and noise suppression built into phones and laptops can all distort what the tuner hears.
  • The room: background noise, other instruments and echoes add competing pitches.
  • The instrument: strings that are old, badly intonated or struck hard can sound a few cents off from their resting pitch. See intonation.
  • The window: long windows give accurate pitch but respond slowly; short windows respond quickly but are less precise, especially at low frequencies.

Under good conditions, in a quiet room with a clean tone, readings within a cent or two are realistic, which is well below what the ear needs. The audio is analyzed entirely on your device and is never sent anywhere. Try it yourself with the tuner.

All guides