@audio/pitch-yin

YIN pitch detection (de Cheveigné & Kawahara, 2002)
npm install @audio/pitch-yin
import yin from '@audio/pitch-yin'
de Cheveigné & Kawahara, 2002. The reference algorithm for monophonic pitch estimation. Most cited, most tested, most robust.
let result = yin(samples, { fs: 44100 })
// → { freq: 440.1, clarity: 0.97 } or null
| Param | Default | |
|---|---|---|
fs | 44100 | Sample rate (Hz) |
threshold | 0.15 | CMND threshold — lower = stricter, fewer detections |
minFreq | — | Minimum frequency (Hz); also uses more of the frame for low pitches |
maxFreq | — | Maximum frequency (Hz) |
Pass the expected range when known: yin(samples, { fs, minFreq: 60, maxFreq: 520 }). Besides rejecting out-of-range results, minFreq lets YIN use a longer comparison window and improves low-pitch detection near onsets.
Use when: General-purpose monophonic pitch tracking — speech, singing, solo instruments. The most reliable choice when in doubt.
Not for: Polyphonic audio (returns dominant or null), real-time with hard latency budgets (needs full window).
Ref: de Cheveigné & Kawahara, "YIN, a fundamental frequency estimator for speech and music", JASA 2002.
Complexity: $O(N^2/4)$ — two nested passes over half the window.
Part of @audio/pitch — the pitch family umbrella. This README is generated from the umbrella docs.
MIT © audiojs