1 #ifndef PY_AUBIO_MUSICUTILS_H
2 #define PY_AUBIO_MUSICUTILS_H
4 static char Py_aubio_window_doc[] = ""
5 "window(window_type, size)\n"
7 "Create a window of length `size`. `window_type` should be one\n"
10 "- `default` (same as `hanningz`).\n"
17 "- `blackman_harris`\n"
27 " Length of window.\n"
32 " Array of shape `(length,)` containing the new window.\n"
40 "Compute a zero-phase Hann window on `1024` points:\n"
42 ">>> aubio.window('hanningz', 1024)\n"
43 "array([ 0.00000000e+00, 9.41753387e-06, 3.76403332e-05, ...,\n"
44 " 8.46982002e-05, 3.76403332e-05, 9.41753387e-06], dtype=float32)\n"
46 "Plot different window types with `matplotlib <https://matplotlib.org/>`_:\n"
48 ">>> import matplotlib.pyplot as plt\n"
49 ">>> modes = ['default', 'ones', 'rectangle', 'hamming', 'hanning',\n"
50 "... 'hanningz', 'blackman', 'blackman_harris', 'gaussian',\n"
51 "... 'welch', 'parzen']; n = 2048\n"
52 ">>> for m in modes: plt.plot(aubio.window(m, n), label=m)\n"
54 ">>> plt.legend(); plt.show()\n"
58 "The following examples contain the equivalent source code to compute\n"
59 "each type of window with `NumPy <https://numpy.org>`_:\n"
61 ">>> n = 1024; x = np.arange(n, dtype=aubio.float_type)\n"
62 ">>> ones = np.ones(n).astype(aubio.float_type)\n"
63 ">>> rectangle = 0.5 * ones\n"
64 ">>> hanning = 0.5 - 0.5 * np.cos(2 * np.pi * x / n)\n"
65 ">>> hanningz = 0.5 * (1 - np.cos(2 * np.pi * x / n))\n"
66 ">>> hamming = 0.54 - 0.46 * np.cos(2.*np.pi * x / (n - 1))\n"
67 ">>> blackman = 0.42 \\\n"
68 "... - 0.50 * np.cos(2 * np.pi * x / (n - 1)) \\\n"
69 "... + 0.08 * np.cos(4 * np.pi * x / (n - 1))\n"
70 ">>> blackman_harris = 0.35875 \\\n"
71 "... - 0.48829 * np.cos(2 * np.pi * x / (n - 1)) \\\n"
72 "... + 0.14128 * np.cos(4 * np.pi * x / (n - 1)) \\\n"
73 "... + 0.01168 * np.cos(6 * np.pi * x / (n - 1))\n"
74 ">>> gaussian = np.exp( - 0.5 * ((x - 0.5 * (n - 1)) \\\n"
75 "... / (0.25 * (n - 1)) )**2 )\n"
76 ">>> welch = 1 - ((2 * x - n) / (n + 1))**2\n"
77 ">>> parzen = 1 - np.abs((2 * x - n) / (n + 1))\n"
78 ">>> default = hanningz\n"
82 "`Window function <https://en.wikipedia.org/wiki/Window_function>`_ on\n"
86 ".. [1] Amalia de Götzen, Nicolas Bernardini, and Daniel Arfib. Traditional\n"
87 " (?) implementations of a phase vocoder: the tricks of the trade.\n"
88 " In *Proceedings of the International Conference on Digital Audio\n"
89 " Effects* (DAFx-00), pages 37–44, University of Verona, Italy, 2000.\n"
91 "https://www.cs.princeton.edu/courses/archive/spr09/cos325/Bernardini.pdf"
95 PyObject * Py_aubio_window(PyObject *self, PyObject *args);
97 static char Py_aubio_level_lin_doc[] = ""
100 "Compute sound pressure level of `x`, on a linear scale.\n"
110 " Linear level of `x`.\n"
115 ">>> aubio.level_lin(aubio.fvec(numpy.ones(1024)))\n"
120 "Computed as the average of the squared amplitudes:\n"
122 ".. math:: L = \\frac {\\sum_{n=0}^{N-1} {x_n}^2} {N}\n"
126 "db_spl, silence_detection, level_detection\n"
129 PyObject * Py_aubio_level_lin(PyObject *self, PyObject *args);
131 static char Py_aubio_db_spl_doc[] = ""
134 "Compute Sound Pressure Level (SPL) of `x`, in dB.\n"
144 " Level of `x`, in dB SPL.\n"
149 ">>> aubio.db_spl(aubio.fvec(np.ones(1024)))\n"
151 ">>> aubio.db_spl(0.7*aubio.fvec(np.ones(32)))\n"
152 "-3.098040819168091\n"
156 "Computed as `log10` of :py:func:`level_lin`:\n"
160 " {SPL}_{dB} = log10{\\frac {\\sum_{n=0}^{N-1}{x_n}^2} {N}}\n"
162 "This quantity is often incorrectly called 'loudness'.\n"
166 "level_lin, silence_detection, level_detection\n"
169 PyObject * Py_aubio_db_spl(PyObject *self, PyObject *args);
171 static char Py_aubio_silence_detection_doc[] = ""
172 "silence_detection(vec, level)\n"
174 "Check if level of `vec`, in dB SPL, is under a given threshold.\n"
181 " level threshold, in dB SPL\n"
186 " `1` if level of `vec`, in dB SPL, is under `level`,\n"
192 ">>> aubio.silence_detection(aubio.fvec(32), -100.)\n"
194 ">>> aubio.silence_detection(aubio.fvec(np.ones(32)), 0.)\n"
199 "level_detection, db_spl, level_lin\n"
202 PyObject * Py_aubio_silence_detection(PyObject *self, PyObject *args);
204 static char Py_aubio_level_detection_doc[] = ""
205 "level_detection(vec, level)\n"
207 "Check if `vec` is above threshold `level`, in dB SPL.\n"
214 " level threshold, in dB SPL\n"
219 " `1.0` if level of `vec` in dB SPL is under `level`,\n"
220 " `db_spl(vec)` otherwise.\n"
225 ">>> aubio.level_detection(0.7*aubio.fvec(np.ones(1024)), -3.)\n"
227 ">>> aubio.level_detection(0.7*aubio.fvec(np.ones(1024)), -4.)\n"
228 "-3.0980708599090576\n"
232 "silence_detection, db_spl, level_lin\n"
235 PyObject * Py_aubio_level_detection(PyObject *self, PyObject *args);
237 static char Py_aubio_shift_doc[] = ""
240 "Swap left and right partitions of a vector, in-place.\n"
245 " input vector to shift\n"
250 " The swapped vector.\n"
254 "The input vector is also modified.\n"
256 "For a vector of length N, the partition is split at index N - N//2.\n"
261 ">>> aubio.shift(aubio.fvec(np.arange(3)))\n"
262 "array([2., 0., 1.], dtype=" AUBIO_NPY_SMPL_STR ")\n"
268 PyObject * Py_aubio_shift(PyObject *self, PyObject *args);
270 static char Py_aubio_ishift_doc[] = ""
273 "Swap right and left partitions of a vector, in-place.\n"
278 " input vector to shift\n"
283 " The swapped vector.\n"
287 "The input vector is also modified.\n"
289 "Unlike with :py:func:`shift`, the partition is split at index N//2.\n"
294 ">>> aubio.ishift(aubio.fvec(np.arange(3)))\n"
295 "array([1., 2., 0.], dtype=" AUBIO_NPY_SMPL_STR ")\n"
301 PyObject * Py_aubio_ishift(PyObject *self, PyObject *args);
303 static char Py_aubio_hztomel_doc[] = ""
304 "hztomel(f, htk=False)\n"
306 "Convert a scalar from frequency to mel scale.\n"
311 " input frequency, in Hz\n"
313 " if `True`, use Htk mel scale instead of Slaney.\n"
324 PyObject * Py_aubio_hztomel(PyObject *self, PyObject *args);
326 static char Py_aubio_meltohz_doc[] = ""
327 "meltohz(m, htk=False)\n"
329 "Convert a scalar from mel scale to frequency.\n"
336 " if `True`, use Htk mel scale instead of Slaney.\n"
341 " output frequency, in Hz\n"
347 PyObject * Py_aubio_meltohz(PyObject *self, PyObject *args);
349 static char Py_aubio_hztomel_htk_doc[] = ""
352 "Same as `hztomel(m, htk=True)`\n"
358 PyObject * Py_aubio_hztomel_htk(PyObject *self, PyObject *args);
360 static char Py_aubio_meltohz_htk_doc[] = ""
363 "Same as `meltohz(m, htk=True)`\n"
369 PyObject * Py_aubio_meltohz_htk(PyObject *self, PyObject *args);
371 #endif /* PY_AUBIO_MUSICUTILS_H */