diffsptk 2.0.1__tar.gz → 2.1.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.
Files changed (106) hide show
  1. {diffsptk-2.0.1 → diffsptk-2.1.1}/PKG-INFO +28 -23
  2. {diffsptk-2.0.1 → diffsptk-2.1.1}/README.md +22 -20
  3. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/functional.py +90 -0
  4. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/misc/utils.py +14 -4
  5. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/__init__.py +4 -0
  6. diffsptk-2.1.1/diffsptk/modules/acr2csm.py +118 -0
  7. diffsptk-2.1.1/diffsptk/modules/csm2acr.py +92 -0
  8. diffsptk-2.1.1/diffsptk/modules/drc.py +183 -0
  9. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/imglsadf.py +0 -8
  10. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/levdur.py +1 -0
  11. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/mglsadf.py +10 -3
  12. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/poledf.py +6 -0
  13. diffsptk-2.1.1/diffsptk/version.py +1 -0
  14. {diffsptk-2.0.1 → diffsptk-2.1.1}/pyproject.toml +5 -2
  15. diffsptk-2.0.1/diffsptk/version.py +0 -1
  16. {diffsptk-2.0.1 → diffsptk-2.1.1}/.gitignore +0 -0
  17. {diffsptk-2.0.1 → diffsptk-2.1.1}/CITATION.cff +0 -0
  18. {diffsptk-2.0.1 → diffsptk-2.1.1}/LICENSE +0 -0
  19. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/__init__.py +0 -0
  20. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/misc/__init__.py +0 -0
  21. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/misc/signals.py +0 -0
  22. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/acorr.py +0 -0
  23. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/alaw.py +0 -0
  24. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/ap.py +0 -0
  25. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/b2mc.py +0 -0
  26. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/c2acr.py +0 -0
  27. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/c2mpir.py +0 -0
  28. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/c2ndps.py +0 -0
  29. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/cdist.py +0 -0
  30. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/cqt.py +0 -0
  31. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/dct.py +0 -0
  32. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/decimate.py +0 -0
  33. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/delay.py +0 -0
  34. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/delta.py +0 -0
  35. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/dequantize.py +0 -0
  36. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/df2.py +0 -0
  37. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/dfs.py +0 -0
  38. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/entropy.py +0 -0
  39. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/excite.py +0 -0
  40. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/fbank.py +0 -0
  41. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/fftcep.py +0 -0
  42. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/frame.py +0 -0
  43. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/freqt.py +0 -0
  44. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/freqt2.py +0 -0
  45. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/gmm.py +0 -0
  46. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/gnorm.py +0 -0
  47. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/grpdelay.py +0 -0
  48. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/histogram.py +0 -0
  49. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/ialaw.py +0 -0
  50. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/icqt.py +0 -0
  51. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/idct.py +0 -0
  52. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/ifreqt2.py +0 -0
  53. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/ignorm.py +0 -0
  54. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/imsvq.py +0 -0
  55. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/interpolate.py +0 -0
  56. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/ipqmf.py +0 -0
  57. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/istft.py +0 -0
  58. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/iulaw.py +0 -0
  59. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/ivq.py +0 -0
  60. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/lar2par.py +0 -0
  61. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/lbg.py +0 -0
  62. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/linear_intpl.py +0 -0
  63. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/lpc.py +0 -0
  64. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/lpc2lsp.py +0 -0
  65. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/lpc2par.py +0 -0
  66. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/lpccheck.py +0 -0
  67. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/lsp2lpc.py +0 -0
  68. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/lsp2sp.py +0 -0
  69. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/lspcheck.py +0 -0
  70. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/magic_intpl.py +0 -0
  71. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/mc2b.py +0 -0
  72. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/mcep.py +0 -0
  73. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/mcpf.py +0 -0
  74. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/mfcc.py +0 -0
  75. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/mgc2mgc.py +0 -0
  76. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/mgc2sp.py +0 -0
  77. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/mgcep.py +0 -0
  78. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/mlpg.py +0 -0
  79. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/mlsacheck.py +0 -0
  80. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/mpir2c.py +0 -0
  81. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/msvq.py +0 -0
  82. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/ndps2c.py +0 -0
  83. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/norm0.py +0 -0
  84. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/par2lar.py +0 -0
  85. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/par2lpc.py +0 -0
  86. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/pca.py +0 -0
  87. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/phase.py +0 -0
  88. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/pitch.py +0 -0
  89. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/plp.py +0 -0
  90. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/pol_root.py +0 -0
  91. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/pqmf.py +0 -0
  92. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/quantize.py +0 -0
  93. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/rlevdur.py +0 -0
  94. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/rmse.py +0 -0
  95. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/root_pol.py +0 -0
  96. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/smcep.py +0 -0
  97. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/snr.py +0 -0
  98. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/spec.py +0 -0
  99. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/stft.py +0 -0
  100. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/ulaw.py +0 -0
  101. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/unframe.py +0 -0
  102. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/vq.py +0 -0
  103. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/window.py +0 -0
  104. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/yingram.py +0 -0
  105. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/zcross.py +0 -0
  106. {diffsptk-2.0.1 → diffsptk-2.1.1}/diffsptk/modules/zerodf.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: diffsptk
