Expand description
YinFFT: the YIN difference function computed via an FFT autocorrelation
rather than the O(W · max_lag) direct double loop.
The YIN difference function expands as
d(τ) = Σ_{j<W}(x[j] − x[j+τ])²
= Σ_{j<W} x[j]² (E0, constant)
+ Σ_{j<W} x[j+τ]² (sliding energy, from a prefix sum of squares)
− 2 · Σ_{j<W} x[j]x[j+τ] (autocorrelation, from the FFT)The autocorrelation term is obtained as IFFT(conj(FFT(a)) · FFT(b)) where
a is the first W samples (zero-padded) and b is the whole frame
(zero-padded), giving the linear correlation at lags 0..=max_lag with no
circular wrap. The two energy terms come from one prefix-sum pass. The
result is the same difference function as super::yin, so it feeds the
identical CMND → threshold → parabolic-interpolation spine.
Zero-heap hot path: a single caller scratch buffer is carved into the two
complex FFT work areas, the prefix-sum table, and the difference/CMND buffer.
Nothing is allocated per call.
Functions§
- yin_
fft_ pitch - Estimate the fundamental frequency of
framewith YinFFT. - yin_
fft_ scratch_ len - Minimum
scratchlength (inf32) required for a frame ofnsamples with a maximum lag ofmax_lag.lis the FFT size (nrounded up to a power of two). Exposed so callers can size the buffer without guessing.