Showing the changes to python (2 of 2 files). Show all
Unified · Split
| @@ -39,6 +39,23 @@ Py_alpha_norm (PyObject * self, PyObject * args) · 38 unmodified lines | ||
| 39 | 39 | return result; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | +static char Py_unwrap2pi_doc[] = "unwrap phase value to [-pi, pi]"; | |
| 43 | + | |
| 44 | +static PyObject * | |
| 45 | +Py_unwrap2pi (PyObject * self, PyObject * args) | |
| 46 | +{ | |
| 47 | + smpl_t input; | |
| 48 | + smpl_t output; | |
| 49 | + | |
| 50 | + if (!PyArg_ParseTuple (args, "|f", &input)) { | |
| 51 | + return NULL; | |
| 52 | + } | |
| 53 | + | |
| 54 | + output = aubio_unwrap2pi (input); | |
| 55 | + | |
| 56 | + return (PyObject *)PyFloat_FromDouble (output); | |
| 57 | +} | |
| 58 | + | |
| 42 | 59 | static char Py_bintomidi_doc[] = "convert bin to midi"; |
| 43 | 60 | |
| 44 | 61 | static PyObject * |
| @@ -208,6 +225,7 @@ Py_min_removal(PyObject * self, PyObject * args) · 163 unmodified lines | ||
| 208 | 225 | } |
| 209 | 226 | |
| 210 | 227 | static PyMethodDef aubio_methods[] = { |
| 228 | + {"unwrap2pi", Py_unwrap2pi, METH_VARARGS, Py_unwrap2pi_doc}, | |
| 211 | 229 | {"bintomidi", Py_bintomidi, METH_VARARGS, Py_bintomidi_doc}, |
| 212 | 230 | {"miditobin", Py_miditobin, METH_VARARGS, Py_miditobin_doc}, |
| 213 | 231 | {"bintofreq", Py_bintofreq, METH_VARARGS, Py_bintofreq_doc}, |
| @@ -3,9 +3,15 @@ · 2 unmodified lines | ||
| 3 | 3 | from numpy.testing import TestCase, run_module_suite |
| 4 | 4 | from numpy.testing import assert_equal, assert_almost_equal |
| 5 | 5 | from aubio import bintomidi, miditobin, freqtobin, bintofreq, freqtomidi, miditofreq |
| 6 | +from aubio import unwrap2pi | |
| 6 | 7 | |
| 7 | 8 | class aubio_mathutils(TestCase): |
| 8 | 9 | |
| 10 | + def test_unwrap2pi(self): | |
| 11 | + a = [ x/100. for x in range(-600,600,100) ] | |
| 12 | + b = [ unwrap2pi(x) for x in a ] | |
| 13 | + #print b | |
| 14 | + | |
| 9 | 15 | def test_miditobin(self): |
| 10 | 16 | a = [ miditobin(a, 44100, 512) for a in range(128) ] |
| 11 | 17 | |
| @@ -24,7 +30,6 @@ class aubio_mathutils(TestCase): · 12 unmodified lines | ||
| 24 | 30 | def test_miditofreq(self): |
| 25 | 31 | freqs = [ miditofreq(a) for a in range(128) ] |
| 26 | 32 | midis = [ freqtomidi(a) for a in freqs ] |
| 27 | − print midis | |
| 28 | 33 | |
| 29 | 34 | if __name__ == '__main__': |
| 30 | 35 | from unittest import main |