diffsptk 4.0.1__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.1 → diffsptk-4.1.0}/PKG-INFO +44 -6
- {diffsptk-4.0.1 → diffsptk-4.1.0}/README.md +33 -1
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/functional.py +61 -1
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/__init__.py +2 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/dfs.py +4 -13
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/excite.py +34 -9
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/freqt.py +2 -6
- diffsptk-4.1.0/diffsptk/modules/iltcdf.py +122 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/linear_intpl.py +7 -4
- diffsptk-4.1.0/diffsptk/modules/ltcdf.py +143 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/mc2b.py +3 -7
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/mcep.py +2 -5
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/mgcep.py +9 -6
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/mglsadf.py +4 -11
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/mpir2c.py +2 -2
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/pitch_spec.py +1 -1
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/poledf.py +4 -6
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/utils/private.py +46 -0
- diffsptk-4.1.0/diffsptk/version.py +1 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/pyproject.toml +30 -5
- diffsptk-4.0.1/diffsptk/version.py +0 -1
- {diffsptk-4.0.1 → diffsptk-4.1.0}/.gitignore +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/CITATION.cff +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/LICENSE +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/__init__.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/acorr.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/acr2csm.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/alaw.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/ap.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/b2mc.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/base.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/c2acr.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/c2mpir.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/c2ndps.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/cdist.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/chroma.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/cqt.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/csm2acr.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/dct.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/decimate.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/delay.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/delta.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/dequantize.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/df2.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/dht.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/drc.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/dst.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/dtw.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/entropy.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/f0eval.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/fbank.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/fftcep.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/fftr.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/flux.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/frame.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/freqt2.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/gammatone.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/gmm.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/gnorm.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/griffin.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/grpdelay.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/hilbert.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/histogram.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/ialaw.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/ica.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/icqt.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/idct.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/idht.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/idst.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/ifbank.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/ifftr.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/ifreqt2.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/igammatone.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/ignorm.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/imdct.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/imdst.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/imglsadf.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/imsvq.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/interpolate.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/ipnorm.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/ipqmf.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/is2par.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/istft.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/iulaw.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/ivq.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/lar2par.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/lbg.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/levdur.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/lpc.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/lpc2lsp.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/lpc2par.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/lpccheck.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/lsp2lpc.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/lsp2sp.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/lspcheck.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/magic_intpl.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/mcpf.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/mdct.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/mdst.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/medfilt.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/mfcc.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/mgc2mgc.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/mgc2sp.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/mlpg.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/mlsacheck.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/msvq.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/ndps2c.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/nmf.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/norm0.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/oband.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/par2is.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/par2lar.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/par2lpc.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/pca.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/phase.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/pitch.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/plp.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/pnorm.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/pol_root.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/pqmf.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/quantize.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/rlevdur.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/rmse.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/root_pol.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/smcep.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/snr.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/spec.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/stft.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/ulaw.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/unframe.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/vq.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/wht.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/window.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/world_synth.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/yingram.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/zcross.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/modules/zerodf.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/signals.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/third_party/librosa/LICENSE +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/third_party/librosa/__init__.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/third_party/librosa/constantq.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/third_party/librosa/filters.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/third_party/librosa/typing.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/third_party/librosa/util.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/third_party/world/LICENSE +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/third_party/world/__init__.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/third_party/world/common.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/typing.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/utils/__init__.py +0 -0
- {diffsptk-4.0.1 → diffsptk-4.1.0}/diffsptk/utils/public.py +0 -0
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: diffsptk
|
|
3
|
-
Version: 4.0
|
|
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,9 +33,10 @@ 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'
|
|
@@ -44,6 +47,9 @@ 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
|
|
@@ -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
|
|
@@ -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)
|
|
@@ -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
|
|
|
@@ -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
|
*,
|
|
@@ -259,11 +278,16 @@ class ExcitationGeneration(BaseFunctionalModule):
|
|
|
259
278
|
|
|
260
279
|
# Compute phase.
|
|
261
280
|
voiced_pos = torch.gt(p, 0)
|
|
262
|
-
q = torch.zeros_like(p)
|
|
263
|
-
q[voiced_pos] = torch.reciprocal(p[voiced_pos])
|
|
264
|
-
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)
|
|
265
284
|
bias, _ = torch.cummax(s * ~mask, dim=-1)
|
|
266
|
-
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)
|
|
267
291
|
|
|
268
292
|
if polarity == "auto":
|
|
269
293
|
bipolar = voiced_region != "pulse"
|
|
@@ -276,6 +300,7 @@ class ExcitationGeneration(BaseFunctionalModule):
|
|
|
276
300
|
generators = {
|
|
277
301
|
"pulse": generate_pulse,
|
|
278
302
|
"harmonic-pulse": generate_harmonic_pulse,
|
|
303
|
+
"smooth-harmonic-pulse": partial(generate_harmonic_pulse, smooth=True),
|
|
279
304
|
}
|
|
280
305
|
if voiced_region not in generators:
|
|
281
306
|
raise ValueError(f"voiced_region {voiced_region} is not supported.")
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
import torch
|
|
18
18
|
|
|
19
|
-
from ..utils.private import check_size, filter_values, to
|
|
19
|
+
from ..utils.private import check_size, fill_warping_matrix, filter_values, to
|
|
20
20
|
from .base import BaseFunctionalModule, Precomputed
|
|
21
21
|
|
|
22
22
|
|
|
@@ -130,11 +130,7 @@ class FrequencyTransform(BaseFunctionalModule):
|
|
|
130
130
|
A[0, :] = alpha**ramp
|
|
131
131
|
if 1 < L2 and 1 < L1:
|
|
132
132
|
A[1, 1:] = A[0, :-1] * beta * ramp[1:]
|
|
133
|
-
|
|
134
|
-
i1 = i - 1
|
|
135
|
-
for j in range(1, L1):
|
|
136
|
-
j1 = j - 1
|
|
137
|
-
A[i, j] = A[i1, j1] + alpha * (A[i, j1] - A[i1, j])
|
|
133
|
+
A = fill_warping_matrix(A, alpha, 2)
|
|
138
134
|
|
|
139
135
|
return Precomputed(tensors={"A": to(A.T, dtype=dtype)})
|
|
140
136
|
|
|
@@ -0,0 +1,122 @@
|
|
|
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
|
+
import torch
|
|
18
|
+
|
|
19
|
+
from ..utils.private import check_size, filter_values
|
|
20
|
+
from .base import BaseFunctionalModule, Precomputed
|
|
21
|
+
from .linear_intpl import LinearInterpolation
|
|
22
|
+
from .ltcdf import AllPoleLatticeDigitalFilter
|
|
23
|
+
from .zerodf import AllZeroDigitalFilter
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class AllZeroLatticeDigitalFilter(BaseFunctionalModule):
|
|
27
|
+
"""See `this page <https://sp-nitech.github.io/sptk/latest/main/iltcdf.html>`_
|
|
28
|
+
for details.
|
|
29
|
+
|
|
30
|
+
Parameters
|
|
31
|
+
----------
|
|
32
|
+
filter_order : int >= 0
|
|
33
|
+
The order of the filter, :math:`M`.
|
|
34
|
+
|
|
35
|
+
frame_period : int >= 1
|
|
36
|
+
The frame period in samples, :math:`P`.
|
|
37
|
+
|
|
38
|
+
ignore_gain : bool
|
|
39
|
+
If True, perform filtering without the gain.
|
|
40
|
+
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
_takes_input_size = True
|
|
44
|
+
|
|
45
|
+
def __init__(
|
|
46
|
+
self, filter_order: int, frame_period: int, ignore_gain: bool = False
|
|
47
|
+
) -> None:
|
|
48
|
+
super().__init__()
|
|
49
|
+
|
|
50
|
+
self.in_dim = filter_order + 1
|
|
51
|
+
|
|
52
|
+
self._register_precomputed(self._precompute(**filter_values(locals())))
|
|
53
|
+
|
|
54
|
+
def forward(self, x: torch.Tensor, k: torch.Tensor) -> torch.Tensor:
|
|
55
|
+
"""Apply an all-zero lattice digital filter.
|
|
56
|
+
|
|
57
|
+
Parameters
|
|
58
|
+
----------
|
|
59
|
+
x : Tensor [shape=(..., T)]
|
|
60
|
+
The input signal.
|
|
61
|
+
|
|
62
|
+
k : Tensor [shape=(..., T/P, M+1)]
|
|
63
|
+
The PARCOR coefficients.
|
|
64
|
+
|
|
65
|
+
Returns
|
|
66
|
+
-------
|
|
67
|
+
out : Tensor [shape=(..., T)]
|
|
68
|
+
The residual signal.
|
|
69
|
+
|
|
70
|
+
Examples
|
|
71
|
+
--------
|
|
72
|
+
>>> import diffsptk
|
|
73
|
+
>>> iltcdf = diffsptk.AllZeroLatticeDigitalFilter(0, 1)
|
|
74
|
+
>>> x = diffsptk.step(4)
|
|
75
|
+
>>> k = diffsptk.ramp(1, 5)
|
|
76
|
+
>>> y = iltcdf(x, k.view(-1, 1))
|
|
77
|
+
>>> y
|
|
78
|
+
tensor([1.0000, 0.5000, 0.3333, 0.2500, 0.2000])
|
|
79
|
+
|
|
80
|
+
"""
|
|
81
|
+
check_size(k.size(-1), self.in_dim, "dimension of PARCOR coefficients")
|
|
82
|
+
return self._call_forward(x, k)
|
|
83
|
+
|
|
84
|
+
@staticmethod
|
|
85
|
+
def _func(x: torch.Tensor, k: torch.Tensor, *args, **kwargs) -> torch.Tensor:
|
|
86
|
+
_p = AllZeroLatticeDigitalFilter._precompute(k.size(-1) - 1, *args, **kwargs)
|
|
87
|
+
return AllZeroLatticeDigitalFilter._apply_precomputed(_p, x=x, k=k)
|
|
88
|
+
|
|
89
|
+
@staticmethod
|
|
90
|
+
def _check(filter_order: int, frame_period: int) -> None:
|
|
91
|
+
if filter_order < 0:
|
|
92
|
+
raise ValueError("filter_order must be non-negative.")
|
|
93
|
+
if frame_period <= 0:
|
|
94
|
+
raise ValueError("frame_period must be positive.")
|
|
95
|
+
|
|
96
|
+
@staticmethod
|
|
97
|
+
def _precompute(
|
|
98
|
+
filter_order: int, frame_period: int, ignore_gain: bool = False
|
|
99
|
+
) -> Precomputed:
|
|
100
|
+
AllZeroLatticeDigitalFilter._check(filter_order, frame_period)
|
|
101
|
+
return Precomputed(
|
|
102
|
+
values={"frame_period": frame_period, "ignore_gain": ignore_gain}
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
@staticmethod
|
|
106
|
+
def _forward(
|
|
107
|
+
x: torch.Tensor,
|
|
108
|
+
k: torch.Tensor,
|
|
109
|
+
*,
|
|
110
|
+
frame_period: int,
|
|
111
|
+
ignore_gain: bool,
|
|
112
|
+
) -> torch.Tensor:
|
|
113
|
+
check_size(x.size(-1), k.size(-2) * frame_period, "sequence length")
|
|
114
|
+
|
|
115
|
+
k = LinearInterpolation._func(k, frame_period)
|
|
116
|
+
K, k = torch.split(k, [1, k.size(-1) - 1], dim=-1)
|
|
117
|
+
|
|
118
|
+
a = AllPoleLatticeDigitalFilter._lattice_to_direct_form(k)
|
|
119
|
+
y = AllZeroDigitalFilter._func(x, a, frame_period=1)
|
|
120
|
+
if not ignore_gain:
|
|
121
|
+
y = y / K[..., 0]
|
|
122
|
+
return y
|
|
@@ -44,12 +44,12 @@ class LinearInterpolation(BaseFunctionalModule):
|
|
|
44
44
|
|
|
45
45
|
Parameters
|
|
46
46
|
----------
|
|
47
|
-
x : Tensor [shape=(
|
|
47
|
+
x : Tensor [shape=(..., N, D) or (N,)]
|
|
48
48
|
The filter coefficients.
|
|
49
49
|
|
|
50
50
|
Returns
|
|
51
51
|
-------
|
|
52
|
-
out : Tensor [shape=(
|
|
52
|
+
out : Tensor [shape=(..., NxP, D) or (NxP,)]
|
|
53
53
|
The upsampled filter coefficients.
|
|
54
54
|
|
|
55
55
|
Examples
|
|
@@ -86,13 +86,14 @@ class LinearInterpolation(BaseFunctionalModule):
|
|
|
86
86
|
if upsampling_factor == 1:
|
|
87
87
|
return x
|
|
88
88
|
|
|
89
|
+
org_shape = x.shape
|
|
89
90
|
d = x.dim()
|
|
90
91
|
if d == 1:
|
|
91
92
|
x = x.view(1, -1, 1)
|
|
92
93
|
elif d == 2:
|
|
93
94
|
x = x.unsqueeze(0)
|
|
94
|
-
|
|
95
|
-
|
|
95
|
+
else:
|
|
96
|
+
x = x.reshape(-1, *org_shape[-2:])
|
|
96
97
|
|
|
97
98
|
B, N, D = x.shape
|
|
98
99
|
x = x.transpose(-2, -1) # (B, D, N)
|
|
@@ -109,4 +110,6 @@ class LinearInterpolation(BaseFunctionalModule):
|
|
|
109
110
|
y = y.view(-1)
|
|
110
111
|
elif d == 2:
|
|
111
112
|
y = y.squeeze(0)
|
|
113
|
+
else:
|
|
114
|
+
y = y.reshape(*org_shape[:-2], *y.shape[-2:])
|
|
112
115
|
return y
|