History

ext/: use new proxy functions

Paul Brossier committed 10 years ago

Commit b5bef111 parent bfe82567 files · +118 −87Browse files

Showing the changes to python (7 of 7 files). Show all

Unified · Split

7 files
  1. python/ext/aubiomodule.c +11 −9
  2. python/ext/py-fft.c +27 −14
  3. python/ext/py-filter.c +7 −7
  4. python/ext/py-filterbank.c +21 −18
  5. python/ext/py-musicutils.c +16 −8
  6. python/ext/py-phasevoc.c +23 −13
  7. python/ext/py-sink.c +13 −18
python/ext/aubiomodule.c+11−9
@@ -95,14 +95,15 @@ Py_alpha_norm (PyObject * self, PyObject * args) · 94 unmodified lines
9595 return NULL;
9696 }
9797
98− vec = PyAubio_ArrayToCFvec (input);
99−
100− if (vec == NULL) {
98+ vec = (fvec_t *)malloc(sizeof(fvec_t));
99+ if (!PyAubio_ArrayToCFvec(input, vec)) {
100+ free(vec);
101101 return NULL;
102102 }
103103
104104 // compute the function
105105 result = Py_BuildValue ("f", fvec_alpha_norm (vec, alpha));
106+ free(vec);
106107 if (result == NULL) {
107108 return NULL;
108109 }
@@ -185,14 +186,15 @@ Py_zero_crossing_rate (PyObject * self, PyObject * args) · 76 unmodified lines
185186 return NULL;
186187 }
187188
188− vec = PyAubio_ArrayToCFvec (input);
189−
190− if (vec == NULL) {
189+ vec = (fvec_t *)malloc(sizeof(fvec_t));
190+ if (!PyAubio_ArrayToCFvec(input, vec)) {
191+ free(vec);
191192 return NULL;
192193 }
193194
194195 // compute the function
195196 result = Py_BuildValue ("f", aubio_zero_crossing_rate (vec));
197+ free(vec);
196198 if (result == NULL) {
197199 return NULL;
198200 }
@@ -214,9 +216,9 @@ Py_min_removal(PyObject * self, PyObject * args) · 15 unmodified lines
214216 return NULL;
215217 }
216218
217− vec = PyAubio_ArrayToCFvec (input);
218−
219− if (vec == NULL) {
219+ vec = (fvec_t *)malloc(sizeof(fvec_t));
220+ if (!PyAubio_ArrayToCFvec(input, vec)) {
221+ free(vec);
220222 return NULL;
221223 }
222224
python/ext/py-fft.c+27−14
@@ -7,7 +7,10 @@ typedef struct · 6 unmodified lines
77 PyObject_HEAD
88 aubio_fft_t * o;
99 uint_t win_s;
10+ fvec_t *vecin;
1011 cvec_t *out;
12+ Py_cvec *py_out;
13+ cvec_t *cvecin;
1114 fvec_t *rout;
1215 } Py_fft;
1316
@@ -52,7 +55,13 @@ Py_fft_init (Py_fft * self, PyObject * args, PyObject * kwds) · 38 unmodified lines
5255 PyErr_SetString (PyExc_Exception, errstr);
5356 return -1;
5457 }
58+
59+ self->cvecin = (cvec_t *)malloc(sizeof(cvec_t));
60+ self->vecin = (fvec_t *)malloc(sizeof(fvec_t));
61+
5562 self->out = new_cvec(self->win_s);
63+ self->py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
64+ Py_XINCREF(self->py_out);
5665 self->rout = new_fvec(self->win_s);
5766
5867 return 0;
@@ -61,31 +70,38 @@ Py_fft_init (Py_fft * self, PyObject * args, PyObject * kwds) · 2 unmodified lines
6170 static void
6271 Py_fft_del (Py_fft *self, PyObject *unused)
6372 {
73+ Py_XDECREF((PyObject*)(self->py_out));
6474 del_aubio_fft(self->o);
6575 del_cvec(self->out);
6676 del_fvec(self->rout);
77+ free(self->cvecin);
78+ free(self->vecin);
6779 Py_TYPE(self)->tp_free((PyObject *) self);
6880 }
6981
70−static PyObject *
82+static PyObject *
7183 Py_fft_do(Py_fft * self, PyObject * args)
7284 {
7385 PyObject *input;
74− fvec_t *vec;
7586
7687 if (!PyArg_ParseTuple (args, "O", &input)) {
7788 return NULL;
7889 }
7990
80− vec = PyAubio_ArrayToCFvec (input);
81−
82− if (vec == NULL) {
91+ if (!PyAubio_ArrayToCFvec(input, self->vecin)) {
8392 return NULL;
8493 }
8594
8695 // compute the function
87− aubio_fft_do (((Py_fft *)self)->o, vec, self->out);
88− return (PyObject *)PyAubio_CCvecToPyCvec(self->out);
96+ aubio_fft_do (((Py_fft *)self)->o, self->vecin, self->out);
97+#if 0
98+ Py_cvec * py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
99+ PyObject* output = PyAubio_CCvecToPyCvec(self->out, py_out);
100+ return output;
101+#else
102+ // convert cvec to py_cvec, incrementing refcount to keep a copy
103+ return PyAubio_CCvecToPyCvec(self->out, self->py_out);
104+#endif
89105 }
90106
91107 static PyMemberDef Py_fft_members[] = {
@@ -94,25 +110,22 @@ static PyMemberDef Py_fft_members[] = { · 2 unmodified lines
94110 {NULL}
95111 };
96112
97−static PyObject *
113+static PyObject *
98114 Py_fft_rdo(Py_fft * self, PyObject * args)
99115 {
100116 PyObject *input;
101− cvec_t *vec;
102117
103118 if (!PyArg_ParseTuple (args, "O", &input)) {
104119 return NULL;
105120 }
106121
107− vec = PyAubio_ArrayToCCvec (input);
108−
109− if (vec == NULL) {
122+ if (!PyAubio_ArrayToCCvec (input, self->cvecin) ) {
110123 return NULL;
111124 }
112125
113126 // compute the function
114− aubio_fft_rdo (((Py_fft *)self)->o, vec, self->rout);
115− return (PyObject *)PyAubio_CFvecToArray(self->rout);
127+ aubio_fft_rdo (self->o, self->cvecin, self->rout);
128+ return PyAubio_CFvecToArray(self->rout);
116129 }
117130
118131 static PyMethodDef Py_fft_methods[] = {
python/ext/py-filter.c+7−7
@@ -5,6 +5,7 @@ typedef struct · 4 unmodified lines
55 PyObject_HEAD
66 aubio_filter_t * o;
77 uint_t order;
8+ fvec_t *vec;
89 fvec_t *out;
910 } Py_filter;
1011
@@ -49,6 +50,7 @@ Py_filter_init (Py_filter * self, PyObject * args, PyObject * kwds) · 38 unmodified lines
4950 return -1;
5051 }
5152 self->out = new_fvec(Py_default_vector_length);
53+ self->vec = (fvec_t *)malloc(sizeof(fvec_t));
5254 return 0;
5355 }
5456
@@ -57,6 +59,7 @@ Py_filter_del (Py_filter * self) · 2 unmodified lines
5759 {
5860 del_fvec(self->out);
5961 del_aubio_filter (self->o);
62+ free(self->vec);
6063 Py_TYPE(self)->tp_free ((PyObject *) self);
6164 }
6265
@@ -64,7 +67,6 @@ static PyObject * · 1 unmodified line
6467 Py_filter_do(Py_filter * self, PyObject * args)
6568 {
6669 PyObject *input;
67− fvec_t *vec;
6870
6971 if (!PyArg_ParseTuple (args, "O:digital_filter.do", &input)) {
7072 return NULL;
@@ -74,19 +76,17 @@ Py_filter_do(Py_filter * self, PyObject * args) · 3 unmodified lines
7476 return NULL;
7577 }
7678
77− vec = PyAubio_ArrayToCFvec (input);
78−
79− if (vec == NULL) {
79+ if (!PyAubio_ArrayToCFvec(input, self->vec)) {
8080 return NULL;
8181 }
8282
8383 // reallocate the output if needed
84− if (vec->length != self->out->length) {
84+ if (self->vec->length != self->out->length) {
8585 del_fvec(self->out);
86− self->out = new_fvec(vec->length);
86+ self->out = new_fvec(self->vec->length);
8787 }
8888 // compute the function
89− aubio_filter_do_outplace (self->o, vec, self->out);
89+ aubio_filter_do_outplace (self->o, self->vec, self->out);
9090 return PyAubio_CFvecToArray(self->out);
9191 }
9292
python/ext/py-filterbank.c+21−18
@@ -8,7 +8,10 @@ typedef struct · 7 unmodified lines
88 aubio_filterbank_t * o;
99 uint_t n_filters;
1010 uint_t win_s;
11+ cvec_t *vec;
1112 fvec_t *out;
13+ fvec_t *freqs;
14+ fmat_t *coeffs;
1215 } Py_filterbank;
1316
1417 static PyObject *
@@ -63,6 +66,14 @@ Py_filterbank_init (Py_filterbank * self, PyObject * args, PyObject * kwds) · 48 unmodified lines
6366 }
6467 self->out = new_fvec(self->n_filters);
6568
69+ self->vec = (cvec_t *)malloc(sizeof(cvec_t));
70+
71+ self->freqs = (fvec_t *)malloc(sizeof(fvec_t));
72+
73+ self->coeffs = (fmat_t *)malloc(sizeof(fmat_t));
74+ self->coeffs->data = (smpl_t **)malloc(sizeof(smpl_t*) * self->n_filters);
75+ self->coeffs->height = self->n_filters;
76+
6677 return 0;
6778 }
6879
@@ -71,6 +82,10 @@ Py_filterbank_del (Py_filterbank *self, PyObject *unused) · 2 unmodified lines
7182 {
7283 del_aubio_filterbank(self->o);
7384 del_fvec(self->out);
85+ free(self->vec);
86+ free(self->freqs);
87+ free(self->coeffs->data);
88+ free(self->coeffs);
7489 Py_TYPE(self)->tp_free((PyObject *) self);
7590 }
7691
@@ -78,20 +93,17 @@ static PyObject * · 1 unmodified line
7893 Py_filterbank_do(Py_filterbank * self, PyObject * args)
7994 {
8095 PyObject *input;
81− cvec_t *vec;
8296
8397 if (!PyArg_ParseTuple (args, "O", &input)) {
8498 return NULL;
8599 }
86100
87− vec = PyAubio_ArrayToCCvec (input);
88−
89− if (vec == NULL) {
101+ if (!PyAubio_ArrayToCCvec(input, self->vec)) {
90102 return NULL;
91103 }
92104
93105 // compute the function
94− aubio_filterbank_do (self->o, vec, self->out);
106+ aubio_filterbank_do (self->o, self->vec, self->out);
95107 return (PyObject *)PyAubio_CFvecToArray(self->out);
96108 }
97109
@@ -110,7 +122,6 @@ Py_filterbank_set_triangle_bands (Py_filterbank * self, PyObject *args) · 12 unmodified lines
110122
111123 PyObject *input;
112124 uint_t samplerate;
113− fvec_t *freqs;
114125 if (!PyArg_ParseTuple (args, "OI", &input, &samplerate)) {
115126 return NULL;
116127 }
@@ -119,14 +130,12 @@ Py_filterbank_set_triangle_bands (Py_filterbank * self, PyObject *args) · 2 unmodified lines
119130 return NULL;
120131 }
121132
122− freqs = PyAubio_ArrayToCFvec (input);
123−
124− if (freqs == NULL) {
133+ if (!PyAubio_ArrayToCFvec(input, self->freqs)) {
125134 return NULL;
126135 }
127136
128137 err = aubio_filterbank_set_triangle_bands (self->o,
129− freqs, samplerate);
138+ self->freqs, samplerate);
130139 if (err > 0) {
131140 PyErr_SetString (PyExc_ValueError,
132141 "error when setting filter to A-weighting");
@@ -160,21 +169,15 @@ Py_filterbank_set_coeffs (Py_filterbank * self, PyObject *args) · 27 unmodified lines
160169 uint_t err = 0;
161170
162171 PyObject *input;
163− fmat_t *coeffs;
164−
165172 if (!PyArg_ParseTuple (args, "O", &input)) {
166173 return NULL;
167174 }
168175
169− coeffs = PyAubio_ArrayToCFmat (input);
170−
171− if (coeffs == NULL) {
172− PyErr_SetString (PyExc_ValueError,
173− "unable to parse input array");
176+ if (!PyAubio_ArrayToCFmat(input, self->coeffs)) {
174177 return NULL;
175178 }
176179
177− err = aubio_filterbank_set_coeffs (self->o, coeffs);
180+ err = aubio_filterbank_set_coeffs (self->o, self->coeffs);
178181
179182 if (err > 0) {
180183 PyErr_SetString (PyExc_ValueError,
python/ext/py-musicutils.c+16−8
@@ -37,12 +37,14 @@ Py_aubio_level_lin(PyObject *self, PyObject *args) · 36 unmodified lines
3737 return NULL;
3838 }
3939
40− vec = PyAubio_ArrayToCFvec (input);
41− if (vec == NULL) {
40+ vec = (fvec_t *)malloc(sizeof(fvec_t));
41+ if (!PyAubio_ArrayToCFvec(input, vec)) {
42+ free(vec);
4243 return NULL;
4344 }
4445
4546 level_lin = Py_BuildValue("f", aubio_level_lin(vec));
47+ free(vec);
4648 if (level_lin == NULL) {
4749 PyErr_SetString (PyExc_ValueError, "failed computing level_lin");
4850 return NULL;
@@ -67,12 +69,14 @@ Py_aubio_db_spl(PyObject *self, PyObject *args) · 18 unmodified lines
6769 return NULL;
6870 }
6971
70− vec = PyAubio_ArrayToCFvec (input);
71− if (vec == NULL) {
72+ vec = (fvec_t *)malloc(sizeof(fvec_t));
73+ if (!PyAubio_ArrayToCFvec(input, vec)) {
74+ free(vec);
7275 return NULL;
7376 }
7477
7578 db_spl = Py_BuildValue("f", aubio_db_spl(vec));
79+ free(vec);
7680 if (db_spl == NULL) {
7781 PyErr_SetString (PyExc_ValueError, "failed computing db_spl");
7882 return NULL;
@@ -98,12 +102,14 @@ Py_aubio_silence_detection(PyObject *self, PyObject *args) · 19 unmodified lines
98102 return NULL;
99103 }
100104
101− vec = PyAubio_ArrayToCFvec (input);
102− if (vec == NULL) {
105+ vec = (fvec_t *)malloc(sizeof(fvec_t));
106+ if (!PyAubio_ArrayToCFvec(input, vec)) {
107+ free(vec);
103108 return NULL;
104109 }
105110
106111 silence_detection = Py_BuildValue("I", aubio_silence_detection(vec, threshold));
112+ free(vec);
107113 if (silence_detection == NULL) {
108114 PyErr_SetString (PyExc_ValueError, "failed computing silence_detection");
109115 return NULL;
@@ -129,12 +135,14 @@ Py_aubio_level_detection(PyObject *self, PyObject *args) · 19 unmodified lines
129135 return NULL;
130136 }
131137
132− vec = PyAubio_ArrayToCFvec (input);
133− if (vec == NULL) {
138+ vec = (fvec_t *)malloc(sizeof(fvec_t));
139+ if (!PyAubio_ArrayToCFvec(input, vec)) {
140+ free(vec);
134141 return NULL;
135142 }
136143
137144 level_detection = Py_BuildValue("f", aubio_level_detection(vec, threshold));
145+ free(vec);
138146 if (level_detection == NULL) {
139147 PyErr_SetString (PyExc_ValueError, "failed computing level_detection");
140148 return NULL;
python/ext/py-phasevoc.c+23−13
@@ -8,7 +8,10 @@ typedef struct · 7 unmodified lines
88 aubio_pvoc_t * o;
99 uint_t win_s;
1010 uint_t hop_s;
11+ fvec_t *vecin;
1112 cvec_t *output;
13+ Py_cvec *py_out;
14+ cvec_t *cvecin;
1215 fvec_t *routput;
1316 } Py_pvoc;
1417
@@ -68,7 +71,11 @@ Py_pvoc_init (Py_pvoc * self, PyObject * args, PyObject * kwds) · 53 unmodified lines
6871 return -1;
6972 }
7073
74+ self->cvecin = (cvec_t *)malloc(sizeof(cvec_t));
75+ self->vecin = (fvec_t *)malloc(sizeof(fvec_t));
76+
7177 self->output = new_cvec(self->win_s);
78+ self->py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
7279 self->routput = new_fvec(self->hop_s);
7380
7481 return 0;
@@ -81,29 +88,35 @@ Py_pvoc_del (Py_pvoc *self, PyObject *unused) · 6 unmodified lines
8188 del_aubio_pvoc(self->o);
8289 del_cvec(self->output);
8390 del_fvec(self->routput);
91+ free(self->cvecin);
92+ free(self->vecin);
8493 Py_TYPE(self)->tp_free((PyObject *) self);
8594 }
8695
8796
88−static PyObject *
97+static PyObject *
8998 Py_pvoc_do(Py_pvoc * self, PyObject * args)
9099 {
91100 PyObject *input;
92− fvec_t *vec;
93101
94102 if (!PyArg_ParseTuple (args, "O", &input)) {
95103 return NULL;
96104 }
97105
98− vec = PyAubio_ArrayToCFvec (input);
99−
100− if (vec == NULL) {
106+ if (!PyAubio_ArrayToCFvec (input, self->vecin)) {
101107 return NULL;
102108 }
103109
104110 // compute the function
105− aubio_pvoc_do (self->o, vec, self->output);
106− return (PyObject *)PyAubio_CCvecToPyCvec(self->output);
111+ aubio_pvoc_do (self->o, self->vecin, self->output);
112+#if 0
113+ Py_cvec * py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
114+ PyObject* output = PyAubio_CCvecToPyCvec(self->output, py_out);
115+ return output;
116+#else
117+ // convert cvec to py_cvec, incrementing refcount to keep a copy
118+ return PyAubio_CCvecToPyCvec(self->output, self->py_out);
119+#endif
107120 }
108121
109122 static PyMemberDef Py_pvoc_members[] = {
@@ -118,20 +131,17 @@ static PyObject * · 8 unmodified lines
118131 Py_pvoc_rdo(Py_pvoc * self, PyObject * args)
119132 {
120133 PyObject *input;
121− cvec_t *vec;
122134 if (!PyArg_ParseTuple (args, "O", &input)) {
123135 return NULL;
124136 }
125137
126− vec = PyAubio_ArrayToCCvec (input);
127−
128− if (vec == NULL) {
138+ if (!PyAubio_ArrayToCCvec (input, self->cvecin)) {
129139 return NULL;
130140 }
131141
132142 // compute the function
133− aubio_pvoc_rdo (self->o, vec, self->routput);
134− return (PyObject *)PyAubio_CFvecToArray(self->routput);
143+ aubio_pvoc_rdo (self->o, self->cvecin, self->routput);
144+ return PyAubio_CFvecToArray(self->routput);
135145 }
136146
137147 static PyMethodDef Py_pvoc_methods[] = {
python/ext/py-sink.c+13−18
@@ -7,6 +7,8 @@ typedef struct · 6 unmodified lines
77 char_t* uri;
88 uint_t samplerate;
99 uint_t channels;
10+ fvec_t *write_data;
11+ fmat_t *mwrite_data;
1012 } Py_sink;
1113
1214 static char Py_sink_doc[] = ""
@@ -121,6 +123,10 @@ Py_sink_init (Py_sink * self, PyObject * args, PyObject * kwds) · 108 unmodified lines
121123 self->samplerate = aubio_sink_get_samplerate ( self->o );
122124 self->channels = aubio_sink_get_channels ( self->o );
123125
126+ self->write_data = (fvec_t *)malloc(sizeof(fvec_t));
127+ self->mwrite_data = (fmat_t *)malloc(sizeof(fmat_t));
128+ self->mwrite_data->height = self->channels;
129+ self->mwrite_data->data = (smpl_t **)malloc(sizeof(smpl_t*) * self->channels);
124130 return 0;
125131 }
126132
@@ -128,6 +134,9 @@ static void · 1 unmodified line
128134 Py_sink_del (Py_sink *self, PyObject *unused)
129135 {
130136 del_aubio_sink(self->o);
137+ free(self->write_data);
138+ free(self->mwrite_data->data);
139+ free(self->mwrite_data);
131140 Py_TYPE(self)->tp_free((PyObject *) self);
132141 }
133142
@@ -139,7 +148,6 @@ Py_sink_do(Py_sink * self, PyObject * args) · 5 unmodified lines
139148 PyObject * write_data_obj;
140149
141150 /* input vectors prototypes */
142− fvec_t* write_data;
143151 uint_t write;
144152
145153
@@ -147,20 +155,14 @@ Py_sink_do(Py_sink * self, PyObject * args) · 1 unmodified line
147155 return NULL;
148156 }
149157
150−
151158 /* input vectors parsing */
152− write_data = PyAubio_ArrayToCFvec (write_data_obj);
153−
154− if (write_data == NULL) {
159+ if (!PyAubio_ArrayToCFvec(write_data_obj, self->write_data)) {
155160 return NULL;
156161 }
157162
158163
159−
160−
161−
162164 /* compute _do function */
163− aubio_sink_do (self->o, write_data, write);
165+ aubio_sink_do (self->o, self->write_data, write);
164166
165167 Py_RETURN_NONE;
166168 }
@@ -173,7 +175,6 @@ Py_sink_do_multi(Py_sink * self, PyObject * args) · 6 unmodified lines
173175 PyObject * write_data_obj;
174176
175177 /* input vectors prototypes */
176− fmat_t * write_data;
177178 uint_t write;
178179
179180
@@ -183,18 +184,12 @@ Py_sink_do_multi(Py_sink * self, PyObject * args) · 3 unmodified lines
183184
184185
185186 /* input vectors parsing */
186− write_data = PyAubio_ArrayToCFmat (write_data_obj);
187−
188− if (write_data == NULL) {
187+ if (!PyAubio_ArrayToCFmat(write_data_obj, self->mwrite_data)) {
189188 return NULL;
190189 }
191190
192−
193−
194−
195−
196191 /* compute _do function */
197− aubio_sink_do_multi (self->o, write_data, write);
192+ aubio_sink_do_multi (self->o, self->mwrite_data, write);
198193 Py_RETURN_NONE;
199194 }
200195

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