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
hehl2
Torchaudio
Commits
7763ed87
"vscode:/vscode.git/clone" did not exist on "02e79e93a47a5cf4e975da831fa028e4eb70b7ba"
Unverified
Commit
7763ed87
authored
May 20, 2021
by
Caroline Chen
Committed by
GitHub
May 20, 2021
Browse files
Add F.resample torchscript test (#1516)
parent
a21b08e3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
6 deletions
+28
-6
test/torchaudio_unittest/functional/torchscript_consistency_impl.py
...audio_unittest/functional/torchscript_consistency_impl.py
+22
-0
torchaudio/functional/functional.py
torchaudio/functional/functional.py
+6
-6
No files found.
test/torchaudio_unittest/functional/torchscript_consistency_impl.py
View file @
7763ed87
...
...
@@ -591,6 +591,28 @@ class Functional(TempDirMixin, TestBaseMixin):
tensor
=
common_utils
.
get_whitenoise
(
sample_rate
=
44100
)
self
.
_assert_consistency
(
func
,
tensor
)
def
test_resample_sinc
(
self
):
def
func
(
tensor
):
sr1
,
sr2
=
16000.
,
8000.
return
F
.
resample
(
tensor
,
sr1
,
sr2
,
resampling_method
=
"sinc_interpolation"
)
tensor
=
common_utils
.
get_whitenoise
(
sample_rate
=
16000
)
self
.
_assert_consistency
(
func
,
tensor
)
def
test_resample_kaiser
(
self
):
def
func
(
tensor
):
sr1
,
sr2
=
16000.
,
8000.
return
F
.
resample
(
tensor
,
sr1
,
sr2
,
resampling_method
=
"kaiser_window"
)
def
func_beta
(
tensor
):
sr1
,
sr2
=
16000.
,
8000.
beta
=
6.
return
F
.
resample
(
tensor
,
sr1
,
sr2
,
resampling_method
=
"kaiser_window"
,
beta
=
beta
)
tensor
=
common_utils
.
get_whitenoise
(
sample_rate
=
16000
)
self
.
_assert_consistency
(
func
,
tensor
)
self
.
_assert_consistency
(
func_beta
,
tensor
)
@
parameterized
.
expand
([(
True
,
),
(
False
,
)])
def
test_phase_vocoder
(
self
,
test_paseudo_complex
):
def
func
(
tensor
):
...
...
torchaudio/functional/functional.py
View file @
7763ed87
...
...
@@ -1328,9 +1328,6 @@ def _get_sinc_resample_kernel(
orig_freq
=
int
(
orig_freq
)
//
gcd
new_freq
=
int
(
new_freq
)
//
gcd
if
resampling_method
==
"kaiser_window"
and
beta
is
None
:
beta
=
14.769656459379492
assert
lowpass_filter_width
>
0
kernels
=
[]
base_freq
=
min
(
orig_freq
,
new_freq
)
...
...
@@ -1373,9 +1370,12 @@ def _get_sinc_resample_kernel(
# at specific positions, not over a regular grid.
if
resampling_method
==
"sinc_interpolation"
:
window
=
torch
.
cos
(
t
*
math
.
pi
/
lowpass_filter_width
/
2
)
**
2
elif
resampling_method
==
"kaiser_window"
:
beta
=
torch
.
tensor
(
beta
,
dtype
=
float
)
window
=
torch
.
i0
(
beta
*
torch
.
sqrt
(
1
-
(
t
/
lowpass_filter_width
)
**
2
))
/
torch
.
i0
(
beta
)
else
:
# kaiser_window
if
beta
is
None
:
beta
=
14.769656459379492
beta_tensor
=
torch
.
tensor
(
float
(
beta
))
window
=
torch
.
i0
(
beta_tensor
*
torch
.
sqrt
(
1
-
(
t
/
lowpass_filter_width
)
**
2
))
/
torch
.
i0
(
beta_tensor
)
t
*=
math
.
pi
kernel
=
torch
.
where
(
t
==
0
,
torch
.
tensor
(
1.
).
to
(
t
),
torch
.
sin
(
t
)
/
t
)
kernel
.
mul_
(
window
)
...
...
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