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
4b2de71f
"src/diffusers/pipelines/amused/__init__.py" did not exist on "b94880e536d5e46acc374a5cebe49b442466d913"
Unverified
Commit
4b2de71f
authored
May 11, 2021
by
Caroline Chen
Committed by
GitHub
May 11, 2021
Browse files
Add warning for non-integer resampling frequencies (#1490)
parent
c2740644
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
1 deletion
+39
-1
test/torchaudio_unittest/functional/functional_impl.py
test/torchaudio_unittest/functional/functional_impl.py
+26
-1
torchaudio/functional/functional.py
torchaudio/functional/functional.py
+13
-0
No files found.
test/torchaudio_unittest/functional/functional_impl.py
View file @
4b2de71f
...
...
@@ -9,7 +9,7 @@ import torchaudio.functional as F
from
parameterized
import
parameterized
from
scipy
import
signal
from
torchaudio_unittest.common_utils
import
TestBaseMixin
,
get_sinusoid
,
nested_params
from
torchaudio_unittest.common_utils
import
TestBaseMixin
,
get_sinusoid
,
nested_params
,
get_whitenoise
class
Functional
(
TestBaseMixin
):
...
...
@@ -259,6 +259,31 @@ class Functional(TestBaseMixin):
self
.
assertEqual
(
specgrams
,
specgrams_copy
)
def
test_resample_no_warning
(
self
):
sample_rate
=
44100
waveform
=
get_whitenoise
(
sample_rate
=
sample_rate
,
duration
=
0.1
)
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
warnings
.
simplefilter
(
"always"
)
F
.
resample
(
waveform
,
float
(
sample_rate
),
sample_rate
/
2.
)
assert
len
(
w
)
==
0
def
test_resample_warning
(
self
):
"""resample should throw a warning if an input frequency is not of an integer value"""
sample_rate
=
44100
waveform
=
get_whitenoise
(
sample_rate
=
sample_rate
,
duration
=
0.1
)
with
warnings
.
catch_warnings
(
record
=
True
)
as
w
:
warnings
.
simplefilter
(
"always"
)
F
.
resample
(
waveform
,
sample_rate
,
5512.5
)
assert
len
(
w
)
==
1
class
FunctionalComplex
(
TestBaseMixin
):
complex_dtype
=
None
real_dtype
=
None
device
=
None
@
nested_params
(
[
0.5
,
1.01
,
1.3
],
[
True
,
False
],
...
...
torchaudio/functional/functional.py
View file @
4b2de71f
...
...
@@ -1387,6 +1387,19 @@ def resample(
assert
orig_freq
>
0.0
and
new_freq
>
0.0
if
not
(
int
(
orig_freq
)
==
orig_freq
and
int
(
new_freq
)
==
new_freq
):
warnings
.
warn
(
"Non-integer frequencies are being cast to ints and may result in poor resampling quality "
"because the underlying algorithm requires an integer ratio between `orig_freq` and `new_freq`. "
"Using non-integer valued frequencies will throw an error in the next release. "
"To work around this issue, manually convert both frequencies to integer values "
"that maintain their resampling rate ratio before passing them into the function "
"Example: To downsample a 44100 hz waveform by a factor of 8, use "
"`orig_freq=8` and `new_freq=1` instead of `orig_freq=44100` and `new_freq=5512.5` "
"For more information or to leave feedback about this change, please refer to "
"https://github.com/pytorch/audio/issues/1487."
)
orig_freq
=
int
(
orig_freq
)
new_freq
=
int
(
new_freq
)
gcd
=
math
.
gcd
(
orig_freq
,
new_freq
)
...
...
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