ext/: no more hell, use plain c
authorPaul Brossier <piem@piem.org>
Tue, 19 Apr 2016 00:16:39 +0000 (02:16 +0200)
committerPaul Brossier <piem@piem.org>
Tue, 19 Apr 2016 00:16:39 +0000 (02:16 +0200)
python/ext/aubiowraphell.h [deleted file]
python/ext/py-fft.c
python/ext/py-filterbank.c
python/ext/py-phasevoc.c
python/ext/py-sink.c
python/ext/py-source.c

diff --git a/python/ext/aubiowraphell.h b/python/ext/aubiowraphell.h
deleted file mode 100644 (file)
index 3b17038..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-#include "aubio-types.h"
-
-#define AUBIO_DECLARE(NAME, PARAMS...) \
-typedef struct { \
-  PyObject_HEAD \
-  aubio_ ## NAME ## _t * o; \
-  PARAMS; \
-} Py_## NAME;
-
-#define AUBIO_INIT(NAME, PARAMS... ) \
-static int \
-Py_ ## NAME ## _init (Py_ ## NAME * self, PyObject * args, PyObject * kwds) \
-{ \
-  self->o = new_aubio_## NAME ( PARAMS ); \
-  if (self->o == NULL) { \
-    PyErr_SetString (PyExc_RuntimeError, "error creating object"); \
-    return -1; \
-  } \
-\
-  return 0; \
-}
-
-#define AUBIO_DEL(NAME) \
-static void \
-Py_ ## NAME ## _del ( Py_ ## NAME * self) \
-{ \
-  del_aubio_ ## NAME (self->o); \
-  Py_TYPE(self)->tp_free ((PyObject *) self); \
-}
-
-#define AUBIO_MEMBERS_START(NAME) \
-static PyMemberDef Py_ ## NAME ## _members[] = {
-
-#define AUBIO_MEMBERS_STOP(NAME) \
-  {NULL} \
-};
-
-#define AUBIO_METHODS(NAME) \
-static PyMethodDef Py_ ## NAME ## _methods[] = { \
-  {NULL} \
-};
-
-
-#define AUBIO_TYPEOBJECT(NAME, PYNAME) \
-PyTypeObject Py_ ## NAME ## Type = { \
-  PyVarObject_HEAD_INIT (NULL, 0) \
-  PYNAME,                      \
-  sizeof (Py_ ## NAME),          \
-  0,                           \
-  (destructor) Py_ ## NAME ## _del,  \
-  0,                           \
-  0,                           \
-  0,                           \
-  0,                           \
-  0,                           \
-  0,                           \
-  0,                           \
-  0,                           \
-  0,                           \
-  (ternaryfunc)Py_ ## NAME ## _do,   \
-  0,                           \
-  0,                           \
-  0,                           \
-  0,                           \
-  Py_TPFLAGS_DEFAULT,          \
-  Py_ ## NAME ## _doc,               \
-  0,                           \
-  0,                           \
-  0,                           \
-  0,                           \
-  0,                           \
-  0,                           \
-  Py_ ## NAME ## _methods,           \
-  Py_ ## NAME ## _members,           \
-  0,                           \
-  0,                           \
-  0,                           \
-  0,                           \
-  0,                           \
-  0,                           \
-  (initproc) Py_ ## NAME ## _init,   \
-  0,                           \
-  Py_ ## NAME ## _new,               \
-};
-
-// some more helpers
-#define AUBIO_NEW_VEC(name, type, lengthval) \
-  name = (type *) PyObject_New (type, & type ## Type); \
-  name->length = lengthval;
index 5227000..4e010d8 100644 (file)
@@ -1,4 +1,4 @@
-#include "aubiowraphell.h"
+#include "aubio-types.h"
 
 static char Py_fft_doc[] = "fft object";
 
@@ -11,7 +11,6 @@ typedef struct
   fvec_t *rout;
 } Py_fft;
 
-//AUBIO_NEW(fft)
 static PyObject *
 Py_fft_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
 {
@@ -89,10 +88,11 @@ Py_fft_do(Py_fft * self, PyObject * args)
   return (PyObject *)PyAubio_CCvecToPyCvec(self->out);
 }
 
-AUBIO_MEMBERS_START(fft) 
+static PyMemberDef Py_fft_members[] = {
   {"win_s", T_INT, offsetof (Py_fft, win_s), READONLY,
     "size of the window"},
-AUBIO_MEMBERS_STOP(fft)
+  {NULL}
+};
 
 static PyObject * 
 Py_fft_rdo(Py_fft * self, PyObject * args)
@@ -121,4 +121,43 @@ static PyMethodDef Py_fft_methods[] = {
   {NULL}
 };
 
-AUBIO_TYPEOBJECT(fft, "aubio.fft")
+PyTypeObject Py_fftType = {
+  PyVarObject_HEAD_INIT (NULL, 0)
+  "aubio.fft",
+  sizeof (Py_fft),
+  0,
+  (destructor) Py_fft_del,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  (ternaryfunc)Py_fft_do,
+  0,
+  0,
+  0,
+  0,
+  Py_TPFLAGS_DEFAULT,
+  Py_fft_doc,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  Py_fft_methods,
+  Py_fft_members,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  (initproc) Py_fft_init,
+  0,
+  Py_fft_new,
+};
index 00cac70..fd3af56 100644 (file)
@@ -1,4 +1,4 @@
-#include "aubiowraphell.h"
+#include "aubio-types.h"
 
 static char Py_filterbank_doc[] = "filterbank object";
 
@@ -11,7 +11,6 @@ typedef struct
   fvec_t *out;
 } Py_filterbank;
 
-//AUBIO_NEW(filterbank)
 static PyObject *
 Py_filterbank_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
 {
@@ -96,12 +95,13 @@ Py_filterbank_do(Py_filterbank * self, PyObject * args)
   return (PyObject *)PyAubio_CFvecToArray(self->out);
 }
 
-AUBIO_MEMBERS_START(filterbank)
+static PyMemberDef Py_filterbank_members[] = {
   {"win_s", T_INT, offsetof (Py_filterbank, win_s), READONLY,
     "size of the window"},
   {"n_filters", T_INT, offsetof (Py_filterbank, n_filters), READONLY,
     "number of filters"},
-AUBIO_MEMBERS_STOP(filterbank)
+  {NULL} /* sentinel */
+};
 
 static PyObject *
 Py_filterbank_set_triangle_bands (Py_filterbank * self, PyObject *args)
@@ -203,4 +203,43 @@ static PyMethodDef Py_filterbank_methods[] = {
   {NULL}
 };
 
-AUBIO_TYPEOBJECT(filterbank, "aubio.filterbank")
+PyTypeObject Py_filterbankType = {
+  PyVarObject_HEAD_INIT (NULL, 0)
+  "aubio.filterbank",
+  sizeof (Py_filterbank),
+  0,
+  (destructor) Py_filterbank_del,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  (ternaryfunc)Py_filterbank_do,
+  0,
+  0,
+  0,
+  0,
+  Py_TPFLAGS_DEFAULT,
+  Py_filterbank_doc,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  Py_filterbank_methods,
+  Py_filterbank_members,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  (initproc) Py_filterbank_init,
+  0,
+  Py_filterbank_new,
+};
index 91efa06..a9bf7ca 100644 (file)
@@ -1,4 +1,4 @@
-#include "aubiowraphell.h"
+#include "aubio-types.h"
 
 static char Py_pvoc_doc[] = "pvoc object";
 
@@ -13,7 +13,6 @@ typedef struct
 } Py_pvoc;
 
 
-//AUBIO_NEW(pvoc)
 static PyObject *
 Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
 {
@@ -55,15 +54,27 @@ Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
     return NULL;
   }
 
+  return (PyObject *) self;
+}
+
+static int
+Py_pvoc_init (Py_pvoc * self, PyObject * args, PyObject * kwds)
+{
+  self->o = new_aubio_pvoc ( self->win_s, self->hop_s);
+  if (self->o == NULL) {
+    char_t errstr[30];
+    sprintf(errstr, "error creating pvoc with %d, %d", self->win_s, self->hop_s);
+    PyErr_SetString (PyExc_RuntimeError, errstr);
+    return -1;
+  }
+
   self->output = new_cvec(self->win_s);
   self->routput = new_fvec(self->hop_s);
 
-  return (PyObject *) self;
+  return 0;
 }
 
 
-AUBIO_INIT(pvoc, self->win_s, self->hop_s)
-
 static void
 Py_pvoc_del (Py_pvoc *self, PyObject *unused)
 {
@@ -95,12 +106,13 @@ Py_pvoc_do(Py_pvoc * self, PyObject * args)
   return (PyObject *)PyAubio_CCvecToPyCvec(self->output);
 }
 
-AUBIO_MEMBERS_START(pvoc) 
+static PyMemberDef Py_pvoc_members[] = {
   {"win_s", T_INT, offsetof (Py_pvoc, win_s), READONLY,
     "size of the window"},
   {"hop_s", T_INT, offsetof (Py_pvoc, hop_s), READONLY,
     "size of the hop"},
-AUBIO_MEMBERS_STOP(pvoc)
+  { NULL } // sentinel
+};
 
 static PyObject * 
 Py_pvoc_rdo(Py_pvoc * self, PyObject * args)
@@ -128,4 +140,43 @@ static PyMethodDef Py_pvoc_methods[] = {
   {NULL}
 };
 
