Unverified Commit 3ace5932 authored by moto's avatar moto Committed by GitHub
Browse files

Update calls to torch.stft to have return_complex=True (#1096)

* Resolves https://github.com/pytorch/audio/issues/1095
parent d25a4ddf
......@@ -227,19 +227,22 @@ class TestTransforms(common_utils.TorchaudioTestCase):
test_filepath = common_utils.get_asset_path('steam-train-whistle-daniel_simon.wav')
waveform, _ = torchaudio.load(test_filepath) # (2, 278756), 44100
kwargs = {
'n_fft': 2048,
'hop_length': 512,
'win_length': 2048,
'window': torch.hann_window(2048),
'center': True,
'pad_mode': 'reflect',
'normalized': True,
'onesided': True,
}
rate = 2
complex_specgrams = torch.stft(waveform, **kwargs)
complex_specgrams = torch.view_as_real(
torch.stft(
input=waveform,
n_fft=2048,
hop_length=512,
win_length=2048,
window=torch.hann_window(2048),
center=True,
pad_mode='reflect',
normalized=True,
onesided=True,
return_complex=True,
)
)
# Single then transform then batch
expected = torchaudio.transforms.TimeStretch(
......
......@@ -70,8 +70,19 @@ def spectrogram(
waveform = waveform.reshape(-1, shape[-1])
# default values are consistent with librosa.core.spectrum._spectrogram
spec_f = torch.stft(
waveform, n_fft, hop_length, win_length, window, True, "reflect", False, True
spec_f = torch.view_as_real(
torch.stft(
input=waveform,
n_fft=n_fft,
hop_length=hop_length,
win_length=win_length,
window=window,
center=True,
pad_mode="reflect",
normalized=False,
onesided=True,
return_complex=True,
)
)
# unpack batch
......@@ -174,8 +185,20 @@ def griffinlim(
length=length).float()
# Rebuild the spectrogram
rebuilt = torch.stft(inverse, n_fft, hop_length, win_length, window,
True, 'reflect', False, True)
rebuilt = torch.view_as_real(
torch.stft(
input=inverse,
n_fft=n_fft,
hop_length=hop_length,
win_length=win_length,
window=window,
center=True,
pad_mode='reflect',
normalized=False,
onesided=True,
return_complex=True,
)
)
# Update our phase estimates
angles = rebuilt
......
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