Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Torchaudio
Commits
3ace5932
Unverified
Commit
3ace5932
authored
Dec 16, 2020
by
moto
Committed by
GitHub
Dec 16, 2020
Browse files
Update calls to torch.stft to have return_complex=True (#1096)
* Resolves
https://github.com/pytorch/audio/issues/1095
parent
d25a4ddf
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
15 deletions
+41
-15
test/torchaudio_unittest/batch_consistency_test.py
test/torchaudio_unittest/batch_consistency_test.py
+14
-11
torchaudio/functional/functional.py
torchaudio/functional/functional.py
+27
-4
No files found.
test/torchaudio_unittest/batch_consistency_test.py
View file @
3ace5932
...
...
@@ -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
(
...
...
torchaudio/functional/functional.py
View file @
3ace5932
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment