History

aubiomodule.c: add unwrap2pi

Paul Brossier committed 13 years ago

Commit 6514bb61 parent 6a50b9e2 files · +24 −1Browse files

Showing the changes to python (2 of 2 files). Show all

Unified · Split

2 files
  1. python/aubiomodule.c +18 −0
  2. python/tests/test_mathutils.py +6 −1
python/aubiomodule.c+18−0
@@ -39,6 +39,23 @@ Py_alpha_norm (PyObject * self, PyObject * args) · 38 unmodified lines
3939 return result;
4040 }
4141
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+
4259 static char Py_bintomidi_doc[] = "convert bin to midi";
4360
4461 static PyObject *
@@ -208,6 +225,7 @@ Py_min_removal(PyObject * self, PyObject * args) · 163 unmodified lines
208225 }
209226
210227 static PyMethodDef aubio_methods[] = {
228+ {"unwrap2pi", Py_unwrap2pi, METH_VARARGS, Py_unwrap2pi_doc},
211229 {"bintomidi", Py_bintomidi, METH_VARARGS, Py_bintomidi_doc},
212230 {"miditobin", Py_miditobin, METH_VARARGS, Py_miditobin_doc},
213231 {"bintofreq", Py_bintofreq, METH_VARARGS, Py_bintofreq_doc},
python/tests/test_mathutils.py+6−1
@@ -3,9 +3,15 @@ · 2 unmodified lines
33 from numpy.testing import TestCase, run_module_suite
44 from numpy.testing import assert_equal, assert_almost_equal
55 from aubio import bintomidi, miditobin, freqtobin, bintofreq, freqtomidi, miditofreq
6+from aubio import unwrap2pi
67
78 class aubio_mathutils(TestCase):
89
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+
915 def test_miditobin(self):
1016 a = [ miditobin(a, 44100, 512) for a in range(128) ]
1117
@@ -24,7 +30,6 @@ class aubio_mathutils(TestCase): · 12 unmodified lines
2430 def test_miditofreq(self):
2531 freqs = [ miditofreq(a) for a in range(128) ]
2632 midis = [ freqtomidi(a) for a in freqs ]
27− print midis
2833
2934 if __name__ == '__main__':
3035 from unittest import main

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t