diffsptk 2.2.0__tar.gz → 2.3.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.
Files changed (125) hide show
  1. {diffsptk-2.2.0 → diffsptk-2.3.0}/.gitignore +0 -3
  2. {diffsptk-2.2.0 → diffsptk-2.3.0}/PKG-INFO +28 -4
  3. {diffsptk-2.2.0 → diffsptk-2.3.0}/README.md +26 -2
  4. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/functional.py +162 -22
  5. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/misc/signals.py +5 -2
  6. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/misc/utils.py +77 -9
  7. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/__init__.py +17 -4
  8. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/acr2csm.py +5 -0
  9. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/ap.py +6 -0
  10. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/b2mc.py +6 -0
  11. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/c2ndps.py +5 -0
  12. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/cdist.py +10 -9
  13. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/cqt.py +7 -0
  14. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/csm2acr.py +5 -0
  15. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/dct.py +32 -7
  16. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/decimate.py +0 -3
  17. diffsptk-2.3.0/diffsptk/modules/dht.py +95 -0
  18. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/drc.py +1 -1
  19. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/dst.py +30 -8
  20. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/excite.py +91 -19
  21. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/fbank.py +3 -2
  22. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/fftcep.py +5 -0
  23. diffsptk-2.3.0/diffsptk/modules/flux.py +106 -0
  24. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/freqt.py +5 -0
  25. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/freqt2.py +6 -0
  26. diffsptk-2.3.0/diffsptk/modules/gammatone.py +225 -0
  27. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/gmm.py +144 -87
  28. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/gnorm.py +6 -0
  29. diffsptk-2.3.0/diffsptk/modules/hilbert.py +96 -0
  30. diffsptk-2.3.0/diffsptk/modules/hilbert2.py +105 -0
  31. diffsptk-2.3.0/diffsptk/modules/ica.py +180 -0
  32. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/icqt.py +8 -0
  33. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/idct.py +13 -6
  34. diffsptk-2.3.0/diffsptk/modules/idht.py +88 -0
  35. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/idst.py +13 -6
  36. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/ifreqt2.py +6 -0
  37. diffsptk-2.3.0/diffsptk/modules/igammatone.py +203 -0
  38. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/ignorm.py +6 -0
  39. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/imsvq.py +5 -0
  40. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/ipqmf.py +10 -1
  41. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/ivq.py +5 -0
  42. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/lbg.py +91 -46
  43. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/lpc2lsp.py +6 -0
  44. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/lsp2sp.py +8 -0
  45. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/lspcheck.py +2 -2
  46. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/mc2b.py +6 -0
  47. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/mcpf.py +6 -0
  48. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/mgc2mgc.py +5 -0
  49. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/mglsadf.py +6 -3
  50. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/mlsacheck.py +7 -1
  51. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/msvq.py +5 -0
  52. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/ndps2c.py +5 -0
  53. diffsptk-2.3.0/diffsptk/modules/nmf.py +245 -0
  54. diffsptk-2.3.0/diffsptk/modules/pca.py +211 -0
  55. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/phase.py +1 -1
  56. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/poledf.py +1 -1
  57. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/pqmf.py +10 -1
  58. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/rmse.py +7 -11
  59. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/smcep.py +6 -0
  60. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/spec.py +1 -1
  61. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/vq.py +5 -0
  62. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/zcross.py +1 -1
  63. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/zerodf.py +1 -1
  64. diffsptk-2.3.0/diffsptk/version.py +1 -0
  65. {diffsptk-2.2.0 → diffsptk-2.3.0}/pyproject.toml +3 -1
  66. diffsptk-2.2.0/diffsptk/modules/pca.py +0 -130
  67. diffsptk-2.2.0/diffsptk/version.py +0 -1
  68. {diffsptk-2.2.0 → diffsptk-2.3.0}/CITATION.cff +0 -0
  69. {diffsptk-2.2.0 → diffsptk-2.3.0}/LICENSE +0 -0
  70. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/__init__.py +0 -0
  71. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/misc/__init__.py +0 -0
  72. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/acorr.py +0 -0
  73. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/alaw.py +0 -0
  74. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/c2acr.py +0 -0
  75. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/c2mpir.py +0 -0
  76. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/chroma.py +0 -0
  77. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/delay.py +0 -0
  78. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/delta.py +0 -0
  79. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/dequantize.py +0 -0
  80. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/df2.py +0 -0
  81. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/dfs.py +0 -0
  82. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/entropy.py +0 -0
  83. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/frame.py +0 -0
  84. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/grpdelay.py +0 -0
  85. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/histogram.py +0 -0
  86. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/ialaw.py +0 -0
  87. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/imdct.py +0 -0
  88. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/imdst.py +0 -0
  89. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/imglsadf.py +0 -0
  90. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/interpolate.py +0 -0
  91. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/ipnorm.py +0 -0
  92. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/istft.py +0 -0
  93. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/iulaw.py +0 -0
  94. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/lar2par.py +0 -0
  95. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/levdur.py +0 -0
  96. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/linear_intpl.py +0 -0
  97. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/lpc.py +0 -0
  98. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/lpc2par.py +0 -0
  99. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/lpccheck.py +0 -0
  100. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/lsp2lpc.py +0 -0
  101. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/magic_intpl.py +0 -0
  102. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/mcep.py +0 -0
  103. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/mdct.py +0 -0
  104. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/mdst.py +0 -0
  105. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/mfcc.py +0 -0
  106. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/mgc2sp.py +0 -0
  107. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/mgcep.py +0 -0
  108. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/mlpg.py +0 -0
  109. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/mpir2c.py +0 -0
  110. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/norm0.py +0 -0
  111. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/par2lar.py +0 -0
  112. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/par2lpc.py +0 -0
  113. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/pitch.py +0 -0
  114. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/plp.py +0 -0
  115. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/pnorm.py +0 -0
  116. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/pol_root.py +0 -0
  117. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/quantize.py +0 -0
  118. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/rlevdur.py +0 -0
  119. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/root_pol.py +0 -0
  120. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/snr.py +0 -0
  121. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/stft.py +0 -0
  122. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/ulaw.py +0 -0
  123. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/unframe.py +0 -0
  124. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/window.py +0 -0
  125. {diffsptk-2.2.0 → diffsptk-2.3.0}/diffsptk/modules/yingram.py +0 -0
