shithub: aubio

Download patch

ref: 5652a8c325fbe66ecb765e7e38b4be4a2a9b18ae
parent: f50dea41744364548d0de247b50b1278e8bf7773
author: Paul Brossier <piem@piem.org>
date: Mon Apr 18 22:16:39 EDT 2016

ext/: no more hell, use plain c

--- a/python/ext/aubiowraphell.h
+++ /dev/null
@@ -1,89 +1,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;
--- a/python/ext/py-fft.c
+++ b/python/ext/py-fft.c
@@ -1,4 +1,4 @@
-#include "aubiowraphell.h"
+#include "aubio-types.h"
 
 static char Py_fft_doc[] = "fft object";
 
@@ -11,7 +11,6 @@
   fvec_t *rout;
 } Py_fft;
 
-//AUBIO_NEW(fft)
 static PyObject *
 Py_fft_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
 {
@@ -89,10 +88,11 @@
   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 @@
   {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,
+};
--- a/python/ext/py-filterbank.c
+++ b/python/ext/py-filterbank.c
@@ -1,4 +1,4 @@
-#include "aubiowraphell.h"
+#include "aubio-types.h"
 
 static char Py_filterbank_doc[] = "filterbank object";
 
@@ -11,7 +11,6 @@
   fvec_t *out;
 } Py_filterbank;
 
-//AUBIO_NEW(filterbank)
 static PyObject *
 Py_filterbank_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
 {
@@ -96,12 +95,13 @@
   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 @@
   {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,
+};
--- a/python/ext/py-phasevoc.c
+++ b/python/ext/py-phasevoc.c
@@ -1,4 +1,4 @@
-#include "aubiowraphell.h"
+#include "aubio-types.h"
 
 static char Py_pvoc_doc[] = "pvoc object";
 
@@ -13,7 +13,6 @@
 } Py_pvoc;
 
 
-//AUBIO_NEW(pvoc)
 static PyObject *
 Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
 {
@@ -55,15 +54,27 @@
     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 @@
   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 @@
   {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,
+};
--- a/python/ext/py-sink.c
+++ b/python/ext/py-sink.c
@@ -1,4 +1,4 @@
-#include "aubiowraphell.h"
+#include "aubio-types.h"
 
 typedef struct
 {
@@ -124,7 +124,12 @@
   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,7 +198,7 @@
   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,
@@ -200,7 +205,8 @@
     "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 @@
   {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,
+};
--- a/python/ext/py-source.c
+++ b/python/ext/py-source.c
@@ -1,4 +1,4 @@
-#include "aubiowraphell.h"
+#include "aubio-types.h"
 
 typedef struct
 {
@@ -217,7 +217,7 @@
   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,9 +226,9 @@
     "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 @@
   {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,
+};