shithub: aubio

Download patch

ref: 352fd5f7b20761a99dd66181d8c61e4acbceb5df
parent: eb7f743c55770e6dfae4b0caf66a5363ba233c9e
author: Paul Brossier <piem@piem.org>
date: Fri Oct 2 07:19:48 EDT 2009

python/py-fvec.c, python/aubio-types.g: define AUBIO_FLOAT, move default length and channels here, rename fvec to aubio.fvec

--- a/interfaces/python/aubio-types.h
+++ b/interfaces/python/aubio-types.h
@@ -4,6 +4,24 @@
 #include <numpy/arrayobject.h>
 #include <aubio.h>
 
+#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 @@
   uint_t channels;
 } Py_fvec;
 extern PyTypeObject Py_fvecType;
+
+extern PyObject *PyAubio_FvecToArray (Py_fvec * self);
+
+extern Py_fvec *PyAubio_ArrayToFvec (PyObject * self);
--- a/interfaces/python/py-fvec.c
+++ b/interfaces/python/py-fvec.c
@@ -10,9 +10,6 @@
 
 */
 
-#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 @@
   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 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 @@
 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        */