update fargan to match version 45
This commit is contained in:
parent
d1c5b32add
commit
9e76a7bfb8
7 changed files with 196 additions and 84 deletions
|
@ -48,7 +48,9 @@ model.load_state_dict(checkpoint['state_dict'], strict=False)
|
|||
features = np.reshape(np.memmap(features_file, dtype='float32', mode='r'), (1, -1, nb_features))
|
||||
lpc = features[:,4-1:-1,nb_used_features:]
|
||||
features = features[:, :, :nb_used_features]
|
||||
periods = np.round(50*features[:,:,nb_used_features-2]+100).astype('int')
|
||||
#periods = np.round(50*features[:,:,nb_used_features-2]+100).astype('int')
|
||||
periods = np.round(np.clip(256./2**(features[:,:,nb_used_features-2]+1.5), 32, 255)).astype('int')
|
||||
|
||||
|
||||
nb_frames = features.shape[1]
|
||||
#nb_frames = 1000
|
||||
|
@ -90,18 +92,37 @@ def inverse_perceptual_weighting (pw_signal, filters, weighting_vector):
|
|||
buffer[:] = out_sig_frame[-16:]
|
||||
return signal
|
||||
|
||||
def inverse_perceptual_weighting40 (pw_signal, filters):
|
||||
|
||||
#inverse perceptual weighting= H_preemph / W(z/gamma)
|
||||
|
||||
signal = np.zeros_like(pw_signal)
|
||||
buffer = np.zeros(16)
|
||||
num_frames = pw_signal.shape[0] //40
|
||||
assert num_frames == filters.shape[0]
|
||||
for frame_idx in range(0, num_frames):
|
||||
in_frame = pw_signal[frame_idx*40: (frame_idx+1)*40][:]
|
||||
out_sig_frame = lpc_synthesis_one_frame(in_frame, filters[frame_idx, :], buffer)
|
||||
signal[frame_idx*40: (frame_idx+1)*40] = out_sig_frame[:]
|
||||
buffer[:] = out_sig_frame[-16:]
|
||||
return signal
|
||||
|
||||
from scipy.signal import lfilter
|
||||
|
||||
if __name__ == '__main__':
|
||||
model.to(device)
|
||||
features = torch.tensor(features).to(device)
|
||||
#lpc = torch.tensor(lpc).to(device)
|
||||
periods = torch.tensor(periods).to(device)
|
||||
weighting = gamma**np.arange(1, 17)
|
||||
lpc = lpc*weighting
|
||||
lpc = fargan.interp_lpc(torch.tensor(lpc), 4).numpy()
|
||||
|
||||
sig, _ = model(features, periods, nb_frames - 4)
|
||||
weighting_vector = np.array([gamma**i for i in range(16,0,-1)])
|
||||
#weighting_vector = np.array([gamma**i for i in range(16,0,-1)])
|
||||
sig = sig.detach().numpy().flatten()
|
||||
sig = inverse_perceptual_weighting(sig, lpc[0,:,:], weighting_vector)
|
||||
sig = lfilter(np.array([1.]), np.array([1., -.85]), sig)
|
||||
#sig = inverse_perceptual_weighting40(sig, lpc[0,:,:])
|
||||
|
||||
pcm = np.round(32768*np.clip(sig, a_max=.99, a_min=-.99)).astype('int16')
|
||||
pcm.tofile(signal_file)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue