Unverified Commit fcc9a51a authored by tuxzz's avatar tuxzz Committed by GitHub
Browse files

make istft fast again (#472)

parent d7c79b39
...@@ -180,21 +180,19 @@ def istft( ...@@ -180,21 +180,19 @@ def istft(
# each column of a channel is a frame which needs to be overlap added at the right place # each column of a channel is a frame which needs to be overlap added at the right place
ytmp = ytmp.transpose(1, 2) # size (channel, n_fft, n_frame) ytmp = ytmp.transpose(1, 2) # size (channel, n_fft, n_frame)
eye = torch.eye(n_fft, device=device, dtype=dtype).unsqueeze(1) # size (n_fft, 1, n_fft)
# this does overlap add where the frames of ytmp are added such that the i'th frame of # this does overlap add where the frames of ytmp are added such that the i'th frame of
# ytmp is added starting at i*hop_length in the output # ytmp is added starting at i*hop_length in the output
y = torch.nn.functional.conv_transpose1d( y = torch.nn.functional.fold(
ytmp, eye, stride=hop_length, padding=0 ytmp, (1, (n_frame - 1) * hop_length + n_fft), (1, n_fft), stride=(1, hop_length)
) # size (channel, 1, expected_signal_len) ).squeeze(2)
# do the same for the window function # do the same for the window function
window_sq = ( window_sq = (
window.pow(2).view(n_fft, 1).repeat((1, n_frame)).unsqueeze(0) window.pow(2).view(n_fft, 1).repeat((1, n_frame)).unsqueeze(0)
) # size (1, n_fft, n_frame) ) # size (1, n_fft, n_frame)
window_envelop = torch.nn.functional.conv_transpose1d( window_envelop = torch.nn.functional.fold(
window_sq, eye, stride=hop_length, padding=0 window_sq, (1, (n_frame - 1) * hop_length + n_fft), (1, n_fft), stride=(1, hop_length)
) # size (1, 1, expected_signal_len) ).squeeze(2) # size (1, 1, expected_signal_len)
expected_signal_len = n_fft + hop_length * (n_frame - 1) expected_signal_len = n_fft + hop_length * (n_frame - 1)
assert y.size(2) == expected_signal_len assert y.size(2) == expected_signal_len
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment