From 352fd5f7b20761a99dd66181d8c61e4acbceb5df Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Fri, 2 Oct 2009 11:19:48 +0200 Subject: [PATCH] python/py-fvec.c, python/aubio-types.g: define AUBIO_FLOAT, move default length and channels here, rename fvec to aubio.fvec --- interfaces/python/aubio-types.h | 22 ++++++++++++++++++++++ interfaces/python/py-fvec.c | 11 ++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/interfaces/python/aubio-types.h b/interfaces/python/aubio-types.h index 82fae6ac..f29020f5 100644 --- a/interfaces/python/aubio-types.h +++ b/interfaces/python/aubio-types.h @@ -4,6 +4,24 @@ #include #include +#define Py_fvec_default_length 1024 +#define Py_fvec_default_channels 1 + +#ifdef HAVE_AUBIO_DOUBLE +#define AUBIO_FLOAT NPY_FLOAT +#else +#define AUBIO_FLOAT NPY_LONG +#endif + +/** + +Defining this constant to 1 will allow PyAubio_CastToFvec to convert from data +types different than NPY_FLOAT to and fvec, and therefore creating a copy of +it. + +*/ +#define AUBIO_DO_CASTING 0 + typedef struct { PyObject_HEAD fvec_t * o; @@ -11,3 +29,7 @@ typedef struct uint_t channels; } Py_fvec; extern PyTypeObject Py_fvecType; + +extern PyObject *PyAubio_FvecToArray (Py_fvec * self); + +extern Py_fvec *PyAubio_ArrayToFvec (PyObject * self); diff --git a/interfaces/python/py-fvec.c b/interfaces/python/py-fvec.c index 72d812ed..fb4c5101 100644 --- a/interfaces/python/py-fvec.c +++ b/interfaces/python/py-fvec.c @@ -10,9 +10,6 @@ class fvec(): */ -#define Py_fvec_default_length 1024 -#define Py_fvec_default_channels 1 - static char Py_fvec_doc[] = "fvec object"; static PyObject * @@ -108,8 +105,8 @@ Py_fvec_print (Py_fvec * self, PyObject * unused) return Py_None; } -static PyObject * -Py_fvec_array (Py_fvec * self) +PyObject * +PyAubio_FvecToArray (Py_fvec * self) { PyObject *array = NULL; if (self->channels == 1) { @@ -198,7 +195,7 @@ static PyMemberDef Py_fvec_members[] = { static PyMethodDef Py_fvec_methods[] = { {"dump", (PyCFunction) Py_fvec_print, METH_NOARGS, "Dumps the contents of the vector to stdout."}, - {"__array__", (PyCFunction) Py_fvec_array, METH_NOARGS, + {"__array__", (PyCFunction) PyAubio_FvecToArray, METH_NOARGS, "Returns the first channel as a numpy array."}, {NULL} }; @@ -220,7 +217,7 @@ static PySequenceMethods Py_fvec_tp_as_sequence = { PyTypeObject Py_fvecType = { PyObject_HEAD_INIT (NULL) 0, /* ob_size */ - "fvec", /* tp_name */ + "aubio.fvec", /* tp_name */ sizeof (Py_fvec), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor) Py_fvec_del, /* tp_dealloc */ -- 2.26.2