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
3549c57b
Unverified
Commit
3549c57b
authored
Feb 24, 2020
by
Vincent QB
Committed by
GitHub
Feb 24, 2020
Browse files
remove custom gcd command since python2.7 is deprecated. testing resample. (#441)
parent
4d58bc46
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
21 deletions
+5
-21
test/test_transforms.py
test/test_transforms.py
+3
-3
torchaudio/compliance/kaldi.py
torchaudio/compliance/kaldi.py
+2
-18
No files found.
test/test_transforms.py
View file @
3549c57b
...
...
@@ -321,10 +321,10 @@ class Tester(unittest.TestCase):
def
test_scriptmodule_Resample
(
self
):
tensor
=
torch
.
rand
((
2
,
1000
))
sample_rate
=
100
sample_rate_2
=
50
sample_rate
=
100
.
sample_rate_2
=
50
.
_test_script_module
(
transforms
.
Spectrogram
,
tensor
,
sample_rate
,
sample_rate_2
)
_test_script_module
(
transforms
.
Resample
,
tensor
,
sample_rate
,
sample_rate_2
)
def
test_batch_Resample
(
self
):
waveform
=
torch
.
randn
(
2
,
2786
)
...
...
torchaudio/compliance/kaldi.py
View file @
3549c57b
...
...
@@ -32,22 +32,6 @@ BLACKMAN = 'blackman'
WINDOWS
=
[
HAMMING
,
HANNING
,
POVEY
,
RECTANGULAR
,
BLACKMAN
]
def
gcd
(
a
,
b
):
# type: (int, int) -> int
"""Calculate the Greatest Common Divisor of a and b.
Unless b==0, the result will have the same sign as b (so that when
b is divided by it, the result comes out positive).
"""
try
:
return
math
.
gcd
(
a
,
b
)
except
AttributeError
:
while
b
:
a
,
b
=
b
,
a
%
b
return
a
def
_next_power_of_2
(
x
):
r
"""Returns the smallest power of 2 that is greater than x
"""
...
...
@@ -749,7 +733,7 @@ def _get_LR_indices_and_weights(orig_freq, new_freq, output_samples_in_unit, win
def
_lcm
(
a
,
b
):
# type: (int, int) -> int
return
abs
(
a
*
b
)
//
gcd
(
a
,
b
)
return
abs
(
a
*
b
)
//
math
.
gcd
(
a
,
b
)
def
_get_num_LR_output_samples
(
input_num_samp
,
samp_rate_in
,
samp_rate_out
):
...
...
@@ -826,7 +810,7 @@ def resample_waveform(waveform, orig_freq, new_freq, lowpass_filter_width=6):
assert
lowpass_cutoff
*
2
<=
min_freq
base_freq
=
gcd
(
int
(
orig_freq
),
int
(
new_freq
))
base_freq
=
math
.
gcd
(
int
(
orig_freq
),
int
(
new_freq
))
input_samples_in_unit
=
int
(
orig_freq
)
//
base_freq
output_samples_in_unit
=
int
(
new_freq
)
//
base_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