History

ext/: no more hell, use plain c

Paul Brossier committed 10 years ago

Commit 5652a8c1 parent f50dea46 files · +241 −117Browse files

Showing the changes to python/ext (6 of 6 files). Show all

Unified · Split

6 files
  1. python/ext/aubiowraphell.h +0 −89
  2. python/ext/py-fft.c +44 −5
  3. python/ext/py-filterbank.c +44 −5
  4. python/ext/py-phasevoc.c +59 −8
  5. python/ext/py-sink.c +50 −5
  6. python/ext/py-source.c +44 −5
python/ext/aubiowraphell.h+0−89
@@ -1,89 +0,0 @@
1−#include "aubio-types.h"
2−
3−#define AUBIO_DECLARE(NAME, PARAMS...) \
4−typedef struct { \
5− PyObject_HEAD \
6− aubio_ ## NAME ## _t * o; \
7− PARAMS; \
8−} Py_## NAME;
9−
10−#define AUBIO_INIT(NAME, PARAMS... ) \
11−static int \
12−Py_ ## NAME ## _init (Py_ ## NAME * self, PyObject * args, PyObject * kwds) \
13−{ \
14− self->o = new_aubio_## NAME ( PARAMS ); \
15− if (self->o == NULL) { \
16− PyErr_SetString (PyExc_RuntimeError, "error creating object"); \
17− return -1; \
18− } \
19−\
20− return 0; \
21−}
22−
23−#define AUBIO_DEL(NAME) \
24−static void \
25−Py_ ## NAME ## _del ( Py_ ## NAME * self) \
26−{ \
27− del_aubio_ ## NAME (self->o); \
28− Py_TYPE(self)->tp_free ((PyObject *) self); \
29−}
30−
31−#define AUBIO_MEMBERS_START(NAME) \
32−static PyMemberDef Py_ ## NAME ## _members[] = {
33−
34−#define AUBIO_MEMBERS_STOP(NAME) \
35− {NULL} \
36−};
37−
38−#define AUBIO_METHODS(NAME) \
39−static PyMethodDef Py_ ## NAME ## _methods[] = { \
40− {NULL} \
41−};
42−
43−
44−#define AUBIO_TYPEOBJECT(NAME, PYNAME) \
45−PyTypeObject Py_ ## NAME ## Type = { \
46− PyVarObject_HEAD_INIT (NULL, 0) \
47− PYNAME, \
48− sizeof (Py_ ## NAME), \
49− 0, \
50− (destructor) Py_ ## NAME ## _del, \
51− 0, \
52− 0, \
53− 0, \
54− 0, \
55− 0, \
56− 0, \
57− 0, \
58− 0, \
59− 0, \
60− (ternaryfunc)Py_ ## NAME ## _do, \
61− 0, \
62− 0, \
63− 0, \
64− 0, \
65− Py_TPFLAGS_DEFAULT, \
66− Py_ ## NAME ## _doc, \
67− 0, \
68− 0, \
69− 0, \
70− 0, \
71− 0, \
72− 0, \
73− Py_ ## NAME ## _methods, \
74− Py_ ## NAME ## _members, \
75− 0, \
76− 0, \
77− 0, \
78− 0, \
79− 0, \
80− 0, \
81− (initproc) Py_ ## NAME ## _init, \
82− 0, \
83− Py_ ## NAME ## _new, \
84−};
85−
86−// some more helpers
87−#define AUBIO_NEW_VEC(name, type, lengthval) \
88− name = (type *) PyObject_New (type, & type ## Type); \
89− name->length = lengthval;
python/ext/py-fft.c+44−5
@@ -1,4 +1,4 @@
1−#include "aubiowraphell.h"
1+#include "aubio-types.h"
22
33 static char Py_fft_doc[] = "fft object";
44
@@ -11,7 +11,6 @@ typedef struct · 6 unmodified lines
1111 fvec_t *rout;
1212 } Py_fft;
1313
14−//AUBIO_NEW(fft)
1514 static PyObject *
1615 Py_fft_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
1716 {
@@ -89,10 +88,11 @@ Py_fft_do(Py_fft * self, PyObject * args) · 71 unmodified lines
8988 return (PyObject *)PyAubio_CCvecToPyCvec(self->out);
9089 }
9190
92−AUBIO_MEMBERS_START(fft)
91+static PyMemberDef Py_fft_members[] = {
9392 {"win_s", T_INT, offsetof (Py_fft, win_s), READONLY,
9493 "size of the window"},
95−AUBIO_MEMBERS_STOP(fft)
94+ {NULL}
95+};
9696
9797 static PyObject *
9898 Py_fft_rdo(Py_fft * self, PyObject * args)
@@ -121,4 +121,43 @@ static PyMethodDef Py_fft_methods[] = { · 22 unmodified lines
121121 {NULL}
122122 };
123123
124−AUBIO_TYPEOBJECT(fft, "aubio.fft")
124+PyTypeObject Py_fftType = {
125+ PyVarObject_HEAD_INIT (NULL, 0)
126+ "aubio.fft",
127+ sizeof (Py_fft),
128+ 0,
129+ (destructor) Py_fft_del,
130+ 0,
131+ 0,
132+ 0,
133+ 0,
134+ 0,
135+ 0,
136+ 0,
137+ 0,
138+ 0,
139+ (ternaryfunc)Py_fft_do,
140+ 0,
141+ 0,
142+ 0,
143+ 0,
144+ Py_TPFLAGS_DEFAULT,
145+ Py_fft_doc,
146+ 0,
147+ 0,
148+ 0,
149+ 0,
150+ 0,
151+ 0,
152+ Py_fft_methods,
153+ Py_fft_members,
154+ 0,
155+ 0,
156+ 0,
157+ 0,
158+ 0,
159+ 0,
160+ (initproc) Py_fft_init,
161+ 0,
162+ Py_fft_new,
163+};
python/ext/py-filterbank.c+44−5
@@ -1,4 +1,4 @@
1−#include "aubiowraphell.h"
1+#include "aubio-types.h"
22
33 static char Py_filterbank_doc[] = "filterbank object";
44
@@ -11,7 +11,6 @@ typedef struct · 6 unmodified lines
1111 fvec_t *out;
1212 } Py_filterbank;
1313
14−//AUBIO_NEW(filterbank)
1514 static PyObject *
1615 Py_filterbank_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
1716 {
@@ -96,12 +95,13 @@ Py_filterbank_do(Py_filterbank * self, PyObject * args) · 78 unmodified lines
9695 return (PyObject *)PyAubio_CFvecToArray(self->out);
9796 }
9897
99−AUBIO_MEMBERS_START(filterbank)
98+static PyMemberDef Py_filterbank_members[] = {
10099 {"win_s", T_INT, offsetof (Py_filterbank, win_s), READONLY,
101100 "size of the window"},
102101 {"n_filters", T_INT, offsetof (Py_filterbank, n_filters), READONLY,
103102 "number of filters"},
104−AUBIO_MEMBERS_STOP(filterbank)
103+ {NULL} /* sentinel */
104+};
105105
106106 static PyObject *
107107 Py_filterbank_set_triangle_bands (Py_filterbank * self, PyObject *args)
@@ -203,4 +203,43 @@ static PyMethodDef Py_filterbank_methods[] = { · 95 unmodified lines
203203 {NULL}
204204 };
205205
206−AUBIO_TYPEOBJECT(filterbank, "aubio.filterbank")
206+PyTypeObject Py_filterbankType = {
207+ PyVarObject_HEAD_INIT (NULL, 0)
208+ "aubio.filterbank",
209+ sizeof (Py_filterbank),
210+ 0,
211+ (destructor) Py_filterbank_del,
212+ 0,
213+ 0,
214+ 0,
215+ 0,
216+ 0,
217+ 0,
218+ 0,
219+ 0,
220+ 0,
221+ (ternaryfunc)Py_filterbank_do,
222+ 0,
223+ 0,
224+ 0,
225+ 0,
226+ Py_TPFLAGS_DEFAULT,
227+ Py_filterbank_doc,
228+ 0,
229+ 0,
230+ 0,
231+ 0,
232+ 0,
233+ 0,
234+ Py_filterbank_methods,
235+ Py_filterbank_members,
236+ 0,
237+ 0,
238+ 0,
239+ 0,
240+ 0,
241+ 0,
242+ (initproc) Py_filterbank_init,
243+ 0,
244+ Py_filterbank_new,
245+};
python/ext/py-phasevoc.c+59−8
@@ -1,4 +1,4 @@
1−#include "aubiowraphell.h"
1+#include "aubio-types.h"
22
33 static char Py_pvoc_doc[] = "pvoc object";
44
@@ -13,7 +13,6 @@ typedef struct · 8 unmodified lines
1313 } Py_pvoc;
1414
1515
16−//AUBIO_NEW(pvoc)
1716 static PyObject *
1817 Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
1918 {
@@ -55,15 +54,27 @@ Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds) · 35 unmodified lines
5554 return NULL;
5655 }
5756
57+ return (PyObject *) self;
58+}
59+
60+static int
61+Py_pvoc_init (Py_pvoc * self, PyObject * args, PyObject * kwds)
62+{
63+ self->o = new_aubio_pvoc ( self->win_s, self->hop_s);
64+ if (self->o == NULL) {
65+ char_t errstr[30];
66+ sprintf(errstr, "error creating pvoc with %d, %d", self->win_s, self->hop_s);
67+ PyErr_SetString (PyExc_RuntimeError, errstr);
68+ return -1;
69+ }
70+
5871 self->output = new_cvec(self->win_s);
5972 self->routput = new_fvec(self->hop_s);
6073
61− return (PyObject *) self;
74+ return 0;
6275 }
6376
6477
65−AUBIO_INIT(pvoc, self->win_s, self->hop_s)
66−
6778 static void
6879 Py_pvoc_del (Py_pvoc *self, PyObject *unused)
6980 {
@@ -95,12 +106,13 @@ Py_pvoc_do(Py_pvoc * self, PyObject * args) · 25 unmodified lines
95106 return (PyObject *)PyAubio_CCvecToPyCvec(self->output);
96107 }
97108
98−AUBIO_MEMBERS_START(pvoc)
109+static PyMemberDef Py_pvoc_members[] = {
99110 {"win_s", T_INT, offsetof (Py_pvoc, win_s), READONLY,
100111 "size of the window"},
101112 {"hop_s", T_INT, offsetof (Py_pvoc, hop_s), READONLY,
102113 "size of the hop"},
103−AUBIO_MEMBERS_STOP(pvoc)
114+ { NULL } // sentinel
115+};
104116
105117 static PyObject *
106118 Py_pvoc_rdo(Py_pvoc * self, PyObject * args)
@@ -128,4 +140,43 @@ static PyMethodDef Py_pvoc_methods[] = { · 21 unmodified lines
128140 {NULL}
129141 };
130142
131−AUBIO_TYPEOBJECT(pvoc, "aubio.pvoc")
143+PyTypeObject Py_pvocType = {
144+ PyVarObject_HEAD_INIT (NULL, 0)
145+ "aubio.pvoc",
146+ sizeof (Py_pvoc),
147+ 0,
148+ (destructor) Py_pvoc_del,
149+ 0,
150+ 0,
151+ 0,
152+ 0,
153+ 0,
154+ 0,
155+ 0,
156+ 0,
157+ 0,
158+ (ternaryfunc)Py_pvoc_do,
159+ 0,
160+ 0,
161+ 0,
162+ 0,
163+ Py_TPFLAGS_DEFAULT,
164+ Py_pvoc_doc,
165+ 0,
166+ 0,
167+ 0,
168+ 0,
169+ 0,
170+ 0,
171+ Py_pvoc_methods,
172+ Py_pvoc_members,
173+ 0,
174+ 0,
175+ 0,
176+ 0,
177+ 0,
178+ 0,
179+ (initproc) Py_pvoc_init,
180+ 0,
181+ Py_pvoc_new,
182+};
python/ext/py-sink.c+50−5
@@ -1,4 +1,4 @@
1−#include "aubiowraphell.h"
1+#include "aubio-types.h"
22
33 typedef struct
44 {
@@ -124,7 +124,12 @@ Py_sink_init (Py_sink * self, PyObject * args, PyObject * kwds) · 119 unmodified lines
124124 return 0;
125125 }
126126
127−AUBIO_DEL(sink)
127+static void
128+Py_sink_del (Py_sink *self, PyObject *unused)
129+{
130+ del_aubio_sink(self->o);
131+ Py_TYPE(self)->tp_free((PyObject *) self);
132+}
128133
129134 /* function Py_sink_do */
130135 static PyObject *
@@ -193,14 +198,15 @@ Py_sink_do_multi(Py_sink * self, PyObject * args) · 62 unmodified lines
193198 Py_RETURN_NONE;
194199 }
195200
196−AUBIO_MEMBERS_START(sink)
201+static PyMemberDef Py_sink_members[] = {
197202 {"uri", T_STRING, offsetof (Py_sink, uri), READONLY,
198203 "path at which the sink was created"},
199204 {"samplerate", T_INT, offsetof (Py_sink, samplerate), READONLY,
200205 "samplerate at which the sink was created"},
201206 {"channels", T_INT, offsetof (Py_sink, channels), READONLY,
202207 "number of channels with which the sink was created"},
203−AUBIO_MEMBERS_STOP(sink)
208+ { NULL } // sentinel
209+};
204210
205211 static PyObject *
206212 Pyaubio_sink_close (Py_sink *self, PyObject *unused)
@@ -216,4 +222,43 @@ static PyMethodDef Py_sink_methods[] = { · 9 unmodified lines
216222 {NULL} /* sentinel */
217223 };
218224
219−AUBIO_TYPEOBJECT(sink, "aubio.sink")
225+PyTypeObject Py_sinkType = {
226+ PyVarObject_HEAD_INIT (NULL, 0)
227+ "aubio.sink",
228+ sizeof (Py_sink),
229+ 0,
230+ (destructor) Py_sink_del,
231+ 0,
232+ 0,
233+ 0,
234+ 0,
235+ 0,
236+ 0,
237+ 0,
238+ 0,
239+ 0,
240+ (ternaryfunc)Py_sink_do,
241+ 0,
242+ 0,
243+ 0,
244+ 0,
245+ Py_TPFLAGS_DEFAULT,
246+ Py_sink_doc,
247+ 0,
248+ 0,
249+ 0,
250+ 0,
251+ 0,
252+ 0,
253+ Py_sink_methods,
254+ Py_sink_members,
255+ 0,
256+ 0,
257+ 0,
258+ 0,
259+ 0,
260+ 0,
261+ (initproc) Py_sink_init,
262+ 0,
263+ Py_sink_new,
264+};
python/ext/py-source.c+44−5
@@ -1,4 +1,4 @@
1−#include "aubiowraphell.h"
1+#include "aubio-types.h"
22
33 typedef struct
44 {
@@ -217,7 +217,7 @@ Py_source_do_multi(Py_source * self, PyObject * args) · 212 unmodified lines
217217 return outputs;
218218 }
219219
220−AUBIO_MEMBERS_START(source)
220+static PyMemberDef Py_source_members[] = {
221221 {"uri", T_STRING, offsetof (Py_source, uri), READONLY,
222222 "path at which the source was created"},
223223 {"samplerate", T_INT, offsetof (Py_source, samplerate), READONLY,
@@ -226,8 +226,8 @@ AUBIO_MEMBERS_START(source) · 2 unmodified lines
226226 "number of channels found in the source"},
227227 {"hop_size", T_INT, offsetof (Py_source, hop_size), READONLY,
228228 "number of consecutive frames that will be read at each do or do_multi call"},
229−AUBIO_MEMBERS_STOP(source)
230−
229+ { NULL } // sentinel
230+};
231231
232232 static PyObject *
233233 Pyaubio_source_get_samplerate (Py_source *self, PyObject *unused)
@@ -285,4 +285,43 @@ static PyMethodDef Py_source_methods[] = { · 51 unmodified lines
285285 {NULL} /* sentinel */
286286 };
287287
288−AUBIO_TYPEOBJECT(source, "aubio.source")
288+PyTypeObject Py_sourceType = {
289+ PyVarObject_HEAD_INIT (NULL, 0)
290+ "aubio.source",
291+ sizeof (Py_source),
292+ 0,
293+ (destructor) Py_source_del,
294+ 0,
295+ 0,
296+ 0,
297+ 0,
298+ 0,
299+ 0,
300+ 0,
301+ 0,
302+ 0,
303+ (ternaryfunc)Py_source_do,
304+ 0,
305+ 0,
306+ 0,
307+ 0,
308+ Py_TPFLAGS_DEFAULT,
309+ Py_source_doc,
310+ 0,
311+ 0,
312+ 0,
313+ 0,
314+ 0,
315+ 0,
316+ Py_source_methods,
317+ Py_source_members,
318+ 0,
319+ 0,
320+ 0,
321+ 0,
322+ 0,
323+ 0,
324+ (initproc) Py_source_init,
325+ 0,
326+ Py_source_new,
327+};

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t