From efa62ce685043ab3a0195b2e7477c02521f77b14 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Fri, 10 Jul 2015 00:59:23 +0200 Subject: [PATCH 1/1] ext/py-musicutils.c: complete window implementation --- python/ext/py-musicutils.c | 17 ++++++++++------- python/ext/py-musicutils.h | 4 +++- python/tests/test_musicutils.py | 9 +++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/python/ext/py-musicutils.c b/python/ext/py-musicutils.c index e50939db..ca21fbec 100644 --- 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); } diff --git a/python/ext/py-musicutils.h b/python/ext/py-musicutils.h index ed15a023..bdf85ab1 100644 --- a/python/ext/py-musicutils.h +++ b/python/ext/py-musicutils.h @@ -9,7 +9,9 @@ static char Py_aubio_window_doc[] = "" "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); diff --git a/python/tests/test_musicutils.py b/python/tests/test_musicutils.py index 15282ae5..ece079c4 100755 --- 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): @@ -24,6 +25,14 @@ 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() -- 2.11.0