Skip to main content

Module yin_fft

Module yin_fft 

Source
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 frame with YinFFT.
yin_fft_scratch_len
Minimum scratch length (in f32) required for a frame of n samples with a maximum lag of max_lag. l is the FFT size (n rounded up to a power of two). Exposed so callers can size the buffer without guessing.