ref: efa62ce685043ab3a0195b2e7477c02521f77b14
parent: 5e394ecc78197135efbec3d64ff9b4d3eec61358
author: Paul Brossier <[email protected]>
date: Thu Jul 9 20:59:23 EDT 2015
ext/py-musicutils.c: complete window implementation
--- a/python/ext/py-musicutils.c
+++ b/python/ext/py-musicutils.c
@@ -3,17 +3,20 @@
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);
}
--- a/python/ext/py-musicutils.h
+++ b/python/ext/py-musicutils.h
@@ -9,7 +9,9 @@
"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);
--- a/python/tests/test_musicutils.py
+++ b/python/tests/test_musicutils.py
@@ -1,6 +1,7 @@
#! /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):
@@ -23,6 +24,14 @@
pass
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