diffsptk 3.5.0__tar.gz → 4.0.1__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.1}/.gitignore +1 -0
- {diffsptk-3.5.0 → diffsptk-4.0.1}/PKG-INFO +4 -3
- {diffsptk-3.5.0 → diffsptk-4.0.1}/README.md +1 -1
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/functional.py +3 -3
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/acorr.py +12 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/acr2csm.py +11 -17
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/alaw.py +10 -15
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/ap.py +62 -43
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/b2mc.py +7 -11
- diffsptk-4.0.1/diffsptk/modules/base.py +109 -0
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/c2acr.py +9 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/c2mpir.py +9 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/c2ndps.py +13 -15
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/cdist.py +7 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/chroma.py +12 -13
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/cqt.py +8 -4
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/csm2acr.py +11 -17
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/dct.py +11 -13
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/decimate.py +7 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/delay.py +9 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/delta.py +26 -27
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/dequantize.py +19 -19
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/df2.py +6 -8
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/dfs.py +40 -37
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/dht.py +9 -13
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/drc.py +24 -31
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/dst.py +9 -13
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/dtw.py +32 -23
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/entropy.py +7 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/excite.py +162 -80
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/f0eval.py +16 -17
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/fbank.py +21 -22
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/fftcep.py +11 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/fftr.py +16 -18
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/flux.py +7 -11
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/frame.py +14 -16
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/freqt.py +9 -13
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/freqt2.py +9 -13
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/gammatone.py +6 -2
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/gmm.py +17 -16
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/gnorm.py +9 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/griffin.py +19 -19
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/grpdelay.py +15 -17
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/hilbert.py +9 -13
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/histogram.py +13 -18
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/ialaw.py +10 -15
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/ica.py +18 -14
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/icqt.py +12 -6
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/idct.py +8 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/idht.py +8 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/idst.py +8 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/ifbank.py +17 -20
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/ifftr.py +13 -18
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/ifreqt2.py +9 -13
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/igammatone.py +9 -3
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/ignorm.py +8 -11
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/imdct.py +31 -37
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/imdst.py +4 -10
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/imsvq.py +7 -7
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/interpolate.py +6 -11
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/ipnorm.py +5 -8
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/ipqmf.py +1 -1
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/is2par.py +9 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/istft.py +18 -19
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/iulaw.py +7 -16
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/lar2par.py +9 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/lbg.py +10 -6
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/levdur.py +9 -13
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/linear_intpl.py +7 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/lpc.py +17 -17
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/lpc2lsp.py +15 -17
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/lpc2par.py +11 -14
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/lpccheck.py +9 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/lsp2lpc.py +23 -17
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/lsp2sp.py +13 -14
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/lspcheck.py +15 -16
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/magic_intpl.py +13 -17
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/mc2b.py +7 -11
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/mcep.py +27 -37
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/mcpf.py +20 -17
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/mdct.py +28 -34
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/mdst.py +4 -10
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/medfilt.py +14 -11
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/mfcc.py +18 -20
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/mgc2mgc.py +32 -23
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/mgc2sp.py +18 -16
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/mgcep.py +3 -3
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/mglsadf.py +75 -58
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/mlpg.py +19 -17
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/mlsacheck.py +21 -17
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/mpir2c.py +9 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/msvq.py +3 -1
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/ndps2c.py +13 -15
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/nmf.py +8 -5
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/norm0.py +5 -8
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/oband.py +3 -1
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/par2is.py +9 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/par2lar.py +9 -14
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/par2lpc.py +10 -13
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/pca.py +2 -1
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/phase.py +10 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/pitch.py +5 -3
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/pitch_spec.py +31 -16
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/plp.py +31 -36
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/pnorm.py +17 -17
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/pol_root.py +10 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/poledf.py +16 -11
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/pqmf.py +1 -1
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/quantize.py +23 -23
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/rlevdur.py +9 -13
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/rmse.py +7 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/root_pol.py +12 -13
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/smcep.py +26 -33
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/snr.py +14 -11
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/spec.py +24 -28
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/stft.py +22 -22
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/ulaw.py +8 -15
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/unframe.py +27 -22
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/wht.py +9 -13
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/window.py +18 -20
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/world_synth.py +6 -2
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/yingram.py +16 -15
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/zcross.py +9 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/zerodf.py +21 -17
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/signals.py +46 -16
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/third_party/librosa/constantq.py +2 -2
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/third_party/librosa/filters.py +1 -1
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/third_party/world/common.py +2 -2
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/typing.py +5 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/utils/private.py +15 -12
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/utils/public.py +1 -1
- diffsptk-4.0.1/diffsptk/version.py +1 -0
- {diffsptk-3.5.0 → diffsptk-4.0.1}/pyproject.toml +9 -2
- 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.1}/CITATION.cff +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.1}/LICENSE +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/__init__.py +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/__init__.py +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/imglsadf.py +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/ivq.py +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/modules/vq.py +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/third_party/librosa/LICENSE +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/third_party/librosa/__init__.py +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/third_party/librosa/typing.py +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/third_party/librosa/util.py +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/third_party/world/LICENSE +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/third_party/world/__init__.py +0 -0
- {diffsptk-3.5.0 → diffsptk-4.0.1}/diffsptk/utils/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: diffsptk
|
|
3
|
-
Version:
|
|
3
|
+
Version: 4.0.1
|
|
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]; 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], [1, -2, 1]],
|
|
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
|
|
@@ -45,7 +46,8 @@ class Aperiodicity(BaseNonFunctionalModule):
|
|
|
45
46
|
(uninterpolated aperiodicity) is returned as the output.
|
|
46
47
|
|
|
47
48
|
algorithm : ['tandem', 'd4c']
|
|
48
|
-
The algorithm to estimate aperiodicity.
|
|
49
|
+
The algorithm to estimate aperiodicity. Note that 'tandem' is a simplified
|
|
50
|
+
version of the SPTK's TANDEM-STRAIGHT.
|
|
49
51
|
|
|
50
52
|
out_format : ['a', 'p', 'a/p', 'p/a']
|
|
51
53
|
The output format.
|
|
@@ -53,7 +55,7 @@ class Aperiodicity(BaseNonFunctionalModule):
|
|
|
53
55
|
lower_bound : float >= 0
|
|
54
56
|
The lower bound of aperiodicity.
|
|
55
57
|
|
|
56
|
-
upper_bound : float <= 1
|
|
58
|
+
upper_bound : float <= 1 or None
|
|
57
59
|
The upper bound of aperiodicity.
|
|
58
60
|
|
|
59
61
|
device : torch.device or None
|
|
@@ -81,7 +83,7 @@ class Aperiodicity(BaseNonFunctionalModule):
|
|
|
81
83
|
algorithm: str = "tandem",
|
|
82
84
|
out_format: str | int = "a",
|
|
83
85
|
lower_bound: float = 0.001,
|
|
84
|
-
upper_bound: float =
|
|
86
|
+
upper_bound: float | None = None,
|
|
85
87
|
**kwargs,
|
|
86
88
|
) -> None:
|
|
87
89
|
super().__init__()
|
|
@@ -92,6 +94,8 @@ class Aperiodicity(BaseNonFunctionalModule):
|
|
|
92
94
|
raise ValueError("sample_rate must be at least 8000 Hz.")
|
|
93
95
|
if fft_length is not None and fft_length < 16:
|
|
94
96
|
raise ValueError("fft_length must be at least 16.")
|
|
97
|
+
if upper_bound is None:
|
|
98
|
+
upper_bound = math.sqrt(1 - lower_bound**2)
|
|
95
99
|
if not 0 <= lower_bound < upper_bound <= 1:
|
|
96
100
|
raise ValueError("Invalid lower_bound and upper_bound.")
|
|
97
101
|
|
|
@@ -112,11 +116,11 @@ class Aperiodicity(BaseNonFunctionalModule):
|
|
|
112
116
|
if out_format in (0, "a"):
|
|
113
117
|
self.convert = lambda x: x
|
|
114
118
|
elif out_format in (1, "p"):
|
|
115
|
-
self.convert = lambda x: 1 - x
|
|
119
|
+
self.convert = lambda x: torch.sqrt(1 - x * x)
|
|
116
120
|
elif out_format in (2, "a/p"):
|
|
117
|
-
self.convert = lambda x: x / (1 - x)
|
|
121
|
+
self.convert = lambda x: x / torch.sqrt(1 - x * x)
|
|
118
122
|
elif out_format in (3, "p/a"):
|
|
119
|
-
self.convert = lambda x: (1 - x) / x
|
|
123
|
+
self.convert = lambda x: torch.sqrt(1 - x * x) / x
|
|
120
124
|
else:
|
|
121
125
|
raise ValueError(f"out_format {out_format} is not supported.")
|
|
122
126
|
|
|
@@ -161,7 +165,9 @@ class Aperiodicity(BaseNonFunctionalModule):
|
|
|
161
165
|
if f0.dim() != 2:
|
|
162
166
|
raise ValueError("F0 must be 1D or 2D tensor.")
|
|
163
167
|
|
|
168
|
+
unvoiced = (f0 == 0).unsqueeze(-1)
|
|
164
169
|
ap = self.extractor(x, f0)
|
|
170
|
+
ap = ap.masked_fill(unvoiced, 1)
|
|
165
171
|
ap = torch.clip(ap, min=self.lower_bound, max=self.upper_bound)
|
|
166
172
|
ap = self.convert(ap)
|
|
167
173
|
|
|
@@ -230,15 +236,18 @@ class AperiodicityExtractionByTANDEM(nn.Module):
|
|
|
230
236
|
self.sample_rate = sample_rate
|
|
231
237
|
self.n_band = int(np.log2(sample_rate / 600))
|
|
232
238
|
|
|
233
|
-
self.
|
|
239
|
+
self.floor_f0 = 32
|
|
234
240
|
self.n_trial = 10
|
|
235
241
|
|
|
236
242
|
self.cutoff_list = [sample_rate / 2**i for i in range(2, self.n_band + 1)]
|
|
237
243
|
self.cutoff_list.append(self.cutoff_list[-1])
|
|
238
244
|
|
|
239
245
|
if fft_length is not None:
|
|
240
|
-
coarse_axis = [
|
|
246
|
+
coarse_axis = [
|
|
247
|
+
sample_rate / 2**i * math.sqrt(0.5) for i in range(self.n_band, 0, -1)
|
|
248
|
+
]
|
|
241
249
|
coarse_axis.insert(0, 0)
|
|
250
|
+
coarse_axis.append(sample_rate / 2)
|
|
242
251
|
coarse_axis = np.asarray(coarse_axis)
|
|
243
252
|
freq_axis = np.arange(fft_length // 2 + 1) * (sample_rate / fft_length)
|
|
244
253
|
|
|
@@ -246,14 +255,18 @@ class AperiodicityExtractionByTANDEM(nn.Module):
|
|
|
246
255
|
idx = np.clip(idx, 0, len(coarse_axis) - 2)
|
|
247
256
|
idx = idx.reshape(1, 1, -1)
|
|
248
257
|
self.register_buffer(
|
|
249
|
-
"interp_indices",
|
|
258
|
+
"interp_indices",
|
|
259
|
+
to(idx, device=device, dtype=torch.long),
|
|
260
|
+
persistent=False,
|
|
250
261
|
)
|
|
251
262
|
|
|
252
263
|
x0 = coarse_axis[:-1]
|
|
253
264
|
dx = coarse_axis[1:] - x0
|
|
254
265
|
weights = (freq_axis - np.take(x0, idx)) / np.take(dx, idx)
|
|
255
266
|
self.register_buffer(
|
|
256
|
-
"interp_weights",
|
|
267
|
+
"interp_weights",
|
|
268
|
+
to(weights, device=device, dtype=dtype),
|
|
269
|
+
persistent=False,
|
|
257
270
|
)
|
|
258
271
|
|
|
259
272
|
self.segment_length = [
|
|
@@ -262,24 +275,32 @@ class AperiodicityExtractionByTANDEM(nn.Module):
|
|
|
262
275
|
ramp = torch.arange(-1, self.segment_length[0] + 1, device=device).view(
|
|
263
276
|
1, 1, -1
|
|
264
277
|
)
|
|
265
|
-
self.register_buffer("ramp", ramp)
|
|
266
|
-
self.register_buffer(
|
|
278
|
+
self.register_buffer("ramp", ramp, persistent=False)
|
|
279
|
+
self.register_buffer(
|
|
280
|
+
"eye", torch.eye(6, device=device, dtype=dtype) * eps, persistent=False
|
|
281
|
+
)
|
|
267
282
|
|
|
268
283
|
hHP = self._qmf_high()
|
|
269
284
|
hLP = self._qmf_low()
|
|
270
|
-
self.register_buffer(
|
|
271
|
-
|
|
285
|
+
self.register_buffer(
|
|
286
|
+
"hHP", to(hHP, device=device, dtype=dtype).view(1, 1, -1), persistent=False
|
|
287
|
+
)
|
|
288
|
+
self.register_buffer(
|
|
289
|
+
"hLP", to(hLP, device=device, dtype=dtype).view(1, 1, -1), persistent=False
|
|
290
|
+
)
|
|
272
291
|
self.hHP_pad = nn.ReflectionPad1d(self.hHP.size(-1) // 2)
|
|
273
292
|
self.hLP_pad = nn.ReflectionPad1d(self.hLP.size(-1) // 2)
|
|
274
293
|
|
|
275
294
|
window = np.zeros((self.n_band, self.segment_length[0]))
|
|
276
295
|
for i, s in enumerate(self.segment_length):
|
|
277
296
|
window[i, :s] = np.hanning(s + 2)[1:-1]
|
|
278
|
-
self.register_buffer(
|
|
279
|
-
|
|
297
|
+
self.register_buffer(
|
|
298
|
+
"window", to(window, device=device, dtype=dtype), persistent=False
|
|
299
|
+
)
|
|
300
|
+
self.register_buffer("window_sqrt", self.window.sqrt(), persistent=False)
|
|
280
301
|
|
|
281
302
|
def forward(self, x: torch.Tensor, f0: torch.Tensor) -> torch.Tensor:
|
|
282
|
-
f0 = torch.
|
|
303
|
+
f0 = torch.clip(f0, min=self.floor_f0).detach()
|
|
283
304
|
|
|
284
305
|
B, N = f0.shape
|
|
285
306
|
time_axis = torch.arange(N, dtype=f0.dtype, device=f0.device) * (
|
|
@@ -330,9 +351,9 @@ class AperiodicityExtractionByTANDEM(nn.Module):
|
|
|
330
351
|
m = 10**n
|
|
331
352
|
u, info = torch.linalg.cholesky_ex(R + self.eye * m)
|
|
332
353
|
if 0 == info.sum().item():
|
|
333
|
-
if n == self.n_trial - 1:
|
|
334
|
-
raise RuntimeError("Failed to compute Cholesky decomposition.")
|
|
335
354
|
break
|
|
355
|
+
if n == self.n_trial - 1:
|
|
356
|
+
raise RuntimeError("Failed to compute Cholesky decomposition.")
|
|
336
357
|
|
|
337
358
|
b = torch.matmul(Hw, X) # (B, N, 6, 1)
|
|
338
359
|
a = torch.cholesky_solve(b, u)
|
|
@@ -351,7 +372,7 @@ class AperiodicityExtractionByTANDEM(nn.Module):
|
|
|
351
372
|
|
|
352
373
|
# Interpolate band aperiodicity.
|
|
353
374
|
if hasattr(self, "interp_indices"):
|
|
354
|
-
y = torch.log(ap)
|
|
375
|
+
y = torch.log(F.pad(ap, (0, 1), mode="replicate"))
|
|
355
376
|
y0 = y[..., :-1]
|
|
356
377
|
dy = y[..., 1:] - y0
|
|
357
378
|
index = self.interp_indices.expand(B, N, -1)
|
|
@@ -360,8 +381,8 @@ class AperiodicityExtractionByTANDEM(nn.Module):
|
|
|
360
381
|
ap = torch.exp(y)
|
|
361
382
|
return ap
|
|
362
383
|
|
|
363
|
-
def _qmf_high(self
|
|
364
|
-
hHP = np.zeros(41, dtype=
|
|
384
|
+
def _qmf_high(self) -> np.ndarray:
|
|
385
|
+
hHP = np.zeros(41, dtype=np.float64)
|
|
365
386
|
hHP[0] = +0.00041447996898231424
|
|
366
387
|
hHP[1] = +0.00078125051417292477
|
|
367
388
|
hHP[2] = -0.0010917236836275842
|
|
@@ -386,8 +407,8 @@ class AperiodicityExtractionByTANDEM(nn.Module):
|
|
|
386
407
|
hHP[21:] = hHP[19::-1]
|
|
387
408
|
return hHP
|
|
388
409
|
|
|
389
|
-
def _qmf_low(self
|
|
390
|
-
hLP = np.zeros(37, dtype=
|
|
410
|
+
def _qmf_low(self) -> np.ndarray:
|
|
411
|
+
hLP = np.zeros(37, dtype=np.float64)
|
|
391
412
|
hLP[0] = -0.00065488170077483048
|
|
392
413
|
hLP[1] = +0.00007561994958159384
|
|
393
414
|
hLP[2] = +0.0020408456937895227
|
|
@@ -456,7 +477,6 @@ class AperiodicityExtractionByD4C(nn.Module):
|
|
|
456
477
|
fft_length: int | None = None,
|
|
457
478
|
*,
|
|
458
479
|
threshold: float = 0,
|
|
459
|
-
default_f0: float = 150,
|
|
460
480
|
device: torch.device | None = None,
|
|
461
481
|
dtype: torch.dtype | None = None,
|
|
462
482
|
) -> None:
|
|
@@ -466,24 +486,21 @@ class AperiodicityExtractionByD4C(nn.Module):
|
|
|
466
486
|
raise ValueError("sample_rate must be at least 12000 Hz.")
|
|
467
487
|
if threshold < 0:
|
|
468
488
|
raise ValueError("threshold must be non-negative.")
|
|
469
|
-
if default_f0 <= 0:
|
|
470
|
-
raise ValueError("default_f0 must be positive.")
|
|
471
489
|
|
|
472
490
|
self.frame_period = frame_period
|
|
473
491
|
self.sample_rate = sample_rate
|
|
474
492
|
self.threshold = threshold
|
|
475
|
-
self.default_f0 = default_f0
|
|
476
493
|
|
|
477
494
|
freqency_interval = 3000
|
|
478
495
|
upper_limit = 15000
|
|
479
|
-
floor_f0 = 47
|
|
480
496
|
self.lowest_f0 = 40
|
|
497
|
+
self.floor_f0 = 47
|
|
481
498
|
|
|
482
499
|
self.fft_length_love = 2 ** (
|
|
483
500
|
1 + int(np.log(3 * sample_rate / self.lowest_f0 + 1) / np.log(2))
|
|
484
501
|
)
|
|
485
502
|
self.fft_length_d4c = 2 ** (
|
|
486
|
-
1 + int(np.log(4 * sample_rate / floor_f0 + 1) / np.log(2))
|
|
503
|
+
1 + int(np.log(4 * sample_rate / self.floor_f0 + 1) / np.log(2))
|
|
487
504
|
)
|
|
488
505
|
|
|
489
506
|
n_aperiodicity = int(
|
|
@@ -501,7 +518,7 @@ class AperiodicityExtractionByD4C(nn.Module):
|
|
|
501
518
|
left = center - half_window_length
|
|
502
519
|
right = center + half_window_length + 1
|
|
503
520
|
windows.append(F.pad(window, (left, padded_window_length - right)))
|
|
504
|
-
self.register_buffer("windows", torch.stack(windows))
|
|
521
|
+
self.register_buffer("windows", torch.stack(windows), persistent=False)
|
|
505
522
|
self.window_length = window_length
|
|
506
523
|
|
|
507
524
|
if fft_length is not None:
|
|
@@ -512,31 +529,33 @@ class AperiodicityExtractionByD4C(nn.Module):
|
|
|
512
529
|
idx = np.clip(idx, 0, len(coarse_axis) - 2)
|
|
513
530
|
idx = idx.reshape(1, 1, -1)
|
|
514
531
|
self.register_buffer(
|
|
515
|
-
"interp_indices",
|
|
532
|
+
"interp_indices",
|
|
533
|
+
to(idx, device=device, dtype=torch.long),
|
|
534
|
+
persistent=False,
|
|
516
535
|
)
|
|
517
536
|
|
|
518
537
|
x0 = coarse_axis[:-1]
|
|
519
538
|
dx = coarse_axis[1:] - x0
|
|
520
539
|
weights = (freq_axis - np.take(x0, idx)) / np.take(dx, idx)
|
|
521
540
|
self.register_buffer(
|
|
522
|
-
"interp_weights",
|
|
541
|
+
"interp_weights",
|
|
542
|
+
to(weights, device=device, dtype=dtype),
|
|
543
|
+
persistent=False,
|
|
523
544
|
)
|
|
524
545
|
|
|
525
546
|
self.spec_love = Spectrum(self.fft_length_love)
|
|
526
547
|
self.spec_d4c = Spectrum(self.fft_length_d4c)
|
|
527
548
|
|
|
528
|
-
self.register_buffer(
|
|
529
|
-
|
|
530
|
-
def forward(self, x: torch.Tensor, f0: torch.Tensor) -> torch.Tensor:
|
|
531
|
-
f0 = (
|
|
532
|
-
torch.where(f0 < self.lowest_f0, self.default_f0, f0).unsqueeze(-1).detach()
|
|
549
|
+
self.register_buffer(
|
|
550
|
+
"ramp", torch.arange(self.fft_length_d4c, device=device), persistent=False
|
|
533
551
|
)
|
|
534
552
|
|
|
553
|
+
def forward(self, x: torch.Tensor, f0: torch.Tensor) -> torch.Tensor:
|
|
535
554
|
# D4CLoveTrain()
|
|
536
555
|
if 0 < self.threshold:
|
|
537
556
|
waveform = get_windowed_waveform(
|
|
538
557
|
x,
|
|
539
|
-
f0,
|
|
558
|
+
torch.clip(f0, min=self.lowest_f0).unsqueeze(-1).detach(),
|
|
540
559
|
3,
|
|
541
560
|
0,
|
|
542
561
|
self.frame_period,
|
|
@@ -581,6 +600,7 @@ class AperiodicityExtractionByD4C(nn.Module):
|
|
|
581
600
|
return centroid
|
|
582
601
|
|
|
583
602
|
# GetStaticCentroid()
|
|
603
|
+
f0 = torch.clip(f0, min=self.floor_f0).unsqueeze(-1).detach()
|
|
584
604
|
centroid1 = get_centroid(x, f0, -0.25)
|
|
585
605
|
centroid2 = get_centroid(x, f0, 0.25)
|
|
586
606
|
static_centroid = centroid1 + centroid2
|
|
@@ -596,7 +616,7 @@ class AperiodicityExtractionByD4C(nn.Module):
|
|
|
596
616
|
0,
|
|
597
617
|
self.frame_period,
|
|
598
618
|
self.sample_rate,
|
|
599
|
-
self.
|
|
619
|
+
self.fft_length_d4c,
|
|
600
620
|
"hanning",
|
|
601
621
|
False,
|
|
602
622
|
1e-6,
|
|
@@ -646,7 +666,6 @@ class AperiodicityExtractionByD4C(nn.Module):
|
|
|
646
666
|
aperiodicity = 10 ** (y / 20)
|
|
647
667
|
|
|
648
668
|
if 0 < self.threshold:
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
)
|
|
669
|
+
condition = cast(torch.Tensor, aperiodicity0 <= self.threshold)
|
|
670
|
+
aperiodicity = torch.where(condition, 1 - eps, aperiodicity)
|
|
652
671
|
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)
|