Skip to content

ISTFT infers FFT size from frame count and misaligns centered output with length #957

Description

@pentaoa

The public mlx_audio.dsp.istft fails with its default window length for many valid (frequency, frames) inputs, and supplying length with center=True returns audio starting at the left padding instead of the signal.

On 407eb61, this valid 32-point spectrum fails with a broadcast error because the default window length is inferred from the 9 time frames instead of the 17 frequency bins:

import mlx.core as mx
from mlx_audio.dsp import istft

spectrum = mx.ones((17, 9), dtype=mx.complex64)
mx.eval(istft(spectrum))

There are related reconstruction problems when passing explicit options:

  • center=True, length=N skips left-padding removal, shifting the requested waveform.
  • win_length < n_fft uses the window length for overlap-add geometry although the inverse FFT still produces n_fft samples, causing a broadcast error.
  • A requested length beyond the reconstructed buffer returns too few samples.
  • Hann-window reconstruction can have finite output but NaN gradients: division by zero happens inside the unselected branch of mx.where at window endpoints.

Expected: infer FFT geometry from the frequency axis, center-pad a short window, remove left padding before selecting the requested length, and keep gradients finite. The existing normalized option's window vs. squared-window convention should remain unchanged.

Reproduced with MLX 0.32.2 on macOS arm64 (CPU and Metal). I have regression tests plus comparisons against NumPy overlap-add, PyTorch ISTFT/autograd, and synthetic audio; no pretrained models are needed.

Activity

  1. linear-code commented on Sep 14, 2026

    @linear-code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions