From d6f9b3a234dd2fb03b30356f854d58ec11491ea7 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sun, 15 Nov 2009 15:01:06 +0100 Subject: [PATCH] py-fvec.c: add PyAubio_CFvecToArray --- interfaces/python/aubio-types.h | 1 + interfaces/python/py-fvec.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/interfaces/python/aubio-types.h b/interfaces/python/aubio-types.h index 7311ee66..8d00191c 100644 --- a/interfaces/python/aubio-types.h +++ b/interfaces/python/aubio-types.h @@ -35,6 +35,7 @@ typedef struct } 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 diff --git a/interfaces/python/py-fvec.c b/interfaces/python/py-fvec.c index bb68df33..a6254510 100644 --- a/interfaces/python/py-fvec.c +++ b/interfaces/python/py-fvec.c @@ -175,6 +175,23 @@ fail: return NULL; } +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) { @@ -264,7 +281,7 @@ static PyMemberDef Py_fvec_members[] = { 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} }; -- 2.26.2