Skip to main content

inverse_stft

Function inverse_stft 

Source
pub fn inverse_stft(
    spec: &[Vec<[f32; 2]>],
    frame_size: usize,
    hop: usize,
) -> Result<Vec<f32>, StftBakeError>
Expand description

Inverse STFT of the two-sided complex frames from crate::audio::stft::forward_stft back into a single time-domain signal.

  • spec: num_frames frames, each a length-frame_size two-sided spectrum of [re, im] bins (exactly the crate::audio::stft::forward_stft output).
  • frame_size: N, a power of two; the analysis/synthesis frame length.
  • hop: sample advance between frames (> 0). A COLA Hann at hop = N/2 gives exact interior reconstruction.

The frames are flattened into a num_frames × 2·N interleaved-complex buffer ([re, im, …]), a length-N Hann window is built for both the analysis and synthesis arguments, and the WOLA resynthesiser [qualia_audio::features::framing::istft] is invoked with caller-owned scratch/norm/out buffers (out_len = (num_frames − 1)·hop + N).

The core-db forward sign (exp(-2πi·k·j/N), crate::audio::stft) matches qualia-audio’s inverse sign (fft_radix2(_, false) uses e^{-j2πk/L}), so no conjugation is required — the forward output feeds straight in.

Returns the reconstructed samples (length out_len), or an empty Vec when spec is empty. Errors map [qualia_audio::types::AudioError] → StftBakeError.