ISTFT

The inverse of STFT: overlap-add synthesis back to the time domain, with the window-envelope normalization, in two kernels riding one GPU submission. Round trips are exact to float precision (the figure’s title carries the measured error).
specux.istft(Z, n_fft=2048, hop_length=None, win_length=None, window="hann", center=True, length=None, backend="auto")import numpy as np
import specux
x = np.random.randn(8, 32768).astype(np.float32)Z = specux.stft(x, n_fft=1024, hop_length=256) # complex spectrumy = specux.istft(Z, n_fft=1024, hop_length=256, length=x.shape[-1])np.abs(y - x).max() # ~1e-5, float32 roundoffParameters
Z: the complex spectrum, shaped(..., n_fft // 2 + 1, n_frames), as produced byspecux.stft(..., output="complex"). The output is(..., time). torch inputs are differentiable (adjoint backward).n_fft,hop_length,win_length,window,center: must match the analysis parameters.length: crop or bound the output length in samples.backend:"auto","cuda","cpu", or"metal".
A window/hop combination that violates the NOLA condition, meaning no exact
reconstruction exists, raises ValueError instead of returning silently
wrong audio [griffin1984].
Determinism
GPU overlap-add uses atomics by default; large n_fft (past the fused
kernels) always runs a gather pipeline with no atomics, so it is
bitwise-reproducible as-is. specux.deterministic(True) (or
torch’s use_deterministic_algorithms) switches the fused path to a
bitwise-reproducible
ordered gather, at the cost of a larger intermediate buffer:
with specux.deterministic(True): y = specux.istft(Z, n_fft=1024, hop_length=256, length=x.shape[-1])The configured form
specux.ISTFT holds the parameters and broadcasts over any leading shape;
to_dict() round-trips the configuration:
t = specux.ISTFT(n_fft=1024, hop_length=256)y = t(Z, length=x.shape[-1]) # (..., time)assert specux.ISTFT(**t.to_dict()) == tThe torch Module for training pipelines is
specux.transforms.InverseSpectrogram.
References
- [allen1977]: overlap-add synthesis.
- [griffin1984]: the NOLA condition and least-squares inversion of modified spectra.