snails.fm/ docs voice tuner

How pitch detection works

Pitch is repetition. A voiced note is a waveform repeating itself (the vocal folds snapping shut at a steady rate), and the pitch you hear is the rate: 220 times a second is the A just below middle C; 110 is the A an octave under it. So a pitch detector's job reduces to one question: how often does this signal repeat?

The classic way to answer it is to compare the signal with a delayed copy of itself. Slide the delay; at most delays the copy disagrees with the original, but when the delay equals exactly one cycle of the note, the two line up. The delay where they match best is the period, and the pitch is one over it.

Why it's hard anyway

Three things make voices difficult:

  • Onsets. At the start of a note the waveform hasn't settled into a repeating shape yet, and the detector's analysis window is still partly full of whatever came before. First guesses at a note are routinely wrong (often by a whole octave), and any tuner that trusts them will act on fiction.
  • Octave ambiguity. A signal that repeats every cycle also lines up with itself every two cycles. The comparison finds a good match at the true period, and another at double it, one octave down. On a clean, strong tone the true period wins easily; on breathy or quiet tone the two scores get close, and the detector can flicker between a note and its octave.
  • Unvoiced sound. Consonants, breaths, and silence don't repeat: there is no pitch to find. A good detector must know when it doesn't know, and say so.

This is why modern detectors report more than a number: each estimate comes with a confidence score and a voiced-or-unvoiced verdict, and everything downstream is built on taking those honestly.

The consequence for any tuner is blunt: correction quality is bounded by detection quality, and most of the artefacts blamed on pitch correction gone wrong (warble, octave stutter, scooped onsets) are detection errors acted on confidently. The interesting engineering isn't detecting pitch; it's deciding when to believe the detector.

last updated · Charlie