Changeset 5a7e2c3


Ignore:
Timestamp:
Jul 10, 2015, 1:51:25 AM (4 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
Children:
4615886a
Parents:
efa62ce
Message:

ext/py-musicutils.c: add level_lin

Location:
python
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • python/ext/aubiomodule.c

    refa62ce r5a7e2c3  
    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},
     243  {"level_lin", Py_aubio_level_lin, METH_VARARGS, Py_aubio_level_lin_doc},
    243244  {"window", Py_aubio_window, METH_VARARGS, Py_aubio_window_doc},
    244245  {NULL, NULL} /* Sentinel */
  • python/ext/py-musicutils.c

    refa62ce r5a7e2c3  
    2121  return (PyObject *) PyAubio_CFvecToArray(window);
    2222}
     23
     24PyObject *
     25Py_aubio_level_lin(PyObject *self, PyObject *args)
     26{
     27  PyObject *input;
     28  fvec_t *vec;
     29  PyObject *level_lin;
     30
     31  if (!PyArg_ParseTuple (args, "O:level_lin", &input)) {
     32    PyErr_SetString (PyExc_ValueError, "failed parsing arguments");
     33    return NULL;
     34  }
     35
     36  if (input == NULL) {
     37    return NULL;
     38  }
     39
     40  vec = PyAubio_ArrayToCFvec (input);
     41  if (vec == NULL) {
     42    return NULL;
     43  }
     44
     45  level_lin = Py_BuildValue("f", aubio_level_lin(vec));
     46  if (level_lin == NULL) {
     47    PyErr_SetString (PyExc_ValueError, "failed computing level_lin");
     48    return NULL;
     49  }
     50
     51  return level_lin;
     52}
  • python/tests/test_musicutils.py

    refa62ce r5a7e2c3  
    22
    33from numpy.testing import TestCase
    4 from numpy.testing.utils import assert_almost_equal
    5 from aubio import window
     4from numpy.testing.utils import assert_equal, assert_almost_equal
     5from numpy import cos, arange
     6from math import pi
     7
     8from aubio import window, level_lin
     9
     10from aubio import fvec
    611
    712class aubio_window(TestCase):
     
    2732
    2833    def test_compute_hanning_1024(self):
    29         from numpy import cos, arange
    30         from math import pi
    3134        size = 1024
    3235        aubio_window = window("hanning", size)
     
    3437        assert_almost_equal(aubio_window, numpy_window)
    3538
     39class aubio_level_lin(TestCase):
     40    def test_accept_fvec(self):
     41        level_lin(fvec(1024))
     42
     43    def test_fail_not_fvec(self):
     44        try:
     45            level_lin("default")
     46        except ValueError, e:
     47            pass
     48        else:
     49            self.fail('non-number input phase does not raise a TypeError')
     50
     51    def test_zeros_is_zeros(self):
     52        assert_equal(level_lin(fvec(1024)), 0.)
     53
     54    def test_minus_ones_is_one(self):
     55        from numpy import ones
     56        assert_equal(level_lin(-ones(1024, dtype="float32")), 1.)
     57
    3658if __name__ == '__main__':
    3759    from unittest import main
Note: See TracChangeset for help on using the changeset viewer.