3
- Version: 2.0.1
3
+ Version: 2.1.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/latest/
@@ -20,16 +20,19 @@ Classifier: Programming Language :: Python :: 3.11
20
20
  Classifier: Programming Language :: Python :: 3.12
21
21
  Requires-Python: >=3.8
22
22
  Requires-Dist: librosa>=0.10.1
23
- Requires-Dist: numpy
23
+ Requires-Dist: numpy<2.0.0,>=1.20.3
24
+ Requires-Dist: scipy<1.14.0,>=1.0.0
24
25
  Requires-Dist: soundfile>=0.10.2
25
26
  Requires-Dist: torch>=1.11.0
26
27
  Requires-Dist: torchaudio>=0.11.0
28
+ Requires-Dist: torchcomp>=0.1.1
27
29
  Requires-Dist: torchcrepe>=0.0.21
28
- Requires-Dist: torchlpc>=0.2.0
30
+ Requires-Dist: torchlpc<0.5.0,>=0.2.0
29
31
  Requires-Dist: vector-quantize-pytorch<=1.12.12,>=0.8.0
30
32
  Provides-Extra: dev
31
33
  Requires-Dist: build; extra == 'dev'
32
34
  Requires-Dist: isort; extra == 'dev'
35
+ Requires-Dist: mdformat; extra == 'dev'
33
36
  Requires-Dist: numpydoc; extra == 'dev'
34
37
  Requires-Dist: pydata-sphinx-theme; extra == 'dev'
35
38
  Requires-Dist: pytest; extra == 'dev'
@@ -39,49 +42,49 @@ Requires-Dist: sphinx; extra == 'dev'
39
42
  Requires-Dist: twine; extra == 'dev'
40
43
  Description-Content-Type: text/markdown
41
44
 
