ref: d6f9b3a234dd2fb03b30356f854d58ec11491ea7
parent: 965ea78a7a4aefa68e54f7c108e635740ed8b0fb
author: Paul Brossier <piem@piem.org>
date: Sun Nov 15 10:01:06 EST 2009
py-fvec.c: add PyAubio_CFvecToArray
--- a/interfaces/python/aubio-types.h
+++ b/interfaces/python/aubio-types.h
@@ -35,6 +35,7 @@
} Py_fvec;
extern PyTypeObject Py_fvecType;
extern PyObject *PyAubio_FvecToArray (Py_fvec * self);
+extern PyObject *PyAubio_CFvecToArray (fvec_t * self);
extern Py_fvec *PyAubio_ArrayToFvec (PyObject * self);
typedef struct
--- a/interfaces/python/py-fvec.c
+++ b/interfaces/python/py-fvec.c
@@ -176,6 +176,23 @@
}
PyObject *
+PyAubio_CFvecToArray (fvec_t * self)
+{
+ PyObject *array = NULL;
+ uint_t i;
+ npy_intp dims[] = { self->length, 1 };
+ PyObject *concat = PyList_New (0), *tmp = NULL;
+ for (i = 0; i < self->channels; i++) {
+ tmp = PyArray_SimpleNewFromData (1, dims, AUBIO_NPY_SMPL, self->data[i]);
+ PyList_Append (concat, tmp);
+ Py_DECREF (tmp);
+ }
+ array = PyArray_FromObject (concat, AUBIO_NPY_SMPL, 2, 2);
+ Py_DECREF (concat);
+ return array;
+}
+
+PyObject *
PyAubio_FvecToArray (Py_fvec * self)
{
PyObject *array = NULL;
@@ -264,7 +281,7 @@
static PyMethodDef Py_fvec_methods[] = {
{"__array__", (PyCFunction) PyAubio_FvecToArray, METH_NOARGS,
- "Returns the first channel as a numpy array."},
+ "Returns the vector as a numpy array."},
{NULL}
};