Skip to main content

mfcc

Function mfcc 

Source
pub fn mfcc(
    power_spectrum: &[f32],
    bank_weights: &[f32],
    n_mel: usize,
    n_coeffs: usize,
    out: &mut [f32],
    scratch: &mut [f32],
) -> Result<(), AudioError>
Expand description

Compute the first n_coeffs MFCCs of one power-spectrum frame, allocation-free.

Pipeline: apply the triangular bank_weights (n_mel × n_fft_bins, row-major), take ln(energy + 1e-10) per band, run an orthonormal DCT-II, and copy the leading n_coeffs cepstral coefficients into out. Coefficient 0 (c0) is the overall log-energy; higher coefficients describe spectral shape.

  • power_spectrum: ≥ n_fft_bins (= bank_weights.len()/n_mel) values.
  • bank_weights: the precomputed bank.
  • n_mel: number of bank rows.
  • n_coeffs: how many leading coefficients to emit (1..=n_mel).
  • out: ≥ n_coeffs floats.
  • scratch: ≥ 2 * n_mel floats (log-mel buffer + DCT output); clobbered.

Returns AudioError::InvalidParameter for degenerate sizes and AudioError::OutputBufferTooSmall if out or scratch are short.