42
- diffsptk
43
- ========
45
+ # diffsptk
46
+
44
47
  *diffsptk* is a differentiable version of [SPTK](https://github.com/sp-nitech/SPTK) based on the PyTorch framework.
45
48
 
46
49
  [![Latest Manual](https://img.shields.io/badge/docs-latest-blue.svg)](https://sp-nitech.github.io/diffsptk/latest/)
47
- [![Stable Manual](https://img.shields.io/badge/docs-stable-blue.svg)](https://sp-nitech.github.io/diffsptk/2.0.1/)
50
+ [![Stable Manual](https://img.shields.io/badge/docs-stable-blue.svg)](https://sp-nitech.github.io/diffsptk/2.1.1/)
48
51
  [![Downloads](https://static.pepy.tech/badge/diffsptk)](https://pepy.tech/project/diffsptk)
49
52
  [![Python Version](https://img.shields.io/pypi/pyversions/diffsptk.svg)](https://pypi.python.org/pypi/diffsptk)
50
- [![PyTorch Version](https://img.shields.io/badge/pytorch-1.11.0%20%7C%202.3.0-orange.svg)](https://pypi.python.org/pypi/diffsptk)
53
+ [![PyTorch Version](https://img.shields.io/badge/pytorch-1.12.0%20%7C%202.3.1-orange.svg)](https://pypi.python.org/pypi/diffsptk)
51
54
  [![PyPI Version](https://img.shields.io/pypi/v/diffsptk.svg)](https://pypi.python.org/pypi/diffsptk)
52
55
  [![Codecov](https://codecov.io/gh/sp-nitech/diffsptk/branch/master/graph/badge.svg)](https://app.codecov.io/gh/sp-nitech/diffsptk)
53
56
  [![License](https://img.shields.io/github/license/sp-nitech/diffsptk.svg)](https://github.com/sp-nitech/diffsptk/blob/master/LICENSE)
54
57
  [![GitHub Actions](https://github.com/sp-nitech/diffsptk/workflows/package/badge.svg)](https://github.com/sp-nitech/diffsptk/actions)
55
58
  [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
56
59
 
60
+ ## Requirements
57
61
 
58
- Requirements
59
- ------------
60
62
  - Python 3.8+
61
- - PyTorch 1.11.0+
63
+ - PyTorch 1.12.0+
62
64
 
65
+ ## Documentation
63
66
 
64
- Documentation
65
- -------------
66
67
  - See [this page](https://sp-nitech.github.io/diffsptk/latest/) for a reference manual.
67
68
  - Our [paper](https://www.isca-speech.org/archive/ssw_2023/yoshimura23_ssw.html) is available on the ISCA Archive.
68
69
 
70
+ ## Installation
69
71
 
70
- Installation
71
- ------------
72
72
  The latest stable release can be installed through PyPI by running
73
+
73
74
  ```sh
74
75
  pip install diffsptk
75
76
  ```
77
+
76
78
  The development release can be installed from the master branch:
79
+
77
80
  ```sh
78
81
  pip install git+https://github.com/sp-nitech/diffsptk.git@master
79
82
  ```
80
83
 
84
+ ## Examples
81
85
 
82
- Examples
83
- --------
84
86
  ### Mel-cepstral analysis and synthesis
87
+
85
88
  ```python
86
89
  import diffsptk
87
90
 
@@ -132,6 +135,7 @@ diffsptk.write("unvoiced.wav", x_unvoiced, sr)
132
135
  ```
133
136
 
134
137
  ### Mel-spectrogram, MFCC, and PLP extraction
138
+
135
139
  ```python
136
140
  import diffsptk
137
141
 
@@ -149,7 +153,7 @@ stft = diffsptk.STFT(frame_length=fl, frame_period=fp, fft_length=n_fft)
149
153
  X = stft(x)
150
154
 
151
155
  # Extract mel-spectrogram.
152
- fbank = diffsptk.MelFilterBankAnalysis(
156
+ fbank = diffsptk.FBANK(
153
157
  n_channel=n_channel,
154
158
  fft_length=n_fft,
155
159
  sample_rate=sr,
@@ -179,6 +183,7 @@ print(Y.shape)
179
183
  ```
180
184
 
181
185
  ### Subband decomposition
186
+
182
187
  ```python
183
188
  import diffsptk
184
189
 
@@ -191,12 +196,12 @@ x, sr = diffsptk.read("assets/data.wav")
191
196
  # Decompose x.
192
197
  pqmf = diffsptk.PQMF(K, M)
193
198
  decimate = diffsptk.Decimation(K)
194
- y = decimate(pqmf(x), dim=-1)
199
+ y = decimate(pqmf(x))
195
200
 
196
201
  # Reconstruct x.
197
202
  interpolate = diffsptk.Interpolation(K)
198
203
  ipqmf = diffsptk.IPQMF(K, M)
199
- x_hat = ipqmf(interpolate(K * y, dim=-1)).reshape(-1)
204
+ x_hat = ipqmf(interpolate(K * y)).reshape(-1)
200
205
 
201
206
  # Write reconstructed waveform.
202
207
  diffsptk.write("reconst.wav", x_hat, sr)
@@ -207,6 +212,7 @@ print(error)
207
212
  ```
208
213
 
209
214
  ### Constant-Q transform
215
+
210
216
  ```python
211
217
  import diffsptk
212
218
  import librosa # This is to get sample audio.
@@ -235,6 +241,7 @@ print(error)
235
241
  ```
236
242
 
237
243
  ### Vector quantization
244
+
238
245
  ```python
239
246
  import diffsptk
240
247
 
@@ -253,14 +260,12 @@ error = (x_hat - x).abs().sum()
253
260
  print(error)
254
261
  ```
255
262
 
263
+ ## License
256
264
 
257
- License
258
- -------
259
265
  This software is released under the Apache License 2.0.
260
266
 
267
+ ## Citation
261
268
 
262
- Citation
263
- --------
264
269
  ```bibtex
265
270
  @InProceedings{sp-nitech2023sptk,
266
271
  author = {Takenori Yoshimura and Takato Fujimoto and Keiichiro Oura and Keiichi Tokuda},
@@ -1,46 +1,46 @@
1
- diffsptk
2
- ========
1
+ # diffsptk
2
+
3
3
  *diffsptk* is a differentiable version of [SPTK](https://github.com/sp-nitech/SPTK) based on the PyTorch framework.
4
4
 
5
5
  [![Latest Manual](https://img.shields.io/badge/docs-latest-blue.svg)](https://sp-nitech.github.io/diffsptk/latest/)
6
- [![Stable Manual](https://img.shields.io/badge/docs-stable-blue.svg)](https://sp-nitech.github.io/diffsptk/2.0.1/)
6
+ [![Stable Manual](https://img.shields.io/badge/docs-stable-blue.svg)](https://sp-nitech.github.io/diffsptk/2.1.1/)
7
7
  [![Downloads](https://static.pepy.tech/badge/diffsptk)](https://pepy.tech/project/diffsptk)
8
8
  [![Python Version](https://img.shields.io/pypi/pyversions/diffsptk.svg)](https://pypi.python.org/pypi/diffsptk)
9
- [![PyTorch Version](https://img.shields.io/badge/pytorch-1.11.0%20%7C%202.3.0-orange.svg)](https://pypi.python.org/pypi/diffsptk)
9
+ [![PyTorch Version](https://img.shields.io/badge/pytorch-1.12.0%20%7C%202.3.1-orange.svg)](https://pypi.python.org/pypi/diffsptk)
10
10
  [![PyPI Version](https://img.shields.io/pypi/v/diffsptk.svg)](https://pypi.python.org/pypi/diffsptk)
11
11
  [![Codecov](https://codecov.io/gh/sp-nitech/diffsptk/branch/master/graph/badge.svg)](https://app.codecov.io/gh/sp-nitech/diffsptk)
12
12
  [![License](https://img.shields.io/github/license/sp-nitech/diffsptk.svg)](https://github.com/sp-nitech/diffsptk/blob/master/LICENSE)
13
13
  [![GitHub Actions](https://github.com/sp-nitech/diffsptk/workflows/package/badge.svg)](https://github.com/sp-nitech/diffsptk/actions)
14
14
  [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
15
15
 
16
+ ## Requirements
16
17
 
17
- Requirements
18
- ------------
19
18
  - Python 3.8+
20
- - PyTorch 1.11.0+
19
+ - PyTorch 1.12.0+
21
20
 
21
+ ## Documentation
22
22
 
23
- Documentation
24
- -------------
25
23
  - See [this page](https://sp-nitech.github.io/diffsptk/latest/) for a reference manual.
26
24
  - Our [paper](https://www.isca-speech.org/archive/ssw_2023/yoshimura23_ssw.html) is available on the ISCA Archive.
27
25
 
26
+ ## Installation
28
27
 
29
- Installation
30
- ------------
31
28
  The latest stable release can be installed through PyPI by running
29
+
32
30
  ```sh
33
31
  pip install diffsptk
34
32
  ```
33
+
35
34
  The development release can be installed from the master branch:
35
+
36
36
  ```sh
37
37
  pip install git+https://github.com/sp-nitech/diffsptk.git@master
38
38
  ```
39
39
 
40
+ ## Examples
40
41
 
41
- Examples
42
- --------
43
42
  ### Mel-cepstral analysis and synthesis
43
+
44
44
  ```python
45
45
  import diffsptk
46
46
 
@@ -91,6 +91,7 @@ diffsptk.write("unvoiced.wav", x_unvoiced, sr)
91
91
  ```
92
92
 
93
93
  ### Mel-spectrogram, MFCC, and PLP extraction
94
+
94
95
  ```python
95
96
  import diffsptk
96
97
 
@@ -108,7 +109,7 @@ stft = diffsptk.STFT(frame_length=fl, frame_period=fp, fft_length=n_fft)
108
109
  X = stft(x)
109
110
 
110
111
  # Extract mel-spectrogram.
111
- fbank = diffsptk.MelFilterBankAnalysis(
112
+ fbank = diffsptk.FBANK(
112
113
  n_channel=n_channel,
113
114
  fft_length=n_fft,
114
115
  sample_rate=sr,
@@ -138,6 +139,7 @@ print(Y.shape)
138
139
  ```
139
140
 
140
141
  ### Subband decomposition
142
+
141
143
  ```python
142
144
  import diffsptk
143
145
 
@@ -150,12 +152,12 @@ x, sr = diffsptk.read("assets/data.wav")
150
152
  # Decompose x.
151
153
  pqmf = diffsptk.PQMF(K, M)
152
154
  decimate = diffsptk.Decimation(K)
153
- y = decimate(pqmf(x), dim=-1)
155
+ y = decimate(pqmf(x))
154
156
 
155
157
  # Reconstruct x.
156
158
  interpolate = diffsptk.Interpolation(K)
157
159
  ipqmf = diffsptk.IPQMF(K, M)
158
- x_hat = ipqmf(interpolate(K * y, dim=-1)).reshape(-1)
160
+ x_hat = ipqmf(interpolate(K * y)).reshape(-1)
159
161
 
160
162
  # Write reconstructed waveform.
161
163
  diffsptk.write("reconst.wav", x_hat, sr)
@@ -166,6 +168,7 @@ print(error)
166
168
  ```
167
169
 
168
170
  ### Constant-Q transform
171
+
169
172
  ```python
170
173
  import diffsptk
171
174
  import librosa # This is to get sample audio.
@@ -194,6 +197,7 @@ print(error)
194
197
  ```
195
198
 
196
199
  ### Vector quantization
200
+
197
201
  ```python
198
202
  import diffsptk
199
203
 
@@ -212,14 +216,12 @@ error = (x_hat - x).abs().sum()
212
216
  print(error)
213
217
  ```
214
218
 
219
+ ## License
215
220
 
216
- License
217
- -------
218
221
  This software is released under the Apache License 2.0.
219
222
 
223
+ ## Citation
220
224
 
221
- Citation
222
- --------
223
225
  ```bibtex
224
226
  @InProceedings{sp-nitech2023sptk,
225
227
  author = {Takenori Yoshimura and Takato Fujimoto and Keiichiro Oura and Keiichi Tokuda},
@@ -45,6 +45,23 @@ def acorr(x, acr_order, norm=False, estimator="none"):
45
45
  )
46
46
 
47
47
 
48
+ def acr2csm(r):
49
+ """Convert autocorrelation to CSM coefficients.
50
+
51
+ Parameters
52
+ ----------
53
+ r : Tensor [shape=(..., M+1)]
54
+ Autocorrelation.
55
+
56
+ Returns
57
+ -------
58
+ out : Tensor [shape=(..., M+1)]
59
+ CSM coefficients.
60
+
61
+ """
62
+ return nn.AutocorrelationToCompositeSinusoidalModelCoefficients._func(r)
63
+
64
+
48
65
  def alaw(x, abs_max=1, a=87.6):
49
66
  """Compress waveform by A-law algorithm.
50
67
 
@@ -187,6 +204,23 @@ def cdist(c1, c2, full=False, reduction="mean", eps=1e-8):
187
204
  return nn.CepstralDistance._func(c1, c2, full=full, reduction=reduction, eps=eps)
188
205
 
189
206
 
207
+ def csm2acr(c):
208
+ """Convert CSM coefficients to autocorrelation.
209
+
210
+ Parameters
211
+ ----------
212
+ c : Tensor [shape=(..., M+1)]
213
+ CSM coefficients.
214
+
215
+ Returns
216
+ -------
217
+ out : Tensor [shape=(..., M+1)]
218
+ Autocorrelation.
219
+
220
+ """
221
+ return nn.CompositeSinusoidalModelCoefficientsToAutocorrelation._func(c)
222
+
223
+
190
224
  def dct(x):
191
225
  """Compute DCT.
192
226
 
@@ -330,6 +364,62 @@ def dfs(x, b=None, a=None):
330
364
  return nn.InfiniteImpulseResponseDigitalFilter._func(x, b=b, a=a)
331
365
 
332
366
 
367
+ def drc(
368
+ x,
369
+ threshold,
370
+ ratio,
371
+ attack_time,
372
+ release_time,
373
+ sample_rate,
374
+ makeup_gain=0,
375
+ abs_max=1,
376
+ ):
377
+ """Apply dynamic range compression.
378
+
379
+ Parameters
380
+ ----------
381
+ x : Tensor [shape=(..., T)]
382
+ Input signal.
383
+
384
+ threshold : float <= 0
385
+ Threshold in dB.
386
+
387
+ ratio : float > 1
388
+ Input/output ratio.
389
+
390
+ attack_time : float > 0
391
+ Attack time in msec.
392
+
393
+ release_time : float > 0
394
+ Release time in msec.
395
+
396
+ sample_rate : int >= 1
397
+ Sample rate in Hz.
398
+
399
+ makeup_gain : float >= 0
400
+ Make-up gain in dB.
401
+
402
+ abs_max : float > 0
403
+ Absolute maximum value of input.
404
+
405
+ Returns
406
+ -------
407
+ out : Tensor [shape=(..., T)]
408
+ Compressed signal.
409
+
410
+ """
411
+ return nn.DynamicRangeCompression._func(
412
+ x,
413
+ threshold=threshold,
414
+ ratio=ratio,
415
+ attack_time=attack_time,
416
+ release_time=release_time,
417
+ sample_rate=sample_rate,
418
+ makeup_gain=makeup_gain,
419
+ abs_max=abs_max,
420
+ )
421
+
422
+
333
423
  def entropy(p, out_format="nat"):
334
424
  """Calculate entropy.
335
425
 
@@ -82,6 +82,11 @@ def to(x, dtype=None):
82
82
  return x.to(dtype=dtype)
83
83
 
84
84
 
85
+ def to_2d(x):
86
+ y = x.view(-1, x.size(-1))
87
+ return y
88
+
89
+
85
90
  def to_3d(x):
86
91
  y = x.view(-1, 1, x.size(-1))
87
92
  return y
@@ -103,9 +108,9 @@ def replicate1(x, left=True, right=True):
103
108
  return y
104
109
 
105
110
 
106
- def remove_gain(a, return_gain=False):
111
+ def remove_gain(a, value=1, return_gain=False):
107
112
  K, a1 = torch.split(a, [1, a.size(-1) - 1], dim=-1)
108
- a = F.pad(a1, (1, 0), value=1)
113
+ a = F.pad(a1, (1, 0), value=value)
109
114
  if return_gain:
110
115
  ret = (K, a)
111
116
  else:
@@ -211,8 +216,13 @@ def symmetric_toeplitz(x):
211
216
 
212
217
  def hankel(x):
213
218
  d = x.size(-1)
214
- assert d % 2 == 1
215
- X = x.unfold(-1, (d + 1) // 2, 1)
219
+ n = (d + 1) // 2
220
+ X = x.unfold(-1, n, 1)[..., :n, :]
221
+ return X
222
+
223
+
224
+ def vander(x):
225
+ X = torch.linalg.vander(x).transpose(-2, -1)
216
226
  return X
217
227
 
218
228
 
@@ -1,4 +1,5 @@
1
1
  from .acorr import Autocorrelation
2
+ from .acr2csm import AutocorrelationToCompositeSinusoidalModelCoefficients
2
3
  from .alaw import ALawCompression
3
4
  from .ap import Aperiodicity
4
5
  from .b2mc import MLSADigitalFilterCoefficientsToMelCepstrum
@@ -8,6 +9,7 @@ from .c2ndps import CepstrumToNegativeDerivativeOfPhaseSpectrum
8
9
  from .cdist import CepstralDistance
9
10
  from .cqt import ConstantQTransform
10
11
  from .cqt import ConstantQTransform as CQT
12
+ from .csm2acr import CompositeSinusoidalModelCoefficientsToAutocorrelation
11
13
  from .dct import DiscreteCosineTransform
12
14
  from .dct import DiscreteCosineTransform as DCT
13
15
  from .decimate import Decimation
@@ -17,6 +19,8 @@ from .dequantize import InverseUniformQuantization
17
19
  from .df2 import SecondOrderDigitalFilter
18
20
  from .dfs import InfiniteImpulseResponseDigitalFilter
19
21
  from .dfs import InfiniteImpulseResponseDigitalFilter as IIR
22
+ from .drc import DynamicRangeCompression
23
+ from .drc import DynamicRangeCompression as DRC
20
24
  from .entropy import Entropy
21
25
  from .excite import ExcitationGeneration
22
26
  from .fbank import MelFilterBankAnalysis
@@ -0,0 +1,118 @@
1
+ # ------------------------------------------------------------------------ #
2
+ # Copyright 2022 SPTK Working Group #
3
+ # #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); #
5
+ # you may not use this file except in compliance with the License. #
6
+ # You may obtain a copy of the License at #
7
+ # #
8
+ # http://www.apache.org/licenses/LICENSE-2.0 #
9
+ # #
10
+ # Unless required by applicable law or agreed to in writing, software #
11
+ # distributed under the License is distributed on an "AS IS" BASIS, #
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
+ # See the License for the specific language governing permissions and #
14
+ # limitations under the License. #
15
+ # ------------------------------------------------------------------------ #
16
+
17
+ from scipy.special import comb
18
+ import torch
19
+ from torch import nn
20
+ import torch.nn.functional as F
21
+
22
+ from ..misc.utils import check_size
23
+ from ..misc.utils import hankel
24
+ from ..misc.utils import to
25
+ from ..misc.utils import vander
26
+ from .root_pol import PolynomialToRoots
27
+
28
+
29
+ class AutocorrelationToCompositeSinusoidalModelCoefficients(nn.Module):
30
+ """See `this page <https://sp-nitech.github.io/sptk/latest/main/acr2csm.html>`_
31
+ for details.
32
+
33
+ Parameters
34
+ ----------
35
+ csm_order : int >= 0
36
+ Order of CSM coefficients, :math:`M`.
37
+
38
+ """
39
+
40
+ def __init__(self, csm_order):
41
+ super().__init__()
42
+
43
+ assert 0 <= csm_order <= 30 # This is due to computational accuracy.
44
+ assert csm_order % 2 == 1
45
+
46
+ self.csm_order = csm_order
47
+ self.register_buffer("C", self._precompute(self.csm_order))
48
+
49
+ def forward(self, r):
50
+ """Convert autocorrelation to CSM coefficients.
51
+
52
+ Parameters
53
+ ----------
54
+ r : Tensor [shape=(..., M+1)]
55
+ Autocorrelation.
56
+
57
+ Returns
58
+ -------
59
+ out : Tensor [shape=(..., M+1)]
60
+ Composite sinusoidal model coefficients.
61
+
62
+ Examples
63
+ --------
64
+ >>> x = diffsptk.nrand(4)
65
+ >>> x
66
+ tensor([ 0.0165, -2.3693, 0.1375, -0.2262, 1.3307])
67
+ >>> acorr = diffsptk.Autocorrelation(5, 3)
68
+ >>> acr2csm = diffsptk.AutocorrelationToCompositeSinusoidalModelCoefficients(3)
69
+ >>> c = acr2csm(acorr(x))
70
+ >>> c
71
+ tensor([0.9028, 2.5877, 3.8392, 3.6153])
72
+
73
+ """
74
+ check_size(r.size(-1), self.csm_order + 1, "dimension of autocorrelation")
75
+ return self._forward(r, self.C)
76
+
77
+ @staticmethod
78
+ def _forward(r, C):
79
+ u = torch.matmul(r, C)
80
+ u1, u2 = torch.tensor_split(u, 2, dim=-1)
81
+
82
+ U = hankel(-u)
83
+ p = torch.matmul(U.inverse(), u2.unsqueeze(-1)).squeeze(-1)
84
+ x = PolynomialToRoots._func(F.pad(p.flip(-1), (1, 0), value=1))
85
+ x, _ = torch.sort(x.real, descending=True)
86
+ w = torch.acos(x)
87
+
88
+ V = vander(x)
89
+ m = torch.matmul(V.inverse(), u1.unsqueeze(-1)).squeeze(-1)
90
+ c = torch.cat((w, m), dim=-1)
91
+ return c
92
+
93
+ @staticmethod
94
+ def _func(r):
95
+ C = AutocorrelationToCompositeSinusoidalModelCoefficients._precompute(
96
+ r.size(-1) - 1, dtype=r.dtype, device=r.device
97
+ )
98
+ return AutocorrelationToCompositeSinusoidalModelCoefficients._forward(r, C)
99
+
100
+ @staticmethod
101
+ def _precompute(csm_order, dtype=None, device=None):
102
+ N = csm_order + 1
103
+ B = torch.zeros((N, N), dtype=torch.double, device=device)
104
+ for n in range(N):
105
+ z = 2**-n
106
+ for k in range(n + 1):
107
+ B[k, n] = comb(n, k, exact=True) * z
108
+
109
+ C = torch.zeros((N, N), dtype=torch.double, device=device)
110
+ for k in range(N):
111
+ bias = k % 2
112
+ center = k // 2
113
+ length = center + 1
114
+ C[bias : bias + 2 * length : 2, k] = B[
115
+ bias + center : bias + center + length, k
116
+ ]
117
+ C[1:] *= 2
118
+ return to(C, dtype=dtype)
@@ -0,0 +1,92 @@
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
+ from torch import nn
19
+
20
+ from ..misc.utils import check_size
21
+ from ..misc.utils import to
22
+
23
+
24
+ class CompositeSinusoidalModelCoefficientsToAutocorrelation(nn.Module):
25
+ """See `this page <https://sp-nitech.github.io/sptk/latest/main/csm2acr.html>`_
26
+ for details.
27
+
28
+ Parameters
29
+ ----------
30
+ csm_order : int >= 0
31
+ Order of CSM coefficients, :math:`M`.
32
+
33
+ """
34
+
35
+ def __init__(self, csm_order):
36
+ super().__init__()
37
+
38
+ assert 1 <= csm_order
39
+ assert csm_order % 2 == 1
40
+
41
+ self.csm_order = csm_order
42
+ self.register_buffer("ramp", self._precompute(self.csm_order))
43
+
44
+ def forward(self, c):
45
+ """Convert CSM coefficients to autocorrelation.
46
+
47
+ Parameters
48
+ ----------
49
+ c : Tensor [shape=(..., M+1)]
50
+ Composite sinusoidal model coefficients.
51
+
52
+ Returns
53
+ -------
54
+ out : Tensor [shape=(..., M+1)]
55
+ Autocorrelation.
56
+
57
+ Examples
58
+ --------
59
+ >>> x = diffsptk.nrand(4)
60
+ >>> acorr = diffsptk.Autocorrelation(5, 3)
61
+ >>> acr2csm = diffsptk.AutocorrelationToCompositeSinusoidalModelCoefficients(3)
62
+ >>> csm2acr = diffsptk.CompositeSinusoidalModelCoefficientsToAutocorrelation(3)
63
+ >>> r = acorr(x)
64
+ >>> r
65
+ tensor([ 8.8894, -0.1102, -4.1748, 0.7501])
66
+ >>> r2 = csm2acr(acr2csm(r))
67
+ >>> r2
68
+ tensor([ 8.8894, -0.1102, -4.1748, 0.7501])
69
+
70
+ """
71
+ check_size(c.size(-1), self.csm_order + 1, "dimension of autocorrelation")
72
+ return self._forward(c, self.ramp)
73
+
74
+ @staticmethod
75
+ def _forward(c, ramp):
76
+ w, m = torch.tensor_split(c, 2, dim=-1)
77
+ a = m.unsqueeze(-2)
78
+ b = torch.cos(w.unsqueeze(-1) * ramp)
79
+ r = torch.matmul(a, b).squeeze(-2)
80
+ return r
81
+
82
+ @staticmethod
83
+ def _func(c):
84
+ ramp = CompositeSinusoidalModelCoefficientsToAutocorrelation._precompute(
85
+ c.size(-1) - 1, dtype=c.dtype, device=c.device
86
+ )
87
+ return CompositeSinusoidalModelCoefficientsToAutocorrelation._forward(c, ramp)
88
+
89
+ @staticmethod
90
+ def _precompute(csm_order, dtype=None, device=None):
91
+ ramp = torch.arange(csm_order + 1, device=device)
92
+ return to(ramp, dtype=dtype)