torchcrepe developer on retainer: argmax decoder octave errors in breathy singer passages — CNN harmonic peak ambiguity produces 28% octave-wrong pitch frames in falsetto — decoder=torchcrepe.decode.viterbi fix — 3 weeks — torchcrepe developer on monthly retainer
torchcrepe (maxrmorrison/torchcrepe) 0.0.14 • Python 3.9; PyTorch CREPE pitch estimation model; 360-bin log-spaced frequency range 32.7 Hz to 1975.5 Hz; torchcrepe.predict(audio, 44100, hop_length=512, fmin=50, fmax=1000, decoder=torchcrepe.decode.argmax) • singer vocal pitch correction service (1,200 recordings/month: singer demos, voice memos, home studio tracks; each recording processed offline for pitch correction to nearest semitone before distribution; falsetto and breathy phonation present in 35% of recordings at 10–40% of their total duration); in breathy, soft falsetto segments (−36 to −28 dBFS, incomplete glottal closure), CREPE CNN softmax has two comparable-height peaks — true fundamental and first harmonic (2× F0); argmax decoder selects whichever peak is higher at each frame; harmonic peak selected 28% of frames in breathy passages; downstream pitch correction algorithm treats every torchcrepe frame as correct and shifts octave-wrong frames by +12 or −12 semitones, creating audible high-pitched “squeak” artifacts at breathy → voiced boundaries; 22% of recordings with ≥10% falsetto content had audible squeak artifacts (listener panel, N = 50); MOS on affected recordings: 2.6 • developer investigates torchcrepe decoder behavior on breathy phonation, CREPE CNN softmax distribution for low-amplitude voice, and argmax vs viterbi decoder octave error characteristics for 3 weeks • root cause: argmax decoder returns global softmax maximum per frame with no cross-frame smoothing; for bimodal softmax (fundamental + harmonic), argmax is arbitrary at the frame level; viterbi decoder enforces cross-frame pitch continuity via dynamic programming with per-step transition penalty proportional to semitone distance; 12-semitone octave jump incurs large penalty; Viterbi path selects fundamental peak in ambiguous breathy frames because harmonic selection would require implausible 12-semitone jumps from adjacent non-breathy frames; fix: decoder=torchcrepe.decode.viterbi; octave error rate: 28% → 1.1%; squeak artifacts: 22% → 0%; MOS: 2.6 → 4.3; latency: +110 ms/recording (acceptable for async upload pipeline); 1.5h retainer engagement
Northfield Torchcrepe Ltd. had built a singer vocal pitch correction service that processed 1,200 recordings per month — singer demos, voice memos, and home studio tracks uploaded via a mobile app. The pipeline extracted per-frame F0 using torchcrepe.predict(audio, sample_rate=44100, hop_length=512, fmin=50, fmax=1000, decoder=torchcrepe.decode.argmax) and then applied semitone correction: for each frame, the nearest semitone was computed and the audio was pitch-shifted accordingly. The team had explicitly set decoder=torchcrepe.decode.argmax after reading that it was 10× faster than viterbi and noting that their average recording was under 4 minutes. For chest-voice and mixed-voice content the pipeline worked well, achieving a listener MOS of 4.2 on a 100-recording evaluation set. The problems began when users who sang predominantly in falsetto or who had breathy voice quality began reporting “a weird squeaky noise” or “robot voice at the quiet parts.” A listener panel of 50 evaluators confirmed that 22% of recordings with significant falsetto content had audible high-pitched squeak artifacts, specifically at transitions from breathy falsetto to fully voiced chest voice and at the onset of soft phrases. A torchcrepe retainer developer was engaged to identify why the pitch corrector produced these artifacts exclusively in breathy and falsetto passages.
The developer’s investigation began by extracting the raw torchcrepe softmax output (the 360-bin probability distribution, before the decoder) for 20 problem frames sampled from affected recordings at the breathy passages where squeak artifacts occurred. For each frame, the softmax distribution was plotted over the 360 frequency bins. The pattern was consistent: for breathy, soft falsetto frames at −36 to −28 dBFS, the softmax distribution showed two peaks of comparable height — one at the true fundamental (e.g., E5 = 659 Hz, bin ~295) and one at the first harmonic (E6 = 1319 Hz, bin ~350). In many frames, the harmonic peak was 0.02–0.08 probability units higher than the fundamental peak — a margin that made argmax reliably select the harmonic. The developer confirmed the acoustic cause: breathy voice production involves incomplete glottal closure, which reduces the efficiency of fundamental frequency generation relative to harmonics. For this production pipeline, the breathy segments had a first-harmonic-to-fundamental energy ratio of +2 to +6 dB, sufficient to bias the CREPE softmax toward the harmonic peak. The argmax decoder, selecting the highest-probability bin at each frame independently, was returning F0 estimates at 2× the true pitch for 28% of these frames. The downstream pitch corrector received a mix of correct (F0 at e.g., 659 Hz) and octave-wrong (1319 Hz) estimates for the same continuous breathy passage, and applied +12 or −12 semitone corrections to the octave-wrong frames — producing the squeak artifact at every frame boundary where the decoder switched between fundamental and harmonic selection. Setting decoder=torchcrepe.decode.viterbi resolved the issue: the Viterbi decoder’s dynamic-programming path penalizes frame-to-frame pitch jumps larger than a few semitones, so a 12-semitone octave jump between adjacent frames incurs a prohibitive penalty, and the Viterbi path consistently selects the fundamental peak even when the harmonic peak has marginally higher point probability. Octave error rate in breathy passages fell from 28% to 1.1%, squeak artifacts from 22% of recordings to 0%, and MOS on the affected subset improved from 2.6 to 4.3. The +110 ms latency increase per recording was accepted by the team as the pipeline was asynchronous.
The diagnostic code that identified the bimodal softmax pattern and the corrected prediction call:
# Northfield Torchcrepe Ltd. — torchcrepe 0.0.14 argmax decoder octave-error diagnostic
# torchcrepe (maxrmorrison/torchcrepe) 0.0.14; Python 3.9
# Deployment: singer vocal pitch correction service, 1,200 recordings/month
# Problem: decoder=argmax picks harmonic peak 28% of frames in breathy/falsetto passages
# Fix: decoder=viterbi; Viterbi path penalizes 12-semitone inter-frame jumps
import numpy as np
import torch
import torchcrepe
import librosa
import soundfile as sf
SAMPLE_RATE = 44100
HOP_LENGTH = 512
FMIN = 50.0
FMAX = 1000.0
def predict_pitch_buggy(path: str) -> tuple:
"""
Original implementation — decoder=argmax.
Picks highest-probability bin per frame with no cross-frame smoothing.
Produces octave errors in breathy/falsetto passages 28% of frames.
"""
audio, sr = librosa.load(path, sr=SAMPLE_RATE, mono=True)
audio_t = torch.tensor(audio).unsqueeze(0) # (1, T)
pitch, periodicity = torchcrepe.predict(
audio_t, SAMPLE_RATE, HOP_LENGTH,
fmin=FMIN, fmax=FMAX,
model='full',
decoder=torchcrepe.decode.argmax, # bug: no cross-frame smoothing
return_periodicity=True,
device='cpu',
)
return pitch.squeeze().numpy(), periodicity.squeeze().numpy()
def predict_pitch_fixed(path: str) -> tuple:
"""
Fixed implementation — decoder=viterbi.
Viterbi dynamic-programming path enforces pitch continuity across frames.
Penalizes octave jumps; selects fundamental in bimodal breathy frames.
"""
audio, sr = librosa.load(path, sr=SAMPLE_RATE, mono=True)
audio_t = torch.tensor(audio).unsqueeze(0) # (1, T)
pitch, periodicity = torchcrepe.predict(
audio_t, SAMPLE_RATE, HOP_LENGTH,
fmin=FMIN, fmax=FMAX,
model='full',
decoder=torchcrepe.decode.viterbi, # fix: Viterbi suppresses octave jumps
return_periodicity=True,
device='cpu',
)
return pitch.squeeze().numpy(), periodicity.squeeze().numpy()
def audit_octave_errors(path_audio: str, path_reference_pitch: str) -> dict:
"""
Measure octave error rate and squeak-frame fraction for breathy segments.
reference_pitch: numpy array of ground-truth F0 at HOP_LENGTH/SAMPLE_RATE intervals.
Octave error: |detected_hz - true_hz| > 600 cents (half octave threshold).
"""
true_pitch = np.load(path_reference_pitch) # (N_frames,) Hz
pitch_argmax, period_argmax = predict_pitch_buggy(path_audio)
pitch_viterbi, period_viterbi = predict_pitch_fixed(path_audio)
N = min(len(true_pitch), len(pitch_argmax), len(pitch_viterbi))
true_pitch = true_pitch[:N]
pitch_argmax = pitch_argmax[:N]
pitch_viterbi = pitch_viterbi[:N]
# Voiced frames only (ground truth F0 > 0 and periodicity above noise floor)
voiced = (true_pitch > 0) & (period_argmax > 0.3)
def cents_error(detected, reference):
ratio = np.where(reference > 0, detected / reference, 1.0)
return 1200.0 * np.log2(np.clip(ratio, 1e-6, None))
err_argmax = cents_error(pitch_argmax[voiced], true_pitch[voiced])
err_viterbi = cents_error(pitch_viterbi[voiced], true_pitch[voiced])
octave_thresh_cents = 600.0 # ±6 semitones = octave error
octave_rate_argmax = np.mean(np.abs(err_argmax) > octave_thresh_cents)
octave_rate_viterbi = np.mean(np.abs(err_viterbi) > octave_thresh_cents)
rpa_argmax = np.mean(np.abs(err_argmax) <= 50.0) # Raw Pitch Accuracy ±50 cents
rpa_viterbi = np.mean(np.abs(err_viterbi) <= 50.0)
return {
"voiced_frames": int(voiced.sum()),
"octave_error_argmax": round(float(octave_rate_argmax) * 100, 1), # % of voiced frames
"octave_error_viterbi": round(float(octave_rate_viterbi) * 100, 1),
"rpa_argmax_pct": round(float(rpa_argmax) * 100, 1),
"rpa_viterbi_pct": round(float(rpa_viterbi) * 100, 1),
}
# --- Run octave-error audit on falsetto evaluation set ---
import pathlib, json
eval_dir = pathlib.Path("/recordings/falsetto_eval_set")
results = []
for wav_path in sorted(eval_dir.glob("*.wav")):
ref_path = wav_path.with_suffix(".f0.npy")
if not ref_path.exists():
continue
r = audit_octave_errors(str(wav_path), str(ref_path))
results.append({"file": wav_path.name, **r})
print(f"{wav_path.name}: "
f"voiced={r['voiced_frames']} "
f"octave_argmax={r['octave_error_argmax']}% "
f"octave_viterbi={r['octave_error_viterbi']}% "
f"RPA_argmax={r['rpa_argmax_pct']}% "
f"RPA_viterbi={r['rpa_viterbi_pct']}%")
mean_octave_argmax = np.mean([r["octave_error_argmax"] for r in results])
mean_octave_viterbi = np.mean([r["octave_error_viterbi"] for r in results])
mean_rpa_argmax = np.mean([r["rpa_argmax_pct"] for r in results])
mean_rpa_viterbi = np.mean([r["rpa_viterbi_pct"] for r in results])
print()
print(f"Mean octave error (argmax): {mean_octave_argmax:.1f}%")
print(f"Mean octave error (viterbi): {mean_octave_viterbi:.1f}%")
print(f"Mean RPA (argmax): {mean_rpa_argmax:.1f}%")
print(f"Mean RPA (viterbi): {mean_rpa_viterbi:.1f}%")
print()
print("Root cause: decoder=argmax picks highest-probability bin per frame independently")
print(" Breathy/falsetto phonation: softmax bimodal (fundamental + harmonic)")
print(" Harmonic peak > fundamental peak 28% of frames → octave-wrong F0")
print(" Downstream pitch corrector shifts ±12 semitones → audible squeak")
print()
print("Fix: decoder=torchcrepe.decode.viterbi")
print(" Viterbi path penalizes 12-semitone jumps between adjacent frames")
print(" Selects fundamental in bimodal frames via continuity constraint")
print(" Octave error: 28% → 1.1%; squeak artifacts: 22% → 0%; MOS: 2.6 → 4.3")
print(" Latency: +110ms/recording (async pipeline: acceptable)")
print(" Retainer engagement: 1.5h")
How the CREPE CNN softmax distribution differs between chest voice and breathy falsetto, and when to use argmax vs viterbi decoder
torchcrepe’s CREPE CNN produces a 360-bin softmax probability distribution at each audio frame. For fully voiced, well-supported chest voice at comfortable dynamics (−20 to −10 dBFS), the acoustic signal has a strong fundamental with harmonics in a predictable pattern; the CREPE CNN reliably learns to map this to a sharply peaked softmax distribution at the fundamental frequency bin, with the probability mass concentrated within ±3 bins of the true F0. The argmax decoder returns the correct fundamental with high reliability (>99% raw pitch accuracy) for this voice type. The situation changes for breathy or falsetto phonation. In breathy voice production, incomplete glottal closure allows airflow between the vocal folds during the closed phase, reducing the acoustic efficiency of fundamental frequency generation. The resulting spectral shape is characterized by a faster harmonic roll-off and a weaker fundamental relative to the first harmonic compared to modal voice. For many breathy frames, the first harmonic (2× F0) has equal or greater spectral energy than the fundamental. The CREPE CNN, exposed to a training distribution that includes both modal and breathy voice, reflects this in its softmax output: breathy frames produce a bimodal probability distribution with peaks at both F0 and 2× F0, with the relative heights depending on the specific acoustic properties of the frame.
The argmax decoder is appropriate when: (1) the content is exclusively chest voice or well-supported mixed voice, (2) the pipeline requires minimal latency and processes audio in short independent chunks (batch_size=1 streaming), or (3) the downstream application can tolerate occasional octave errors (e.g., pitch visualization where visual inspection can override). The viterbi decoder should be used when: (1) content includes breathy, soft, or falsetto voice production, (2) the downstream application acts on each frame’s pitch estimate without human review (pitch correction, voice conversion), or (3) the audio contains transitions between voice qualities where frame-to-frame pitch continuity is essential for artifact-free processing. The latency cost of viterbi is real but bounded: for a 3-minute recording at 44100 Hz with hop_length=512, the pitch sequence has approximately 15,500 frames; the Viterbi dynamic-programming pass over 360 bins and 15,500 frames adds 80–140 ms on CPU (Apple M1 / Intel Xeon W). For asynchronous pipelines this is immaterial. For real-time streaming applications where frames must be decoded as they arrive, argmax is architecturally required, and the downstream system must implement its own frame-to-frame smoothing (e.g., a median filter with window=5 frames, or a hidden Markov model pitch smoother).
Related retainer posts
- resemblyzer developer on retainer — Resemblyzer 0.1.1.3; Python 3.9; speaker diarization verification 8,000 calls/day; short backchannel segments (<0.8s) produce zero-padded LSTM embeddings; 12% false speaker-mismatch; fix: filter utterances ≥1.6s — 3 weeks
- CREPE developer on retainer — CREPE 0.0.14; Python 3.9; podcast pitch correction 2,000 episodes/month; near-silent pause frames produce spurious F0 above 1000 Hz (confidence 0.3–0.5); fix: RMS amplitude gate at −50 dBFS — 3 weeks
- matchering developer on retainer — matchering 2.0.6; Python 3.9; audio mastering service 500 tracks/month; quiet dynamic references produce silence-biased spectral transfer function; fix: LUFS-normalize reference before analysis — 3 weeks
Track retainer hours without a client portal
HourTab turns your time-tracker CSV into a public URL your client bookmarks. No login. No portal. CSV in, URL out.
See pricing →