Showing the changes to python (2 of 2 files). Show all
Unified · Split
| @@ -39,6 +39,108 @@ Py_alpha_norm (PyObject * self, PyObject * args) · 38 unmodified lines | ||
| 39 | 39 | return result; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | +static char Py_bintomidi_doc[] = "convert bin to midi"; | |
| 43 | + | |
| 44 | +static PyObject * | |
| 45 | +Py_bintomidi (PyObject * self, PyObject * args) | |
| 46 | +{ | |
| 47 | + smpl_t input, samplerate, fftsize; | |
| 48 | + smpl_t output; | |
| 49 | + | |
| 50 | + if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) { | |
| 51 | + return NULL; | |
| 52 | + } | |
| 53 | + | |
| 54 | + output = aubio_bintomidi (input, samplerate, fftsize); | |
| 55 | + | |
| 56 | + return (PyObject *)PyFloat_FromDouble (output); | |
| 57 | +} | |
| 58 | + | |
| 59 | +static char Py_miditobin_doc[] = "convert midi to bin"; | |
| 60 | + | |
| 61 | +static PyObject * | |
| 62 | +Py_miditobin (PyObject * self, PyObject * args) | |
| 63 | +{ | |
| 64 | + smpl_t input, samplerate, fftsize; | |
| 65 | + smpl_t output; | |
| 66 | + | |
| 67 | + if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) { | |
| 68 | + return NULL; | |
| 69 | + } | |
| 70 | + | |
| 71 | + output = aubio_miditobin (input, samplerate, fftsize); | |
| 72 | + | |
| 73 | + return (PyObject *)PyFloat_FromDouble (output); | |
| 74 | +} | |
| 75 | + | |
| 76 | +static char Py_bintofreq_doc[] = "convert bin to freq"; | |
| 77 | + | |
| 78 | +static PyObject * | |
| 79 | +Py_bintofreq (PyObject * self, PyObject * args) | |
| 80 | +{ | |
| 81 | + smpl_t input, samplerate, fftsize; | |
| 82 | + smpl_t output; | |
| 83 | + | |
| 84 | + if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) { | |
| 85 | + return NULL; | |
| 86 | + } | |
| 87 | + | |
| 88 | + output = aubio_bintofreq (input, samplerate, fftsize); | |
| 89 | + | |
| 90 | + return (PyObject *)PyFloat_FromDouble (output); | |
| 91 | +} | |
| 92 | + | |
| 93 | +static char Py_freqtobin_doc[] = "convert freq to bin"; | |
| 94 | + | |
| 95 | +static PyObject * | |
| 96 | +Py_freqtobin (PyObject * self, PyObject * args) | |
| 97 | +{ | |
| 98 | + smpl_t input, samplerate, fftsize; | |
| 99 | + smpl_t output; | |
| 100 | + | |
| 101 | + if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) { | |
| 102 | + return NULL; | |
| 103 | + } | |
| 104 | + | |
| 105 | + output = aubio_freqtobin (input, samplerate, fftsize); | |
| 106 | + | |
| 107 | + return (PyObject *)PyFloat_FromDouble (output); | |
| 108 | +} | |
| 109 | + | |
| 110 | +static char Py_freqtomidi_doc[] = "convert freq to midi"; | |
| 111 | + | |
| 112 | +static PyObject * | |
| 113 | +Py_freqtomidi (PyObject * self, PyObject * args) | |
| 114 | +{ | |
| 115 | + smpl_t input; | |
| 116 | + smpl_t output; | |
| 117 | + | |
| 118 | + if (!PyArg_ParseTuple (args, "|f", &input)) { | |
| 119 | + return NULL; | |
| 120 | + } | |
| 121 | + | |
| 122 | + output = aubio_freqtomidi (input); | |
| 123 | + | |
| 124 | + return (PyObject *)PyFloat_FromDouble (output); | |
| 125 | +} | |
| 126 | + | |
| 127 | +static char Py_miditofreq_doc[] = "convert midi to freq"; | |
| 128 | + | |
| 129 | +static PyObject * | |
| 130 | +Py_miditofreq (PyObject * self, PyObject * args) | |
| 131 | +{ | |
| 132 | + smpl_t input; | |
| 133 | + smpl_t output; | |
| 134 | + | |
| 135 | + if (!PyArg_ParseTuple (args, "|f", &input)) { | |
| 136 | + return NULL; | |
| 137 | + } | |
| 138 | + | |
| 139 | + output = aubio_miditofreq (input); | |
| 140 | + | |
| 141 | + return (PyObject *)PyFloat_FromDouble (output); | |
| 142 | +} | |
| 143 | + | |
| 42 | 144 | static char Py_zero_crossing_rate_doc[] = "compute zero crossing rate"; |
| 43 | 145 | |
| 44 | 146 | static PyObject * |
| @@ -106,9 +208,14 @@ Py_min_removal(PyObject * self, PyObject * args) · 61 unmodified lines | ||
| 106 | 208 | } |
| 107 | 209 | |
| 108 | 210 | static PyMethodDef aubio_methods[] = { |
| 211 | + {"bintomidi", Py_bintomidi, METH_VARARGS, Py_bintomidi_doc}, | |
| 212 | + {"miditobin", Py_miditobin, METH_VARARGS, Py_miditobin_doc}, | |
| 213 | + {"bintofreq", Py_bintofreq, METH_VARARGS, Py_bintofreq_doc}, | |
| 214 | + {"freqtobin", Py_freqtobin, METH_VARARGS, Py_freqtobin_doc}, | |
| 215 | + {"miditofreq", Py_miditofreq, METH_VARARGS, Py_miditofreq_doc}, | |
| 216 | + {"freqtomidi", Py_freqtomidi, METH_VARARGS, Py_freqtomidi_doc}, | |
| 109 | 217 | {"alpha_norm", Py_alpha_norm, METH_VARARGS, Py_alpha_norm_doc}, |
| 110 | − {"zero_crossing_rate", Py_zero_crossing_rate, METH_VARARGS, | |
| 111 | − Py_zero_crossing_rate_doc}, | |
| 218 | + {"zero_crossing_rate", Py_zero_crossing_rate, METH_VARARGS, Py_zero_crossing_rate_doc}, | |
| 112 | 219 | {"min_removal", Py_min_removal, METH_VARARGS, Py_min_removal_doc}, |
| 113 | 220 | {NULL, NULL} /* Sentinel */ |
| 114 | 221 | }; |
| @@ -0,0 +1,31 @@ | ||
| 1 | +#! /usr/bin/env python | |
| 2 | + | |
| 3 | +from numpy.testing import TestCase, run_module_suite | |
| 4 | +from numpy.testing import assert_equal, assert_almost_equal | |
| 5 | +from aubio import bintomidi, miditobin, freqtobin, bintofreq, freqtomidi, miditofreq | |
| 6 | + | |
| 7 | +class aubio_mathutils(TestCase): | |
| 8 | + | |
| 9 | + def test_miditobin(self): | |
| 10 | + a = [ miditobin(a, 44100, 512) for a in range(128) ] | |
| 11 | + | |
| 12 | + def test_bintomidi(self): | |
| 13 | + a = [ bintomidi(a, 44100, 512) for a in range(128) ] | |
| 14 | + | |
| 15 | + def test_freqtobin(self): | |
| 16 | + a = [ freqtobin(a, 44100, 512) for a in range(128) ] | |
| 17 | + | |
| 18 | + def test_bintofreq(self): | |
| 19 | + a = [ bintofreq(a, 44100, 512) for a in range(128) ] | |
| 20 | + | |
| 21 | + def test_freqtomidi(self): | |
| 22 | + a = [ freqtomidi(a) for a in range(128) ] | |
| 23 | + | |
| 24 | + def test_miditofreq(self): | |
| 25 | + freqs = [ miditofreq(a) for a in range(128) ] | |
| 26 | + midis = [ freqtomidi(a) for a in freqs ] | |
| 27 | + print midis | |
| 28 | + | |
| 29 | +if __name__ == '__main__': | |
| 30 | + from unittest import main | |
| 31 | + main() | |