Designs by Duhart All writing

·1 min read·audioprocessing · signalprocessing · machinelearning · musictech · python

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.

Cover slide: Pitch Tracking With pYIN: From 24 Seconds to 2.2 Per Song. Bottom left, an "Interviewing at" badge with the logos of Spotify, Apple Music, YouTube Music, SoundCloud.

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

Numbers come from the engine README, the stored records and the catalogue medians; sources at the end.
Opening frame of the video: Pitch Tracking With pYIN: From 24 Seconds to 2.2 Per Song
Numbers come from the engine README, the stored records and the catalogue medians; sources at the end. Watch the video: https://designsbyduhart.org/blog/pitch-tracking-with-pyin-24-seconds-to-2/

pitch_analysis.py: the call (excerpt)

python
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"

Slide 4 of 8 of "Pitch Tracking With pYIN: From 24 Seconds to 2.2 Per Song", near-black background, white Inter type with mono labels. "Voiced" is not "voice". Classical scores highest: a bowed string is as periodic as a singer. Chart or diagram from the video at its final state.
Median voiced fraction per catalogue genre.

Voiced fraction by genre

Median share of voiced frames per genre. Hover for the median f0. Open full screen
Cover slide: Pitch Tracking With pYIN: From 24 Seconds to 2.2 Per Song. Bottom left, an "Interviewing at" badge with the logos of Spotify, Apple Music, YouTube Music, SoundCloud.
Median share of voiced frames per genre. Hover for the median f0. Interactive version: https://designsbyduhart.org/blog/pitch-tracking-with-pyin-24-seconds-to-2/

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.

Pitch Tracking With pYIN: From 24 Seconds to 2.2 Per Song, Designs by Duhart