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...) \
4typedef struct { \
5 PyObject_HEAD \
6 aubio_ ## NAME ## _t * o; \
7 PARAMS; \
8} Py_## NAME;
9
10#define AUBIO_INIT(NAME, PARAMS... ) \
11static int \
12Py_ ## 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) \
24static void \
25Py_ ## 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) \
32static PyMemberDef Py_ ## NAME ## _members[] = {
33
34#define AUBIO_MEMBERS_STOP(NAME) \
35 {NULL} \
36};
37
38#define AUBIO_METHODS(NAME) \
39static PyMethodDef Py_ ## NAME ## _methods[] = { \
40 {NULL} \
41};
42
43
44#define AUBIO_TYPEOBJECT(NAME, PYNAME) \
45PyTypeObject 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"
2 2
3static char Py_fft_doc[] = "fft object";3static char Py_fft_doc[] = "fft object";
4 4
@@ -11,7 +11,6 @@ typedef struct · 6 unmodified lines
11 fvec_t *rout;11 fvec_t *rout;
12} Py_fft;12} Py_fft;
13 13
14//AUBIO_NEW(fft)
15static PyObject *14static PyObject *
16Py_fft_new (PyTypeObject * type, PyObject * args, PyObject * kwds)15Py_fft_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
17{16{
@@ -89,10 +88,11 @@ Py_fft_do(Py_fft * self, PyObject * args) · 71 unmodified lines
89 return (PyObject *)PyAubio_CCvecToPyCvec(self->out);88 return (PyObject *)PyAubio_CCvecToPyCvec(self->out);
90}89}
91 90
92AUBIO_MEMBERS_START(fft) 91static PyMemberDef Py_fft_members[] = {
93 {"win_s", T_INT, offsetof (Py_fft, win_s), READONLY,92 {"win_s", T_INT, offsetof (Py_fft, win_s), READONLY,
94 "size of the window"},93 "size of the window"},
95AUBIO_MEMBERS_STOP(fft)94 {NULL}
95};
96 96
97static PyObject * 97static PyObject *
98Py_fft_rdo(Py_fft * self, PyObject * args)98Py_fft_rdo(Py_fft * self, PyObject * args)
@@ -121,4 +121,43 @@ static PyMethodDef Py_fft_methods[] = { · 22 unmodified lines
121 {NULL}121 {NULL}
122};122};
123 123
124AUBIO_TYPEOBJECT(fft, "aubio.fft")124PyTypeObject 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"
2 2
3static char Py_filterbank_doc[] = "filterbank object";3static char Py_filterbank_doc[] = "filterbank object";
4 4
@@ -11,7 +11,6 @@ typedef struct · 6 unmodified lines
11 fvec_t *out;11 fvec_t *out;
12} Py_filterbank;12} Py_filterbank;
13 13
14//AUBIO_NEW(filterbank)
15static PyObject *14static PyObject *
16Py_filterbank_new (PyTypeObject * type, PyObject * args, PyObject * kwds)15Py_filterbank_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
17{16{
@@ -96,12 +95,13 @@ Py_filterbank_do(Py_filterbank * self, PyObject * args) · 78 unmodified lines
96 return (PyObject *)PyAubio_CFvecToArray(self->out);95 return (PyObject *)PyAubio_CFvecToArray(self->out);
97}96}
98 97
99AUBIO_MEMBERS_START(filterbank)98static PyMemberDef Py_filterbank_members[] = {
100 {"win_s", T_INT, offsetof (Py_filterbank, win_s), READONLY,99 {"win_s", T_INT, offsetof (Py_filterbank, win_s), READONLY,
101 "size of the window"},100 "size of the window"},
102 {"n_filters", T_INT, offsetof (Py_filterbank, n_filters), READONLY,101 {"n_filters", T_INT, offsetof (Py_filterbank, n_filters), READONLY,
103 "number of filters"},102 "number of filters"},
104AUBIO_MEMBERS_STOP(filterbank)103 {NULL} /* sentinel */
104};
105 105
106static PyObject *106static PyObject *
107Py_filterbank_set_triangle_bands (Py_filterbank * self, PyObject *args)107Py_filterbank_set_triangle_bands (Py_filterbank * self, PyObject *args)
@@ -203,4 +203,43 @@ static PyMethodDef Py_filterbank_methods[] = { · 95 unmodified lines
203 {NULL}203 {NULL}
204};204};
205 205
206AUBIO_TYPEOBJECT(filterbank, "aubio.filterbank")206PyTypeObject 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"
2 2
3static char Py_pvoc_doc[] = "pvoc object";3static char Py_pvoc_doc[] = "pvoc object";
4 4
@@ -13,7 +13,6 @@ typedef struct · 8 unmodified lines
13} Py_pvoc;13} Py_pvoc;
14 14
15 15
16//AUBIO_NEW(pvoc)
17static PyObject *16static PyObject *
18Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds)17Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
19{18{
@@ -55,15 +54,27 @@ Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds) · 35 unmodified lines
55 return NULL;54 return NULL;
56 }55 }
57 56
57 return (PyObject *) self;
58}
59
60static int
61Py_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
58 self->output = new_cvec(self->win_s);71 self->output = new_cvec(self->win_s);
59 self->routput = new_fvec(self->hop_s);72 self->routput = new_fvec(self->hop_s);
60 73
61 return (PyObject *) self;74 return 0;
62}75}
63 76
64 77
65AUBIO_INIT(pvoc, self->win_s, self->hop_s)
66
67static void78static void
68Py_pvoc_del (Py_pvoc *self, PyObject *unused)79Py_pvoc_del (Py_pvoc *self, PyObject *unused)
69{80{
@@ -95,12 +106,13 @@ Py_pvoc_do(Py_pvoc * self, PyObject * args) · 25 unmodified lines
95 return (PyObject *)PyAubio_CCvecToPyCvec(self->output);106 return (PyObject *)PyAubio_CCvecToPyCvec(self->output);
96}107}
97 108
98AUBIO_MEMBERS_START(pvoc) 109static PyMemberDef Py_pvoc_members[] = {
99 {"win_s", T_INT, offsetof (Py_pvoc, win_s), READONLY,110 {"win_s", T_INT, offsetof (Py_pvoc, win_s), READONLY,
100 "size of the window"},111 "size of the window"},
101 {"hop_s", T_INT, offsetof (Py_pvoc, hop_s), READONLY,112 {"hop_s", T_INT, offsetof (Py_pvoc, hop_s), READONLY,
102 "size of the hop"},113 "size of the hop"},
103AUBIO_MEMBERS_STOP(pvoc)114 { NULL } // sentinel
115};
104 116
105static PyObject * 117static PyObject *
106Py_pvoc_rdo(Py_pvoc * self, PyObject * args)118Py_pvoc_rdo(Py_pvoc * self, PyObject * args)
@@ -128,4 +140,43 @@ static PyMethodDef Py_pvoc_methods[] = { · 21 unmodified lines
128 {NULL}140 {NULL}
129};141};
130 142
131AUBIO_TYPEOBJECT(pvoc, "aubio.pvoc")143PyTypeObject 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"
2 2
3typedef struct3typedef struct
4{4{
@@ -124,7 +124,12 @@ Py_sink_init (Py_sink * self, PyObject * args, PyObject * kwds) · 119 unmodified lines
124 return 0;124 return 0;
125}125}
126 126
127AUBIO_DEL(sink)127static void
128Py_sink_del (Py_sink *self, PyObject *unused)
129{
130 del_aubio_sink(self->o);
131 Py_TYPE(self)->tp_free((PyObject *) self);
132}
128 133
129/* function Py_sink_do */134/* function Py_sink_do */
130static PyObject *135static PyObject *
@@ -193,14 +198,15 @@ Py_sink_do_multi(Py_sink * self, PyObject * args) · 62 unmodified lines
193 Py_RETURN_NONE;198 Py_RETURN_NONE;
194}199}
195 200
196AUBIO_MEMBERS_START(sink)201static PyMemberDef Py_sink_members[] = {
197 {"uri", T_STRING, offsetof (Py_sink, uri), READONLY,202 {"uri", T_STRING, offsetof (Py_sink, uri), READONLY,
198 "path at which the sink was created"},203 "path at which the sink was created"},
199 {"samplerate", T_INT, offsetof (Py_sink, samplerate), READONLY,204 {"samplerate", T_INT, offsetof (Py_sink, samplerate), READONLY,
200 "samplerate at which the sink was created"},205 "samplerate at which the sink was created"},
201 {"channels", T_INT, offsetof (Py_sink, channels), READONLY,206 {"channels", T_INT, offsetof (Py_sink, channels), READONLY,
202 "number of channels with which the sink was created"},207 "number of channels with which the sink was created"},
203AUBIO_MEMBERS_STOP(sink)208 { NULL } // sentinel
209};
204 210
205static PyObject *211static PyObject *
206Pyaubio_sink_close (Py_sink *self, PyObject *unused)212Pyaubio_sink_close (Py_sink *self, PyObject *unused)
@@ -216,4 +222,43 @@ static PyMethodDef Py_sink_methods[] = { · 9 unmodified lines
216 {NULL} /* sentinel */222 {NULL} /* sentinel */
217};223};
218 224
219AUBIO_TYPEOBJECT(sink, "aubio.sink")225PyTypeObject 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"
2 2
3typedef struct3typedef struct
4{4{
@@ -217,7 +217,7 @@ Py_source_do_multi(Py_source * self, PyObject * args) · 212 unmodified lines
217 return outputs;217 return outputs;
218}218}
219 219
220AUBIO_MEMBERS_START(source)220static PyMemberDef Py_source_members[] = {
221 {"uri", T_STRING, offsetof (Py_source, uri), READONLY,221 {"uri", T_STRING, offsetof (Py_source, uri), READONLY,
222 "path at which the source was created"},222 "path at which the source was created"},
223 {"samplerate", T_INT, offsetof (Py_source, samplerate), READONLY,223 {"samplerate", T_INT, offsetof (Py_source, samplerate), READONLY,
@@ -226,8 +226,8 @@ AUBIO_MEMBERS_START(source) · 2 unmodified lines
226 "number of channels found in the source"},226 "number of channels found in the source"},
227 {"hop_size", T_INT, offsetof (Py_source, hop_size), READONLY,227 {"hop_size", T_INT, offsetof (Py_source, hop_size), READONLY,
228 "number of consecutive frames that will be read at each do or do_multi call"},228 "number of consecutive frames that will be read at each do or do_multi call"},
229AUBIO_MEMBERS_STOP(source)229 { NULL } // sentinel
230 230};
231 231
232static PyObject *232static PyObject *
233Pyaubio_source_get_samplerate (Py_source *self, PyObject *unused)233Pyaubio_source_get_samplerate (Py_source *self, PyObject *unused)
@@ -285,4 +285,43 @@ static PyMethodDef Py_source_methods[] = { · 51 unmodified lines
285 {NULL} /* sentinel */285 {NULL} /* sentinel */
286};286};
287 287
288AUBIO_TYPEOBJECT(source, "aubio.source")288PyTypeObject 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