Studio6 min

Tune a Guitar in the Browser: How Autocorrelation Pitch Detection Works

A browser tuner turns your mic into a pitch meter using autocorrelation on the WebAudio stream. Here's the algorithm, the accuracy, and how to use it.

Zro7 Instrument Tuner analyzes mic audio in your browser via WebAudio. Nothing is recorded, saved, or transmitted.

A browser guitar tuner works by feeding your mic into a WebAudio AnalyserNode, then running autocorrelation on each buffer to find the fundamental frequency. Convert that frequency to the nearest semitone and display cents-off. Zro7 Instrument Tuner uses this approach — accurate to ±1 cent on a clean signal.

Why autocorrelation, not FFT

FFT tells you which frequencies are present with amplitude — great for spectrograms, weak for the fundamental when a plucked string is dominated by harmonics. Autocorrelation asks 'at what lag does the signal repeat?' which nails the fundamental even with strong overtones. The bin resolution isn't quantized to FFT frequency bins, so accuracy is sub-Hz.

The algorithm (simplified)

  1. Get ~2048 samples with analyser.getFloatTimeDomainData.
  2. Compute autocorrelation: r[k] = Σ x[i] * x[i+k] for k in the plausible period range (e.g. 40 Hz–1000 Hz).
  3. Find the first peak after the initial trough — its lag k is the period.
  4. Frequency = sampleRate / k. Parabolic interpolation between neighbours gives sub-sample accuracy.

From frequency to note and cents

Use the 12-TET formula: semitone = 12 * log2(freq / 440) + 69. Round to nearest integer for note; the fractional part × 100 gives cents-off from perfect.

Steps

  1. Open Instrument Tuner.
  2. Grant mic permission; pluck one string cleanly.
  3. The dial shows the detected note and cents-off.
  4. Tune until the dial is centered and reads within ±2 cents.

Frequently asked questions

How accurate is it?

±1 cent on a clean, sustained note in a quiet room. Noisier environments degrade to ±5 cents.

Does it work for bass and ukulele?

Yes — the analysis range covers 40 Hz (low B on bass) to 1 kHz (high harmonics).

Chromatic or preset tuning?

Zro7 is chromatic; select any target note or use Standard Guitar/Bass/Ukulele/Violin presets.

Why is my note wrong by an octave?

Very common with pickups picking up second harmonic — pluck softer or move away from the pickup.

Is my mic audio uploaded?

No — WebAudio processes the stream in the tab. Nothing is stored or sent.

Related posts

← Back to blog