def undo_stft(spect, hop_size, frame_len=None, unwindow='auto'):
"""
Undoes an SFTF via overlap-add, returning a numpy array of samples.
"""
# transform into time domain
spect = np.fft.irfft(spect, n=frame_len, axis=1)
# overlap-and-add
num_frames, frame_len = spect.shape
win = np.hanning(frame_len)
#win = np.sin(np.pi * np.arange(frame_len) / frame_len)
#win = 1
if unwindow == 'auto':
unwindow = (hop_size <= frame_len//2)
samples = np.zeros((num_frames - 1) * hop_size + frame_len)
if unwindow:
factors = np.zeros_like(samples)
for idx, frame in enumerate(spect):
oidx = int(idx*hop_size)
samples[oidx:oidx+frame_len] += frame * win
if unwindow:
factors[oidx:oidx+frame_len] += win**2
if unwindow:
np.maximum(factors, .1 * factors.max(), factors)
samples /= factors
return samples
评论列表
文章目录