n_fft = 2 * (stft_matrix.shape[0] - 1)
// By default, use the entire frame
if win_length is None:
win_length = n_fft
// Set the default hop, if it"s not already specified
if hop_length is None:
hop_length = win_length / 4
if window is None:
// Default is an asymmetric Hann window.
// 2/3 scaling is to make stft(istft(.)) identity for 25% hop
ifft_window = scipy.signal.hann(win_length, sym=False) * (2.0 / 3)
elif hasattr(window, "__call__"):
// User supplied a windowing function
ifft_window = window(win_length)
else:
// User supplied a window vector.
// Make it into an array
ifft_window = np.asarray(window)
// Verify that the shape matches
if ifft_window.size != n_fft:
raise ValueError("Size mismatch between n_fft and window size")
// Pad out to match n_fft
ifft_window = util.pad_center(ifft_window, n_fft)
n_frames = stft_matrix.shape[1]
y = np.zeros(n_fft + hop_length * (n_frames - 1))