History

ext/py-musicutils.c: add db_spl

Paul Brossier committed 11 years ago

Commit 46158861 parent 5a7e2c33 files · +52 −1Browse files

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

Unified · Split

3 files
  1. python/ext/aubiomodule.c +1 −0
  2. python/ext/py-musicutils.c +30 −0
  3. python/tests/test_musicutils.py +21 −1
python/ext/aubiomodule.c+1−0
@@ -241,6 +241,7 @@ static PyMethodDef aubio_methods[] = { · 240 unmodified lines
241241 {"zero_crossing_rate", Py_zero_crossing_rate, METH_VARARGS, Py_zero_crossing_rate_doc},
242242 {"min_removal", Py_min_removal, METH_VARARGS, Py_min_removal_doc},
243243 {"level_lin", Py_aubio_level_lin, METH_VARARGS, Py_aubio_level_lin_doc},
244+ {"db_spl", Py_aubio_db_spl, METH_VARARGS, Py_aubio_db_spl_doc},
244245 {"window", Py_aubio_window, METH_VARARGS, Py_aubio_window_doc},
245246 {NULL, NULL} /* Sentinel */
246247 };
python/ext/py-musicutils.c+30−0
@@ -50,3 +50,33 @@ Py_aubio_level_lin(PyObject *self, PyObject *args) · 49 unmodified lines
5050
5151 return level_lin;
5252 }
53+
54+PyObject *
55+Py_aubio_db_spl(PyObject *self, PyObject *args)
56+{
57+ PyObject *input;
58+ fvec_t *vec;
59+ PyObject *db_spl;
60+
61+ if (!PyArg_ParseTuple (args, "O:db_spl", &input)) {
62+ PyErr_SetString (PyExc_ValueError, "failed parsing arguments");
63+ return NULL;
64+ }
65+
66+ if (input == NULL) {
67+ return NULL;
68+ }
69+
70+ vec = PyAubio_ArrayToCFvec (input);
71+ if (vec == NULL) {
72+ return NULL;
73+ }
74+
75+ db_spl = Py_BuildValue("f", aubio_db_spl(vec));
76+ if (db_spl == NULL) {
77+ PyErr_SetString (PyExc_ValueError, "failed computing db_spl");
78+ return NULL;
79+ }
80+
81+ return db_spl;
82+}
python/tests/test_musicutils.py+21−1
@@ -5,7 +5,7 @@ from numpy.testing.utils import assert_equal, assert_almost_equal · 4 unmodified lines
55 from numpy import cos, arange
66 from math import pi
77
8−from aubio import window, level_lin
8+from aubio import window, level_lin, db_spl
99
1010 from aubio import fvec
1111
@@ -55,6 +55,26 @@ class aubio_level_lin(TestCase): · 43 unmodified lines
5555 from numpy import ones
5656 assert_equal(level_lin(-ones(1024, dtype="float32")), 1.)
5757
58+class aubio_db_spl(TestCase):
59+ def test_accept_fvec(self):
60+ db_spl(fvec(1024))
61+
62+ def test_fail_not_fvec(self):
63+ try:
64+ db_spl("default")
65+ except ValueError, e:
66+ pass
67+ else:
68+ self.fail('non-number input phase does not raise a TypeError')
69+
70+ def test_zeros_is_inf(self):
71+ from math import isinf
72+ assert isinf(db_spl(fvec(1024)))
73+
74+ def test_minus_ones_is_zero(self):
75+ from numpy import ones
76+ assert_equal(db_spl(-ones(1024, dtype="float32")), 0.)
77+
5878 if __name__ == '__main__':
5979 from unittest import main
6080 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