diffsptk 3.5.0__tar.gz → 4.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {diffsptk-3.5.0 → diffsptk-4.0.0}/.gitignore +1 -0
- {diffsptk-3.5.0 → diffsptk-4.0.0}/PKG-INFO +3 -2
- {diffsptk-3.5.0 → diffsptk-4.0.0}/README.md +1 -1
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/functional.py +3 -3
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/acorr.py +12 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/acr2csm.py +11 -17
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/alaw.py +10 -15
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/ap.py +37 -19
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/b2mc.py +7 -11
- diffsptk-4.0.0/diffsptk/modules/base.py +109 -0
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/c2acr.py +9 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/c2mpir.py +9 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/c2ndps.py +13 -15
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/cdist.py +7 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/chroma.py +12 -13
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/cqt.py +8 -4
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/csm2acr.py +11 -17
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/dct.py +9 -13
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/decimate.py +7 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/delay.py +9 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/delta.py +26 -27
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/dequantize.py +19 -19
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/df2.py +6 -8
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/dfs.py +37 -35
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/dht.py +9 -13
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/drc.py +24 -31
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/dst.py +9 -13
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/dtw.py +29 -20
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/entropy.py +7 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/excite.py +161 -80
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/f0eval.py +7 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/fbank.py +21 -22
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/fftcep.py +11 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/fftr.py +16 -18
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/flux.py +7 -11
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/frame.py +14 -16
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/freqt.py +9 -13
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/freqt2.py +9 -13
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/gammatone.py +6 -2
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/gmm.py +17 -16
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/gnorm.py +9 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/griffin.py +19 -19
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/grpdelay.py +15 -17
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/hilbert.py +9 -13
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/histogram.py +10 -15
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/ialaw.py +10 -15
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/ica.py +5 -2
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/icqt.py +12 -6
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/idct.py +8 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/idht.py +8 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/idst.py +8 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/ifbank.py +17 -20
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/ifftr.py +13 -18
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/ifreqt2.py +9 -13
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/igammatone.py +9 -3
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/ignorm.py +8 -11
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/imdct.py +31 -37
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/imdst.py +4 -10
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/imsvq.py +7 -7
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/interpolate.py +6 -11
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/ipnorm.py +5 -8
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/ipqmf.py +1 -1
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/is2par.py +9 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/istft.py +18 -19
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/iulaw.py +7 -16
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/lar2par.py +9 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/lbg.py +10 -6
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/levdur.py +9 -13
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/linear_intpl.py +7 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/lpc.py +17 -17
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/lpc2lsp.py +15 -17
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/lpc2par.py +11 -14
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/lpccheck.py +9 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/lsp2lpc.py +23 -17
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/lsp2sp.py +13 -14
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/lspcheck.py +14 -15
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/magic_intpl.py +13 -17
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/mc2b.py +7 -11
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/mcep.py +27 -37
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/mcpf.py +20 -17
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/mdct.py +28 -34
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/mdst.py +4 -10
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/medfilt.py +14 -11
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/mfcc.py +16 -18
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/mgc2mgc.py +32 -23
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/mgc2sp.py +18 -16
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/mgcep.py +3 -3
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/mglsadf.py +75 -58
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/mlpg.py +19 -17
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/mlsacheck.py +21 -17
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/mpir2c.py +9 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/msvq.py +3 -1
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/ndps2c.py +13 -15
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/nmf.py +8 -5
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/norm0.py +5 -8
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/oband.py +3 -1
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/par2is.py +9 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/par2lar.py +9 -14
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/par2lpc.py +10 -13
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/pca.py +2 -1
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/phase.py +10 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/pitch.py +4 -2
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/pitch_spec.py +31 -16
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/plp.py +29 -34
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/pnorm.py +17 -17
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/pol_root.py +10 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/poledf.py +16 -11
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/pqmf.py +1 -1
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/quantize.py +23 -23
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/rlevdur.py +9 -13
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/rmse.py +7 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/root_pol.py +12 -13
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/smcep.py +26 -33
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/snr.py +14 -11
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/spec.py +24 -28
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/stft.py +22 -22
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/ulaw.py +8 -15
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/unframe.py +27 -22
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/wht.py +9 -13
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/window.py +16 -20
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/world_synth.py +6 -2
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/yingram.py +16 -15
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/zcross.py +9 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/zerodf.py +21 -17
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/signals.py +46 -16
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/third_party/librosa/constantq.py +2 -2
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/third_party/librosa/filters.py +1 -1
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/third_party/world/common.py +2 -2
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/typing.py +5 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/utils/private.py +15 -12
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/utils/public.py +1 -1
- diffsptk-4.0.0/diffsptk/version.py +1 -0
- {diffsptk-3.5.0 → diffsptk-4.0.0}/pyproject.toml +7 -0
- diffsptk-3.5.0/diffsptk/modules/base.py +0 -59
- diffsptk-3.5.0/diffsptk/version.py +0 -1
- {diffsptk-3.5.0 → diffsptk-4.0.0}/CITATION.cff +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.0}/LICENSE +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/__init__.py +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/__init__.py +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/imglsadf.py +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/ivq.py +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/modules/vq.py +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/third_party/librosa/LICENSE +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/third_party/librosa/__init__.py +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/third_party/librosa/typing.py +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/third_party/librosa/util.py +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/third_party/world/LICENSE +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/third_party/world/__init__.py +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.0}/diffsptk/utils/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: diffsptk
|
|
3
|
-
Version:
|
|
3
|
+
Version: 4.0.0
|
|
4
4
|
Summary: Speech signal processing modules for machine learning
|
|
5
5
|
Project-URL: Homepage, https://sp-tk.sourceforge.net/
|
|
6
6
|
Project-URL: Documentation, https://sp-nitech.github.io/diffsptk/stable/
|
|
@@ -38,6 +38,7 @@ Requires-Dist: mdformat; extra == 'dev'
|
|
|
38
38
|
Requires-Dist: numpydoc; extra == 'dev'
|
|
39
39
|
Requires-Dist: pkginfo; extra == 'dev'
|
|
40
40
|
Requires-Dist: pydata-sphinx-theme; extra == 'dev'
|
|
41
|
+
Requires-Dist: pyright[nodejs]<1.1.409; extra == 'dev'
|
|
41
42
|
Requires-Dist: pytest; extra == 'dev'
|
|
42
43
|
Requires-Dist: pytest-cov; extra == 'dev'
|
|
43
44
|
Requires-Dist: ruff; extra == 'dev'
|
|
@@ -55,7 +56,7 @@ allowing users to integrate classic signal processing algorithms directly into n
|
|
|
55
56
|
[](https://pepy.tech/project/diffsptk)
|
|
56
57
|
[](https://clickpy.clickhouse.com/dashboard/diffsptk)
|
|
57
58
|
[](https://pypi.python.org/pypi/diffsptk)
|
|
58
|
-
[](https://pypi.python.org/pypi/diffsptk)
|
|
59
60
|
[](https://pypi.python.org/pypi/diffsptk)
|
|
60
61
|
[](https://app.codecov.io/gh/sp-nitech/diffsptk)
|
|
61
62
|
[](https://github.com/sp-nitech/diffsptk/blob/master/LICENSE)
|
|
@@ -8,7 +8,7 @@ allowing users to integrate classic signal processing algorithms directly into n
|
|
|
8
8
|
[](https://pepy.tech/project/diffsptk)
|
|
9
9
|
[](https://clickpy.clickhouse.com/dashboard/diffsptk)
|
|
10
10
|
[](https://pypi.python.org/pypi/diffsptk)
|
|
11
|
-
[](https://pypi.python.org/pypi/diffsptk)
|
|
12
12
|
[](https://pypi.python.org/pypi/diffsptk)
|
|
13
13
|
[](https://app.codecov.io/gh/sp-nitech/diffsptk)
|
|
14
14
|
[](https://github.com/sp-nitech/diffsptk/blob/master/LICENSE)
|
|
@@ -333,7 +333,7 @@ def delay(x: Tensor, start: int = 0, keeplen: bool = False, dim: int = -1) -> Te
|
|
|
333
333
|
|
|
334
334
|
def delta(
|
|
335
335
|
x: Tensor,
|
|
336
|
-
seed: ArrayLike[
|
|
336
|
+
seed: ArrayLike[float] | ArrayLike[int] = [[-0.5, 0, 0.5]],
|
|
337
337
|
static_out: bool = True,
|
|
338
338
|
) -> Tensor:
|
|
339
339
|
"""Compute the delta components.
|
|
@@ -635,7 +635,7 @@ def excite(
|
|
|
635
635
|
The frame period in samples, :math:`P`.
|
|
636
636
|
|
|
637
637
|
voiced_region : ['pulse', 'sinusoidal', 'sawtooth', 'inverted-sawtooth', \
|
|
638
|
-
'triangle', 'square']
|
|
638
|
+
'triangle', 'square', 'harmonic-pulse']
|
|
639
639
|
The type of voiced region.
|
|
640
640
|
|
|
641
641
|
unvoiced_region : ['zeros', 'gauss', 'm-sequence', 'uniform']
|
|
@@ -2313,7 +2313,7 @@ def mgc2sp(
|
|
|
2313
2313
|
|
|
2314
2314
|
def mlpg(
|
|
2315
2315
|
u: Tensor,
|
|
2316
|
-
seed: ArrayLike[
|
|
2316
|
+
seed: ArrayLike[float] | ArrayLike[int] = [[-0.5, 0, 0.5], [1, -2, 1]],
|
|
2317
2317
|
) -> Tensor:
|
|
2318
2318
|
"""Perform MLPG given the mean vectors with delta components.
|
|
2319
2319
|
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
|
|
17
17
|
import torch
|
|
18
18
|
|
|
19
|
-
from ..typing import Callable
|
|
19
|
+
from ..typing import Callable
|
|
20
20
|
from ..utils.private import check_size, filter_values
|
|
21
|
-
from .base import BaseFunctionalModule
|
|
21
|
+
from .base import BaseFunctionalModule, Precomputed
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
class Autocorrelation(BaseFunctionalModule):
|
|
@@ -38,6 +38,8 @@ class Autocorrelation(BaseFunctionalModule):
|
|
|
38
38
|
|
|
39
39
|
"""
|
|
40
40
|
|
|
41
|
+
_takes_input_size = True
|
|
42
|
+
|
|
41
43
|
def __init__(
|
|
42
44
|
self, frame_length: int, acr_order: int, out_format: str | int = "naive"
|
|
43
45
|
) -> None:
|
|
@@ -45,7 +47,7 @@ class Autocorrelation(BaseFunctionalModule):
|
|
|
45
47
|
|
|
46
48
|
self.in_dim = frame_length
|
|
47
49
|
|
|
48
|
-
self.
|
|
50
|
+
self._register_precomputed(self._precompute(**filter_values(locals())))
|
|
49
51
|
|
|
50
52
|
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
|
51
53
|
"""Estimate the autocorrelation of the input waveform.
|
|
@@ -71,16 +73,12 @@ class Autocorrelation(BaseFunctionalModule):
|
|
|
71
73
|
|
|
72
74
|
"""
|
|
73
75
|
check_size(x.size(-1), self.in_dim, "length of waveform")
|
|
74
|
-
return self.
|
|
76
|
+
return self._call_forward(x)
|
|
75
77
|
|
|
76
78
|
@staticmethod
|
|
77
79
|
def _func(x: torch.Tensor, *args, **kwargs) -> torch.Tensor:
|
|
78
|
-
|
|
79
|
-
return Autocorrelation.
|
|
80
|
-
|
|
81
|
-
@staticmethod
|
|
82
|
-
def _takes_input_size() -> bool:
|
|
83
|
-
return True
|
|
80
|
+
_p = Autocorrelation._precompute(x.size(-1), *args, **kwargs)
|
|
81
|
+
return Autocorrelation._apply_precomputed(_p, x=x)
|
|
84
82
|
|
|
85
83
|
@staticmethod
|
|
86
84
|
def _check(frame_length: int, acr_order: int) -> None:
|
|
@@ -107,10 +105,12 @@ class Autocorrelation(BaseFunctionalModule):
|
|
|
107
105
|
)
|
|
108
106
|
else:
|
|
109
107
|
raise ValueError(f"out_format {out_format} is not supported.")
|
|
110
|
-
return (acr_order, formatter)
|
|
108
|
+
return Precomputed(values={"acr_order": acr_order, "formatter": formatter})
|
|
111
109
|
|
|
112
110
|
@staticmethod
|
|
113
|
-
def _forward(
|
|
111
|
+
def _forward(
|
|
112
|
+
x: torch.Tensor, *, acr_order: int, formatter: Callable
|
|
113
|
+
) -> torch.Tensor:
|
|
114
114
|
fft_length = x.size(-1) + acr_order
|
|
115
115
|
if fft_length % 2 == 1:
|
|
116
116
|
fft_length += 1
|
|
@@ -17,9 +17,8 @@
|
|
|
17
17
|
import torch
|
|
18
18
|
import torch.nn.functional as F
|
|
19
19
|
|
|
20
|
-
from ..typing import Precomputed
|
|
21
20
|
from ..utils.private import check_size, filter_values, hankel, to, vander
|
|
22
|
-
from .base import BaseFunctionalModule
|
|
21
|
+
from .base import BaseFunctionalModule, Precomputed
|
|
23
22
|
from .root_pol import PolynomialToRoots
|
|
24
23
|
|
|
25
24
|
|
|
@@ -45,6 +44,8 @@ class AutocorrelationToCompositeSinusoidalModelCoefficients(BaseFunctionalModule
|
|
|
45
44
|
|
|
46
45
|
"""
|
|
47
46
|
|
|
47
|
+
_takes_input_size = True
|
|
48
|
+
|
|
48
49
|
def __init__(
|
|
49
50
|
self,
|
|
50
51
|
acr_order: int,
|
|
@@ -55,8 +56,7 @@ class AutocorrelationToCompositeSinusoidalModelCoefficients(BaseFunctionalModule
|
|
|
55
56
|
|
|
56
57
|
self.in_dim = acr_order + 1
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
self.register_buffer("C", tensors[0])
|
|
59
|
+
self._register_precomputed(self._precompute(**filter_values(locals())))
|
|
60
60
|
|
|
61
61
|
def forward(self, r: torch.Tensor) -> torch.Tensor:
|
|
62
62
|
"""Convert autocorrelation to CSM coefficients.
|
|
@@ -83,23 +83,17 @@ class AutocorrelationToCompositeSinusoidalModelCoefficients(BaseFunctionalModule
|
|
|
83
83
|
|
|
84
84
|
"""
|
|
85
85
|
check_size(r.size(-1), self.in_dim, "dimension of autocorrelation")
|
|
86
|
-
return self.
|
|
86
|
+
return self._call_forward(r)
|
|
87
87
|
|
|
88
88
|
@staticmethod
|
|
89
89
|
def _func(r: torch.Tensor, *args, **kwargs) -> torch.Tensor:
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
r.size(-1) - 1, *args, **kwargs, device=r.device, dtype=r.dtype
|
|
93
|
-
)
|
|
90
|
+
_p = AutocorrelationToCompositeSinusoidalModelCoefficients._precompute(
|
|
91
|
+
r.size(-1) - 1, *args, **kwargs, device=r.device, dtype=r.dtype
|
|
94
92
|
)
|
|
95
|
-
return AutocorrelationToCompositeSinusoidalModelCoefficients.
|
|
96
|
-
|
|
93
|
+
return AutocorrelationToCompositeSinusoidalModelCoefficients._apply_precomputed(
|
|
94
|
+
_p, r=r
|
|
97
95
|
)
|
|
98
96
|
|
|
99
|
-
@staticmethod
|
|
100
|
-
def _takes_input_size() -> bool:
|
|
101
|
-
return True
|
|
102
|
-
|
|
103
97
|
@staticmethod
|
|
104
98
|
def _check(acr_order: int) -> None:
|
|
105
99
|
if acr_order <= 0 or acr_order % 2 == 0:
|
|
@@ -132,10 +126,10 @@ class AutocorrelationToCompositeSinusoidalModelCoefficients(BaseFunctionalModule
|
|
|
132
126
|
bias + center : bias + center + length, k
|
|
133
127
|
]
|
|
134
128
|
C[1:] *= 2
|
|
135
|
-
return
|
|
129
|
+
return Precomputed(tensors={"C": to(C, dtype=dtype)})
|
|
136
130
|
|
|
137
131
|
@staticmethod
|
|
138
|
-
def _forward(r: torch.Tensor, C: torch.Tensor) -> torch.Tensor:
|
|
132
|
+
def _forward(r: torch.Tensor, *, C: torch.Tensor) -> torch.Tensor:
|
|
139
133
|
u = torch.matmul(r, C)
|
|
140
134
|
u1, u2 = torch.tensor_split(u, 2, dim=-1)
|
|
141
135
|
|
|
@@ -18,9 +18,8 @@ import math
|
|
|
18
18
|
|
|
19
19
|
import torch
|
|
20
20
|
|
|
21
|
-
from ..typing import Precomputed
|
|
22
21
|
from ..utils.private import filter_values
|
|
23
|
-
from .base import BaseFunctionalModule
|
|
22
|
+
from .base import BaseFunctionalModule, Precomputed
|
|
24
23
|
|
|
25
24
|
|
|
26
25
|
class ALawCompression(BaseFunctionalModule):
|
|
@@ -40,7 +39,7 @@ class ALawCompression(BaseFunctionalModule):
|
|
|
40
39
|
def __init__(self, abs_max: float = 1, a: float = 87.6) -> None:
|
|
41
40
|
super().__init__()
|
|
42
41
|
|
|
43
|
-
self.
|
|
42
|
+
self._register_precomputed(self._precompute(**filter_values(locals())))
|
|
44
43
|
|
|
45
44
|
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
|
46
45
|
"""Compress the input waveform using the A-law algorithm.
|
|
@@ -65,16 +64,12 @@ class ALawCompression(BaseFunctionalModule):
|
|
|
65
64
|
tensor([0.0000, 2.9868, 3.4934, 3.7897, 4.0000])
|
|
66
65
|
|
|
67
66
|
"""
|
|
68
|
-
return self.
|
|
67
|
+
return self._call_forward(x)
|
|
69
68
|
|
|
70
69
|
@staticmethod
|
|
71
70
|
def _func(x: torch.Tensor, *args, **kwargs) -> torch.Tensor:
|
|
72
|
-
|
|
73
|
-
return ALawCompression.
|
|
74
|
-
|
|
75
|
-
@staticmethod
|
|
76
|
-
def _takes_input_size() -> bool:
|
|
77
|
-
return False
|
|
71
|
+
_p = ALawCompression._precompute(*args, **kwargs)
|
|
72
|
+
return ALawCompression._apply_precomputed(_p, x=x)
|
|
78
73
|
|
|
79
74
|
@staticmethod
|
|
80
75
|
def _check(abs_max: float, a: float) -> None:
|
|
@@ -86,14 +81,14 @@ class ALawCompression(BaseFunctionalModule):
|
|
|
86
81
|
@staticmethod
|
|
87
82
|
def _precompute(abs_max: float, a: float) -> Precomputed:
|
|
88
83
|
ALawCompression._check(abs_max, a)
|
|
89
|
-
return (
|
|
90
|
-
abs_max,
|
|
91
|
-
a,
|
|
92
|
-
abs_max / (1 + math.log(a)),
|
|
84
|
+
return Precomputed(
|
|
85
|
+
values={"abs_max": abs_max, "a": a, "c": abs_max / (1 + math.log(a))}
|
|
93
86
|
)
|
|
94
87
|
|
|
95
88
|
@staticmethod
|
|
96
|
-
def _forward(
|
|
89
|
+
def _forward(
|
|
90
|
+
x: torch.Tensor, *, abs_max: float, a: float, c: float
|
|
91
|
+
) -> torch.Tensor:
|
|
97
92
|
x_abs = x.abs() / abs_max
|
|
98
93
|
x1 = a * x_abs
|
|
99
94
|
x2 = 1 + torch.log(x1)
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
# ------------------------------------------------------------------------ #
|
|
16
16
|
|
|
17
17
|
import math
|
|
18
|
+
from typing import cast
|
|
18
19
|
|
|
19
20
|
import numpy as np
|
|
20
21
|
import torch
|
|
@@ -246,14 +247,18 @@ class AperiodicityExtractionByTANDEM(nn.Module):
|
|
|
246
247
|
idx = np.clip(idx, 0, len(coarse_axis) - 2)
|
|
247
248
|
idx = idx.reshape(1, 1, -1)
|
|
248
249
|
self.register_buffer(
|
|
249
|
-
"interp_indices",
|
|
250
|
+
"interp_indices",
|
|
251
|
+
to(idx, device=device, dtype=torch.long),
|
|
252
|
+
persistent=False,
|
|
250
253
|
)
|
|
251
254
|
|
|
252
255
|
x0 = coarse_axis[:-1]
|
|
253
256
|
dx = coarse_axis[1:] - x0
|
|
254
257
|
weights = (freq_axis - np.take(x0, idx)) / np.take(dx, idx)
|
|
255
258
|
self.register_buffer(
|
|
256
|
-
"interp_weights",
|
|
259
|
+
"interp_weights",
|
|
260
|
+
to(weights, device=device, dtype=dtype),
|
|
261
|
+
persistent=False,
|
|
257
262
|
)
|
|
258
263
|
|
|
259
264
|
self.segment_length = [
|
|
@@ -262,21 +267,29 @@ class AperiodicityExtractionByTANDEM(nn.Module):
|
|
|
262
267
|
ramp = torch.arange(-1, self.segment_length[0] + 1, device=device).view(
|
|
263
268
|
1, 1, -1
|
|
264
269
|
)
|
|
265
|
-
self.register_buffer("ramp", ramp)
|
|
266
|
-
self.register_buffer(
|
|
270
|
+
self.register_buffer("ramp", ramp, persistent=False)
|
|
271
|
+
self.register_buffer(
|
|
272
|
+
"eye", torch.eye(6, device=device, dtype=dtype) * eps, persistent=False
|
|
273
|
+
)
|
|
267
274
|
|
|
268
275
|
hHP = self._qmf_high()
|
|
269
276
|
hLP = self._qmf_low()
|
|
270
|
-
self.register_buffer(
|
|
271
|
-
|
|
277
|
+
self.register_buffer(
|
|
278
|
+
"hHP", to(hHP, device=device, dtype=dtype).view(1, 1, -1), persistent=False
|
|
279
|
+
)
|
|
280
|
+
self.register_buffer(
|
|
281
|
+
"hLP", to(hLP, device=device, dtype=dtype).view(1, 1, -1), persistent=False
|
|
282
|
+
)
|
|
272
283
|
self.hHP_pad = nn.ReflectionPad1d(self.hHP.size(-1) // 2)
|
|
273
284
|
self.hLP_pad = nn.ReflectionPad1d(self.hLP.size(-1) // 2)
|
|
274
285
|
|
|
275
286
|
window = np.zeros((self.n_band, self.segment_length[0]))
|
|
276
287
|
for i, s in enumerate(self.segment_length):
|
|
277
288
|
window[i, :s] = np.hanning(s + 2)[1:-1]
|
|
278
|
-
self.register_buffer(
|
|
279
|
-
|
|
289
|
+
self.register_buffer(
|
|
290
|
+
"window", to(window, device=device, dtype=dtype), persistent=False
|
|
291
|
+
)
|
|
292
|
+
self.register_buffer("window_sqrt", self.window.sqrt(), persistent=False)
|
|
280
293
|
|
|
281
294
|
def forward(self, x: torch.Tensor, f0: torch.Tensor) -> torch.Tensor:
|
|
282
295
|
f0 = torch.where(f0 <= 32, self.default_f0, f0).detach()
|
|
@@ -360,8 +373,8 @@ class AperiodicityExtractionByTANDEM(nn.Module):
|
|
|
360
373
|
ap = torch.exp(y)
|
|
361
374
|
return ap
|
|
362
375
|
|
|
363
|
-
def _qmf_high(self
|
|
364
|
-
hHP = np.zeros(41, dtype=
|
|
376
|
+
def _qmf_high(self) -> np.ndarray:
|
|
377
|
+
hHP = np.zeros(41, dtype=np.float64)
|
|
365
378
|
hHP[0] = +0.00041447996898231424
|
|
366
379
|
hHP[1] = +0.00078125051417292477
|
|
367
380
|
hHP[2] = -0.0010917236836275842
|
|
@@ -386,8 +399,8 @@ class AperiodicityExtractionByTANDEM(nn.Module):
|
|
|
386
399
|
hHP[21:] = hHP[19::-1]
|
|
387
400
|
return hHP
|
|
388
401
|
|
|
389
|
-
def _qmf_low(self
|
|
390
|
-
hLP = np.zeros(37, dtype=
|
|
402
|
+
def _qmf_low(self) -> np.ndarray:
|
|
403
|
+
hLP = np.zeros(37, dtype=np.float64)
|
|
391
404
|
hLP[0] = -0.00065488170077483048
|
|
392
405
|
hLP[1] = +0.00007561994958159384
|
|
393
406
|
hLP[2] = +0.0020408456937895227
|
|
@@ -501,7 +514,7 @@ class AperiodicityExtractionByD4C(nn.Module):
|
|
|
501
514
|
left = center - half_window_length
|
|
502
515
|
right = center + half_window_length + 1
|
|
503
516
|
windows.append(F.pad(window, (left, padded_window_length - right)))
|
|
504
|
-
self.register_buffer("windows", torch.stack(windows))
|
|
517
|
+
self.register_buffer("windows", torch.stack(windows), persistent=False)
|
|
505
518
|
self.window_length = window_length
|
|
506
519
|
|
|
507
520
|
if fft_length is not None:
|
|
@@ -512,20 +525,26 @@ class AperiodicityExtractionByD4C(nn.Module):
|
|
|
512
525
|
idx = np.clip(idx, 0, len(coarse_axis) - 2)
|
|
513
526
|
idx = idx.reshape(1, 1, -1)
|
|
514
527
|
self.register_buffer(
|
|
515
|
-
"interp_indices",
|
|
528
|
+
"interp_indices",
|
|
529
|
+
to(idx, device=device, dtype=torch.long),
|
|
530
|
+
persistent=False,
|
|
516
531
|
)
|
|
517
532
|
|
|
518
533
|
x0 = coarse_axis[:-1]
|
|
519
534
|
dx = coarse_axis[1:] - x0
|
|
520
535
|
weights = (freq_axis - np.take(x0, idx)) / np.take(dx, idx)
|
|
521
536
|
self.register_buffer(
|
|
522
|
-
"interp_weights",
|
|
537
|
+
"interp_weights",
|
|
538
|
+
to(weights, device=device, dtype=dtype),
|
|
539
|
+
persistent=False,
|
|
523
540
|
)
|
|
524
541
|
|
|
525
542
|
self.spec_love = Spectrum(self.fft_length_love)
|
|
526
543
|
self.spec_d4c = Spectrum(self.fft_length_d4c)
|
|
527
544
|
|
|
528
|
-
self.register_buffer(
|
|
545
|
+
self.register_buffer(
|
|
546
|
+
"ramp", torch.arange(self.fft_length_d4c, device=device), persistent=False
|
|
547
|
+
)
|
|
529
548
|
|
|
530
549
|
def forward(self, x: torch.Tensor, f0: torch.Tensor) -> torch.Tensor:
|
|
531
550
|
f0 = (
|
|
@@ -646,7 +665,6 @@ class AperiodicityExtractionByD4C(nn.Module):
|
|
|
646
665
|
aperiodicity = 10 ** (y / 20)
|
|
647
666
|
|
|
648
667
|
if 0 < self.threshold:
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
)
|
|
668
|
+
condition = cast(torch.Tensor, aperiodicity0 <= self.threshold)
|
|
669
|
+
aperiodicity = torch.where(condition, 1 - eps, aperiodicity)
|
|
652
670
|
return aperiodicity
|
|
@@ -17,9 +17,8 @@
|
|
|
17
17
|
import torch
|
|
18
18
|
import torch.nn.functional as F
|
|
19
19
|
|
|
20
|
-
from ..typing import Precomputed
|
|
21
20
|
from ..utils.private import check_size, filter_values, to
|
|
22
|
-
from .base import BaseFunctionalModule
|
|
21
|
+
from .base import BaseFunctionalModule, Precomputed
|
|
23
22
|
|
|
24
23
|
|
|
25
24
|
class MLSADigitalFilterCoefficientsToMelCepstrum(BaseFunctionalModule):
|
|
@@ -48,6 +47,8 @@ class MLSADigitalFilterCoefficientsToMelCepstrum(BaseFunctionalModule):
|
|
|
48
47
|
|
|
49
48
|
"""
|
|
50
49
|
|
|
50
|
+
_takes_input_size = True
|
|
51
|
+
|
|
51
52
|
def __init__(
|
|
52
53
|
self,
|
|
53
54
|
cep_order: int,
|
|
@@ -59,8 +60,7 @@ class MLSADigitalFilterCoefficientsToMelCepstrum(BaseFunctionalModule):
|
|
|
59
60
|
|
|
60
61
|
self.in_dim = cep_order + 1
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
self.register_buffer("A", tensors[0])
|
|
63
|
+
self._register_precomputed(self._precompute(**filter_values(locals())))
|
|
64
64
|
|
|
65
65
|
def forward(self, b: torch.Tensor) -> torch.Tensor:
|
|
66
66
|
"""Convert MLSA filter coefficients to mel-cepstrum.
|
|
@@ -87,17 +87,13 @@ class MLSADigitalFilterCoefficientsToMelCepstrum(BaseFunctionalModule):
|
|
|
87
87
|
|
|
88
88
|
"""
|
|
89
89
|
check_size(b.size(-1), self.in_dim, "dimension of cepstrum")
|
|
90
|
-
return self.
|
|
90
|
+
return self._call_forward(b)
|
|
91
91
|
|
|
92
92
|
@staticmethod
|
|
93
93
|
def _func(b: torch.Tensor, alpha: float) -> torch.Tensor:
|
|
94
94
|
MLSADigitalFilterCoefficientsToMelCepstrum._check(b.size(-1) - 1, alpha)
|
|
95
95
|
return b + F.pad(alpha * b[..., 1:], (0, 1))
|
|
96
96
|
|
|
97
|
-
@staticmethod
|
|
98
|
-
def _takes_input_size() -> bool:
|
|
99
|
-
return True
|
|
100
|
-
|
|
101
97
|
@staticmethod
|
|
102
98
|
def _check(cep_order: int, alpha: float) -> None:
|
|
103
99
|
if cep_order < 0:
|
|
@@ -115,8 +111,8 @@ class MLSADigitalFilterCoefficientsToMelCepstrum(BaseFunctionalModule):
|
|
|
115
111
|
MLSADigitalFilterCoefficientsToMelCepstrum._check(cep_order, alpha)
|
|
116
112
|
A = torch.eye(cep_order + 1, device=device, dtype=torch.double)
|
|
117
113
|
A[:, 1:].fill_diagonal_(alpha)
|
|
118
|
-
return
|
|
114
|
+
return Precomputed(tensors={"A": to(A.T, dtype=dtype)})
|
|
119
115
|
|
|
120
116
|
@staticmethod
|
|
121
|
-
def _forward(b: torch.Tensor, A: torch.Tensor) -> torch.Tensor:
|
|
117
|
+
def _forward(b: torch.Tensor, *, A: torch.Tensor) -> torch.Tensor:
|
|
122
118
|
return torch.matmul(b, A)
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# ------------------------------------------------------------------------ #
|
|
2
|
+
# Copyright 2022 SPTK Working Group #
|
|
3
|
+
# #
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); #
|
|
5
|
+
# you may not use this file except in compliance with the License. #
|
|
6
|
+
# You may obtain a copy of the License at #
|
|
7
|
+
# #
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0 #
|
|
9
|
+
# #
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software #
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, #
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
|
13
|
+
# See the License for the specific language governing permissions and #
|
|
14
|
+
# limitations under the License. #
|
|
15
|
+
# ------------------------------------------------------------------------ #
|
|
16
|
+
|
|
17
|
+
from abc import ABC, abstractmethod
|
|
18
|
+
from typing import Any, ClassVar, NamedTuple
|
|
19
|
+
|
|
20
|
+
import torch
|
|
21
|
+
from torch import nn
|
|
22
|
+
|
|
23
|
+
from ..typing import Callable
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Precomputed(NamedTuple):
|
|
27
|
+
"""Precomputed components derived from the given parameters."""
|
|
28
|
+
|
|
29
|
+
values: dict[str, Any] = {}
|
|
30
|
+
layers: dict[str, Callable] = {}
|
|
31
|
+
tensors: dict[str, torch.Tensor] = {}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class BaseNonFunctionalModule(ABC, nn.Module):
|
|
35
|
+
"""Marker class for modules that provide no functional interface."""
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class BaseFunctionalModule(ABC, nn.Module):
|
|
39
|
+
"""Base class for modules that provide a functional interface."""
|
|
40
|
+
|
|
41
|
+
# Whether the first parameter of _precompute is the input size.
|
|
42
|
+
_takes_input_size: ClassVar[bool] = False
|
|
43
|
+
|
|
44
|
+
# Names of the values/layers passed to _forward by keyword.
|
|
45
|
+
_value_names: tuple[str, ...] = ()
|
|
46
|
+
_layer_names: tuple[str, ...] = ()
|
|
47
|
+
|
|
48
|
+
def _register_precomputed(
|
|
49
|
+
self,
|
|
50
|
+
precomputed: Precomputed,
|
|
51
|
+
learnable: bool = False,
|
|
52
|
+
) -> None:
|
|
53
|
+
"""Store the precomputed values, layers, and tensors in this module."""
|
|
54
|
+
|
|
55
|
+
self._value_names = tuple(precomputed.values)
|
|
56
|
+
for name, value in precomputed.values.items():
|
|
57
|
+
setattr(self, name, value)
|
|
58
|
+
|
|
59
|
+
self._layer_names = tuple(precomputed.layers)
|
|
60
|
+
for name, layer in precomputed.layers.items():
|
|
61
|
+
setattr(self, name, layer)
|
|
62
|
+
|
|
63
|
+
for name, tensor in precomputed.tensors.items():
|
|
64
|
+
if learnable:
|
|
65
|
+
setattr(self, name, nn.Parameter(tensor))
|
|
66
|
+
else:
|
|
67
|
+
self.register_buffer(name, tensor, persistent=False)
|
|
68
|
+
|
|
69
|
+
def _call_forward(self, *args) -> Any:
|
|
70
|
+
"""Call _forward with the stored state resolved by name."""
|
|
71
|
+
named = {name: getattr(self, name) for name in self._value_names}
|
|
72
|
+
named.update({name: getattr(self, name) for name in self._layer_names})
|
|
73
|
+
named.update(self._buffers)
|
|
74
|
+
named.update(self._parameters)
|
|
75
|
+
return self._forward(*args, **named)
|
|
76
|
+
|
|
77
|
+
@classmethod
|
|
78
|
+
def _apply_precomputed(cls, precomputed: Precomputed, **inputs: Any) -> Any:
|
|
79
|
+
"""Call _forward with a name-binding Precomputed."""
|
|
80
|
+
state = {**precomputed.values, **precomputed.layers, **precomputed.tensors}
|
|
81
|
+
return cls._forward(**inputs, **state)
|
|
82
|
+
|
|
83
|
+
@staticmethod
|
|
84
|
+
@abstractmethod
|
|
85
|
+
def _func(*args, **kwargs) -> Any:
|
|
86
|
+
"""Perform the operation in a functional manner."""
|
|
87
|
+
|
|
88
|
+
@staticmethod
|
|
89
|
+
@abstractmethod
|
|
90
|
+
def _check(*args, **kwargs) -> None:
|
|
91
|
+
"""Validate the given parameters."""
|
|
92
|
+
|
|
93
|
+
@staticmethod
|
|
94
|
+
@abstractmethod
|
|
95
|
+
def _precompute(*args, **kwargs) -> Precomputed:
|
|
96
|
+
"""Precompute the values, layers, and tensors used in _forward."""
|
|
97
|
+
|
|
98
|
+
@staticmethod
|
|
99
|
+
@abstractmethod
|
|
100
|
+
def _forward(*args, **kwargs) -> Any:
|
|
101
|
+
"""Perform the core operation."""
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class BaseLearnerModule(ABC, nn.Module):
|
|
105
|
+
"""Base class for modules that learn their parameters from data."""
|
|
106
|
+
|
|
107
|
+
@abstractmethod
|
|
108
|
+
def transform(self, *args, **kwargs) -> Any:
|
|
109
|
+
"""Transform the input using the learned parameters."""
|
|
@@ -16,9 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
import torch
|
|
18
18
|
|
|
19
|
-
from ..typing import Precomputed
|
|
20
19
|
from ..utils.private import check_size, filter_values
|
|
21
|
-
from .base import BaseFunctionalModule
|
|
20
|
+
from .base import BaseFunctionalModule, Precomputed
|
|
22
21
|
|
|
23
22
|
|
|
24
23
|
class CepstrumToAutocorrelation(BaseFunctionalModule):
|
|
@@ -39,12 +38,14 @@ class CepstrumToAutocorrelation(BaseFunctionalModule):
|
|
|
39
38
|
|
|
40
39
|
"""
|
|
41
40
|
|
|
41
|
+
_takes_input_size = True
|
|
42
|
+
|
|
42
43
|
def __init__(self, cep_order: int, acr_order: int, n_fft: int = 512) -> None:
|
|
43
44
|
super().__init__()
|
|
44
45
|
|
|
45
46
|
self.in_dim = cep_order + 1
|
|
46
47
|
|
|
47
|
-
self.
|
|
48
|
+
self._register_precomputed(self._precompute(**filter_values(locals())))
|
|
48
49
|
|
|
49
50
|
def forward(self, c: torch.Tensor) -> torch.Tensor:
|
|
50
51
|
"""Convert cepstrum to autocorrelation.
|
|
@@ -71,16 +72,12 @@ class CepstrumToAutocorrelation(BaseFunctionalModule):
|
|
|
71
72
|
|
|
72
73
|
"""
|
|
73
74
|
check_size(c.size(-1), self.in_dim, "dimension of cepstrum")
|
|
74
|
-
return self.
|
|
75
|
+
return self._call_forward(c)
|
|
75
76
|
|
|
76
77
|
@staticmethod
|
|
77
78
|
def _func(c: torch.Tensor, *args, **kwargs) -> torch.Tensor:
|
|
78
|
-
|
|
79
|
-
return CepstrumToAutocorrelation.
|
|
80
|
-
|
|
81
|
-
@staticmethod
|
|
82
|
-
def _takes_input_size() -> bool:
|
|
83
|
-
return True
|
|
79
|
+
_p = CepstrumToAutocorrelation._precompute(c.size(-1) - 1, *args, **kwargs)
|
|
80
|
+
return CepstrumToAutocorrelation._apply_precomputed(_p, c=c)
|
|
84
81
|
|
|
85
82
|
@staticmethod
|
|
86
83
|
def _check(cep_order: int, acr_order: int, n_fft: int) -> None:
|
|
@@ -94,10 +91,10 @@ class CepstrumToAutocorrelation(BaseFunctionalModule):
|
|
|
94
91
|
@staticmethod
|
|
95
92
|
def _precompute(cep_order: int, acr_order: int, n_fft: int) -> Precomputed:
|
|
96
93
|
CepstrumToAutocorrelation._check(cep_order, acr_order, n_fft)
|
|
97
|
-
return (acr_order, n_fft)
|
|
94
|
+
return Precomputed(values={"acr_order": acr_order, "n_fft": n_fft})
|
|
98
95
|
|
|
99
96
|
@staticmethod
|
|
100
|
-
def _forward(c: torch.Tensor, acr_order: int, n_fft: int) -> torch.Tensor:
|
|
97
|
+
def _forward(c: torch.Tensor, *, acr_order: int, n_fft: int) -> torch.Tensor:
|
|
101
98
|
x = torch.fft.rfft(c, n=n_fft).real
|
|
102
99
|
x = torch.exp(2 * x)
|
|
103
100
|
r = torch.fft.hfft(x, norm="forward")[..., : acr_order + 1]
|