Short on time? Sections
marked core path are the
essential pipeline. Everything else is a deep dive worth coming back for.
00 · enginecore path
If I Could Turn Back Realtime
Plain EnglishThe part that touches the speakers, moment to moment, has to be instant, no waiting, no pausing to think, or you hear a glitch. So that part only ever moves audio in and out of a queue. All the actual thinking, detecting the pitch, deciding what to do about it, happens on a separate helper that isn't held to that razor-thin instant, but it still has to keep up with the flow of incoming audio on average, or sound starts dropping out.
The OS calls the audio callback on a hard deadline: one buffer's worth of time. Miss it
and you hear an audible glitch. So the audio callback only pushes or pops a
lock-free queue. Detect, quantize, and shift happen on a separate worker thread where we have time for some real math.
One callback, both directions: same processBlock invocation pushes freshly arrived
input and pops whatever output the worker thread already finished. If fewer output samples are ready
than the block needs, the shortfall gets filled with silence instead of blocking to wait. Silence is
the correct real-time-safe failure mode.
why each one is fatal
blocka mutex, file I/O, or sleep. The callback simply doesn't return in time, no matter how briefly it was going to block for
allocatenew, a growing Vec/vector. The allocator can itself take an internal lock or walk a free list; worst case is unbounded
lockany mutex, even uncontended. If the other side is ever preempted while holding it, the audio thread stalls waiting on a thread the OS isn't scheduling
Block-size decoupling (the host doesn't owe you a fixed size)
The detector needs a fixed-size block (2048 samples) to run its FFT against. Hosts don't owe you
that. A DAW can hand the callback 64, 128, or 512 samples depending on its own buffer
setting, and can change its mind mid-session.
The C++ and Rust engines use the identical pattern, ported line-for-line on the second
implementation.
the logic
accumulateappend whatever the host handed over into analysisBuffer
gateif filled < blockSize: keep waiting, don't run detect/quantize/shift yet
fireonce filled == blockSize exactly: run one full correction pass, then reset
Plain EnglishListen to a short slice of audio and figure out what note is being sung, by checking how well it matches a slightly-delayed copy of itself. Whichever delay lines up best tells you the pitch.
A pitched sound is periodic. Its waveform repeats every T samples, where T is the
pitch period. Take a copy of the signal, slide it sideways by some lag τ, and ask whether the copy
looks like the original again. For almost every τ the answer is no. But the moment τ equals the
true period T (or a whole multiple of it), the shifted copy lines back up with the original almost
exactly, because that's what "periodic" means. Try every possible τ and measure how well each
shifted copy matches. The τ with the best match, past the trivial τ=0 case, is
the pitch period. That measuring is autocorrelation. Normalizing it
so it's comparable at every τ is the McLeod Pitch Method's own contribution, covered further down.
τ=6 → f=7350Hz · match 0.00
The true period here is 20 samples. Drag τ to 0 (trivial self-match, always perfect and always
skipped) or to 20 (the real answer) and watch the cyan copy snap into alignment with the gray one. That
alignment is the high correlation score.
This is the real match score from the demo above, computed at every τ from 0 to 44 (via
FFT in the real detector, computed once rather than by sliding and
re-measuring one τ at a time (see "every τ at once" above), and normalized into
NSDF. Drag the slider in the demo above. The marker here tracks it live, landing exactly on
the peak at τ=20. No window taper gets applied before this autocorrelation, unlike the shift stage
below. MPM runs on the raw fixed-size block, and the energy gate (not drawn) skips this whole
computation on silence.
why the formula looks like this
1. square itx[n]−x[n+τ] can land negative or positive. Squaring makes every difference count as positive, and makes big mismatches count far more than small ones (a difference twice as large contributes four times as much)
2. normalize by energya raw difference score alone is meaningless. A loud passage and a quiet one score very differently at an equally good match, and different τ naturally have different energy in their windows regardless of periodicity. Dividing by m(τ), the energy actually present at that τ, turns the raw mismatch into a fraction of available energy, comparable across every τ. That division turns the raw difference into NSDF.
3. every τ at onceO(·) describes how the worst-case cost grows as input size N grows. Literally sliding a copy and comparing at every τ costs O(N²). For this project's N=4096, that's ~16.8 million operations. Computing every τ's score at once via FFT costs O(N log N) instead. 4096×log₂(4096) = 4096×12 ≈ 49,000 operations. About 340× less work, for the exact same set of numbers.
Plain English: why bother normalizing at all? Without it, the score depends on how loud the singing was, not just how good the match is. A loud, clear note and a quiet, breathy one can match their own delayed copy equally well, but the loud one's raw score would look bigger just because there's more signal to work with, not because the match is actually better. Dividing by how much energy was actually available at that moment turns the raw number into something closer to a percentage, how good is this match out of the best possible match right now, so a great match reads as great whether the singer is loud or quiet.
Plain English: why does FFT make this faster? Checking every possible shift by hand means comparing the whole signal all over again for every single guess, thousands of guesses, thousands of full comparisons, and it adds up fast. FFT answers a completely different-sounding question first, which musical tones make up this sound, and how loud is each one, but that question and "check every possible shift at once" turn out to be the same information in two different disguises. Once the sound's been translated into that tones-and-loudness form, checking every shift at once costs about the same as checking just one shift the slow way. So instead of redoing the slow comparison thousands of times, this project translates into that other form once, does one cheap step while it's there, and translates back once, getting the answer for every shift simultaneously instead of one at a time.
the math
energy gateE = Σ x[n]²: skip the block entirely if E < 0.15
energy termm(τ) = Σ x[n]² + Σ x[n+τ]² (left window energy + right window energy)
NSDFnsdf(τ) = 2·ACF(τ) / m(τ): bounded to [−1, 1], comparable across every τ
peak choicefirst τ past the initial positive run where nsdf(τ) > 0.1, not the tallest peak
sub-sample refinefit a parabola through (−1,y₀), (0,y₁), (1,y₂) around the peak, solve the vertex
period → frequencyf = sampleRate / τ. The whole search above exists to find the true τ, the pitch period in samples; once it's found, this one division is the actual frequency
Plain EnglishTake that detected note and, if it's already one of the notes in the chosen scale, leave it alone. If it isn't, nudge it to the nearest note that is.
Twelve pitch classes, wrapped into an octave. If the detected note is already in the scale, it passes
through untouched. If not, the search walks outward by semitone. One below, one above, two below,
two above. Until it lands on one that belongs. This is genuinely two separate steps. A detected
frequency is continuous (say, pitch-class 3.7, a fractional value), so it gets rounded
to the nearest chromatic semitone first, with ordinary rounding, completely independent of the
scale. Only that already-integer result ever reaches the search below. Anything that rounds
straight into the scale never touches it at all.
pc 3.7 · searching…
The search loop allows up to distance 6, but never actually needs more than 1 for any of the
seven modes this scale type supports. All seven are rotations of the same major-scale step pattern
(W‑W‑H‑W‑W‑W‑H), so the largest gap between two scale members is always exactly a whole
tone, and the note squarely between them is always one semitone from one side or the other. 6 is a
generic worst-case bound instead, sized for a hypothetical single-note scale: the
sparsest membership set possible, where the farthest chromatic note sits 6 semitones away on the
opposite side of the circle. Today's largest actual gap is a whole tone, so that reach never gets
exercised. The bound fits a case this codebase doesn't currently support, wider than any of the seven modes it does.
Try 3.7: it rounds to 4 (E), already in C major, so the search below never runs. The outward search
only fires for a chromatic note that's genuinely off-scale after rounding. "In-between" frequencies get resolved by ordinary rounding, a step earlier.
the math
1. round to chromaticnote = round(hzToMidi(freq)): ordinary nearest-integer rounding, before the scale is ever consulted
2. pitch classpc(note) = ((note mod 12) + 12) mod 12: the extra +12 handles negative notes safely
Plain EnglishSwitching which pitch-shifting method is running, live, mid-note, without a click or a dropout. The new method gets ready in the background, then for a brief moment both the old and new methods play at once, faded smoothly from one to the other, so your ear never catches the seam.
In the actual plugin, swapping from the phase vocoder to TD-PSOLA mid-performance is one pick from the
Engine dropdown, instant, no pause, no click. This section covers the mechanism that makes that possible.
One atomic pointer exchange, picked up by the worker thread between blocks, never
mid-process(), with the outgoing engine's warmed-up internal state cross-faded out instead
of just discarded.
The UI thread calls this the moment the Engine dropdown changes.
A naive instant switch discards the outgoing engine's warmed-up phase accumulator and
overlap-add buffer. Testing swaps live surfaced an audible click. A dedicated dropout test followed to
quantify it, measuring a 0.340 max-sample discontinuity against a 0.014 natural baseline
(~24×). Two different deletes happen in this code, worth telling apart. requestEngineSwap()
(step 2) deletes an unconsumed, never-processed prior request immediately, since nothing was ever
reading it. The previously-active engine is destroyed separately, at the handoff in step 6, deferred
specifically because the crossfade above was still reading its state a moment earlier.
t=20% · power 1.00
Drag to any point and the power stays flat, gainOld²+gainNew² ≡ 1, which is why
equal-power was chosen over a linear blend. A linear blend ((1−t) and t) doesn't hold that; at the
midpoint it drops to 0.5²+0.5² = 0.5, a real, audible loudness dip mid-transition.
the math
both engines runfor crossfadeBlocks = 4 blocks (≈185ms @ 44.1kHz/2048), old and new both process the same input
equal-power blendgainOld = cos(θ), gainNew = sin(θ), θ ramped 0→π/2 continuously across the whole window
why it's exactly 1sin²θ + cos²θ ≡ 1 for any θ. The Pythagorean identity, using the same angle both times.
gain vs. powerthe blend itself is linear in amplitude (gainOld·old + gainNew·new, no squaring anywhere in the code). But scaling a signal's amplitude by g scales its power by g², and power is what predicts the blended signal's loudness
the assumptionconstant power only follows if the two engines' outputs are roughly equal-power and uncorrelated, so their powers add without a cross-term. True enough for two algorithms independently processing the same input, the standard crossfade assumption for two independent, roughly equal-power sources
why not linearlinear (1−t)/t dips below full power mid-transition (gainOld²+gainNew² < 1); equal-power keeps the sum exactly 1 throughout
That's the mechanism for switching. What's actually being switched between:
engine
mechanism
measured latency
Phase Vocoder
relocates FFT bins in the frequency domain
23.22ms
TD-PSOLA
re-spaces time-domain grains at pitch marks
31.29ms
Varispeed+WSOLA
resamples at a varying playback rate
33.97ms
Each one's own math, and the full latency
and quality comparison, is in the deep-dive sections below.
04 · shiftcore path
Tailored Shift
Once the target note is known, something has to actually move the pitch there. Pitchzazz ships
three hot-swappable engines, each solving this with unrelated physics: one reasons about
frequency, one about time-domain grains, one about playback rate. This is where the real windowing and
math show up hardest.
Phase Vocoder (frequency domain)
Plain EnglishBreak the sound into its underlying frequencies, shift every one of them up or down by the same ratio, then rebuild the sound from those shifted frequencies. Careful bookkeeping keeps the rebuild from sounding smeared or underwater.
Take the signal into the frequency domain with an FFT, then move each bin's content to a new bin
scaled by the pitch ratio. Relocating spectral content is the pitch shift. The phase
math below just keeps that relocation sounding coherent instead of smeared.
What's an FFT anyway? A Fast Fourier Transform takes one block of samples, a little
slice of a waveform over time, and re-expresses it as a set of frequency bins: bin k answers
"how much of frequency k·sampleRate/N is present in this block?" Each bin's answer is a complex
number, magnitude (how much of that frequency) and phase (where in its cycle that frequency
sits). An inverse FFT undoes the trip, bins back to a waveform. Nothing here is approximate, it's an
exact, reversible change of representation, just a faster way to compute it than the textbook formula.
w(n) = 0.5 − 0.5·cos(2πn / (N−1)). Tapering each frame to zero at its
edges is what lets overlapping frames sum back into a clean signal instead of clicking at frame boundaries.
Live demo below: drag the slider. It recomputes bin′ = round(k · shift)
for 12 source bins in real time and redraws where each one actually lands.
0 st · ×1.000
Shift < 1 (pitch down): several source bins collide into one destination bin (magnitudes add). Shift > 1 (pitch up):
some destination bins never get written at all. This collision/gap pattern is the pitch shift.
Same four hop boundaries (dashed), two resynthesis strategies. Reset the phase every frame and
each boundary becomes an audible discontinuity, the classic "phasiness" artifact. PitchShifter.cpp
instead carries phaseSum forward across frames, and the waveform stays phase-continuous through
every boundary.
bin relocationbin′ = round(k · shift): magnitude and ωk both move here
phase accumulationφ′k[t] = φ′k[t−1] + hop·ωk: persists across frames, the fix for "phasiness"
where latency comes fromframeSize samples, the nearest power of two to windowSizeMs · sampleRate / 1000. A full analysis frame has to fill before the first FFT can even run, so this is a hard floor. Measured real pipeline latency: 23.22ms / 21.33ms / 21.33ms (44.1 / 48 / 96kHz), matching the formula exactly, no extra delay hiding in the block-accumulation stage
Plain EnglishCut the sound into small pieces timed to the pitch, then paste those same pieces back down closer together or farther apart to raise or lower the pitch, without changing what's actually in each piece.
No FFT at all. Cut the signal into small windowed grains, one centered on each detected pitch period,
then paste them back down at new positions. Closer together to raise pitch, farther apart to lower
it. Each grain's own content never changes, only its spacing does.
+5 st · denser
All three rows update live from the same six-period recording. Row 2 shows a naive resample
at this ratio: pitch moves, but so does the cycle's own shape, shifting formants along with it. Row 3
is the real overlap-add sum, not an illustration of one: every ghosted grain is unmodified, only
re-spaced. Drag to ±12 for the extremes this engine supports. Summed loudness stays close to a
single grain's level at moderate overlap and drifts 10–15% higher at the heaviest overlap this
waveform reaches, a property of this illustrative signal, not a separate measurement against real
audio.
the math
synthesis spacingspacing = periodSamples / shiftRatio. Denser for a shift up, sparser for a shift down
grain half-widthhalfWidth = periodSamples · grainWidthMultiplier. Multiplier of the unshifted period, so formants survive
read positionreadMark = floor(synthesisMarkPos / periodSamples + ε) · periodSamples, using floor specifically to bound lookahead
where latency comes fromlatencySamples = 2 · maxHalfWidthSamples, the worst-case grain half-width at minHz, the lowest pitch this engine supports. Fixed regardless of whatever note is actually playing, since latency that fluctuated with the detected pitch would make host delay-compensation wrong mid-performance. Measured real pipeline latency: 31.29ms / 31.25ms / 31.25ms (44.1 / 48 / 96kHz), matching the formula
Plain EnglishStretch or squeeze the sound's length first without touching its pitch, then play that stretched version back faster or slower to restore the original length. That playback-speed change is what actually shifts the pitch, the same trick as speeding up a tape reel.
The odd one out: pitch changes by genuinely changing playback rate, like varispeed-ing a tape reel,
formants included, on purpose. Two stages: WSOLA stretches the signal in
time, pitch-preserving. A resample then plays that stretched signal back at the
inverse ratio, tape-style, changing duration and pitch together. Duration cancels, since the resample
undoes WSOLA's own stretch. Pitch doesn't, since WSOLA never touched it, so the full shift survives at
the original duration.
Time-stretch: WSOLA
An illustrative synthetic waveform standing in for three candidates the
search might consider. Each row's left portion is the reference's own phase. The candidate's own read
offset only takes over at the marker, and the join itself is what's drawn. The dashed template shows
what the reference would continue into if the period held perfectly steady. It didn't, so guesses A
and B both hand off at the wrong phase, a real jump at the marker, the click's actual mechanism.
Candidate C is 8 samples from the fixed hop, close enough for a search radius this small to find, and
its join shows no jump at all. A hard minimum-improvement margin keeps the search from collapsing onto
zero on stationary material, where every nearby offset scores about the same.
Resampling
Cubic Hermite (Catmull-Rom) fits a curve through four neighboring samples and reads it at the target
position. Linear is cheaper but dulls highs and stairsteps at extreme ratios. Windowed-sinc is the
correct band-limited choice, but its width scales with ratio, costing real per-sample latency this
engine's fixed budget doesn't have. Catmull-Rom is the real-time middle ground, FluidSynth's own sample
interpolation among them: a fixed 4-tap kernel, cheap, allocation-free, with its own mild roll-off and
self-aliasing at extreme ratios, left alone the way tape and vinyl varispeed never anti-aliased
either.
Every point on this curve is the real formula, sampled densely.
p₀ and p₃ only shape the curve's tangent at the endpoints and are never themselves
interpolated through by this call. The actual output sample always lies between p₁ and
p₂, at fractional position t. The dimmer curve on either side isn't decoration either. It's
what the next call's own four-sample window produces as the read position keeps advancing, each
segment computed from its own correct four points, joining smoothly because the shared endpoints and
their neighbors agree.
+7 st · ×1.50
Row 1: source, drawn once, never changes. T marks one period, tick to tick, and frequency is
1/period. Row 2 is computed live from the current ratio: same period as row 1, since WSOLA doesn't
touch pitch, but the bar's own length grows or shrinks by the ratio, the whole point of a
time-stretcher. Row 3 inverts that: the resample compresses (or expands) row 2 back to row 1's exact
width. The total cycle count carried over from row 2 doesn't change during that step, so packing it
into row 1's width changes the period instead, and a shorter period means a higher frequency. Watch
row 3's width against row 1's: they match at every position on the slider. Watch row 3's tick spacing
against row 1's: that's the pitch shift landing. Row 2's own phase stays perfectly continuous here,
the ideal case a good splice search actually achieves. It isn't a live model of the search itself, and
it doesn't show what a bad candidate would do to that phase. The splice-search diagram above shows the
real per-candidate mechanics, including what a mismatch actually looks like.
the math
splice scoreNCC(offset) = Σ(a·b) / √(Σa² · Σb²): normalized cross-correlation, capped to a 256-sample window
deviate only ifNCC(offset) > NCC(0) + 0.02, a hard margin on the required improvement
read rateread position advances by shift = 2^(semitoneShift/12) samples per output sample
where latency comes fromon paper: windowSizeSamples + searchRadiusSamples + kernelLookahead ≈ 26.6ms at 44.1kHz, fixed and ratio-independent since neither WSOLA's search window nor the resampler's kernel depends on shift amount. Measured real pipeline latency runs higher: 33.97ms / 30.21ms / 30.19ms (44.1 / 48 / 96kHz). That gap is disclosed here, still unexplained
All three hot-swap mid-performance with
zero dropout, the mechanism covered above. The real question here is which one actually stays clean,
measured rather than described.
05 · qualitycore path
So Fresh and So Clean Clean
Plain EnglishPlay a known test tone through each shifter and measure how much of the result lands where a clean, correctly-shifted note should, versus how much energy leaks out into noise and unwanted overtones. Two numbers, so a claim like "sounds clean" is backed by an actual measurement, not just an ear.
Every artifact claim on this page so far has been qualitative. QualityMetrics puts a number on
it: one windowed FFT of a shifter's output against the known target fundamental, reduced
to THD+N (energy outside the fundamental) and the sharper question, artifact
energy. Energy outside the fundamental's entire harmonic comb. A clean shift has
real energy at its harmonics, just none outside them.
Real numbers: a 220Hz test tone through each engine's actual shifter
class, swept ±12 semitones. The same synthetic-signal / real-code / numeric-threshold technique
every other test on this page uses.
This chart plots artifact energy% only across all five measured shifts. The
table below has both metrics, including THD+N% and the undefined case at PSOLA −12st. Phase
vocoder bars are drawn at a flat 2px minimum, regardless of their true sub-pixel height. The shape matters as
much as the endpoints: TD-PSOLA is fine everywhere except +12st, where it drops off a cliff instead of
sliding. Varispeed now starts near zero at unison and small shifts and climbs toward the extremes, a real
resampler-interpolation cost left over after the block-rate bug that used to dominate this chart got
fixed (see the Listen section below).
the definitions
THD+N%100 · √((totalEnergy − fundamentalEnergy) / fundamentalEnergy). Standard AES17-style ratio, relative to the fundamental alone
artifact energy%100 · √((totalEnergy − harmonicEnergy) / totalEnergy). Energy outside every harmonic in the whole comb
why bothTD-PSOLA at −12st: THD+N is undefined (the true fundamental nearly vanishes), yet artifact energy is 0.57%. As clean as unison. Either number alone would mislead.
engine
shift
THD+N%
artifact energy%
Phase Vocoder
−12 to +12 st
0.30 – 0.82
0.30 – 0.82
TD-PSOLA
0 st
0.56
0.56
TD-PSOLA
−12 st
undefined
0.57
TD-PSOLA
+12 st
775.86
99.18
Varispeed
0 st
0.56
0.56
Varispeed
−12 / +12 st
10.98 / 18.85
10.92 / 18.53
The phase vocoder drops any bin that would land above
Nyquist instead of wrapping it. Structural anti-aliasing, and it shows: clean across the whole range.
TD-PSOLA breaks down asymmetrically at the extremes: severe and broad at +12 semitones, narrow (a fundamental collapse) at −12. Varispeed's resampler has no anti-aliasing pre-filter by design, same as
physical tape, and a real, shift-dependent residual from that plus its own cubic-Hermite interpolation error still climbs toward the extremes. Most of what this chart used to show here, though, was a real,
since-fixed block-rate bug rather than that inherent cost, see the Listen section below for the fix.
This metric still can't score one thing,
structurally. It only ever uses a stationary test tone, so it can't expose an artifact that depends on real
voice's own natural jitter the way TD-PSOLA's persistent crackle did. That artifact has since been
root-caused and mostly fixed by direct instrumentation against real vocal audio instead. See the Listen
section below for the fix and its small, disclosed residual.
where to spend time next
Varispeed's 22% baselinedone. Mostly a real, since-fixed block-rate bug. What's left is a smaller, real, shift-dependent interpolation cost, accepted and disclosed as a known limitation.
Varispeed shortfallsstill open. About 1.5% of blocks now run genuinely short, up to 30ms, after the fix above. Why the two-stage pipeline occasionally can't keep up hasn't been chased down yet.
TD-PSOLA cracklemostly done. Root-caused and fixed by direct real-voice instrumentation. A small residual remains, isolated to two known spurious-detection glitches.
06 · listendeep dive
Ears Don't Lie
Plain EnglishThe same recording, corrected, run through all four engines, so you can just listen and compare rather than take any of the numbers above on faith.
Everything above this point is a number or a diagram. This section plays real audio instead, one
22-second clip corrected into G major, run through all four engines. The three C++
engines, Corrector, PSOLACorrector, and VarispeedCorrector, use
the plugin's 420ms "Smooth" retune-speed glide. Rust has no such control, so its render runs at its only
mode, instant-snap. Every render calls each engine's actual production code, block by block, the same
way the plugin's worker thread (or pitch-cli's) runs it live.
Rendered offline: two small render tools,
cpp-plugin/benchmarks/RenderDemoAudio.cpp for the three C++ engines and
crates/pitch-core/examples/render_demo_audio.rs for Rust, each feeding a WAV through the
corrector at its real block size and calling the identical process() path the live
plugin/CLI uses. The Rust render uses pitch-cli's real defaults (block size 2048, 50ms
analysis window).
Do You Believe in Life After Bugs?
TD-PSOLA and Varispeed historically carried real, audible artifacts here,
matching the quality-metrics data above (99.18% artifact energy for TD-PSOLA at +12 semitones, a 22-30%
baseline for Varispeed at every shift). Both were known, actively-investigated limitations of these
experimental engines. The phase vocoder's design resists this class of artifact structurally, and it
remains the plugin's default engine. Further investigation, below, found and fixed a much larger cause on
both engines than originally understood.
A shared bug across two unrelated engines. Closer listening found a
persistent roughness, roughly an octave below the fundamental, tracking the singer's pitch, with the
same character on TD-PSOLA and Varispeed despite them being structurally unrelated algorithms.
That similarity was the clue. The cause wasn't in either pitch-shifting engine. It was the pitch detector
all three engines share, which occasionally locks onto a note's second harmonic instead of the true
fundamental, and since all three engines run the same input through an identical, deterministic detector,
they all get the same wrong reading at once, biasing the correction by roughly an octave on real,
correctly-pitched audio. The phase vocoder gets the same bad reading but isn't audibly affected, since its
shifting method spreads the correction across many overlapping analysis windows, smoothing out a single
bad reading instead of applying it as a sharp jump. Fixed by checking the detector's own confidence for
each reading and falling back to the last trustworthy value when it's low. Confirmed with a small
standalone probe,
PitchDetectorOctaveProbe.cpp,
built to run only the shared pitch detector against this real vocal clip and print its confidence per
reading, rather than a synthetic test tone.
The real cause of the persistent roughness on TD-PSOLA. After the fix
above shipped, the persistent roughness was still there, unchanged. That first fix caught a real but
smaller, separate bug. A first guess, that the real problem was a periodic artifact tied to the plugin's
internal processing block size, was tested directly by re-rendering this same clip at different block
sizes (an override added to the render tool above) and checking whether the artifact's frequency moved to
the exactly predicted new value. It did, three times running, but the effect
mattered far more for Varispeed than for TD-PSOLA, and fixing it on TD-PSOLA changed nothing audible. The
real cause was found by instrumenting TD-PSOLA's grain-placement code directly against this real vocal
clip rather than a synthetic tone, and it turned out to be a numerical instability. The code located each grain's read position by
dividing an ever-growing sample count by the detected pitch period, and that period shifts slightly every
processing block from ordinary detection noise, so even a tiny shift in the divisor produced large
read-position jumps, recurring roughly 24 times a second throughout almost the entire clip. Fixed using a
standard technique from granular synthesis and audio resampling. Instead of recomputing the read position
from an ever-growing absolute position each time, it's now tracked as a running total that only ever
moves in small, bounded steps.
A known, disclosed limitation that remains on TD-PSOLA.
A small, subtle crackle is still audible on TD-PSOLA at two moments in this clip, both landing on moments
where the singer's pitch genuinely and quickly changes within a single processing block, unrelated to the
bad detector readings above. A plausible explanation, not yet confirmed by targeted measurement, is that
the fix above smooths pitch changes evenly across a whole processing block, which works well for ordinary
block-to-block variation but not for a real vocal transition that fast, so a brief mismatch can still occur
right at the transition. A second attempt at fixing this, rejecting implausibly large pitch jumps outright,
was implemented, measured, and reverted in the same round of work. The read-position tracking above builds
on its own history, so rejecting even a correct reading permanently shifted grain placement for the rest of
the render, and both a direct audio comparison and listening back confirmed the whole clip got worse
overall. Left open rather than shipped half-fixed.
Varispeed's own block-rate artifact, fixed the same way. The block-size
test above was genuine for Varispeed too, and mattered far more there than for TD-PSOLA. Re-rendering the
same clip at different block sizes and re-checking the artifact's frequency against the exactly predicted
value, at three different sizes, found the mechanism directly. Varispeed's shift stage computed a single
ratio once per processing block and used that one constant value for its entire duration, so its internal
read rate took a genuine step at every block boundary. Fixed the same way as TD-PSOLA above, ramping that
ratio smoothly across each block instead. A second, separate, more direct bug turned up in the same code
while checking whether that first fix was enough. A click-suppression fade meant to run only right before
a genuine gap in the audio was computing its fade window unconditionally, so in ordinary healthy playback
it quietly faded the last few milliseconds of every single block toward silence and then ramped
back up at the start of the next one, an unconditional, periodic dip exactly at the block rate. Fixed by
only fading when there's an actual shortfall to anticipate. Re-checked at three block sizes again after
both fixes, this time with no measurable frequency shift at all, the exact opposite of the result that
first confirmed the bug. An unrelated, independent spectral-purity check
(QualityMetricsTests.cpp)
agreed. Varispeed's baseline artifact energy at unison dropped from about 23% to about 0.6%, now matching
TD-PSOLA and the phase vocoder's own clean baseline almost exactly. A smaller, real remainder at larger
shifts is expected and already disclosed elsewhere on this page. Varispeed's resampling stage has its own
accepted, unrelated interpolation error that scales with shift amount.
A known, disclosed limitation that remains on
Varispeed. A subtler version of the same character is still faintly audible here. Checked directly
rather than guessed at. The click-suppression fade above only fires now on a genuine shortfall, and a real
shortfall still happens occasionally, on about 1.5% of processing blocks in this clip, with individual
gaps up to around 30 milliseconds. These are legitimate shortfalls the fade is correctly responding to, not
a return of the earlier unconditional bug. The more interesting open question is why the underlying
two-stage pipeline runs short at all on those blocks, a buffering question rather than a fade-logic one,
and it wasn't chased down further given the time available before this needed to ship. Same disclosure
standard as TD-PSOLA's own remaining residual above.