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
1059c7ca
Commit
1059c7ca
authored
May 16, 2019
by
Jason Lian
Browse files
pre
parent
95803cf9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
8 deletions
+22
-8
torchaudio/functional.py
torchaudio/functional.py
+18
-3
torchaudio/transforms.py
torchaudio/transforms.py
+4
-5
No files found.
torchaudio/functional.py
View file @
1059c7ca
...
...
@@ -2,6 +2,22 @@ import numpy as np
import
torch
__all__
=
[
'scale'
,
'pad_trim'
,
'downmix_mono'
,
'LC2CL'
,
'spectrogram'
,
'create_fb_matrix'
,
'mel_scale'
,
'spectrogram_to_DB'
,
'create_dct'
,
'MFCC'
,
'BLC2CBL'
,
'mu_law_encoding'
,
'mu_law_expanding'
]
def
scale
(
tensor
,
factor
):
# type: (Tensor, int) -> Tensor
"""Scale audio tensor from a 16-bit integer (represented as a FloatTensor)
...
...
@@ -34,7 +50,6 @@ def pad_trim(tensor, ch_dim, max_len, len_dim, fill_value):
Outputs:
Tensor: Padded/trimmed tensor
"""
assert
tensor
.
size
(
ch_dim
)
<
128
,
\
"Too many channels ({}) detected, see channels_first param."
.
format
(
tensor
.
size
(
ch_dim
))
...
...
@@ -316,7 +331,7 @@ def mu_law_encoding(x, qc):
return
x_mu
def
mu_law_expanding
(
x
,
qc
):
def
mu_law_expanding
(
x
_mu
,
qc
):
# type: (Tensor/ndarray, int) -> Tensor/ndarray
"""Decode mu-law encoded signal. For more info see the
`Wikipedia Entry <https://en.wikipedia.org/wiki/%CE%9C-law_algorithm>`_
...
...
@@ -325,7 +340,7 @@ def mu_law_expanding(x, qc):
and returns a signal scaled between -1 and 1.
Inputs:
x (Tensor): Input tensor
x
_mu
(Tensor): Input tensor
qc (int): Number of channels (i.e. quantization channels)
Outputs:
...
...
torchaudio/transforms.py
View file @
1059c7ca
...
...
@@ -2,8 +2,7 @@ from __future__ import division, print_function
from
warnings
import
warn
import
torch
import
numpy
as
np
import
functional
as
F
from
.
import
functional
as
F
class
Compose
(
object
):
"""Composes several transforms together.
...
...
@@ -58,7 +57,7 @@ class Scale(object):
Tensor: Scaled by the scale factor. (default between -1.0 and 1.0)
"""
return
F
.
scale
(
tensor
,
factor
)
return
F
.
scale
(
tensor
,
self
.
factor
)
def
__repr__
(
self
):
return
self
.
__class__
.
__name__
+
'()'
...
...
@@ -409,7 +408,7 @@ class MuLawEncoding(object):
x_mu (LongTensor or ndarray)
"""
return
self
.
mu_law_encoding
(
x
,
self
.
qc
)
return
F
.
mu_law_encoding
(
x
,
self
.
qc
)
def
__repr__
(
self
):
return
self
.
__class__
.
__name__
+
'()'
...
...
@@ -440,7 +439,7 @@ class MuLawExpanding(object):
x (FloatTensor or ndarray)
"""
return
F
.
mu_law_expanding
(
x
,
self
.
qc
)
return
F
.
mu_law_expanding
(
x
_mu
,
self
.
qc
)
def
__repr__
(
self
):
return
self
.
__class__
.
__name__
+
'()'
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