PyObject *
Py_aubio_window(PyObject *self, PyObject *args)
{
- PyObject *output = NULL;
char_t *wintype = NULL;
uint_t winlen = 0;
- fvec_t *window;
+ fvec_t *window = NULL;
- if (!PyArg_ParseTuple (args, "|sd", &wintype, &winlen)) {
- PyErr_SetString (PyExc_ValueError,
- "failed parsing arguments");
+ if (!PyArg_ParseTuple (args, "|sI", &wintype, &winlen)) {
+ PyErr_SetString (PyExc_ValueError, "failed parsing arguments");
return NULL;
}
- //return (PyObject *) PyAubio_CFvecToArray(vec);
- Py_RETURN_NONE;
+ window = new_aubio_window(wintype, winlen);
+ if (window == NULL) {
+ PyErr_SetString (PyExc_ValueError, "failed computing window");
+ return NULL;
+ }
+
+ return (PyObject *) PyAubio_CFvecToArray(window);
}
"Example\n"
"-------\n"
"\n"
-">>> window('hanningz', 1024)";
+">>> window('hanningz', 1024)\n"
+"array([ 0.00000000e+00, 9.41753387e-06, 3.76403332e-05, ...,\n"
+" 8.46982002e-05, 3.76403332e-05, 9.41753387e-06], dtype=float32)";
PyObject * Py_aubio_window(PyObject *self, PyObject *args);
#! /usr/bin/env python
from numpy.testing import TestCase
+from numpy.testing.utils import assert_almost_equal
from aubio import window
class aubio_window(TestCase):
else:
self.fail('non-integer window length does not raise a ValueError')
+ def test_compute_hanning_1024(self):
+ from numpy import cos, arange
+ from math import pi
+ size = 1024
+ aubio_window = window("hanning", size)
+ numpy_window = .5 - .5 * cos(2. * pi * arange(size) / size)
+ assert_almost_equal(aubio_window, numpy_window)
+
if __name__ == '__main__':
from unittest import main
main()