@@ -9,9 +9,6 @@ coverage.xml
9
9
  # docs
10
10
  _build/
11
11
 
12
- # tests
13
- *.wav
14
-
15
12
  # tools
16
13
  tools/**/
17
14
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: diffsptk
3
- Version: 2.2.0
3
+ Version: 2.3.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/latest/
@@ -25,7 +25,7 @@ Requires-Dist: soundfile>=0.10.2
25
25
  Requires-Dist: torch>=2.0.0
26
26
  Requires-Dist: torchaudio>=2.0.1
27
27
  Requires-Dist: torchcomp>=0.1.0
28
- Requires-Dist: torchcrepe>=0.0.21
28
+ Requires-Dist: torchcrepe>=0.0.22
29
29
  Requires-Dist: torchlpc>=0.2.0
30
30
  Requires-Dist: tqdm>=4.15.0
31
31
  Requires-Dist: vector-quantize-pytorch>=1.14.9
@@ -48,10 +48,10 @@ Description-Content-Type: text/markdown
48
48
  *diffsptk* is a differentiable version of [SPTK](https://github.com/sp-nitech/SPTK) based on the PyTorch framework.
49
49
 
50
50
  [![Latest Manual](https://img.shields.io/badge/docs-latest-blue.svg)](https://sp-nitech.github.io/diffsptk/latest/)
51
- [![Stable Manual](https://img.shields.io/badge/docs-stable-blue.svg)](https://sp-nitech.github.io/diffsptk/2.2.0/)
51
+ [![Stable Manual](https://img.shields.io/badge/docs-stable-blue.svg)](https://sp-nitech.github.io/diffsptk/2.3.0/)
52
52
  [![Downloads](https://static.pepy.tech/badge/diffsptk)](https://pepy.tech/project/diffsptk)
53
53
  [![Python Version](https://img.shields.io/pypi/pyversions/diffsptk.svg)](https://pypi.python.org/pypi/diffsptk)
54
- [![PyTorch Version](https://img.shields.io/badge/pytorch-2.0.0%20%7C%202.4.0-orange.svg)](https://pypi.python.org/pypi/diffsptk)
54
+ [![PyTorch Version](https://img.shields.io/badge/pytorch-2.0.0%20%7C%202.5.1-orange.svg)](https://pypi.python.org/pypi/diffsptk)
55
55
  [![PyPI Version](https://img.shields.io/pypi/v/diffsptk.svg)](https://pypi.python.org/pypi/diffsptk)
56
56
  [![Codecov](https://codecov.io/gh/sp-nitech/diffsptk/branch/master/graph/badge.svg)](https://app.codecov.io/gh/sp-nitech/diffsptk)
57
57
  [![License](https://img.shields.io/github/license/sp-nitech/diffsptk.svg)](https://github.com/sp-nitech/diffsptk/blob/master/LICENSE)
@@ -247,6 +247,30 @@ error = (x_hat - x).abs().sum()
247
247
  print(error)
248
248
  ```
249
249
 
250
+ ### Gammatone filter bank analysis and synthesis
251
+
252
+ ```python
253
+ import diffsptk
254
+
255
+ # Read waveform.
256
+ x, sr = diffsptk.read("assets/data.wav")
257
+
258
+ # Decompose x.
259
+ gammatone = diffsptk.GammatoneFilterBankAnalysis(sr)
260
+ y = gammatone(x)
261
+
262
+ # Reconstruct x.
263
+ igammatone = diffsptk.GammatoneFilterBankSynthesis(sr)
264
+ x_hat = igammatone(y).reshape(-1)
265
+
266
+ # Write reconstructed waveform.
267
+ diffsptk.write("reconst.wav", x_hat, sr)
268
+
269
+ # Compute error.
270
+ error = (x_hat - x).abs().sum()
271
+ print(error)
272
+ ```
273
+
250
274
  ### Constant-Q transform
251
275
 
252
276
  ```python
@@ -3,10 +3,10 @@
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.2.0/)
6
+ [![Stable Manual](https://img.shields.io/badge/docs-stable-blue.svg)](https://sp-nitech.github.io/diffsptk/2.3.0/)
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-2.0.0%20%7C%202.4.0-orange.svg)](https://pypi.python.org/pypi/diffsptk)
9
+ [![PyTorch Version](https://img.shields.io/badge/pytorch-2.0.0%20%7C%202.5.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)
@@ -202,6 +202,30 @@ error = (x_hat - x).abs().sum()
202
202
  print(error)
203
203
  ```
204
204
 
205
+ ### Gammatone filter bank analysis and synthesis
206
+
207
+ ```python
208
+ import diffsptk
209
+
210
+ # Read waveform.
211
+ x, sr = diffsptk.read("assets/data.wav")
212
+
213
+ # Decompose x.
214
+ gammatone = diffsptk.GammatoneFilterBankAnalysis(sr)
215
+ y = gammatone(x)
216
+
217
+ # Reconstruct x.
218
+ igammatone = diffsptk.GammatoneFilterBankSynthesis(sr)
219
+ x_hat = igammatone(y).reshape(-1)
220
+
221
+ # Write reconstructed waveform.
222
+ diffsptk.write("reconst.wav", x_hat, sr)
223
+
224
+ # Compute error.
225
+ error = (x_hat - x).abs().sum()
226
+ print(error)
227
+ ```
228
+
205
229
  ### Constant-Q transform
206
230
 
207
231
  ```python
@@ -175,7 +175,7 @@ def c2ndps(c, fft_length):
175
175
  )
176
176
 
177
177
 
178
- def cdist(c1, c2, full=False, reduction="mean", eps=1e-8):
178
+ def cdist(c1, c2, full=False, reduction="mean"):
179
179
  """Calculate cepstral distance between two inputs.
180
180
 
181
181
  Parameters
@@ -192,16 +192,13 @@ def cdist(c1, c2, full=False, reduction="mean", eps=1e-8):
192
192
  reduction : ['none', 'mean', 'batchmean', 'sum']
193
193
  Reduction type.
194
194
 
195
- eps : float >= 0
196
- A small value to prevent NaN.
197
-
198
195
  Returns
199
196
  -------
200
197
  out : Tensor [shape=(...,) or scalar]
201
198
  Cepstral distance.
202
199
 
203
200
  """
204
- return nn.CepstralDistance._func(c1, c2, full=full, reduction=reduction, eps=eps)
201
+ return nn.CepstralDistance._func(c1, c2, full=full, reduction=reduction)
205
202
 
206
203
 
207
204
  def chroma(x, n_channel, sample_rate, norm=float("inf")):
@@ -253,7 +250,7 @@ def csm2acr(c):
253
250
  return nn.CompositeSinusoidalModelCoefficientsToAutocorrelation._func(c)
254
251
 
255
252
 
256
- def dct(x):
253
+ def dct(x, dct_type=2):
257
254
  """Compute DCT.
258
255
 
259
256
  Parameters
@@ -261,13 +258,16 @@ def dct(x):
261
258
  x : Tensor [shape=(..., L)]
262
259
  Input signal.
263
260
 
261
+ dct_type : int in [1, 4]
262
+ DCT type.
263
+
264
264
  Returns
265
265
  -------
266
266
  out : Tensor [shape=(..., L)]
267
267
  DCT output.
268
268
 
269
269
  """
270
- return nn.DiscreteCosineTransform._func(x)
270
+ return nn.DiscreteCosineTransform._func(x, dct_type=dct_type)
271
271
 
272
272
 
273
273
  def decimate(x, period=1, start=0, dim=-1):
@@ -396,6 +396,26 @@ def dfs(x, b=None, a=None):
396
396
  return nn.InfiniteImpulseResponseDigitalFilter._func(x, b=b, a=a)
397
397
 
398
398
 
399
+ def dht(x, dht_type=2):
400
+ """Compute DHT.
401
+
402
+ Parameters
403
+ ----------
404
+ x : Tensor [shape=(..., L)]
405
+ Input signal.
406
+
407
+ dht_type : int in [1, 4]
408
+ DHT type.
409
+
410
+ Returns
411
+ -------
412
+ out : Tensor [shape=(..., L)]
413
+ DHT output.
414
+
415
+ """
416
+ return nn.DiscreteHartleyTransform._func(x, dht_type=dht_type)
417
+
418
+
399
419
  def drc(
400
420
  x,
401
421
  threshold,
@@ -452,7 +472,7 @@ def drc(
452
472
  )
453
473
 
454
474
 
455
- def dst(x):
475
+ def dst(x, dst_type=2):
456
476
  """Compute DST.
457
477
 
458
478
  Parameters
@@ -460,13 +480,16 @@ def dst(x):
460
480
  x : Tensor [shape=(..., L)]
461
481
  Input signal.
462
482
 
483
+ dst_type : int in [1, 4]
484
+ DST type.
485
+
463
486
  Returns
464
487
  -------
465
488
  out : Tensor [shape=(..., L)]
466
489
  DST output.
467
490
 
468
491
  """
469
- return nn.DiscreteSineTransform._func(x)
492
+ return nn.DiscreteSineTransform._func(x, dst_type=dst_type)
470
493
 
471
494
 
472
495
  def entropy(p, out_format="nat"):
@@ -489,7 +512,15 @@ def entropy(p, out_format="nat"):
489
512
  return nn.Entropy._func(p, out_format=out_format)
490
513
 
491
514
 
492
- def excite(p, frame_period=80, voiced_region="pulse", unvoiced_region="gauss"):
515
+ def excite(
516
+ p,
517
+ frame_period=80,
518
+ *,
519
+ voiced_region="pulse",
520
+ unvoiced_region="gauss",
521
+ polarity="auto",
522
+ init_phase="zeros",
523
+ ):
493
524
  """Generate a simple excitation signal.
494
525
 
495
526
  Parameters
@@ -500,12 +531,19 @@ def excite(p, frame_period=80, voiced_region="pulse", unvoiced_region="gauss"):
500
531
  frame_period : int >= 1
501
532
  Frame period in samples, :math:`P`.
502
533
 
503
- voiced_region : ['pulse', 'sinusoidal', 'sawtooth']
534
+ voiced_region : ['pulse', 'sinusoidal', 'sawtooth', 'inverted-sawtooth', \
535
+ 'triangle', 'square']
504
536
  Value on voiced region.
505
537
 
506
538
  unvoiced_region : ['gauss', 'zeros']
507
539
  Value on unvoiced region.
508
540
 
541
+ polarity : ['auto', 'unipolar', 'bipolar']
542
+ Polarity.
543
+
544
+ init_phase : ['zeros', 'random']
545
+ Initial phase.
546
+
509
547
  Returns
510
548
  -------
511
549
  out : Tensor [shape=(..., NxP)]
@@ -517,6 +555,8 @@ def excite(p, frame_period=80, voiced_region="pulse", unvoiced_region="gauss"):
517
555
  frame_period=frame_period,
518
556
  voiced_region=voiced_region,
519
557
  unvoiced_region=unvoiced_region,
558
+ polarity=polarity,
559
+ init_phase=init_phase,
520
560
  )
521
561
 
522
562
 
@@ -594,6 +634,35 @@ def fftcep(x, cep_order, n_iter=0, accel=0):
594
634
  return nn.CepstralAnalysis._func(x, cep_order=cep_order, n_iter=n_iter, accel=accel)
595
635
 
596
636
 
637
+ def flux(x, y=None, lag=1, norm=2, reduction="mean"):
638
+ """Calculate flux.
639
+
640
+ Parameters
641
+ ----------
642
+ x : Tensor [shape=(..., N, D)]
643
+ Input.
644
+
645
+ y : Tensor [shape=(..., N, D)] or None
646
+ Target (optional).
647
+
648
+ lag : int
649
+ Lag of the distance calculation, :math:`L`.
650
+
651
+ norm : int or float
652
+ Order of norm.
653
+
654
+ reduction : ['none', 'mean', 'batchmean', 'sum']
655
+ Reduction type.
656
+
657
+ Returns
658
+ -------
659
+ out : Tensor [shape=(..., N-\\|L\\|) or scalar]
660
+ Flux.
661
+
662
+ """
663
+ return nn.Flux._func(x, y, lag=lag, norm=norm, reduction=reduction)
664
+
665
+
597
666
  def frame(x, frame_length=400, frame_period=80, center=True, zmean=False):
598
667
  """Perform framing.
599
668
 
@@ -738,6 +807,54 @@ def grpdelay(b=None, a=None, *, fft_length=512, alpha=1, gamma=1, **kwargs):
738
807
  )
739
808
 
740
809
 
810
+ def hilbert(x, fft_length=None, dim=-1):
811
+ """Compute analytic signal using the Hilbert transform.
812
+
813
+ Parameters
814
+ ----------
815
+ x : Tensor [shape=(..., T, ...)]
816
+ Input signal.
817
+
818
+ fft_length : int >= 1 or None
819
+ Number of FFT bins. If None, set to :math:`T`.
820
+
821
+ dim : int
822
+ Dimension along which to take the Hilbert transform.
823
+
824
+ Returns
825
+ -------
826
+ out : Tensor [shape=(..., T, ...)]
827
+ Analytic signal, where real part is the input signal and imaginary part is
828
+ the Hilbert transform of the input signal.
829
+
830
+ """
831
+ return nn.HilbertTransform._func(x, fft_length=fft_length, dim=dim)
832
+
833
+
834
+ def hilbert2(x, fft_length=None, dim=(-2, -1)):
835
+ """Compute analytic signal using the Hilbert transform.
836
+
837
+ Parameters
838
+ ----------
839
+ x : Tensor [shape=(..., T1, T2, ...)]
840
+ Input signal.
841
+
842
+ fft_length : int, list[int], or None
843
+ Number of FFT bins. If None, set to (:math:`T1`, :math:`T2`).
844
+
845
+ dim : list[int]
846
+ Dimensions along which to take the Hilbert transform.
847
+
848
+ Returns
849
+ -------
850
+ out : Tensor [shape=(..., T1, T2, ...)]
851
+ Analytic signal, where real part is the input signal and imaginary part is
852
+ the Hilbert transform of the input signal.
853
+
854
+ """
855
+ return nn.TwoDimensionalHilbertTransform._func(x, fft_length=fft_length, dim=dim)
856
+
857
+
741
858
  def histogram(x, n_bin=10, lower_bound=0, upper_bound=1, norm=False, softness=1e-3):
742
859
  """Compute histogram.
743
860
 
@@ -801,7 +918,7 @@ def ialaw(y, abs_max=1, a=87.6):
801
918
  return nn.ALawExpansion._func(y, abs_max=abs_max, a=a)
802
919
 
803
920
 
804
- def idct(y):
921
+ def idct(y, dct_type=2):
805
922
  """Compute inverse DCT.
806
923
 
807
924
  Parameters
@@ -809,16 +926,39 @@ def idct(y):
809
926
  y : Tensor [shape=(..., L)]
810
927
  Input.
811
928
 
929
+ dct_type : int in [1, 4]
930
+ DCT type.
931
+
812
932
  Returns
813
933
  -------
814
934
  out : Tensor [shape=(..., L)]
815
935
  Inverse DCT output.
816
936
 
817
937
  """
818
- return nn.InverseDiscreteCosineTransform._func(y)
938
+ return nn.InverseDiscreteCosineTransform._func(y, dct_type=dct_type)
939
+
940
+
941
+ def idht(y, dht_type=2):
942
+ """Compute inverse DHT.
943
+
944
+ Parameters
945
+ ----------
946
+ y : Tensor [shape=(..., L)]
947
+ Input.
948
+
949
+ dht_type : int in [1, 4]
950
+ DHT type.
951
+
952
+ Returns
953
+ -------
954
+ out : Tensor [shape=(..., L)]
955
+ Inverse DHT output.
956
+
957
+ """
958
+ return nn.InverseDiscreteHartleyTransform._func(y, dht_type=dht_type)
819
959
 
820
960
 
821
- def idst(y):
961
+ def idst(y, dst_type=2):
822
962
  """Compute inverse DST.
823
963
 
824
964
  Parameters
@@ -826,13 +966,16 @@ def idst(y):
826
966
  y : Tensor [shape=(..., L)]
827
967
  Input.
828
968
 
969
+ dst_type : int in [1, 4]
970
+ DST type.
971
+
829
972
  Returns
830
973
  -------
831
974
  out : Tensor [shape=(..., L)]
832
975
  Inverse DST output.
833
976
 
834
977
  """
835
- return nn.InverseDiscreteSineTransform._func(y)
978
+ return nn.InverseDiscreteSineTransform._func(y, dst_type=dst_type)
836
979
 
837
980
 
838
981
  def ifreqt2(c, out_order, alpha=0, theta=0, n_fft=512):
@@ -1853,30 +1996,27 @@ def rlevdur(a):
1853
1996
  return nn.ReverseLevinsonDurbin._func(a)
1854
1997
 
1855
1998
 
1856
- def rmse(x, y, reduction="mean", eps=1e-8):
1999
+ def rmse(x, y, reduction="mean"):
1857
2000
  """Calculate RMSE.
1858
2001
 
1859
2002
  Parameters
1860
2003
  ----------
1861
- x : Tensor [shape=(..., T)]
2004
+ x : Tensor [shape=(..., D)]
1862
2005
  Input.
1863
2006
 
1864
- y : Tensor [shape=(..., T)]
2007
+ y : Tensor [shape=(..., D)]
1865
2008
  Target.
1866
2009
 
1867
2010
  reduction : ['none', 'mean', 'sum']
1868
2011
  Reduction type.
1869
2012
 
1870
- eps : float >= 0
1871
- A small value to prevent NaN.
1872
-
1873
2013
  Returns
1874
2014
  -------
1875
2015
  out : Tensor [shape=(...,) or scalar]
1876
2016
  RMSE.
1877
2017
 
1878
2018
  """
1879
- return nn.RootMeanSquareError._func(x, y, reduction=reduction, eps=eps)
2019
+ return nn.RootMeanSquareError._func(x, y, reduction=reduction)
1880
2020
 
1881
2021
 
1882
2022
  def root_pol(a, out_format="rectangular"):
@@ -216,7 +216,7 @@ def train(order, frame_period, norm="power", **kwargs):
216
216
  v = torch.full((order + 2,), frequency)
217
217
  v[0] *= -1
218
218
  v = torch.floor(torch.cumsum(v, dim=0))
219
- index = torch.ge(v[..., 1:] - v[..., :-1], 1)
219
+ index = torch.ge(torch.diff(v), 1)
220
220
 
221
221
  x = torch.zeros(order + 1, **kwargs)
222
222
  x[index] = pulse
@@ -266,7 +266,10 @@ def nrand(*order, mean=0, stdv=1, var=None, **kwargs):
266
266
  stdv = var**0.5
267
267
  assert 0 <= stdv
268
268
 
269
- order = list(order)
269
+ if any(isinstance(item, (list, tuple)) for item in order):
270
+ order = list(*order)
271
+ else:
272
+ order = list(order)
270
273
  order[-1] += 1
271
274
  x = torch.randn(*order, **kwargs)
272
275
  x = x * stdv + mean
@@ -15,6 +15,7 @@
15
15
  # ------------------------------------------------------------------------ #
16
16
 
17
17
  from importlib import import_module
18
+ import logging
18
19
  import math
19
20
 
20
21
  import numpy as np
@@ -43,8 +44,24 @@ def delayed_import(module_path, item_name):
43
44
  return getattr(module, item_name)
44
45
 
45
46
 
46
- def is_power_of_two(n):
47
- return (n != 0) and (n & (n - 1) == 0)
47
+ def get_logger(name):
48
+ logger = logging.getLogger(name)
49
+ logger.setLevel(logging.INFO)
50
+ formatter = logging.Formatter(
51
+ "%(asctime)s (%(module)s:%(lineno)d) %(levelname)s: %(message)s"
52
+ )
53
+ logger.handlers.clear()
54
+ handler = logging.StreamHandler()
55
+ handler.setFormatter(formatter)
56
+ logger.addHandler(handler)
57
+ return logger
58
+
59
+
60
+ def get_generator(seed=None):
61
+ generator = torch.Generator()
62
+ if seed is not None:
63
+ generator.manual_seed(seed)
64
+ return generator
48
65
 
49
66
 
50
67
  def next_power_of_two(n):
@@ -53,22 +70,31 @@ def next_power_of_two(n):
53
70
 
54
71
  def default_dtype():
55
72
  t = torch.get_default_dtype()
56
- if t == torch.float: # pragma: no cover
73
+ if t == torch.float:
57
74
  return np.float32
58
- elif t == torch.double: # pragma: no cover
75
+ elif t == torch.double:
59
76
  return np.float64
60
77
  raise RuntimeError("Unknown default dtype: {t}.")
61
78
 
62
79
 
63
80
  def default_complex_dtype():
64
81
  t = torch.get_default_dtype()
65
- if t == torch.float: # pragma: no cover
82
+ if t == torch.float:
66
83
  return np.complex64
67
- elif t == torch.double: # pragma: no cover
84
+ elif t == torch.double:
68
85
  return np.complex128
69
86
  raise RuntimeError("Unknown default dtype: {t}.")
70
87
 
71
88
 
89
+ def torch_default_complex_dtype():
90
+ t = torch.get_default_dtype()
91
+ if t == torch.float:
92
+ return torch.complex64
93
+ elif t == torch.double:
94
+ return torch.complex128
95
+ raise RuntimeError("Unknown default dtype: {t}.")
96
+
97
+
72
98
  def numpy_to_torch(x):
73
99
  if np.iscomplexobj(x):
74
100
  return torch.from_numpy(x.astype(default_complex_dtype()))
@@ -78,7 +104,10 @@ def numpy_to_torch(x):
78
104
 
79
105
  def to(x, dtype=None, device=None):
80
106
  if dtype is None:
81
- dtype = torch.get_default_dtype()
107
+ if torch.is_complex(x):
108
+ dtype = torch_default_complex_dtype()
109
+ else:
110
+ dtype = torch.get_default_dtype()
82
111
  return x.to(dtype=dtype, device=device)
83
112
 
84
113
 
@@ -134,6 +163,27 @@ def remove_gain(a, value=1, return_gain=False):
134
163
  return ret
135
164
 
136
165
 
166
+ def get_resample_params(mode="kaiser_best"):
167
+ # From https://pytorch.org/audio/stable/tutorials/audio_resampling_tutorial.html
168
+ if mode == "kaiser_best":
169
+ params = {
170
+ "lowpass_filter_width": 64,
171
+ "rolloff": 0.9475937167399596,
172
+ "resampling_method": "sinc_interp_kaiser",
173
+ "beta": 14.769656459379492,
174
+ }
175
+ elif mode == "kaiser_fast":
176
+ params = {
177
+ "lowpass_filter_width": 16,
178
+ "rolloff": 0.85,
179
+ "resampling_method": "sinc_interp_kaiser",
180
+ "beta": 8.555504641634386,
181
+ }
182
+ else:
183
+ raise ValueError("Only kaiser_best and kaiser_fast are supported.")
184
+ return params
185
+
186
+
137
187
  def get_alpha(sr, mode="hts", n_freq=10, n_alpha=100):
138
188
  """Compute an appropriate frequency warping factor under given sample rate.
139
189
 
@@ -186,7 +236,7 @@ def get_alpha(sr, mode="hts", n_freq=10, n_alpha=100):
186
236
  def get_auto_alpha(sr, n_freq, n_alpha):
187
237
  # Compute target mel-frequencies.
188
238
  freq = np.arange(n_freq) * (0.5 * sr / (n_freq - 1))
189
- mel_freq = np.log(1 + freq / 1000)
239
+ mel_freq = np.log1p(freq / 1000)
190
240
  mel_freq = mel_freq * (np.pi / mel_freq[-1])
191
241
  mel_freq = np.expand_dims(mel_freq, 0)
192
242
 
@@ -203,7 +253,7 @@ def get_alpha(sr, mode="hts", n_freq=10, n_alpha=100):
203
253
 
204
254
  # Select an appropriate alpha in terms of L2 distance.
205
255
  distance = np.square(mel_freq - warped_omega).sum(axis=1)
206
- selected_alpha = np.squeeze(alpha[np.argmin(distance)])
256
+ selected_alpha = float(np.squeeze(alpha[np.argmin(distance)]))
207
257
  return selected_alpha
208
258
 
209
259
  if mode == "hts":
@@ -242,6 +292,10 @@ def vander(x):
242
292
  return X
243
293
 
244
294
 
295
+ def cas(x):
296
+ return (2**0.5) * torch.cos(x - 0.25 * torch.pi) # cos(x) + sin(x)
297
+
298
+
245
299
  def cexp(x):
246
300
  return torch.polar(torch.exp(x.real), x.imag)
247
301
 
@@ -250,6 +304,12 @@ def clog(x):
250
304
  return torch.log(x.abs())
251
305
 
252
306
 
307
+ def outer(x, y=None):
308
+ return torch.matmul(
309
+ x.unsqueeze(-1), x.unsqueeze(-2) if y is None else y.unsqueeze(-2)
310
+ )
311
+
312
+
253
313
  def iir(x, b=None, a=None):
254
314
  if b is None:
255
315
  b = torch.ones(1, dtype=x.dtype, device=x.device)
@@ -265,6 +325,14 @@ def iir(x, b=None, a=None):
265
325
  return y
266
326
 
267
327
 
328
+ def plateau(length, first, middle, last=None, dtype=None, device=None):
329
+ x = torch.full((length,), middle, dtype=dtype, device=device)
330
+ x[0] = first
331
+ if last is not None:
332
+ x[-1] = last
333
+ return x
334
+
335
+
268
336
  def deconv1d(x, weight):
269
337
  """Deconvolve input. This is not transposed convolution.
270
338