ref: 6514bb6bdc338fa1c446c08408a30a6434096003
parent: 6a50b9e07fb992eb097657acbd34ca50ac70f121
author: Paul Brossier <piem@piem.org>
date: Sun Mar 3 11:27:17 EST 2013
aubiomodule.c: add unwrap2pi
--- a/python/aubiomodule.c
+++ b/python/aubiomodule.c
@@ -39,6 +39,23 @@
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 @@
}
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},
--- 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 @@
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