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
719a39de
"docs/git@developer.sourcefind.cn:OpenDAS/lmdeploy.git" did not exist on "5c9e1e285e50c7be6cbcec04c47b4f0b929ede85"
Unverified
Commit
719a39de
authored
Jan 02, 2020
by
Vincent QB
Committed by
GitHub
Jan 02, 2020
Browse files
use standard naming. (#393)
parent
cdf5c83d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
8 deletions
+8
-8
torchaudio/functional.py
torchaudio/functional.py
+8
-8
No files found.
torchaudio/functional.py
View file @
719a39de
...
@@ -272,7 +272,7 @@ def spectrogram(
...
@@ -272,7 +272,7 @@ def spectrogram(
def
griffinlim
(
def
griffinlim
(
spec
tro
gram
,
window
,
n_fft
,
hop_length
,
win_length
,
power
,
normalized
,
n_iter
,
momentum
,
length
,
rand_init
specgram
,
window
,
n_fft
,
hop_length
,
win_length
,
power
,
normalized
,
n_iter
,
momentum
,
length
,
rand_init
):
):
# type: (Tensor, Tensor, int, int, int, int, bool, int, float, Optional[int], bool) -> Tensor
# type: (Tensor, Tensor, int, int, int, int, bool, int, float, Optional[int], bool) -> Tensor
r
"""Compute waveform from a linear scale magnitude spectrogram using the Griffin-Lim transformation.
r
"""Compute waveform from a linear scale magnitude spectrogram using the Griffin-Lim transformation.
...
@@ -292,7 +292,7 @@ def griffinlim(
...
@@ -292,7 +292,7 @@ def griffinlim(
IEEE Trans. ASSP, vol.32, no.2, pp.236–243, Apr. 1984.
IEEE Trans. ASSP, vol.32, no.2, pp.236–243, Apr. 1984.
Args:
Args:
spec
tro
gram (torch.Tensor): A magnitude-only STFT spectrogram of dimension (channel, freq, frames)
specgram (torch.Tensor): A magnitude-only STFT spectrogram of dimension (channel, freq, frames)
where freq is ``n_fft // 2 + 1``.
where freq is ``n_fft // 2 + 1``.
window (torch.Tensor): Window tensor that is applied/multiplied to each frame/window
window (torch.Tensor): Window tensor that is applied/multiplied to each frame/window
n_fft (int): Size of FFT, creates ``n_fft // 2 + 1`` bins
n_fft (int): Size of FFT, creates ``n_fft // 2 + 1`` bins
...
@@ -315,17 +315,17 @@ def griffinlim(
...
@@ -315,17 +315,17 @@ def griffinlim(
assert
momentum
<
1
,
'momentum=%s > 1 can be unstable'
%
momentum
assert
momentum
<
1
,
'momentum=%s > 1 can be unstable'
%
momentum
assert
momentum
>
0
,
'momentum=%s < 0'
%
momentum
assert
momentum
>
0
,
'momentum=%s < 0'
%
momentum
spec
tro
gram
=
spec
tro
gram
.
pow
(
1
/
power
)
specgram
=
specgram
.
pow
(
1
/
power
)
# randomly initialize the phase
# randomly initialize the phase
batch
,
freq
,
frames
=
spec
tro
gram
.
size
()
batch
,
freq
,
frames
=
specgram
.
size
()
if
rand_init
:
if
rand_init
:
angles
=
2
*
math
.
pi
*
torch
.
rand
(
batch
,
freq
,
frames
)
angles
=
2
*
math
.
pi
*
torch
.
rand
(
batch
,
freq
,
frames
)
else
:
else
:
angles
=
torch
.
zeros
(
batch
,
freq
,
frames
)
angles
=
torch
.
zeros
(
batch
,
freq
,
frames
)
angles
=
torch
.
stack
([
angles
.
cos
(),
angles
.
sin
()],
dim
=-
1
)
\
angles
=
torch
.
stack
([
angles
.
cos
(),
angles
.
sin
()],
dim
=-
1
)
\
.
to
(
dtype
=
spec
tro
gram
.
dtype
,
device
=
spec
tro
gram
.
device
)
.
to
(
dtype
=
specgram
.
dtype
,
device
=
specgram
.
device
)
spec
tro
gram
=
spec
tro
gram
.
unsqueeze
(
-
1
).
expand_as
(
angles
)
specgram
=
specgram
.
unsqueeze
(
-
1
).
expand_as
(
angles
)
# And initialize the previous iterate to 0
# And initialize the previous iterate to 0
rebuilt
=
torch
.
tensor
(
0.
)
rebuilt
=
torch
.
tensor
(
0.
)
...
@@ -335,7 +335,7 @@ def griffinlim(
...
@@ -335,7 +335,7 @@ def griffinlim(
tprev
=
rebuilt
tprev
=
rebuilt
# Invert with our current estimate of the phases
# Invert with our current estimate of the phases
inverse
=
istft
(
spec
tro
gram
*
angles
,
inverse
=
istft
(
specgram
*
angles
,
n_fft
=
n_fft
,
n_fft
=
n_fft
,
hop_length
=
hop_length
,
hop_length
=
hop_length
,
win_length
=
win_length
,
win_length
=
win_length
,
...
@@ -351,7 +351,7 @@ def griffinlim(
...
@@ -351,7 +351,7 @@ def griffinlim(
angles
=
angles
.
div_
(
complex_norm
(
angles
).
add_
(
1e-16
).
unsqueeze
(
-
1
).
expand_as
(
angles
))
angles
=
angles
.
div_
(
complex_norm
(
angles
).
add_
(
1e-16
).
unsqueeze
(
-
1
).
expand_as
(
angles
))
# Return the final phase estimates
# Return the final phase estimates
return
istft
(
spec
tro
gram
*
angles
,
return
istft
(
specgram
*
angles
,
n_fft
=
n_fft
,
n_fft
=
n_fft
,
hop_length
=
hop_length
,
hop_length
=
hop_length
,
win_length
=
win_length
,
win_length
=
win_length
,
...
...
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