Showing the changes to python (7 of 30 files). Show all
Unified · Split
| @@ -0,0 +1,143 @@ | |||
| 1 | #define PYAUBIO_dct_doc \ | ||
| 2 | "dct(size=1024)\n"\ | ||
| 3 | "\n"\ | ||
| 4 | "Compute Discrete Fourier Transorms of Type-II.\n"\ | ||
| 5 | "\n"\ | ||
| 6 | "Parameters\n"\ | ||
| 7 | "----------\n"\ | ||
| 8 | "size : int\n"\ | ||
| 9 | " size of the DCT to compute\n"\ | ||
| 10 | "\n"\ | ||
| 11 | "Example\n"\ | ||
| 12 | "-------\n"\ | ||
| 13 | ">>> d = aubio.dct(16)\n"\ | ||
| 14 | ">>> d.size\n"\ | ||
| 15 | "16\n"\ | ||
| 16 | ">>> x = aubio.fvec(np.ones(d.size))\n"\ | ||
| 17 | ">>> d(x)\n"\ | ||
| 18 | "array([4., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n"\ | ||
| 19 | " dtype=float32)\n"\ | ||
| 20 | ">>> d.rdo(d(x))\n"\ | ||
| 21 | "array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n"\ | ||
| 22 | " dtype=float32)\n"\ | ||
| 23 | "\n"\ | ||
| 24 | "References\n"\ | ||
| 25 | "----------\n"\ | ||
| 26 | "`DCT-II in Discrete Cosine Transform\n"\ | ||
| 27 | "<https://en.wikipedia.org/wiki/Discrete_cosine_transform#DCT-II>`_\n"\ | ||
| 28 | "on Wikipedia.\n" | ||
| 29 | |||
| 30 | #define PYAUBIO_mfcc_doc \ | ||
| 31 | "mfcc(buf_size=1024, n_filters=40, n_coeffs=13, samplerate=44100)\n"\ | ||
| 32 | "\n"\ | ||
| 33 | "Compute Mel Frequency Cepstrum Coefficients (MFCC).\n"\ | ||
| 34 | "\n"\ | ||
| 35 | "`mfcc` creates a callable which takes a `cvec` as input.\n"\ | ||
| 36 | "\n"\ | ||
| 37 | "If `n_filters = 40`, the filterbank will be initialized with\n"\ | ||
| 38 | ":meth:`filterbank.set_mel_coeffs_slaney`. Otherwise, if `n_filters`\n"\ | ||
| 39 | "is greater than `0`, it will be initialized with\n"\ | ||
| 40 | ":meth:`filterbank.set_mel_coeffs` using `fmin = 0`,\n"\ | ||
| 41 | "`fmax = samplerate/`.\n"\ | ||
| 42 | "\n"\ | ||
| 43 | "Example\n"\ | ||
| 44 | "-------\n"\ | ||
| 45 | ">>> buf_size = 2048; n_filters = 128; n_coeffs = 13; samplerate = 44100\n"\ | ||
| 46 | ">>> mf = aubio.mfcc(buf_size, n_filters, n_coeffs, samplerate)\n"\ | ||
| 47 | ">>> fftgrain = aubio.cvec(buf_size)\n"\ | ||
| 48 | ">>> mf(fftgrain).shape\n"\ | ||
| 49 | "(13,)\n"\ | ||
| 50 | "" | ||
| 51 | |||
| 52 | #define PYAUBIO_notes_doc \ | ||
| 53 | "notes(method=\"default\", buf_size=1024, hop_size=512, samplerate=44100)\n"\ | ||
| 54 | "\n"\ | ||
| 55 | "Note detection\n" | ||
| 56 | |||
| 57 | #define PYAUBIO_onset_doc \ | ||
| 58 | "onset(method=\"default\", buf_size=1024, hop_size=512, samplerate=44100)\n"\ | ||
| 59 | "\n"\ | ||
| 60 | "Onset detection object. `method` should be one of method supported by\n"\ | ||
| 61 | ":class:`specdesc`.\n" | ||
| 62 | |||
| 63 | #define PYAUBIO_pitch_doc \ | ||
| 64 | "pitch(method=\"default\", buf_size=1024, hop_size=512, samplerate=44100)\n"\ | ||
| 65 | "\n"\ | ||
| 66 | "Pitch detection.\n"\ | ||
| 67 | "\n"\ | ||
| 68 | "Supported methods: `yinfft`, `yin`, `yinfast`, `fcomb`, `mcomb`,\n"\ | ||
| 69 | "`schmitt`, `specacf`, `default` (`yinfft`).\n" | ||
| 70 | |||
| 71 | #define PYAUBIO_sampler_doc \ | ||
| 72 | "sampler(hop_size=512, samplerate=44100)\n"\ | ||
| 73 | "\n"\ | ||
| 74 | "Sampler.\n" | ||
| 75 | |||
| 76 | #define PYAUBIO_specdesc_doc \ | ||
| 77 | "specdesc(method=\"default\", buf_size=1024)\n"\ | ||
| 78 | "\n"\ | ||
| 79 | "Spectral description functions. Creates a callable that takes a\n"\ | ||
| 80 | ":class:`cvec` as input, typically created by :class:`pvoc` for\n"\ | ||
| 81 | "overlap and windowing, and returns a single float.\n"\ | ||
| 82 | "\n"\ | ||
| 83 | "`method` can be any of the values listed below. If `default` is used\n"\ | ||
| 84 | "the `hfc` function will be selected.\n"\ | ||
| 85 | "\n"\ | ||
| 86 | "Onset novelty functions:\n"\ | ||
| 87 | "\n"\ | ||
| 88 | "- `energy`: local energy,\n"\ | ||
| 89 | "- `hfc`: high frequency content,\n"\ | ||
| 90 | "- `complex`: complex domain,\n"\ | ||
| 91 | "- `phase`: phase-based method,\n"\ | ||
| 92 | "- `wphase`: weighted phase deviation,\n"\ | ||
| 93 | "- `specdiff`: spectral difference,\n"\ | ||
| 94 | "- `kl`: Kullback-Liebler,\n"\ | ||
| 95 | "- `mkl`: modified Kullback-Liebler,\n"\ | ||
| 96 | "- `specflux`: spectral flux.\n"\ | ||
| 97 | "\n"\ | ||
| 98 | "Spectral shape functions:\n"\ | ||
| 99 | "\n"\ | ||
| 100 | "- `centroid`: spectral centroid (barycenter of the norm vector),\n"\ | ||
| 101 | "- `spread`: variance around centroid,\n"\ | ||
| 102 | "- `skewness`: third order moment,\n"\ | ||
| 103 | "- `kurtosis`: a measure of the flatness of the spectrum,\n"\ | ||
| 104 | "- `slope`: decreasing rate of the amplitude,\n"\ | ||
| 105 | "- `decrease`: perceptual based measurement of the decreasing rate,\n"\ | ||
| 106 | "- `rolloff`: 95th energy percentile.\n"\ | ||
| 107 | "\n"\ | ||
| 108 | "Parameters\n"\ | ||
| 109 | "----------\n"\ | ||
| 110 | "method : str\n"\ | ||
| 111 | " Onset novelty or spectral shape function.\n"\ | ||
| 112 | "buf_size : int\n"\ | ||
| 113 | " Length of the input frame.\n"\ | ||
| 114 | "\n"\ | ||
| 115 | "Example\n"\ | ||
| 116 | "-------\n"\ | ||
| 117 | ">>> win_s = 1024; hop_s = win_s // 2\n"\ | ||
| 118 | ">>> pv = aubio.pvoc(win_s, hop_s)\n"\ | ||
| 119 | ">>> sd = aubio.specdesc(\"mkl\", win_s)\n"\ | ||
| 120 | ">>> sd(pv(aubio.fvec(hop_s))).shape\n"\ | ||
| 121 | "(1,)\n"\ | ||
| 122 | "\n"\ | ||
| 123 | "References\n"\ | ||
| 124 | "----------\n"\ | ||
| 125 | "`Detailed description "\ | ||
| 126 | "<https://aubio.org/doc/latest/specdesc_8h.html#details>`_ in\n"\ | ||
| 127 | "`aubio API documentation <https://aubio.org/doc/latest/index.html>`_.\n"\ | ||
| 128 | "" | ||
| 129 | |||
| 130 | #define PYAUBIO_tempo_doc \ | ||
| 131 | "tempo(method=\"default\", buf_size=1024, hop_size=512, samplerate=44100)\n"\ | ||
| 132 | "\n"\ | ||
| 133 | "Tempo detection and beat tracking.\n" | ||
| 134 | |||
| 135 | #define PYAUBIO_tss_doc \ | ||
| 136 | "tss(buf_size=1024, hop_size=512)\n"\ | ||
| 137 | "\n"\ | ||
| 138 | "Transient/Steady-state separation.\n" | ||
| 139 | |||
| 140 | #define PYAUBIO_wavetable_doc \ | ||
| 141 | "wavetable(samplerate=44100, hop_size=512)\n"\ | ||
| 142 | "\n"\ | ||
| 143 | "Wavetable synthesis.\n" | ||
| @@ -1,6 +1,7 @@ | |||
| 1 | #include <Python.h> | 1 | #include <Python.h> |
| 2 | #include <structmember.h> | 2 | #include <structmember.h> |
| 3 | 3 | ||
| 4 | #include "aubio-docstrings.h" | ||
| 4 | #include "aubio-generated.h" | 5 | #include "aubio-generated.h" |
| 5 | 6 | ||
| 6 | #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION | 7 | #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION |
| @@ -1,6 +1,24 @@ | |||
| 1 | #include "aubio-types.h" | 1 | #include "aubio-types.h" |
| 2 | 2 | ||
| 3 | static char Py_fft_doc[] = "fft object"; | 3 | static char Py_fft_doc[] = "" |
| 4 | "fft(size=1024)\n" | ||
| 5 | "\n" | ||
| 6 | "Compute Fast Fourier Transorms.\n" | ||
| 7 | "\n" | ||
| 8 | "Parameters\n" | ||
| 9 | "----------\n" | ||
| 10 | "size : int\n" | ||
| 11 | " size of the FFT to compute\n" | ||
| 12 | "\n" | ||
| 13 | "Example\n" | ||
| 14 | "-------\n" | ||
| 15 | ">>> x = aubio.fvec(512)\n" | ||
| 16 | ">>> f = aubio.fft(512)\n" | ||
| 17 | ">>> c = f(x); c\n" | ||
| 18 | "aubio cvec of 257 elements\n" | ||
| 19 | ">>> x2 = f.rdo(c); x2.shape\n" | ||
| 20 | "(512,)\n" | ||
| 21 | ""; | ||
| 4 | 22 | ||
| 5 | typedef struct | 23 | typedef struct |
| 6 | { | 24 | { |
| @@ -10,7 +10,58 @@ typedef struct · 9 unmodified lines | |||
| 10 | fvec_t c_out; | 10 | fvec_t c_out; |
| 11 | } Py_filter; | 11 | } Py_filter; |
| 12 | 12 | ||
| 13 | static char Py_filter_doc[] = "filter object"; | 13 | static char Py_filter_doc[] = "" |
| 14 | "digital_filter(order=7)\n" | ||
| 15 | "\n" | ||
| 16 | "Create a digital filter.\n" | ||
| 17 | ""; | ||
| 18 | |||
| 19 | static char Py_filter_set_c_weighting_doc[] = "" | ||
| 20 | "set_c_weighting(samplerate)\n" | ||
| 21 | "\n" | ||
| 22 | "Set filter coefficients to C-weighting.\n" | ||
| 23 | "\n" | ||
| 24 | "`samplerate` should be one of 8000, 11025, 16000, 22050, 24000, 32000,\n" | ||
| 25 | "44100, 48000, 88200, 96000, or 192000. `order` of the filter should be 5.\n" | ||
| 26 | "\n" | ||
| 27 | "Parameters\n" | ||
| 28 | "----------\n" | ||
| 29 | "samplerate : int\n" | ||
| 30 | " Sampling-rate of the input signal, in Hz.\n" | ||
| 31 | ""; | ||
| 32 | |||
| 33 | static char Py_filter_set_a_weighting_doc[] = "" | ||
| 34 | "set_a_weighting(samplerate)\n" | ||
| 35 | "\n" | ||
| 36 | "Set filter coefficients to A-weighting.\n" | ||
| 37 | "\n" | ||
| 38 | "`samplerate` should be one of 8000, 11025, 16000, 22050, 24000, 32000,\n" | ||
| 39 | "44100, 48000, 88200, 96000, or 192000. `order` of the filter should be 7.\n" | ||
| 40 | "\n" | ||
| 41 | "Parameters\n" | ||
| 42 | "----------\n" | ||
| 43 | "samplerate : int\n" | ||
| 44 | " Sampling-rate of the input signal.\n" | ||
| 45 | ""; | ||
| 46 | |||
| 47 | static char Py_filter_set_biquad_doc[] = "" | ||
| 48 | "set_biquad(b0, b1, b2, a1, a2)\n" | ||
| 49 | "\n" | ||
| 50 | "Set biquad coefficients. `order` of the filter should be 3.\n" | ||
| 51 | "\n" | ||
| 52 | "Parameters\n" | ||
| 53 | "----------\n" | ||
| 54 | "b0 : float\n" | ||
| 55 | " Forward filter coefficient.\n" | ||
| 56 | "b1 : float\n" | ||
| 57 | " Forward filter coefficient.\n" | ||
| 58 | "b2 : float\n" | ||
| 59 | " Forward filter coefficient.\n" | ||
| 60 | "a1 : float\n" | ||
| 61 | " Feedback filter coefficient.\n" | ||
| 62 | "a2 : float\n" | ||
| 63 | " Feedback filter coefficient.\n" | ||
| 64 | ""; | ||
| 14 | 65 | ||
| 15 | static PyObject * | 66 | static PyObject * |
| 16 | Py_filter_new (PyTypeObject * type, PyObject * args, PyObject * kwds) | 67 | Py_filter_new (PyTypeObject * type, PyObject * args, PyObject * kwds) |
| @@ -156,11 +207,11 @@ static PyMemberDef Py_filter_members[] = { · 139 unmodified lines | |||
| 156 | 207 | ||
| 157 | static PyMethodDef Py_filter_methods[] = { | 208 | static PyMethodDef Py_filter_methods[] = { |
| 158 | {"set_c_weighting", (PyCFunction) Py_filter_set_c_weighting, METH_VARARGS, | 209 | {"set_c_weighting", (PyCFunction) Py_filter_set_c_weighting, METH_VARARGS, |
| 159 | "set filter coefficients to C-weighting"}, | 210 | Py_filter_set_c_weighting_doc}, |
| 160 | {"set_a_weighting", (PyCFunction) Py_filter_set_a_weighting, METH_VARARGS, | 211 | {"set_a_weighting", (PyCFunction) Py_filter_set_a_weighting, METH_VARARGS, |
| 161 | "set filter coefficients to A-weighting"}, | 212 | Py_filter_set_a_weighting_doc}, |
| 162 | {"set_biquad", (PyCFunction) Py_filter_set_biquad, METH_VARARGS, | 213 | {"set_biquad", (PyCFunction) Py_filter_set_biquad, METH_VARARGS, |
| 163 | "set b0, b1, b2, a1, a2 biquad coefficients"}, | 214 | Py_filter_set_biquad_doc}, |
| 164 | {NULL} | 215 | {NULL} |
| 165 | }; | 216 | }; |
| 166 | 217 | ||
| @@ -1,6 +1,188 @@ | |||
| 1 | #include "aubio-types.h" | 1 | #include "aubio-types.h" |
| 2 | 2 | ||
| 3 | static char Py_filterbank_doc[] = "filterbank object"; | 3 | static char Py_filterbank_doc[] = "" |
| 4 | "filterbank(n_filters=40, win_s=1024)\n" | ||
| 5 | "\n" | ||
| 6 | "Create a bank of spectral filters. Each instance is a callable\n" | ||
| 7 | "that holds a matrix of coefficients.\n" | ||
| 8 | "\n" | ||
| 9 | "See also :meth:`set_mel_coeffs`, :meth:`set_mel_coeffs_htk`,\n" | ||
| 10 | ":meth:`set_mel_coeffs_slaney`, :meth:`set_triangle_bands`, and\n" | ||
| 11 | ":meth:`set_coeffs`.\n" | ||
| 12 | "\n" | ||
| 13 | "Parameters\n" | ||
| 14 | "----------\n" | ||
| 15 | "n_filters : int\n" | ||
| 16 | " Number of filters to create.\n" | ||
| 17 | "win_s : int\n" | ||
| 18 | " Size of the input spectrum to process.\n" | ||
| 19 | "\n" | ||
| 20 | "Examples\n" | ||
| 21 | "--------\n" | ||
| 22 | ">>> f = aubio.filterbank(128, 1024)\n" | ||
| 23 | ">>> f.set_mel_coeffs(44100, 0, 10000)\n" | ||
| 24 | ">>> c = aubio.cvec(1024)\n" | ||
| 25 | ">>> f(c).shape\n" | ||
| 26 | "(128, )\n" | ||
| 27 | ""; | ||
| 28 | |||
| 29 | static char Py_filterbank_set_triangle_bands_doc[] ="" | ||
| 30 | "set_triangle_bands(freqs, samplerate)\n" | ||
| 31 | "\n" | ||
| 32 | "Set triangular bands. The coefficients will be set to triangular\n" | ||
| 33 | "overlapping windows using the boundaries specified by `freqs`.\n" | ||
| 34 | "\n" | ||
| 35 | "`freqs` should contain `n_filters + 2` frequencies in Hz, ordered\n" | ||
| 36 | "by value, from smallest to largest. The first element should be greater\n" | ||
| 37 | "or equal to zero; the last element should be smaller or equal to\n" | ||
| 38 | "`samplerate / 2`.\n" | ||
| 39 | "\n" | ||
| 40 | "Parameters\n" | ||
| 41 | "----------\n" | ||
| 42 | "freqs: fvec\n" | ||
| 43 | " List of frequencies, in Hz.\n" | ||
| 44 | "samplerate : float\n" | ||
| 45 | " Sampling-rate of the expected input.\n" | ||
| 46 | "\n" | ||
| 47 | "Example\n" | ||
| 48 | "-------\n" | ||
| 49 | ">>> fb = aubio.filterbank(n_filters=100, win_s=2048)\n" | ||
| 50 | ">>> samplerate = 44100; freqs = np.linspace(0, 20200, 102)\n" | ||
| 51 | ">>> fb.set_triangle_bands(aubio.fvec(freqs), samplerate)\n" | ||
| 52 | ""; | ||
| 53 | |||
| 54 | static char Py_filterbank_set_mel_coeffs_slaney_doc[] = "" | ||
| 55 | "set_mel_coeffs_slaney(samplerate)\n" | ||
| 56 | "\n" | ||
| 57 | "Set coefficients of filterbank to match Slaney's Auditory Toolbox.\n" | ||
| 58 | "\n" | ||
| 59 | "The filter coefficients will be set as in Malcolm Slaney's\n" | ||
| 60 | "implementation. The filterbank should have been created with\n" | ||
| 61 | "`n_filters = 40`.\n" | ||
| 62 | "\n" | ||
| 63 | "This is approximately equivalent to using :meth:`set_mel_coeffs` with\n" | ||
| 64 | "`fmin = 400./3., fmax = 6853.84`.\n" | ||
| 65 | "\n" | ||
| 66 | "Parameters\n" | ||
| 67 | "----------\n" | ||
| 68 | "samplerate : float\n" | ||
| 69 | " Sampling-rate of the expected input.\n" | ||
| 70 | "\n" | ||
| 71 | "References\n" | ||
| 72 | "----------\n" | ||
| 73 | "\n" | ||
| 74 | "Malcolm Slaney, `Auditory Toolbox Version 2, Technical Report #1998-010\n" | ||
| 75 | "<https://engineering.purdue.edu/~malcolm/interval/1998-010/>`_\n" | ||
| 76 | ""; | ||
| 77 | |||
| 78 | static char Py_filterbank_set_mel_coeffs_doc[] = "" | ||
| 79 | "set_mel_coeffs(samplerate, fmin, fmax)\n" | ||
| 80 | "\n" | ||
| 81 | "Set coefficients of filterbank to linearly spaced mel scale.\n" | ||
| 82 | "\n" | ||
| 83 | "Parameters\n" | ||
| 84 | "----------\n" | ||
| 85 | "samplerate : float\n" | ||
| 86 | " Sampling-rate of the expected input.\n" | ||
| 87 | "fmin : float\n" | ||
| 88 | " Lower frequency boundary of the first filter.\n" | ||
| 89 | "fmax : float\n" | ||
| 90 | " Upper frequency boundary of the last filter.\n" | ||
| 91 | "\n" | ||
| 92 | "See also\n" | ||
| 93 | "--------\n" | ||
| 94 | "hztomel\n" | ||
| 95 | ""; | ||
| 96 | |||
| 97 | static char Py_filterbank_set_mel_coeffs_htk_doc[] = "" | ||
| 98 | "set_mel_coeffs_htk(samplerate, fmin, fmax)\n" | ||
| 99 | "\n" | ||
| 100 | "Set coefficients of the filters to be linearly spaced in the HTK mel scale.\n" | ||
| 101 | "\n" | ||
| 102 | "Parameters\n" | ||
| 103 | "----------\n" | ||
| 104 | "samplerate : float\n" | ||
| 105 | " Sampling-rate of the expected input.\n" | ||
| 106 | "fmin : float\n" | ||
| 107 | " Lower frequency boundary of the first filter.\n" | ||
| 108 | "fmax : float\n" | ||
| 109 | " Upper frequency boundary of the last filter.\n" | ||
| 110 | "\n" | ||
| 111 | "See also\n" | ||
| 112 | "--------\n" | ||
| 113 | "hztomel with `htk=True`\n" | ||
| 114 | ""; | ||
| 115 | |||
| 116 | static char Py_filterbank_get_coeffs_doc[] = "" | ||
| 117 | "get_coeffs()\n" | ||
| 118 | "\n" | ||
| 119 | "Get coefficients matrix of filterbank.\n" | ||
| 120 | "\n" | ||
| 121 | "Returns\n" | ||
| 122 | "-------\n" | ||
| 123 | "array_like\n" | ||
| 124 | " Array of shape (n_filters, win_s/2+1) containing the coefficients.\n" | ||
| 125 | ""; | ||
| 126 | |||
| 127 | static char Py_filterbank_set_coeffs_doc[] = "" | ||
| 128 | "set_coeffs(coeffs)\n" | ||
| 129 | "\n" | ||
| 130 | "Set coefficients of filterbank.\n" | ||
| 131 | "\n" | ||
| 132 | "Parameters\n" | ||
| 133 | "----------\n" | ||
| 134 | "coeffs : fmat\n" | ||
| 135 | " Array of shape (n_filters, win_s/2+1) containing the coefficients.\n" | ||
| 136 | ""; | ||
| 137 | |||
| 138 | static char Py_filterbank_set_power_doc[] = "" | ||
| 139 | "set_power(power)\n" | ||
| 140 | "\n" | ||
| 141 | "Set power applied to input spectrum of filterbank.\n" | ||
| 142 | "\n" | ||
| 143 | "Parameters\n" | ||
| 144 | "----------\n" | ||
| 145 | "power : float\n" | ||
| 146 | " Power to raise input spectrum to before computing the filters.\n" | ||
| 147 | ""; | ||
| 148 | |||
| 149 | static char Py_filterbank_get_power_doc[] = "" | ||
| 150 | "get_power()\n" | ||
| 151 | "\n" | ||
| 152 | "Get power applied to filterbank.\n" | ||
| 153 | "\n" | ||
| 154 | "Returns\n" | ||
| 155 | "-------\n" | ||
| 156 | "float\n" | ||
| 157 | " Power parameter.\n" | ||
| 158 | ""; | ||
| 159 | |||
| 160 | static char Py_filterbank_set_norm_doc[] = "" | ||
| 161 | "set_norm(norm)\n" | ||
| 162 | "\n" | ||
| 163 | "Set norm parameter. If set to `0`, the filters will not be normalized.\n" | ||
| 164 | "If set to `1`, the filters will be normalized to one. Default to `1`.\n" | ||
| 165 | "\n" | ||
| 166 | "This function should be called *before* :meth:`set_triangle_bands`,\n" | ||
| 167 | ":meth:`set_mel_coeffs`, :meth:`set_mel_coeffs_htk`, or\n" | ||
| 168 | ":meth:`set_mel_coeffs_slaney`.\n" | ||
| 169 | "\n" | ||
| 170 | "Parameters\n" | ||
| 171 | "----------\n" | ||
| 172 | "norm : int\n" | ||
| 173 | " `0` to disable, `1` to enable\n" | ||
| 174 | ""; | ||
| 175 | |||
| 176 | static char Py_filterbank_get_norm_doc[] = "" | ||
| 177 | "get_norm()\n" | ||
| 178 | "\n" | ||
| 179 | "Get norm parameter of filterbank.\n" | ||
| 180 | "\n" | ||
| 181 | "Returns\n" | ||
| 182 | "-------\n" | ||
| 183 | "float\n" | ||
| 184 | " Norm parameter.\n" | ||
| 185 | ""; | ||
| 4 | 186 | ||
| 5 | typedef struct | 187 | typedef struct |
| 6 | { | 188 | { |
| @@ -288,6 +470,13 @@ Py_filterbank_set_power(Py_filterbank *self, PyObject *args) · 281 unmodified lines | |||
| 288 | Py_RETURN_NONE; | 470 | Py_RETURN_NONE; |
| 289 | } | 471 | } |
| 290 | 472 | ||
| 473 | static PyObject * | ||
| 474 | Py_filterbank_get_power (Py_filterbank * self, PyObject *unused) | ||
| 475 | { | ||
| 476 | smpl_t power = aubio_filterbank_get_power(self->o); | ||
| 477 | return (PyObject *)PyFloat_FromDouble (power); | ||
| 478 | } | ||
| 479 | |||
| 291 | static PyObject * | 480 | static PyObject * |
| 292 | Py_filterbank_set_norm(Py_filterbank *self, PyObject *args) | 481 | Py_filterbank_set_norm(Py_filterbank *self, PyObject *args) |
| 293 | { | 482 | { |
| @@ -311,23 +500,34 @@ Py_filterbank_set_norm(Py_filterbank *self, PyObject *args) · 17 unmodified lines | |||
| 311 | Py_RETURN_NONE; | 500 | Py_RETURN_NONE; |
| 312 | } | 501 | } |
| 313 | 502 | ||
| 503 | static PyObject * | ||
| 504 | Py_filterbank_get_norm (Py_filterbank * self, PyObject *unused) | ||
| 505 | { | ||
| 506 | smpl_t norm = aubio_filterbank_get_norm(self->o); | ||
| 507 | return (PyObject *)PyFloat_FromDouble (norm); | ||
| 508 | } | ||
| 509 | |||
| 314 | static PyMethodDef Py_filterbank_methods[] = { | 510 | static PyMethodDef Py_filterbank_methods[] = { |
| 315 | {"set_triangle_bands", (PyCFunction) Py_filterbank_set_triangle_bands, | 511 | {"set_triangle_bands", (PyCFunction) Py_filterbank_set_triangle_bands, |
| 316 | METH_VARARGS, "set coefficients of filterbanks"}, | 512 | METH_VARARGS, Py_filterbank_set_triangle_bands_doc}, |
| 317 | {"set_mel_coeffs_slaney", (PyCFunction) Py_filterbank_set_mel_coeffs_slaney, | 513 | {"set_mel_coeffs_slaney", (PyCFunction) Py_filterbank_set_mel_coeffs_slaney, |
| 318 | METH_VARARGS, "set coefficients of filterbank as in Auditory Toolbox"}, | 514 | METH_VARARGS, Py_filterbank_set_mel_coeffs_slaney_doc}, |
| 319 | {"set_mel_coeffs", (PyCFunction) Py_filterbank_set_mel_coeffs, | 515 | {"set_mel_coeffs", (PyCFunction) Py_filterbank_set_mel_coeffs, |
| 320 | METH_VARARGS, "set coefficients of filterbank to linearly spaced mel scale"}, | 516 | METH_VARARGS, Py_filterbank_set_mel_coeffs_doc}, |
| 321 | {"set_mel_coeffs_htk", (PyCFunction) Py_filterbank_set_mel_coeffs_htk, | 517 | {"set_mel_coeffs_htk", (PyCFunction) Py_filterbank_set_mel_coeffs_htk, |
| 322 | METH_VARARGS, "set coefficients of filterbank to linearly spaced mel scale"}, | 518 | METH_VARARGS, Py_filterbank_set_mel_coeffs_htk_doc}, |
| 323 | {"get_coeffs", (PyCFunction) Py_filterbank_get_coeffs, | 519 | {"get_coeffs", (PyCFunction) Py_filterbank_get_coeffs, |
| 324 | METH_NOARGS, "get coefficients of filterbank"}, | 520 | METH_NOARGS, Py_filterbank_get_coeffs_doc}, |
| 325 | {"set_coeffs", (PyCFunction) Py_filterbank_set_coeffs, | 521 | {"set_coeffs", (PyCFunction) Py_filterbank_set_coeffs, |
| 326 | METH_VARARGS, "set coefficients of filterbank"}, | 522 | METH_VARARGS, Py_filterbank_set_coeffs_doc}, |
| 327 | {"set_power", (PyCFunction) Py_filterbank_set_power, | 523 | {"set_power", (PyCFunction) Py_filterbank_set_power, |
| 328 | METH_VARARGS, "set power applied to filterbank input spectrum"}, | 524 | METH_VARARGS, Py_filterbank_set_power_doc}, |
| 525 | {"get_power", (PyCFunction) Py_filterbank_get_power, | ||
| 526 | METH_NOARGS, Py_filterbank_get_power_doc}, | ||
| 329 | {"set_norm", (PyCFunction) Py_filterbank_set_norm, | 527 | {"set_norm", (PyCFunction) Py_filterbank_set_norm, |
| 330 | METH_VARARGS, "set norm applied to filterbank input spectrum"}, | 528 | METH_VARARGS, Py_filterbank_set_norm_doc}, |
| 529 | {"get_norm", (PyCFunction) Py_filterbank_get_norm, | ||
| 530 | METH_NOARGS, Py_filterbank_get_norm_doc}, | ||
| 331 | {NULL} | 531 | {NULL} |
| 332 | }; | 532 | }; |
| 333 | 533 | ||
| @@ -231,11 +231,21 @@ typedef struct{{ · 230 unmodified lines | |||
| 231 | return out.format(do_inputs_list = do_inputs_list, **self.__dict__) | 231 | return out.format(do_inputs_list = do_inputs_list, **self.__dict__) |
| 232 | 232 | ||
| 233 | def gen_doc(self): | 233 | def gen_doc(self): |
| 234 | sig = [] | ||
| 235 | for p in self.input_params: | ||
| 236 | name = p['name'] | ||
| 237 | defval = aubiodefvalue[name].replace('"','\\\"') | ||
| 238 | sig.append("{name}={defval}".format(defval=defval, name=name)) | ||
| 234 | out = """ | 239 | out = """ |
| 235 | // TODO: add documentation | 240 | #ifndef PYAUBIO_{shortname}_doc |
| 236 | static char Py_{shortname}_doc[] = \"undefined\"; | 241 | #define PYAUBIO_{shortname}_doc "{shortname}({sig})" |
| 242 | #endif /* PYAUBIO_{shortname}_doc */ | ||
| 243 | |||
| 244 | static char Py_{shortname}_doc[] = "" | ||
| 245 | PYAUBIO_{shortname}_doc | ||
| 246 | ""; | ||
| 237 | """ | 247 | """ |
| 238 | return out.format(**self.__dict__) | 248 | return out.format(sig=', '.join(sig), **self.__dict__) |
| 239 | 249 | ||
| 240 | def gen_new(self): | 250 | def gen_new(self): |
| 241 | out = """ | 251 | out = """ |
| @@ -111,13 +111,15 @@ class aubio_mfcc_fb_params(TestCase): · 110 unmodified lines | |||
| 111 | def test_set_scale(self): | 111 | def test_set_scale(self): |
| 112 | buf_size, n_filters, n_coeffs, samplerate = 512, 20, 10, 16000 | 112 | buf_size, n_filters, n_coeffs, samplerate = 512, 20, 10, 16000 |
| 113 | m = mfcc(buf_size, n_filters, n_coeffs, samplerate) | 113 | m = mfcc(buf_size, n_filters, n_coeffs, samplerate) |
| 114 | m.set_scale(10.) | 114 | m.set_scale(10.5) |
| 115 | assert m.get_scale() == 10.5 | ||
| 115 | m(cvec(buf_size)) | 116 | m(cvec(buf_size)) |
| 116 | 117 | ||
| 117 | def test_set_power(self): | 118 | def test_set_power(self): |
| 118 | buf_size, n_filters, n_coeffs, samplerate = 512, 20, 10, 16000 | 119 | buf_size, n_filters, n_coeffs, samplerate = 512, 20, 10, 16000 |
| 119 | m = mfcc(buf_size, n_filters, n_coeffs, samplerate) | 120 | m = mfcc(buf_size, n_filters, n_coeffs, samplerate) |
| 120 | m.set_power(2.) | 121 | m.set_power(2.5) |
| 122 | assert m.get_power() == 2.5 | ||
| 121 | m(cvec(buf_size)) | 123 | m(cvec(buf_size)) |
| 122 | 124 | ||
| 123 | def test_set_mel_coeffs(self): | 125 | def test_set_mel_coeffs(self): |