History

ext/py-musicutils.c: complete window implementation

Paul Brossier committed 11 years ago

Commit efa62ce1 parent 5e394ec3 files · +22 −8Browse files

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

Unified · Split

3 files
  1. python/ext/py-musicutils.c +10 −7
  2. python/ext/py-musicutils.h +3 −1
  3. python/tests/test_musicutils.py +9 −0
python/ext/py-musicutils.c+10−7
@@ -3,17 +3,20 @@ · 2 unmodified lines
33 PyObject *
44 Py_aubio_window(PyObject *self, PyObject *args)
55 {
6− PyObject *output = NULL;
76 char_t *wintype = NULL;
87 uint_t winlen = 0;
9− fvec_t *window;
8+ fvec_t *window = NULL;
109
11− if (!PyArg_ParseTuple (args, "|sd", &wintype, &winlen)) {
12− PyErr_SetString (PyExc_ValueError,
13− "failed parsing arguments");
10+ if (!PyArg_ParseTuple (args, "|sI", &wintype, &winlen)) {
11+ PyErr_SetString (PyExc_ValueError, "failed parsing arguments");
1412 return NULL;
1513 }
1614
17− //return (PyObject *) PyAubio_CFvecToArray(vec);
18− Py_RETURN_NONE;
15+ window = new_aubio_window(wintype, winlen);
16+ if (window == NULL) {
17+ PyErr_SetString (PyExc_ValueError, "failed computing window");
18+ return NULL;
19+ }
20+
21+ return (PyObject *) PyAubio_CFvecToArray(window);
1922 }
python/ext/py-musicutils.h+3−1
@@ -9,7 +9,9 @@ static char Py_aubio_window_doc[] = "" · 8 unmodified lines
99 "Example\n"
1010 "-------\n"
1111 "\n"
12−">>> window('hanningz', 1024)";
12+">>> window('hanningz', 1024)\n"
13+"array([ 0.00000000e+00, 9.41753387e-06, 3.76403332e-05, ...,\n"
14+" 8.46982002e-05, 3.76403332e-05, 9.41753387e-06], dtype=float32)";
1315
1416 PyObject * Py_aubio_window(PyObject *self, PyObject *args);
1517
python/tests/test_musicutils.py+9−0
@@ -1,6 +1,7 @@
11 #! /usr/bin/env python
22
33 from numpy.testing import TestCase
4+from numpy.testing.utils import assert_almost_equal
45 from aubio import window
56
67 class aubio_window(TestCase):
@@ -24,6 +25,14 @@ class aubio_window(TestCase): · 17 unmodified lines
2425 else:
2526 self.fail('non-integer window length does not raise a ValueError')
2627
28+ def test_compute_hanning_1024(self):
29+ from numpy import cos, arange
30+ from math import pi
31+ size = 1024
32+ aubio_window = window("hanning", size)
33+ numpy_window = .5 - .5 * cos(2. * pi * arange(size) / size)
34+ assert_almost_equal(aubio_window, numpy_window)
35+
2736 if __name__ == '__main__':
2837 from unittest import main
2938 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