diffsptk 4.0.0__tar.gz → 4.1.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-4.0.0 → diffsptk-4.1.0}/PKG-INFO +46 -8
- {diffsptk-4.0.0 → diffsptk-4.1.0}/README.md +33 -1
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/functional.py +62 -2
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/__init__.py +2 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/ap.py +25 -24
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/dct.py +2 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/dfs.py +7 -15
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/dtw.py +3 -3
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/excite.py +36 -10
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/f0eval.py +9 -5
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/freqt.py +2 -6
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/histogram.py +3 -3
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/ica.py +13 -12
- diffsptk-4.1.0/diffsptk/modules/iltcdf.py +122 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/linear_intpl.py +7 -4
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/lspcheck.py +1 -1
- diffsptk-4.1.0/diffsptk/modules/ltcdf.py +143 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/mc2b.py +3 -7
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/mcep.py +2 -5
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/mfcc.py +2 -2
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/mgcep.py +9 -6
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/mglsadf.py +4 -11
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/mpir2c.py +2 -2
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/pitch.py +1 -1
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/pitch_spec.py +1 -1
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/plp.py +2 -2
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/poledf.py +4 -6
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/window.py +2 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/utils/private.py +46 -0
- diffsptk-4.1.0/diffsptk/version.py +1 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/pyproject.toml +33 -8
- diffsptk-4.0.0/diffsptk/version.py +0 -1
- {diffsptk-4.0.0 → diffsptk-4.1.0}/.gitignore +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/CITATION.cff +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/LICENSE +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/__init__.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/acorr.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/acr2csm.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/alaw.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/b2mc.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/base.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/c2acr.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/c2mpir.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/c2ndps.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/cdist.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/chroma.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/cqt.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/csm2acr.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/decimate.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/delay.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/delta.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/dequantize.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/df2.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/dht.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/drc.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/dst.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/entropy.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/fbank.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/fftcep.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/fftr.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/flux.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/frame.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/freqt2.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/gammatone.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/gmm.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/gnorm.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/griffin.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/grpdelay.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/hilbert.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/ialaw.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/icqt.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/idct.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/idht.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/idst.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/ifbank.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/ifftr.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/ifreqt2.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/igammatone.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/ignorm.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/imdct.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/imdst.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/imglsadf.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/imsvq.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/interpolate.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/ipnorm.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/ipqmf.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/is2par.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/istft.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/iulaw.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/ivq.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/lar2par.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/lbg.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/levdur.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/lpc.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/lpc2lsp.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/lpc2par.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/lpccheck.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/lsp2lpc.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/lsp2sp.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/magic_intpl.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/mcpf.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/mdct.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/mdst.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/medfilt.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/mgc2mgc.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/mgc2sp.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/mlpg.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/mlsacheck.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/msvq.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/ndps2c.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/nmf.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/norm0.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/oband.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/par2is.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/par2lar.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/par2lpc.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/pca.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/phase.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/pnorm.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/pol_root.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/pqmf.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/quantize.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/rlevdur.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/rmse.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/root_pol.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/smcep.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/snr.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/spec.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/stft.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/ulaw.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/unframe.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/vq.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/wht.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/world_synth.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/yingram.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/zcross.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/modules/zerodf.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/signals.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/third_party/librosa/LICENSE +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/third_party/librosa/__init__.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/third_party/librosa/constantq.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/third_party/librosa/filters.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/third_party/librosa/typing.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/third_party/librosa/util.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/third_party/world/LICENSE +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/third_party/world/__init__.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/third_party/world/common.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/typing.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/utils/__init__.py +0 -0
- {diffsptk-4.0.0 → diffsptk-4.1.0}/diffsptk/utils/public.py +0 -0
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: diffsptk
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.1.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/
|
|
7
7
|
Project-URL: Source, https://github.com/sp-nitech/diffsptk
|
|
8
8
|
Author: SPTK Working Group
|
|
9
9
|
Maintainer-email: Takenori Yoshimura <takenori@sp.nitech.ac.jp>
|
|
10
|
-
License: Apache
|
|
10
|
+
License-Expression: Apache-2.0 AND BSD-3-Clause AND ISC
|
|
11
11
|
License-File: LICENSE
|
|
12
|
+
License-File: diffsptk/third_party/librosa/LICENSE
|
|
13
|
+
License-File: diffsptk/third_party/world/LICENSE
|
|
12
14
|
Keywords: dsp,pytorch,signal processing,sptk
|
|
13
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
15
|
Classifier: Programming Language :: Python
|
|
15
16
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
17
|
Classifier: Programming Language :: Python :: 3.10
|
|
@@ -18,6 +19,7 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
18
19
|
Classifier: Programming Language :: Python :: 3.12
|
|
19
20
|
Classifier: Programming Language :: Python :: 3.13
|
|
20
21
|
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
21
23
|
Requires-Python: >=3.10
|
|
22
24
|
Requires-Dist: mpmath>=0.17.0
|
|
23
25
|
Requires-Dist: numpy>=1.23.0
|
|
@@ -31,19 +33,23 @@ Requires-Dist: torchcomp<0.3.0,>=0.1.0
|
|
|
31
33
|
Requires-Dist: torchlpc<0.7.0,>=0.4.0
|
|
32
34
|
Requires-Dist: tqdm>=4.63.0
|
|
33
35
|
Requires-Dist: vector-quantize-pytorch>=1.14.9
|
|
36
|
+
Provides-Extra: cpu
|
|
37
|
+
Requires-Dist: torch>=2.3.1; extra == 'cpu'
|
|
38
|
+
Requires-Dist: torchaudio>=2.3.1; extra == 'cpu'
|
|
34
39
|
Provides-Extra: dev
|
|
35
|
-
Requires-Dist: build; extra == 'dev'
|
|
36
|
-
Requires-Dist: codespell; extra == 'dev'
|
|
37
40
|
Requires-Dist: mdformat; extra == 'dev'
|
|
38
41
|
Requires-Dist: numpydoc; extra == 'dev'
|
|
39
42
|
Requires-Dist: pkginfo; extra == 'dev'
|
|
40
43
|
Requires-Dist: pydata-sphinx-theme; extra == 'dev'
|
|
41
|
-
Requires-Dist: pyright[nodejs]
|
|
44
|
+
Requires-Dist: pyright[nodejs]; extra == 'dev'
|
|
42
45
|
Requires-Dist: pytest; extra == 'dev'
|
|
43
46
|
Requires-Dist: pytest-cov; extra == 'dev'
|
|
44
47
|
Requires-Dist: ruff; extra == 'dev'
|
|
45
48
|
Requires-Dist: sphinx; extra == 'dev'
|
|
46
49
|
Requires-Dist: twine; extra == 'dev'
|
|
50
|
+
Provides-Extra: gpu
|
|
51
|
+
Requires-Dist: torch>=2.3.1; extra == 'gpu'
|
|
52
|
+
Requires-Dist: torchaudio>=2.3.1; extra == 'gpu'
|
|
47
53
|
Description-Content-Type: text/markdown
|
|
48
54
|
|
|
49
55
|
# diffsptk
|
|
@@ -56,7 +62,7 @@ allowing users to integrate classic signal processing algorithms directly into n
|
|
|
56
62
|
[](https://pepy.tech/project/diffsptk)
|
|
57
63
|
[](https://clickpy.clickhouse.com/dashboard/diffsptk)
|
|
58
64
|
[](https://pypi.python.org/pypi/diffsptk)
|
|
59
|
-
[](https://pypi.python.org/pypi/diffsptk)
|
|
60
66
|
[](https://pypi.python.org/pypi/diffsptk)
|
|
61
67
|
[](https://app.codecov.io/gh/sp-nitech/diffsptk)
|
|
62
68
|
[](https://github.com/sp-nitech/diffsptk/blob/master/LICENSE)
|
|
@@ -265,6 +271,38 @@ error = (x_hat - x).abs().sum()
|
|
|
265
271
|
print(error)
|
|
266
272
|
```
|
|
267
273
|
|
|
274
|
+
### PARCOR analysis and synthesis
|
|
275
|
+
|
|
276
|
+
```python
|
|
277
|
+
import diffsptk
|
|
278
|
+
|
|
279
|
+
fl = 400 # Frame length.
|
|
280
|
+
fp = 80 # Frame period.
|
|
281
|
+
M = 24 # PARCOR dimensions.
|
|
282
|
+
|
|
283
|
+
# Read waveform.
|
|
284
|
+
x, sr = diffsptk.read("assets/data.wav")
|
|
285
|
+
|
|
286
|
+
# Estimate PARCOR of x.
|
|
287
|
+
frame = diffsptk.Frame(frame_length=fl, frame_period=fp)
|
|
288
|
+
window = diffsptk.Window(in_length=fl)
|
|
289
|
+
lpc = diffsptk.LPC(frame_length=fl, lpc_order=M, eps=1e-5)
|
|
290
|
+
lpc2par = diffsptk.LinearPredictiveCoefficientsToParcorCoefficients(lpc_order=M)
|
|
291
|
+
k = lpc2par(lpc(window(frame(x))))
|
|
292
|
+
|
|
293
|
+
# Reconstruct x.
|
|
294
|
+
iltcdf = diffsptk.AllZeroLatticeDigitalFilter(filter_order=M, frame_period=fp)
|
|
295
|
+
ltcdf = diffsptk.AllPoleLatticeDigitalFilter(filter_order=M, frame_period=fp)
|
|
296
|
+
x_hat = ltcdf(iltcdf(x, k), k)
|
|
297
|
+
|
|
298
|
+
# Write reconstructed waveform.
|
|
299
|
+
diffsptk.write("reconst.wav", x_hat, sr)
|
|
300
|
+
|
|
301
|
+
# Compute error.
|
|
302
|
+
error = (x_hat - x).abs().sum()
|
|
303
|
+
print(error)
|
|
304
|
+
```
|
|
305
|
+
|
|
268
306
|
### Mel spectrogram analysis and synthesis
|
|
269
307
|
|
|
270
308
|
```python
|
|
@@ -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)
|
|
@@ -217,6 +217,38 @@ error = (x_hat - x).abs().sum()
|
|
|
217
217
|
print(error)
|
|
218
218
|
```
|
|
219
219
|
|
|
220
|
+
### PARCOR analysis and synthesis
|
|
221
|
+
|
|
222
|
+
```python
|
|
223
|
+
import diffsptk
|
|
224
|
+
|
|
225
|
+
fl = 400 # Frame length.
|
|
226
|
+
fp = 80 # Frame period.
|
|
227
|
+
M = 24 # PARCOR dimensions.
|
|
228
|
+
|
|
229
|
+
# Read waveform.
|
|
230
|
+
x, sr = diffsptk.read("assets/data.wav")
|
|
231
|
+
|
|
232
|
+
# Estimate PARCOR of x.
|
|
233
|
+
frame = diffsptk.Frame(frame_length=fl, frame_period=fp)
|
|
234
|
+
window = diffsptk.Window(in_length=fl)
|
|
235
|
+
lpc = diffsptk.LPC(frame_length=fl, lpc_order=M, eps=1e-5)
|
|
236
|
+
lpc2par = diffsptk.LinearPredictiveCoefficientsToParcorCoefficients(lpc_order=M)
|
|
237
|
+
k = lpc2par(lpc(window(frame(x))))
|
|
238
|
+
|
|
239
|
+
# Reconstruct x.
|
|
240
|
+
iltcdf = diffsptk.AllZeroLatticeDigitalFilter(filter_order=M, frame_period=fp)
|
|
241
|
+
ltcdf = diffsptk.AllPoleLatticeDigitalFilter(filter_order=M, frame_period=fp)
|
|
242
|
+
x_hat = ltcdf(iltcdf(x, k), k)
|
|
243
|
+
|
|
244
|
+
# Write reconstructed waveform.
|
|
245
|
+
diffsptk.write("reconst.wav", x_hat, sr)
|
|
246
|
+
|
|
247
|
+
# Compute error.
|
|
248
|
+
error = (x_hat - x).abs().sum()
|
|
249
|
+
print(error)
|
|
250
|
+
```
|
|
251
|
+
|
|
220
252
|
### Mel spectrogram analysis and synthesis
|
|
221
253
|
|
|
222
254
|
```python
|
|
@@ -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[float] | ArrayLike[int] = [[-0.5, 0, 0.5]],
|
|
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', 'harmonic-pulse']
|
|
638
|
+
'triangle', 'square', 'harmonic-pulse', 'smooth-harmonic-pulse']
|
|
639
639
|
The type of voiced region.
|
|
640
640
|
|
|
641
641
|
unvoiced_region : ['zeros', 'gauss', 'm-sequence', 'uniform']
|
|
@@ -1407,6 +1407,36 @@ def ignorm(y: Tensor, gamma: float = 0, c: int | None = None) -> Tensor:
|
|
|
1407
1407
|
return nn.GeneralizedCepstrumInverseGainNormalization._func(y, gamma=gamma, c=c)
|
|
1408
1408
|
|
|
1409
1409
|
|
|
1410
|
+
def iltcdf(
|
|
1411
|
+
x: Tensor, k: Tensor, frame_period: int = 80, ignore_gain: bool = False
|
|
1412
|
+
) -> Tensor:
|
|
1413
|
+
"""Apply an all-zero lattice digital filter.
|
|
1414
|
+
|
|
1415
|
+
Parameters
|
|
1416
|
+
----------
|
|
1417
|
+
x : Tensor [shape=(..., T)]
|
|
1418
|
+
The input signal.
|
|
1419
|
+
|
|
1420
|
+
k : Tensor [shape=(..., T/P, M+1)]
|
|
1421
|
+
The PARCOR coefficients.
|
|
1422
|
+
|
|
1423
|
+
frame_period : int >= 1
|
|
1424
|
+
The frame period in samples, :math:`P`.
|
|
1425
|
+
|
|
1426
|
+
ignore_gain : bool
|
|
1427
|
+
If True, perform filtering without the gain.
|
|
1428
|
+
|
|
1429
|
+
Returns
|
|
1430
|
+
-------
|
|
1431
|
+
out : Tensor [shape=(..., T)]
|
|
1432
|
+
The residual signal.
|
|
1433
|
+
|
|
1434
|
+
"""
|
|
1435
|
+
return nn.AllZeroLatticeDigitalFilter._func(
|
|
1436
|
+
x, k, frame_period=frame_period, ignore_gain=ignore_gain
|
|
1437
|
+
)
|
|
1438
|
+
|
|
1439
|
+
|
|
1410
1440
|
def imdct(
|
|
1411
1441
|
y: Tensor,
|
|
1412
1442
|
out_length: int | None = None,
|
|
@@ -1913,6 +1943,36 @@ def lsp2sp(
|
|
|
1913
1943
|
)
|
|
1914
1944
|
|
|
1915
1945
|
|
|
1946
|
+
def ltcdf(
|
|
1947
|
+
x: Tensor, k: Tensor, frame_period: int = 80, ignore_gain: bool = False
|
|
1948
|
+
) -> Tensor:
|
|
1949
|
+
"""Apply an all-pole lattice digital filter.
|
|
1950
|
+
|
|
1951
|
+
Parameters
|
|
1952
|
+
----------
|
|
1953
|
+
x : Tensor [shape=(..., T)]
|
|
1954
|
+
The excitation signal.
|
|
1955
|
+
|
|
1956
|
+
k : Tensor [shape=(..., T/P, M+1)]
|
|
1957
|
+
The PARCOR coefficients.
|
|
1958
|
+
|
|
1959
|
+
frame_period : int >= 1
|
|
1960
|
+
The frame period in samples, :math:`P`.
|
|
1961
|
+
|
|
1962
|
+
ignore_gain : bool
|
|
1963
|
+
If True, perform filtering without the gain.
|
|
1964
|
+
|
|
1965
|
+
Returns
|
|
1966
|
+
-------
|
|
1967
|
+
out : Tensor [shape=(..., T)]
|
|
1968
|
+
The output signal.
|
|
1969
|
+
|
|
1970
|
+
"""
|
|
1971
|
+
return nn.AllPoleLatticeDigitalFilter._func(
|
|
1972
|
+
x, k, frame_period=frame_period, ignore_gain=ignore_gain
|
|
1973
|
+
)
|
|
1974
|
+
|
|
1975
|
+
|
|
1916
1976
|
def magic_intpl(x: Tensor, magic_number: float = 0) -> Tensor:
|
|
1917
1977
|
"""Interpolate magic number.
|
|
1918
1978
|
|
|
@@ -80,6 +80,7 @@ from .ifftr import RealValuedInverseFastFourierTransform
|
|
|
80
80
|
from .ifreqt2 import SecondOrderAllPassInverseFrequencyTransform
|
|
81
81
|
from .igammatone import GammatoneFilterBankSynthesis
|
|
82
82
|
from .ignorm import GeneralizedCepstrumInverseGainNormalization
|
|
83
|
+
from .iltcdf import AllZeroLatticeDigitalFilter
|
|
83
84
|
from .imdct import InverseModifiedDiscreteCosineTransform
|
|
84
85
|
from .imdct import InverseModifiedDiscreteCosineTransform as IMDCT
|
|
85
86
|
from .imdst import InverseModifiedDiscreteSineTransform
|
|
@@ -109,6 +110,7 @@ from .lpccheck import LinearPredictiveCoefficientsStabilityCheck
|
|
|
109
110
|
from .lsp2lpc import LineSpectralPairsToLinearPredictiveCoefficients
|
|
110
111
|
from .lsp2sp import LineSpectralPairsToSpectrum
|
|
111
112
|
from .lspcheck import LineSpectralPairsStabilityCheck
|
|
113
|
+
from .ltcdf import AllPoleLatticeDigitalFilter
|
|
112
114
|
from .magic_intpl import MagicNumberInterpolation
|
|
113
115
|
from .mc2b import MelCepstrumToMLSADigitalFilterCoefficients
|
|
114
116
|
from .mcpf import MelCepstrumPostfiltering
|
|
@@ -46,7 +46,8 @@ class Aperiodicity(BaseNonFunctionalModule):
|
|
|
46
46
|
(uninterpolated aperiodicity) is returned as the output.
|
|
47
47
|
|
|
48
48
|
algorithm : ['tandem', 'd4c']
|
|
49
|
-
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.
|
|
50
51
|
|
|
51
52
|
out_format : ['a', 'p', 'a/p', 'p/a']
|
|
52
53
|
The output format.
|
|
@@ -54,7 +55,7 @@ class Aperiodicity(BaseNonFunctionalModule):
|
|
|
54
55
|
lower_bound : float >= 0
|
|
55
56
|
The lower bound of aperiodicity.
|
|
56
57
|
|
|
57
|
-
upper_bound : float <= 1
|
|
58
|
+
upper_bound : float <= 1 or None
|
|
58
59
|
The upper bound of aperiodicity.
|
|
59
60
|
|
|
60
61
|
device : torch.device or None
|
|
@@ -82,7 +83,7 @@ class Aperiodicity(BaseNonFunctionalModule):
|
|
|
82
83
|
algorithm: str = "tandem",
|
|
83
84
|
out_format: str | int = "a",
|
|
84
85
|
lower_bound: float = 0.001,
|
|
85
|
-
upper_bound: float =
|
|
86
|
+
upper_bound: float | None = None,
|
|
86
87
|
**kwargs,
|
|
87
88
|
) -> None:
|
|
88
89
|
super().__init__()
|
|
@@ -93,6 +94,8 @@ class Aperiodicity(BaseNonFunctionalModule):
|
|
|
93
94
|
raise ValueError("sample_rate must be at least 8000 Hz.")
|
|
94
95
|
if fft_length is not None and fft_length < 16:
|
|
95
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)
|
|
96
99
|
if not 0 <= lower_bound < upper_bound <= 1:
|
|
97
100
|
raise ValueError("Invalid lower_bound and upper_bound.")
|
|
98
101
|
|
|
@@ -113,11 +116,11 @@ class Aperiodicity(BaseNonFunctionalModule):
|
|
|
113
116
|
if out_format in (0, "a"):
|
|
114
117
|
self.convert = lambda x: x
|
|
115
118
|
elif out_format in (1, "p"):
|
|
116
|
-
self.convert = lambda x: 1 - x
|
|
119
|
+
self.convert = lambda x: torch.sqrt(1 - x * x)
|
|
117
120
|
elif out_format in (2, "a/p"):
|
|
118
|
-
self.convert = lambda x: x / (1 - x)
|
|
121
|
+
self.convert = lambda x: x / torch.sqrt(1 - x * x)
|
|
119
122
|
elif out_format in (3, "p/a"):
|
|
120
|
-
self.convert = lambda x: (1 - x) / x
|
|
123
|
+
self.convert = lambda x: torch.sqrt(1 - x * x) / x
|
|
121
124
|
else:
|
|
122
125
|
raise ValueError(f"out_format {out_format} is not supported.")
|
|
123
126
|
|
|
@@ -162,7 +165,9 @@ class Aperiodicity(BaseNonFunctionalModule):
|
|
|
162
165
|
if f0.dim() != 2:
|
|
163
166
|
raise ValueError("F0 must be 1D or 2D tensor.")
|
|
164
167
|
|
|
168
|
+
unvoiced = (f0 == 0).unsqueeze(-1)
|
|
165
169
|
ap = self.extractor(x, f0)
|
|
170
|
+
ap = ap.masked_fill(unvoiced, 1)
|
|
166
171
|
ap = torch.clip(ap, min=self.lower_bound, max=self.upper_bound)
|
|
167
172
|
ap = self.convert(ap)
|
|
168
173
|
|
|
@@ -231,15 +236,18 @@ class AperiodicityExtractionByTANDEM(nn.Module):
|
|
|
231
236
|
self.sample_rate = sample_rate
|
|
232
237
|
self.n_band = int(np.log2(sample_rate / 600))
|
|
233
238
|
|
|
234
|
-
self.
|
|
239
|
+
self.floor_f0 = 32
|
|
235
240
|
self.n_trial = 10
|
|
236
241
|
|
|
237
242
|
self.cutoff_list = [sample_rate / 2**i for i in range(2, self.n_band + 1)]
|
|
238
243
|
self.cutoff_list.append(self.cutoff_list[-1])
|
|
239
244
|
|
|
240
245
|
if fft_length is not None:
|
|
241
|
-
coarse_axis = [
|
|
246
|
+
coarse_axis = [
|
|
247
|
+
sample_rate / 2**i * math.sqrt(0.5) for i in range(self.n_band, 0, -1)
|
|
248
|
+
]
|
|
242
249
|
coarse_axis.insert(0, 0)
|
|
250
|
+
coarse_axis.append(sample_rate / 2)
|
|
243
251
|
coarse_axis = np.asarray(coarse_axis)
|
|
244
252
|
freq_axis = np.arange(fft_length // 2 + 1) * (sample_rate / fft_length)
|
|
245
253
|
|
|
@@ -292,7 +300,7 @@ class AperiodicityExtractionByTANDEM(nn.Module):
|
|
|
292
300
|
self.register_buffer("window_sqrt", self.window.sqrt(), persistent=False)
|
|
293
301
|
|
|
294
302
|
def forward(self, x: torch.Tensor, f0: torch.Tensor) -> torch.Tensor:
|
|
295
|
-
f0 = torch.
|
|
303
|
+
f0 = torch.clip(f0, min=self.floor_f0).detach()
|
|
296
304
|
|
|
297
305
|
B, N = f0.shape
|
|
298
306
|
time_axis = torch.arange(N, dtype=f0.dtype, device=f0.device) * (
|
|
@@ -343,9 +351,9 @@ class AperiodicityExtractionByTANDEM(nn.Module):
|
|
|
343
351
|
m = 10**n
|
|
344
352
|
u, info = torch.linalg.cholesky_ex(R + self.eye * m)
|
|
345
353
|
if 0 == info.sum().item():
|
|
346
|
-
if n == self.n_trial - 1:
|
|
347
|
-
raise RuntimeError("Failed to compute Cholesky decomposition.")
|
|
348
354
|
break
|
|
355
|
+
if n == self.n_trial - 1:
|
|
356
|
+
raise RuntimeError("Failed to compute Cholesky decomposition.")
|
|
349
357
|
|
|
350
358
|
b = torch.matmul(Hw, X) # (B, N, 6, 1)
|
|
351
359
|
a = torch.cholesky_solve(b, u)
|
|
@@ -364,7 +372,7 @@ class AperiodicityExtractionByTANDEM(nn.Module):
|
|
|
364
372
|
|
|
365
373
|
# Interpolate band aperiodicity.
|
|
366
374
|
if hasattr(self, "interp_indices"):
|
|
367
|
-
y = torch.log(ap)
|
|
375
|
+
y = torch.log(F.pad(ap, (0, 1), mode="replicate"))
|
|
368
376
|
y0 = y[..., :-1]
|
|
369
377
|
dy = y[..., 1:] - y0
|
|
370
378
|
index = self.interp_indices.expand(B, N, -1)
|
|
@@ -469,7 +477,6 @@ class AperiodicityExtractionByD4C(nn.Module):
|
|
|
469
477
|
fft_length: int | None = None,
|
|
470
478
|
*,
|
|
471
479
|
threshold: float = 0,
|
|
472
|
-
default_f0: float = 150,
|
|
473
480
|
device: torch.device | None = None,
|
|
474
481
|
dtype: torch.dtype | None = None,
|
|
475
482
|
) -> None:
|
|
@@ -479,24 +486,21 @@ class AperiodicityExtractionByD4C(nn.Module):
|
|
|
479
486
|
raise ValueError("sample_rate must be at least 12000 Hz.")
|
|
480
487
|
if threshold < 0:
|
|
481
488
|
raise ValueError("threshold must be non-negative.")
|
|
482
|
-
if default_f0 <= 0:
|
|
483
|
-
raise ValueError("default_f0 must be positive.")
|
|
484
489
|
|
|
485
490
|
self.frame_period = frame_period
|
|
486
491
|
self.sample_rate = sample_rate
|
|
487
492
|
self.threshold = threshold
|
|
488
|
-
self.default_f0 = default_f0
|
|
489
493
|
|
|
490
494
|
freqency_interval = 3000
|
|
491
495
|
upper_limit = 15000
|
|
492
|
-
floor_f0 = 47
|
|
493
496
|
self.lowest_f0 = 40
|
|
497
|
+
self.floor_f0 = 47
|
|
494
498
|
|
|
495
499
|
self.fft_length_love = 2 ** (
|
|
496
500
|
1 + int(np.log(3 * sample_rate / self.lowest_f0 + 1) / np.log(2))
|
|
497
501
|
)
|
|
498
502
|
self.fft_length_d4c = 2 ** (
|
|
499
|
-
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))
|
|
500
504
|
)
|
|
501
505
|
|
|
502
506
|
n_aperiodicity = int(
|
|
@@ -547,15 +551,11 @@ class AperiodicityExtractionByD4C(nn.Module):
|
|
|
547
551
|
)
|
|
548
552
|
|
|
549
553
|
def forward(self, x: torch.Tensor, f0: torch.Tensor) -> torch.Tensor:
|
|
550
|
-
f0 = (
|
|
551
|
-
torch.where(f0 < self.lowest_f0, self.default_f0, f0).unsqueeze(-1).detach()
|
|
552
|
-
)
|
|
553
|
-
|
|
554
554
|
# D4CLoveTrain()
|
|
555
555
|
if 0 < self.threshold:
|
|
556
556
|
waveform = get_windowed_waveform(
|
|
557
557
|
x,
|
|
558
|
-
f0,
|
|
558
|
+
torch.clip(f0, min=self.lowest_f0).unsqueeze(-1).detach(),
|
|
559
559
|
3,
|
|
560
560
|
0,
|
|
561
561
|
self.frame_period,
|
|
@@ -600,6 +600,7 @@ class AperiodicityExtractionByD4C(nn.Module):
|
|
|
600
600
|
return centroid
|
|
601
601
|
|
|
602
602
|
# GetStaticCentroid()
|
|
603
|
+
f0 = torch.clip(f0, min=self.floor_f0).unsqueeze(-1).detach()
|
|
603
604
|
centroid1 = get_centroid(x, f0, -0.25)
|
|
604
605
|
centroid2 = get_centroid(x, f0, 0.25)
|
|
605
606
|
static_centroid = centroid1 + centroid2
|
|
@@ -615,7 +616,7 @@ class AperiodicityExtractionByD4C(nn.Module):
|
|
|
615
616
|
0,
|
|
616
617
|
self.frame_period,
|
|
617
618
|
self.sample_rate,
|
|
618
|
-
self.
|
|
619
|
+
self.fft_length_d4c,
|
|
619
620
|
"hanning",
|
|
620
621
|
False,
|
|
621
622
|
1e-6,
|
|
@@ -94,6 +94,8 @@ class DiscreteCosineTransform(BaseFunctionalModule):
|
|
|
94
94
|
raise ValueError("dct_length must be positive.")
|
|
95
95
|
if not 1 <= dct_type <= 4:
|
|
96
96
|
raise ValueError("dct_type must be in [1, 4].")
|
|
97
|
+
if dct_type == 1 and dct_length < 2:
|
|
98
|
+
raise ValueError("dct_length must be at least 2 for DCT-I.")
|
|
97
99
|
|
|
98
100
|
@staticmethod
|
|
99
101
|
def _precompute(
|
|
@@ -22,7 +22,7 @@ import torch.nn.functional as F
|
|
|
22
22
|
from torch import nn
|
|
23
23
|
|
|
24
24
|
from ..typing import ArrayLike
|
|
25
|
-
from ..utils.private import filter_values, iir, to, to_3d
|
|
25
|
+
from ..utils.private import filter_values, iir, remove_gain, to, to_3d
|
|
26
26
|
from .base import BaseFunctionalModule, Precomputed
|
|
27
27
|
|
|
28
28
|
|
|
@@ -141,19 +141,10 @@ class InfiniteImpulseResponseDigitalFilter(BaseFunctionalModule):
|
|
|
141
141
|
a_coef = torch.empty(0)
|
|
142
142
|
elif ir_length is not None:
|
|
143
143
|
# Pre-compute the truncated impulse response.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
)
|
|
147
|
-
h =
|
|
148
|
-
a0 = a_coef[0]
|
|
149
|
-
a1 = a_coef[1:]
|
|
150
|
-
for t in range(ir_length):
|
|
151
|
-
x = a0 if t == 0 else 0
|
|
152
|
-
y = x - torch.sum(d[: len(a1)] * a1)
|
|
153
|
-
d = torch.roll(d, 1)
|
|
154
|
-
d[0] = y
|
|
155
|
-
y = torch.sum(d[: len(b_coef)] * b_coef)
|
|
156
|
-
h[t] = y
|
|
144
|
+
impulse = torch.zeros(ir_length, device=device, dtype=torch.double)
|
|
145
|
+
impulse[0] = 1
|
|
146
|
+
K, a1 = remove_gain(to(a_coef, dtype=torch.double), return_gain=True)
|
|
147
|
+
h = iir(impulse, K * to(b_coef, dtype=torch.double), a1)
|
|
157
148
|
h = h.view(1, 1, -1).flip(-1)
|
|
158
149
|
b_coef = to(h, dtype=dtype)
|
|
159
150
|
a_coef = torch.empty(0)
|
|
@@ -167,5 +158,6 @@ class InfiniteImpulseResponseDigitalFilter(BaseFunctionalModule):
|
|
|
167
158
|
y = F.conv1d(y, b)
|
|
168
159
|
y = y.view_as(x)
|
|
169
160
|
else:
|
|
170
|
-
|
|
161
|
+
K, a = remove_gain(a, return_gain=True)
|
|
162
|
+
y = iir(x, K * b, a)
|
|
171
163
|
return y
|
|
@@ -63,19 +63,19 @@ def _soft_dtw_core(
|
|
|
63
63
|
|
|
64
64
|
if has_two_step_transition:
|
|
65
65
|
if steps[k][0] == 0 or steps[k][1] == 0:
|
|
66
|
-
if R_[
|
|
66
|
+
if R_[0, i_k, j_k] != float("inf"):
|
|
67
67
|
rs.append(d * w + R_[:, i_k, j_k])
|
|
68
68
|
if return_indices:
|
|
69
69
|
ps.append(p)
|
|
70
70
|
else:
|
|
71
|
-
if R[
|
|
71
|
+
if R[0, i_k, j_k] != float("inf"):
|
|
72
72
|
rs.append(d * w + R[:, i_k, j_k])
|
|
73
73
|
rs_.append(rs[-1])
|
|
74
74
|
if return_indices:
|
|
75
75
|
ps.append(p)
|
|
76
76
|
ps_.append(ps[-1])
|
|
77
77
|
else:
|
|
78
|
-
if R[
|
|
78
|
+
if R[0, i_k, j_k] != float("inf"):
|
|
79
79
|
rs.append(d * w + R[:, i_k, j_k])
|
|
80
80
|
if return_indices:
|
|
81
81
|
ps.append(p)
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
# ------------------------------------------------------------------------ #
|
|
16
16
|
|
|
17
17
|
import math
|
|
18
|
+
from functools import partial
|
|
18
19
|
|
|
19
20
|
import torch
|
|
20
21
|
import torch.nn.functional as F
|
|
@@ -48,13 +49,23 @@ def generate_harmonic_pulse(
|
|
|
48
49
|
pitch: torch.Tensor,
|
|
49
50
|
phase: torch.Tensor,
|
|
50
51
|
bipolar: bool,
|
|
52
|
+
smooth: bool = False,
|
|
51
53
|
) -> torch.Tensor:
|
|
52
54
|
# The number of harmonics is floor(0.5 * fs / f0) = floor(0.5 * 1 / T)
|
|
53
55
|
n_harmonics = torch.floor(0.5 * pitch)
|
|
54
56
|
|
|
57
|
+
# Make the number of harmonics continuous by weighting the highest harmonic
|
|
58
|
+
# with the fractional part.
|
|
59
|
+
if smooth:
|
|
60
|
+
top_harmonic = n_harmonics
|
|
61
|
+
weight = (0.5 * pitch - top_harmonic) * torch.ge(top_harmonic, 1)
|
|
62
|
+
n_harmonics = (top_harmonic - 1).clip(min=0)
|
|
63
|
+
|
|
55
64
|
# The summation of sinusoids can be computed efficiently using the closed-form
|
|
56
|
-
# expression of the Dirichlet kernel.
|
|
57
|
-
|
|
65
|
+
# expression of the Dirichlet kernel. The phase is centered around zero to avoid
|
|
66
|
+
# the precision loss near the singularities at the end of each period.
|
|
67
|
+
phase = phase[..., :-1]
|
|
68
|
+
theta = TAU * (phase - torch.round(phase))
|
|
58
69
|
half_theta = 0.5 * theta
|
|
59
70
|
if bipolar:
|
|
60
71
|
numer = torch.cos(half_theta) - torch.cos((n_harmonics + 0.5) * theta)
|
|
@@ -72,8 +83,17 @@ def generate_harmonic_pulse(
|
|
|
72
83
|
else:
|
|
73
84
|
e[is_singular] = n_harmonics[is_singular]
|
|
74
85
|
|
|
86
|
+
if smooth:
|
|
87
|
+
if bipolar:
|
|
88
|
+
e = e + weight * torch.sin(top_harmonic * theta)
|
|
89
|
+
else:
|
|
90
|
+
e = e + weight * torch.cos(top_harmonic * theta)
|
|
91
|
+
energy = n_harmonics + weight**2
|
|
92
|
+
else:
|
|
93
|
+
energy = n_harmonics
|
|
94
|
+
|
|
75
95
|
# Normalize as the same energy as the pulse excitation.
|
|
76
|
-
norm_factor = torch.sqrt(2 /
|
|
96
|
+
norm_factor = torch.sqrt(2 / energy.clip(min=1))
|
|
77
97
|
return norm_factor * e
|
|
78
98
|
|
|
79
99
|
|
|
@@ -123,7 +143,7 @@ def generate_mseq(source: torch.Tensor) -> torch.Tensor:
|
|
|
123
143
|
|
|
124
144
|
|
|
125
145
|
def generate_uniform(source: torch.Tensor) -> torch.Tensor:
|
|
126
|
-
return math.sqrt(12) * torch.rand_like(source)
|
|
146
|
+
return math.sqrt(12) * (torch.rand_like(source) - 0.5)
|
|
127
147
|
|
|
128
148
|
|
|
129
149
|
class ExcitationGeneration(BaseFunctionalModule):
|
|
@@ -136,7 +156,7 @@ class ExcitationGeneration(BaseFunctionalModule):
|
|
|
136
156
|
The frame period in samples, :math:`P`.
|
|
137
157
|
|
|
138
158
|
voiced_region : ['pulse', 'sinusoidal', 'sawtooth', 'inverted-sawtooth', \
|
|
139
|
-
'triangle', 'square', 'harmonic-pulse']
|
|
159
|
+
'triangle', 'square', 'harmonic-pulse', 'smooth-harmonic-pulse']
|
|
140
160
|
The type of voiced region.
|
|
141
161
|
|
|
142
162
|
unvoiced_region : ['zeros', 'gauss', 'm-sequence', 'uniform']
|
|
@@ -218,7 +238,6 @@ class ExcitationGeneration(BaseFunctionalModule):
|
|
|
218
238
|
)
|
|
219
239
|
|
|
220
240
|
@staticmethod
|
|
221
|
-
@torch.inference_mode()
|
|
222
241
|
def _forward(
|
|
223
242
|
p: torch.Tensor,
|
|
224
243
|
*,
|
|
@@ -236,6 +255,7 @@ class ExcitationGeneration(BaseFunctionalModule):
|
|
|
236
255
|
# Extend right side for interpolation.
|
|
237
256
|
tmp_mask = F.pad(base_mask, (1, 0))
|
|
238
257
|
tmp_mask = torch.eq(torch.diff(tmp_mask), -1)
|
|
258
|
+
p = p.clone()
|
|
239
259
|
p[tmp_mask] = torch.roll(p, 1, dims=-1)[tmp_mask]
|
|
240
260
|
|
|
241
261
|
# Interpolate pitch.
|
|
@@ -258,11 +278,16 @@ class ExcitationGeneration(BaseFunctionalModule):
|
|
|
258
278
|
|
|
259
279
|
# Compute phase.
|
|
260
280
|
voiced_pos = torch.gt(p, 0)
|
|
261
|
-
q = torch.zeros_like(p)
|
|
262
|
-
q[voiced_pos] = torch.reciprocal(p[voiced_pos])
|
|
263
|
-
s = torch.cumsum(q
|
|
281
|
+
q = torch.zeros_like(p, dtype=torch.double)
|
|
282
|
+
q[voiced_pos] = torch.reciprocal(p[voiced_pos].double())
|
|
283
|
+
s = torch.cumsum(q, dim=-1)
|
|
264
284
|
bias, _ = torch.cummax(s * ~mask, dim=-1)
|
|
265
|
-
phase =
|
|
285
|
+
phase = s - bias
|
|
286
|
+
if voiced_region != "pulse":
|
|
287
|
+
# Wrap phase to keep precision in single precision. Note that the pulse
|
|
288
|
+
# excitation requires the unwrapped phase to detect pulse positions.
|
|
289
|
+
phase = torch.frac(phase)
|
|
290
|
+
phase = phase.to(p.dtype)
|
|
266
291
|
|
|
267
292
|
if polarity == "auto":
|
|
268
293
|
bipolar = voiced_region != "pulse"
|
|
@@ -275,6 +300,7 @@ class ExcitationGeneration(BaseFunctionalModule):
|
|
|
275
300
|
generators = {
|
|
276
301
|
"pulse": generate_pulse,
|
|
277
302
|
"harmonic-pulse": generate_harmonic_pulse,
|
|
303
|
+
"smooth-harmonic-pulse": partial(generate_harmonic_pulse, smooth=True),
|
|
278
304
|
}
|
|
279
305
|
if voiced_region not in generators:
|
|
280
306
|
raise ValueError(f"voiced_region {voiced_region} is not supported.")
|
|
@@ -18,7 +18,6 @@ import torch
|
|
|
18
18
|
|
|
19
19
|
from ..utils.private import UNVOICED_SYMBOL, filter_values
|
|
20
20
|
from .base import BaseFunctionalModule, Precomputed
|
|
21
|
-
from .rmse import RootMeanSquareError
|
|
22
21
|
|
|
23
22
|
|
|
24
23
|
class F0Evaluation(BaseFunctionalModule):
|
|
@@ -94,16 +93,21 @@ class F0Evaluation(BaseFunctionalModule):
|
|
|
94
93
|
if out_format.startswith("f0-rmse"):
|
|
95
94
|
voiced = (x != UNVOICED_SYMBOL) & (y != UNVOICED_SYMBOL)
|
|
96
95
|
if out_format == "f0-rmse-hz":
|
|
97
|
-
convert = lambda x:
|
|
96
|
+
convert = lambda x: (
|
|
97
|
+
x if x.is_floating_point() else x.to(torch.get_default_dtype())
|
|
98
|
+
)
|
|
98
99
|
elif out_format == "f0-rmse-cent":
|
|
99
100
|
convert = lambda x: 1200 * torch.log2(x)
|
|
100
101
|
elif out_format == "f0-rmse-semitone":
|
|
101
102
|
convert = lambda x: 12 * torch.log2(x)
|
|
102
103
|
else:
|
|
103
104
|
raise ValueError(f"out_format {out_format} is not supported.")
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
)
|
|
105
|
+
# Replace unvoiced frames with a dummy value to avoid log(0).
|
|
106
|
+
x = torch.where(voiced, x, 1)
|
|
107
|
+
y = torch.where(voiced, y, 1)
|
|
108
|
+
diff = convert(x) - convert(y)
|
|
109
|
+
n_voiced = voiced.sum(dim=-1).to(diff.dtype)
|
|
110
|
+
out = torch.linalg.vector_norm(diff, dim=-1) / torch.sqrt(n_voiced)
|
|
107
111
|
else:
|
|
108
112
|
TP = torch.sum((x != UNVOICED_SYMBOL) & (y != UNVOICED_SYMBOL), dim=-1)
|
|
109
113
|
FP = torch.sum((x != UNVOICED_SYMBOL) & (y == UNVOICED_SYMBOL), dim=-1)
|