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.
The public
mlx_audio.dsp.istftfails with its default window length for many valid(frequency, frames)inputs, and supplyinglengthwithcenter=Truereturns 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:
There are related reconstruction problems when passing explicit options:
center=True, length=Nskips left-padding removal, shifting the requested waveform.win_length < n_fftuses the window length for overlap-add geometry although the inverse FFT still producesn_fftsamples, causing a broadcast error.mx.whereat 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
normalizedoption'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.