spects.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:singing_horse 作者: f0k 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号