shithub: aubio

Download patch

ref: f6cbefe280382d27f221cecdbed2a990985a86b2
parent: 93004d5e0bdd2735bca41834855862eecd2d03b6
author: Paul Brossier <piem@piem.org>
date: Wed Jul 11 12:38:40 EDT 2012

py-filterbank.c: add set_coeffs

--- a/interfaces/python/py-filterbank.c
+++ b/interfaces/python/py-filterbank.c
@@ -49,7 +49,7 @@
 
 AUBIO_DEL(filterbank)
 
-static PyObject * 
+static PyObject *
 Py_filterbank_do(Py_filterbank * self, PyObject * args)
 {
   PyObject *input;
@@ -73,7 +73,7 @@
   return (PyObject *)PyAubio_CFvecToArray(out);
 }
 
-AUBIO_MEMBERS_START(filterbank) 
+AUBIO_MEMBERS_START(filterbank)
   {"win_s", T_INT, offsetof (Py_filterbank, win_s), READONLY,
     "size of the window"},
   {"n_filters", T_INT, offsetof (Py_filterbank, n_filters), READONLY,
@@ -80,7 +80,7 @@
     "number of filters"},
 AUBIO_MEMBERS_STOP(filterbank)
 
-static PyObject * 
+static PyObject *
 Py_filterbank_set_triangle_bands (Py_filterbank * self, PyObject *args)
 {
   uint_t err = 0;
@@ -112,7 +112,7 @@
   return Py_None;
 }
 
-static PyObject * 
+static PyObject *
 Py_filterbank_set_mel_coeffs_slaney (Py_filterbank * self, PyObject *args)
 {
   uint_t err = 0;
@@ -131,7 +131,37 @@
   return Py_None;
 }
 
-static PyObject * 
+static PyObject *
+Py_filterbank_set_coeffs (Py_filterbank * self, PyObject *args)
+{
+  uint_t err = 0;
+
+  PyObject *input;
+  fmat_t *coeffs;
+
+  if (!PyArg_ParseTuple (args, "O", &input)) {
+    return NULL;
+  }
+
+  coeffs = PyAubio_ArrayToCFmat (input);
+
+  if (coeffs == NULL) {
+    PyErr_SetString (PyExc_ValueError,
+        "unable to parse input array");
+    return NULL;
+  }
+
+  err = aubio_filterbank_set_coeffs (self->o, coeffs);
+
+  if (err > 0) {
+    PyErr_SetString (PyExc_ValueError,
+        "error when setting filter coefficients");
+    return NULL;
+  }
+  return Py_None;
+}
+
+static PyObject *
 Py_filterbank_get_coeffs (Py_filterbank * self, PyObject *unused)
 {
   return (PyObject *)PyAubio_CFmatToArray(
@@ -145,6 +175,8 @@
     METH_VARARGS, "set coefficients of filterbank as in Auditory Toolbox"},
   {"get_coeffs", (PyCFunction) Py_filterbank_get_coeffs,
     METH_NOARGS, "get coefficients of filterbank"},
+  {"set_coeffs", (PyCFunction) Py_filterbank_set_coeffs,
+    METH_VARARGS, "set coefficients of filterbank"},
   {NULL}
 };