From: Paul Brossier Date: Sun, 3 Mar 2013 21:27:17 +0000 (-0500) Subject: aubiomodule.c: add unwrap2pi X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6514bb6bdc338fa1c446c08408a30a6434096003;p=aubio.git aubiomodule.c: add unwrap2pi --- diff --git a/python/aubiomodule.c b/python/aubiomodule.c index a3f6d92b..ccbc28ba 100644 --- a/python/aubiomodule.c +++ b/python/aubiomodule.c @@ -39,6 +39,23 @@ Py_alpha_norm (PyObject * self, PyObject * args) return result; } +static char Py_unwrap2pi_doc[] = "unwrap phase value to [-pi, pi]"; + +static PyObject * +Py_unwrap2pi (PyObject * self, PyObject * args) +{ + smpl_t input; + smpl_t output; + + if (!PyArg_ParseTuple (args, "|f", &input)) { + return NULL; + } + + output = aubio_unwrap2pi (input); + + return (PyObject *)PyFloat_FromDouble (output); +} + static char Py_bintomidi_doc[] = "convert bin to midi"; static PyObject * @@ -208,6 +225,7 @@ Py_min_removal(PyObject * self, PyObject * args) } static PyMethodDef aubio_methods[] = { + {"unwrap2pi", Py_unwrap2pi, METH_VARARGS, Py_unwrap2pi_doc}, {"bintomidi", Py_bintomidi, METH_VARARGS, Py_bintomidi_doc}, {"miditobin", Py_miditobin, METH_VARARGS, Py_miditobin_doc}, {"bintofreq", Py_bintofreq, METH_VARARGS, Py_bintofreq_doc}, diff --git a/python/tests/test_mathutils.py b/python/tests/test_mathutils.py index 9a8fea91..752c7899 100755 --- a/python/tests/test_mathutils.py +++ b/python/tests/test_mathutils.py @@ -3,9 +3,15 @@ from numpy.testing import TestCase, run_module_suite from numpy.testing import assert_equal, assert_almost_equal from aubio import bintomidi, miditobin, freqtobin, bintofreq, freqtomidi, miditofreq +from aubio import unwrap2pi class aubio_mathutils(TestCase): + def test_unwrap2pi(self): + a = [ x/100. for x in range(-600,600,100) ] + b = [ unwrap2pi(x) for x in a ] + #print b + def test_miditobin(self): a = [ miditobin(a, 44100, 512) for a in range(128) ] @@ -24,7 +30,6 @@ class aubio_mathutils(TestCase): def test_miditofreq(self): freqs = [ miditofreq(a) for a in range(128) ] midis = [ freqtomidi(a) for a in freqs ] - print midis if __name__ == '__main__': from unittest import main