Pitch Tracking With pYIN: From 24 Seconds to 2.2 Per Song
How my music engine tracks pitch with pYIN: the call and its bounds, the two settings that took a 60 s excerpt from 24 s to 2.2 s for a 0.5 % drift, and why classical music scores as the most "voiced" genre.

One pitch per frame
pYIN, probabilistic YIN, estimates a fundamental frequency (f0) for every frame, plus a voiced decision and a voicing probability. My engine runs it through librosa on the 60 second excerpt, searching from 65.41 Hz to 2,093 Hz (C2 to C7).
pYIN in 40 seconds

pitch_analysis.py: the call (excerpt)
hop = settings.hop_length * max(1, settings.pitch_hop_multiplier)
f0, voiced, prob = librosa.pyin(y, fmin=settings.pitch_fmin_hz, fmax=settings.pitch_fmax_hz,
...
hop_length=hop, resolution=settings.pitch_resolution, fill_na=np.nan)24 seconds to 2.2
Before tuning, pYIN took 24 seconds on a 60 second excerpt. Two settings changed: the hop doubled to 1,024 samples, and the frequency grid went to 0.2 semitones. Result: 2.2 seconds, with the mean f0 moving by half a percent. Across 3,141 tracks the pitch stage now has a median of 2.4 s (95th percentile 5.4 s).
"Voiced" is not "voice"

Voiced fraction by genre

Voiced means periodic
Classical is the most voiced genre in my catalogue. That is not a bug: a bowed string is as periodic as a voice, and pYIN measures periodicity. On a full mix it follows whichever monophonic line dominates the frame, which is what the melody stage wants and exactly why the vocal stage is a separate analyzer.
The pitch class is the most-weighted note across voiced frames, not the key: a song in C minor whose melody lives on G reports G here and C minor under harmony.
Every test run sends a 440 Hz sine through the real engine: it must read 440 Hz within 2 %, pitch class A, and be at least 90 % voiced.
Part 6 of 14, next: Can Math Tell a Catchy Melody From a Boring One? I Measured It.
Part 6 of 14, next: Can Math Tell a Catchy Melody From a Boring One? I Measured It.
More: LinkedIn · Instagram. Portfolio and case studies: designsbyduhart.org.
If any of this saved you an afternoon, Buy me a coffee.