Down you go
0 pipes
How it works
Why not just take the biggest FFT bin?
Because a hummed vowel is rich in harmonics, and the second harmonic is often louder than the fundamental. A spectral peak detector reports one octave too high, constantly, and the bird jumps.
YIN works in the time domain instead
Four steps, and the second one is the entire algorithm:
- the squared difference function
d(Ο)β how unlike itself the signal is when shifted by Ο samples - the cumulative mean normalised difference β dividing by the running mean suppresses the dips at multiples of the true period, which is exactly what causes octave errors
- take the first dip below a threshold, not the global minimum β again, because the global minimum is often an octave down
- parabolic interpolation around that dip, for sub-sample precision
Measured against synthetic waveforms
This is the rare case where ground truth is exact: generate a 220 Hz sawtooth and the answer is 220 Hz, so any deviation is the detector's.
| Test | Result |
|---|---|
| 10 sine tones, E2 to A5 | worst 0.6 cents |
| sawtooth and square waves | within 15 cents |
| second harmonic louder than the fundamental | no octave error |
| fundamental removed entirely | recovered at 180.0 Hz |
| 443 Hz (a non-integer sample period) | 443.01 Hz β 0.05 cents |
| 20% additive noise | within 0.5 cents |
| silence and white noise | rejected |
Without step 4, the detector can only report whole-sample periods β at 443 Hz that's a choice between 441 and 445.5 Hz, a permanent error of about ten cents.
Your range, not a fixed one
A bass and a soprano do not share a comfortable octave, so the game measures yours: hum low, slide high, and it takes the 10th and 90th percentiles β not the min and max, because one squeak at the top would compress everything else into a sliver.
The mapping is in note space, not Hz. An octave is a doubling, so a linear map in Hz gives you almost no control at the bottom of your range and far too much at the top.
Two small mercies
- Losing the pitch holds your line. Pausing for breath shouldn't be fatal, so no detection means the bird keeps its altitude rather than dropping.
- The browser's audio processing is switched off. Echo cancellation and noise suppression are tuned for speech intelligibility and they mangle a sustained hum β which is the entire signal here.