def process(self, wave, W):
wave.check_mono()
if wave.sample_rate != self.sr: raise Exception("Wrong sample rate")
n = int(np.ceil(2 * wave.num_frames / float(self.w_len)))
m = (n + 1) * self.w_len / 2
if n != W.shape[1]: raise Exception("Wrong size for W")
swindow = self.make_signal_window(n)
win_ratios = [self.window / swindow[t * self.w_len / 2 :
t * self.w_len / 2 + self.w_len]
for t in range(n)]
wave = wave.zero_pad(0, int((n + 1) * self.w_len / 2.0 - wave.num_frames))
wave = audio.Wave(signal.hilbert(wave), wave.sample_rate)
result = np.zeros(wave.shape)
for b in range(self.n_bins):
w = self.widths[b]
wc = 1/np.square(w + 1)
filter = 1/w * self.filters[b]
band = fftfilt(filter, wave.zero_pad(0, int(2 * w))[:,0])
band = band[int(w) : int(w + (n + 1) * self.w_len / 2), np.newaxis]
out_band = audio.Wave(np.zeros(band.shape, np.complex128), wave.sample_rate)
for t in range(n):
start = int(t * self.w_len / 2)
end = int(t * self.w_len / 2 + self.w_len)
frame = band[start:end,:] * win_ratios[t]**2
out_band[start:end,:] = out_band[start:end,:] + frame * W[b,t]
out_band = np.real(fftfilt(filter, out_band.zero_pad(0, int(2 * w))[:,0]))
result[:,0] = result[:,0] + self.weights[b] * out_band[int(w): int(w + m)]
return result
评论列表
文章目录