Merge pull request #20 from eginhard/return-complex

fix: torch.stft will soon require return_complex=True
This commit is contained in:
Enno Hermann 2024-03-13 13:50:21 +01:00 committed by GitHub
commit e5c6da1c98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 91 additions and 77 deletions

View File

@ -179,7 +179,8 @@ def _wav_to_spec(y, n_fft, hop_length, win_length, center=False):
) )
y = y.squeeze(1) y = y.squeeze(1)
spec = torch.stft( spec = torch.view_as_real(
torch.stft(
y, y,
n_fft, n_fft,
hop_length=hop_length, hop_length=hop_length,
@ -189,7 +190,8 @@ def _wav_to_spec(y, n_fft, hop_length, win_length, center=False):
pad_mode="reflect", pad_mode="reflect",
normalized=False, normalized=False,
onesided=True, onesided=True,
return_complex=False, return_complex=True,
)
) )
return spec return spec
@ -274,7 +276,8 @@ def wav_to_mel(y, n_fft, num_mels, sample_rate, hop_length, win_length, fmin, fm
) )
y = y.squeeze(1) y = y.squeeze(1)
spec = torch.stft( spec = torch.view_as_real(
torch.stft(
y, y,
n_fft, n_fft,
hop_length=hop_length, hop_length=hop_length,
@ -284,7 +287,8 @@ def wav_to_mel(y, n_fft, num_mels, sample_rate, hop_length, win_length, fmin, fm
pad_mode="reflect", pad_mode="reflect",
normalized=False, normalized=False,
onesided=True, onesided=True,
return_complex=False, return_complex=True,
)
) )
spec = torch.sqrt(spec.pow(2).sum(-1) + 1e-6) spec = torch.sqrt(spec.pow(2).sum(-1) + 1e-6)

View File

@ -121,7 +121,8 @@ def wav_to_spec(y, n_fft, hop_length, win_length, center=False):
) )
y = y.squeeze(1) y = y.squeeze(1)
spec = torch.stft( spec = torch.view_as_real(
torch.stft(
y, y,
n_fft, n_fft,
hop_length=hop_length, hop_length=hop_length,
@ -131,7 +132,8 @@ def wav_to_spec(y, n_fft, hop_length, win_length, center=False):
pad_mode="reflect", pad_mode="reflect",
normalized=False, normalized=False,
onesided=True, onesided=True,
return_complex=False, return_complex=True,
)
) )
spec = torch.sqrt(spec.pow(2).sum(-1) + 1e-6) spec = torch.sqrt(spec.pow(2).sum(-1) + 1e-6)
@ -189,7 +191,8 @@ def wav_to_mel(y, n_fft, num_mels, sample_rate, hop_length, win_length, fmin, fm
) )
y = y.squeeze(1) y = y.squeeze(1)
spec = torch.stft( spec = torch.view_as_real(
torch.stft(
y, y,
n_fft, n_fft,
hop_length=hop_length, hop_length=hop_length,
@ -199,7 +202,8 @@ def wav_to_mel(y, n_fft, num_mels, sample_rate, hop_length, win_length, fmin, fm
pad_mode="reflect", pad_mode="reflect",
normalized=False, normalized=False,
onesided=True, onesided=True,
return_complex=False, return_complex=True,
)
) )
spec = torch.sqrt(spec.pow(2).sum(-1) + 1e-6) spec = torch.sqrt(spec.pow(2).sum(-1) + 1e-6)

View File

@ -119,7 +119,8 @@ class TorchSTFT(nn.Module): # pylint: disable=abstract-method
padding = int((self.n_fft - self.hop_length) / 2) padding = int((self.n_fft - self.hop_length) / 2)
x = torch.nn.functional.pad(x, (padding, padding), mode="reflect") x = torch.nn.functional.pad(x, (padding, padding), mode="reflect")
# B x D x T x 2 # B x D x T x 2
o = torch.stft( o = torch.view_as_real(
torch.stft(
x.squeeze(1), x.squeeze(1),
self.n_fft, self.n_fft,
self.hop_length, self.hop_length,
@ -129,7 +130,8 @@ class TorchSTFT(nn.Module): # pylint: disable=abstract-method
pad_mode="reflect", # compatible with audio.py pad_mode="reflect", # compatible with audio.py
normalized=self.normalized, normalized=self.normalized,
onesided=True, onesided=True,
return_complex=False, return_complex=True,
)
) )
M = o[:, :, :, 0] M = o[:, :, :, 0]
P = o[:, :, :, 1] P = o[:, :, :, 1]

View File

@ -54,7 +54,8 @@ def spectrogram_torch(y, n_fft, sampling_rate, hop_size, win_size, center=False)
) )
y = y.squeeze(1) y = y.squeeze(1)
spec = torch.stft( spec = torch.view_as_real(
torch.stft(
y, y,
n_fft, n_fft,
hop_length=hop_size, hop_length=hop_size,
@ -64,7 +65,8 @@ def spectrogram_torch(y, n_fft, sampling_rate, hop_size, win_size, center=False)
pad_mode="reflect", pad_mode="reflect",
normalized=False, normalized=False,
onesided=True, onesided=True,
return_complex=False, return_complex=True,
)
) )
spec = torch.sqrt(spec.pow(2).sum(-1) + 1e-6) spec = torch.sqrt(spec.pow(2).sum(-1) + 1e-6)
@ -104,7 +106,8 @@ def mel_spectrogram_torch(y, n_fft, num_mels, sampling_rate, hop_size, win_size,
) )
y = y.squeeze(1) y = y.squeeze(1)
spec = torch.stft( spec = torch.view_as_real(
torch.stft(
y, y,
n_fft, n_fft,
hop_length=hop_size, hop_length=hop_size,
@ -114,7 +117,8 @@ def mel_spectrogram_torch(y, n_fft, num_mels, sampling_rate, hop_size, win_size,
pad_mode="reflect", pad_mode="reflect",
normalized=False, normalized=False,
onesided=True, onesided=True,
return_complex=False, return_complex=True,
)
) )
spec = torch.sqrt(spec.pow(2).sum(-1) + 1e-6) spec = torch.sqrt(spec.pow(2).sum(-1) + 1e-6)