-AUBIO_TYPEOBJECT(pvoc, "aubio.pvoc")
+PyTypeObject Py_pvocType = {
+  PyVarObject_HEAD_INIT (NULL, 0)
+  "aubio.pvoc",
+  sizeof (Py_pvoc),
+  0,
+  (destructor) Py_pvoc_del,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  (ternaryfunc)Py_pvoc_do,
+  0,
+  0,
+  0,
+  0,
+  Py_TPFLAGS_DEFAULT,
+  Py_pvoc_doc,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  Py_pvoc_methods,
+  Py_pvoc_members,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  (initproc) Py_pvoc_init,
+  0,
+  Py_pvoc_new,
+};
index 51b9bc3..829e79c 100644 (file)
@@ -1,4 +1,4 @@
-#include "aubiowraphell.h"
+#include "aubio-types.h"
 
 typedef struct
 {
@@ -124,7 +124,12 @@ Py_sink_init (Py_sink * self, PyObject * args, PyObject * kwds)
   return 0;
 }
 
-AUBIO_DEL(sink)
+static void
+Py_sink_del (Py_sink *self, PyObject *unused)
+{
+  del_aubio_sink(self->o);
+  Py_TYPE(self)->tp_free((PyObject *) self);
+}
 
 /* function Py_sink_do */
 static PyObject *
@@ -193,14 +198,15 @@ Py_sink_do_multi(Py_sink * self, PyObject * args)
   Py_RETURN_NONE;
 }
 
-AUBIO_MEMBERS_START(sink)
+static PyMemberDef Py_sink_members[] = {
   {"uri", T_STRING, offsetof (Py_sink, uri), READONLY,
     "path at which the sink was created"},
   {"samplerate", T_INT, offsetof (Py_sink, samplerate), READONLY,
     "samplerate at which the sink was created"},
   {"channels", T_INT, offsetof (Py_sink, channels), READONLY,
     "number of channels with which the sink was created"},
-AUBIO_MEMBERS_STOP(sink)
+  { NULL } // sentinel
+};
 
 static PyObject *
 Pyaubio_sink_close (Py_sink *self, PyObject *unused)
@@ -216,4 +222,43 @@ static PyMethodDef Py_sink_methods[] = {
   {NULL} /* sentinel */
 };
 
-AUBIO_TYPEOBJECT(sink, "aubio.sink")
+PyTypeObject Py_sinkType = {
+  PyVarObject_HEAD_INIT (NULL, 0)
+  "aubio.sink",
+  sizeof (Py_sink),
+  0,
+  (destructor) Py_sink_del,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  (ternaryfunc)Py_sink_do,
+  0,
+  0,
+  0,
+  0,
+  Py_TPFLAGS_DEFAULT,
+  Py_sink_doc,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  Py_sink_methods,
+  Py_sink_members,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  (initproc) Py_sink_init,
+  0,
+  Py_sink_new,
+};
index fde99e3..b0eb2d9 100644 (file)
@@ -1,4 +1,4 @@
-#include "aubiowraphell.h"
+#include "aubio-types.h"
 
 typedef struct
 {
@@ -217,7 +217,7 @@ Py_source_do_multi(Py_source * self, PyObject * args)
   return outputs;
 }
 
-AUBIO_MEMBERS_START(source)
+static PyMemberDef Py_source_members[] = {
   {"uri", T_STRING, offsetof (Py_source, uri), READONLY,
     "path at which the source was created"},
   {"samplerate", T_INT, offsetof (Py_source, samplerate), READONLY,
@@ -226,8 +226,8 @@ AUBIO_MEMBERS_START(source)
     "number of channels found in the source"},
   {"hop_size", T_INT, offsetof (Py_source, hop_size), READONLY,
     "number of consecutive frames that will be read at each do or do_multi call"},
-AUBIO_MEMBERS_STOP(source)
-
+  { NULL } // sentinel
+};
 
 static PyObject *
 Pyaubio_source_get_samplerate (Py_source *self, PyObject *unused)
@@ -285,4 +285,43 @@ static PyMethodDef Py_source_methods[] = {
   {NULL} /* sentinel */
 };
 
-AUBIO_TYPEOBJECT(source, "aubio.source")
+PyTypeObject Py_sourceType = {
+  PyVarObject_HEAD_INIT (NULL, 0)
+  "aubio.source",
+  sizeof (Py_source),
+  0,
+  (destructor) Py_source_del,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  (ternaryfunc)Py_source_do,
+  0,
+  0,
+  0,
+  0,
+  Py_TPFLAGS_DEFAULT,
+  Py_source_doc,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  Py_source_methods,
+  Py_source_members,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  (initproc) Py_source_init,
+  0,
+  Py_source_new,
+};