History

python/ext: simplify memory allocations, removed unneeded malloc/free calls

Paul Brossier committed 10 years ago

Commit 569b3631 parent a35db129 files · +75 −125Browse files

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

Unified · Split

8 files
  1. python/ext/aubiomodule.c +10 −18
  2. python/ext/aubioproxy.c +7 −9
  3. python/ext/py-fft.c +10 −12
  4. python/ext/py-filter.c +5 −7
  5. python/ext/py-filterbank.c +10 −21
  6. python/ext/py-musicutils.c +12 −24
  7. python/ext/py-phasevoc.c +6 −13
  8. python/ext/py-sink.c +7 −13
python/ext/aubiomodule.c+10−18
@@ -83,7 +83,7 @@ static PyObject * · 82 unmodified lines
83Py_alpha_norm (PyObject * self, PyObject * args)83Py_alpha_norm (PyObject * self, PyObject * args)
84{84{
85 PyObject *input;85 PyObject *input;
86 fvec_t *vec;86 fvec_t vec;
87 smpl_t alpha;87 smpl_t alpha;
88 PyObject *result;88 PyObject *result;
89 89
@@ -95,15 +95,12 @@ Py_alpha_norm (PyObject * self, PyObject * args) · 5 unmodified lines
95 return NULL;95 return NULL;
96 }96 }
97 97
98 vec = (fvec_t *)malloc(sizeof(fvec_t));98 if (!PyAubio_ArrayToCFvec(input, &vec)) {
99 if (!PyAubio_ArrayToCFvec(input, vec)) {
100 free(vec);
101 return NULL;99 return NULL;
102 }100 }
103 101
104 // compute the function102 // compute the function
105 result = Py_BuildValue ("f", fvec_alpha_norm (vec, alpha));103 result = Py_BuildValue ("f", fvec_alpha_norm (&vec, alpha));
106 free(vec);
107 if (result == NULL) {104 if (result == NULL) {
108 return NULL;105 return NULL;
109 }106 }
@@ -175,7 +172,7 @@ static PyObject * · 65 unmodified lines
175Py_zero_crossing_rate (PyObject * self, PyObject * args)172Py_zero_crossing_rate (PyObject * self, PyObject * args)
176{173{
177 PyObject *input;174 PyObject *input;
178 fvec_t *vec;175 fvec_t vec;
179 PyObject *result;176 PyObject *result;
180 177
181 if (!PyArg_ParseTuple (args, "O:zero_crossing_rate", &input)) {178 if (!PyArg_ParseTuple (args, "O:zero_crossing_rate", &input)) {
@@ -186,15 +183,12 @@ Py_zero_crossing_rate (PyObject * self, PyObject * args) · 4 unmodified lines
186 return NULL;183 return NULL;
187 }184 }
188 185
189 vec = (fvec_t *)malloc(sizeof(fvec_t));186 if (!PyAubio_ArrayToCFvec(input, &vec)) {
190 if (!PyAubio_ArrayToCFvec(input, vec)) {
191 free(vec);
192 return NULL;187 return NULL;
193 }188 }
194 189
195 // compute the function190 // compute the function
196 result = Py_BuildValue ("f", aubio_zero_crossing_rate (vec));191 result = Py_BuildValue ("f", aubio_zero_crossing_rate (&vec));
197 free(vec);
198 if (result == NULL) {192 if (result == NULL) {
199 return NULL;193 return NULL;
200 }194 }
@@ -206,7 +200,7 @@ static PyObject * · 5 unmodified lines
206Py_min_removal(PyObject * self, PyObject * args)200Py_min_removal(PyObject * self, PyObject * args)
207{201{
208 PyObject *input;202 PyObject *input;
209 fvec_t *vec;203 fvec_t vec;
210 204
211 if (!PyArg_ParseTuple (args, "O:min_removal", &input)) {205 if (!PyArg_ParseTuple (args, "O:min_removal", &input)) {
212 return NULL;206 return NULL;
@@ -216,19 +210,17 @@ Py_min_removal(PyObject * self, PyObject * args) · 3 unmodified lines
216 return NULL;210 return NULL;
217 }211 }
218 212
219 vec = (fvec_t *)malloc(sizeof(fvec_t));213 if (!PyAubio_ArrayToCFvec(input, &vec)) {
220 if (!PyAubio_ArrayToCFvec(input, vec)) {
221 free(vec);
222 return NULL;214 return NULL;
223 }215 }
224 216
225 // compute the function217 // compute the function
226 fvec_min_removal (vec);218 fvec_min_removal (&vec);
227 219
228 // since this function does not return, we could return None220 // since this function does not return, we could return None
229 //Py_RETURN_NONE;221 //Py_RETURN_NONE;
230 // however it is convenient to return the modified vector222 // however it is convenient to return the modified vector
231 return (PyObject *) PyAubio_CFvecToArray(vec);223 return (PyObject *) PyAubio_CFvecToArray(&vec);
232 // or even without converting it back to an array224 // or even without converting it back to an array
233 //Py_INCREF(vec);225 //Py_INCREF(vec);
234 //return (PyObject *)vec;226 //return (PyObject *)vec;
python/ext/aubioproxy.c+7−9
@@ -143,17 +143,15 @@ PyAubio_ArrayToCFmat (PyObject *input, fmat_t *mat) { · 142 unmodified lines
143 return 0;143 return 0;
144 }144 }
145 145
146 if (mat->height != (uint_t)PyArray_DIM ((PyArrayObject *)input, 0)) {146 uint_t new_height = (uint_t)PyArray_DIM ((PyArrayObject *)input, 0);
147 /*147 if (mat->height != new_height) {
148 free(mat->data);148 if (mat->data) {
149 mat->height = (uint_t)PyArray_DIM ((PyArrayObject *)input, 0);149 free(mat->data);
150 mat->data = (smpl_t **)malloc(sizeof(smpl_t*) * mat->height);150 }
151 */151 mat->data = (smpl_t **)malloc(sizeof(smpl_t*) * new_height);
152 PyErr_Format(PyExc_ValueError, "too many rows, %d but %ld expected",
153 mat->height, PyArray_DIM ((PyArrayObject *)input, 0) );
154 return 0;
155 }152 }
156 153
154 mat->height = new_height;
157 mat->length = (uint_t)PyArray_DIM ((PyArrayObject *)input, 1);155 mat->length = (uint_t)PyArray_DIM ((PyArrayObject *)input, 1);
158 for (i=0; i< mat->height; i++) {156 for (i=0; i< mat->height; i++) {
159 mat->data[i] = (smpl_t*)PyArray_GETPTR1 ((PyArrayObject *)input, i);157 mat->data[i] = (smpl_t*)PyArray_GETPTR1 ((PyArrayObject *)input, i);
python/ext/py-fft.c+10−12
@@ -7,11 +7,14 @@ typedef struct · 6 unmodified lines
7 PyObject_HEAD7 PyObject_HEAD
8 aubio_fft_t * o;8 aubio_fft_t * o;
9 uint_t win_s;9 uint_t win_s;
10 fvec_t *vecin;10 // do / rdo input vectors
11 fvec_t vecin;
12 cvec_t cvecin;
13 // do / rdo output results
11 cvec_t *out;14 cvec_t *out;
12 Py_cvec *py_out;
13 cvec_t *cvecin;
14 fvec_t *rout;15 fvec_t *rout;
16 // bridge for cvec output
17 Py_cvec *py_out;
15} Py_fft;18} Py_fft;
16 19
17static PyObject *20static PyObject *
@@ -56,9 +59,6 @@ Py_fft_init (Py_fft * self, PyObject * args, PyObject * kwds) · 38 unmodified lines
56 return -1;59 return -1;
57 }60 }
58 61
59 self->cvecin = (cvec_t *)malloc(sizeof(cvec_t));
60 self->vecin = (fvec_t *)malloc(sizeof(fvec_t));
61
62 self->out = new_cvec(self->win_s);62 self->out = new_cvec(self->win_s);
63 self->py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);63 self->py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
64 Py_XINCREF(self->py_out);64 Py_XINCREF(self->py_out);
@@ -74,8 +74,6 @@ Py_fft_del (Py_fft *self, PyObject *unused) · 9 unmodified lines
74 del_aubio_fft(self->o);74 del_aubio_fft(self->o);
75 del_cvec(self->out);75 del_cvec(self->out);
76 del_fvec(self->rout);76 del_fvec(self->rout);
77 free(self->cvecin);
78 free(self->vecin);
79 Py_TYPE(self)->tp_free((PyObject *) self);77 Py_TYPE(self)->tp_free((PyObject *) self);
80}78}
81 79
@@ -88,12 +86,12 @@ Py_fft_do(Py_fft * self, PyObject * args) · 6 unmodified lines
88 return NULL;86 return NULL;
89 }87 }
90 88
91 if (!PyAubio_ArrayToCFvec(input, self->vecin)) {89 if (!PyAubio_ArrayToCFvec(input, &(self->vecin))) {
92 return NULL;90 return NULL;
93 }91 }
94 92
95 // compute the function93 // compute the function
96 aubio_fft_do (((Py_fft *)self)->o, self->vecin, self->out);94 aubio_fft_do (((Py_fft *)self)->o, &(self->vecin), self->out);
97#if 095#if 0
98 Py_cvec * py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);96 Py_cvec * py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
99 PyObject* output = PyAubio_CCvecToPyCvec(self->out, py_out);97 PyObject* output = PyAubio_CCvecToPyCvec(self->out, py_out);
@@ -119,12 +117,12 @@ Py_fft_rdo(Py_fft * self, PyObject * args) · 19 unmodified lines
119 return NULL;117 return NULL;
120 }118 }
121 119
122 if (!PyAubio_ArrayToCCvec (input, self->cvecin) ) {120 if (!PyAubio_ArrayToCCvec (input, &(self->cvecin)) ) {
123 return NULL;121 return NULL;
124 }122 }
125 123
126 // compute the function124 // compute the function
127 aubio_fft_rdo (self->o, self->cvecin, self->rout);125 aubio_fft_rdo (self->o, &(self->cvecin), self->rout);
128 return PyAubio_CFvecToArray(self->rout);126 return PyAubio_CFvecToArray(self->rout);
129}127}
130 128
python/ext/py-filter.c+5−7
@@ -5,7 +5,7 @@ typedef struct · 4 unmodified lines
5 PyObject_HEAD5 PyObject_HEAD
6 aubio_filter_t * o;6 aubio_filter_t * o;
7 uint_t order;7 uint_t order;
8 fvec_t *vec;8 fvec_t vec;
9 fvec_t *out;9 fvec_t *out;
10} Py_filter;10} Py_filter;
11 11
@@ -50,7 +50,6 @@ Py_filter_init (Py_filter * self, PyObject * args, PyObject * kwds) · 38 unmodified lines
50 return -1;50 return -1;
51 }51 }
52 self->out = new_fvec(Py_default_vector_length);52 self->out = new_fvec(Py_default_vector_length);
53 self->vec = (fvec_t *)malloc(sizeof(fvec_t));
54 return 0;53 return 0;
55}54}
56 55
@@ -59,7 +58,6 @@ Py_filter_del (Py_filter * self) · 2 unmodified lines
59{58{
60 del_fvec(self->out);59 del_fvec(self->out);
61 del_aubio_filter (self->o);60 del_aubio_filter (self->o);
62 free(self->vec);
63 Py_TYPE(self)->tp_free ((PyObject *) self);61 Py_TYPE(self)->tp_free ((PyObject *) self);
64}62}
65 63
@@ -76,17 +74,17 @@ Py_filter_do(Py_filter * self, PyObject * args) · 10 unmodified lines
76 return NULL;74 return NULL;
77 }75 }
78 76
79 if (!PyAubio_ArrayToCFvec(input, self->vec)) {77 if (!PyAubio_ArrayToCFvec(input, &(self->vec))) {
80 return NULL;78 return NULL;
81 }79 }
82 80
83 // reallocate the output if needed81 // reallocate the output if needed
84 if (self->vec->length != self->out->length) {82 if (self->vec.length != self->out->length) {
85 del_fvec(self->out);83 del_fvec(self->out);
86 self->out = new_fvec(self->vec->length);84 self->out = new_fvec(self->vec.length);
87 }85 }
88 // compute the function86 // compute the function
89 aubio_filter_do_outplace (self->o, self->vec, self->out);87 aubio_filter_do_outplace (self->o, &(self->vec), self->out);
90 return PyAubio_CFvecToArray(self->out);88 return PyAubio_CFvecToArray(self->out);
91}89}
92 90
python/ext/py-filterbank.c+10−21
@@ -8,10 +8,10 @@ typedef struct · 7 unmodified lines
8 aubio_filterbank_t * o;8 aubio_filterbank_t * o;
9 uint_t n_filters;9 uint_t n_filters;
10 uint_t win_s;10 uint_t win_s;
11 cvec_t *vec;11 cvec_t vec;
12 fvec_t freqs;
13 fmat_t coeffs;
12 fvec_t *out;14 fvec_t *out;
13 fvec_t *freqs;
14 fmat_t *coeffs;
15} Py_filterbank;15} Py_filterbank;
16 16
17static PyObject *17static PyObject *
@@ -66,14 +66,6 @@ Py_filterbank_init (Py_filterbank * self, PyObject * args, PyObject * kwds) · 48 unmodified lines
66 }66 }
67 self->out = new_fvec(self->n_filters);67 self->out = new_fvec(self->n_filters);
68 68
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
77 return 0;69 return 0;
78}70}
79 71
@@ -82,10 +74,7 @@ Py_filterbank_del (Py_filterbank *self, PyObject *unused) · 2 unmodified lines
82{74{
83 del_aubio_filterbank(self->o);75 del_aubio_filterbank(self->o);
84 del_fvec(self->out);76 del_fvec(self->out);
85 free(self->vec);77 free(self->coeffs.data);
86 free(self->freqs);
87 free(self->coeffs->data);
88 free(self->coeffs);
89 Py_TYPE(self)->tp_free((PyObject *) self);78 Py_TYPE(self)->tp_free((PyObject *) self);
90}79}
91 80
@@ -98,12 +87,12 @@ Py_filterbank_do(Py_filterbank * self, PyObject * args) · 6 unmodified lines
98 return NULL;87 return NULL;
99 }88 }
100 89
101 if (!PyAubio_ArrayToCCvec(input, self->vec)) {90 if (!PyAubio_ArrayToCCvec(input, &(self->vec) )) {
102 return NULL;91 return NULL;
103 }92 }
104 93
105 // compute the function94 // compute the function
106 aubio_filterbank_do (self->o, self->vec, self->out);95 aubio_filterbank_do (self->o, &(self->vec), self->out);
107 return (PyObject *)PyAubio_CFvecToArray(self->out);96 return (PyObject *)PyAubio_CFvecToArray(self->out);
108}97}
109 98
@@ -130,12 +119,12 @@ Py_filterbank_set_triangle_bands (Py_filterbank * self, PyObject *args) · 20 unmodified lines
130 return NULL;119 return NULL;
131 }120 }
132 121
133 if (!PyAubio_ArrayToCFvec(input, self->freqs)) {122 if (!PyAubio_ArrayToCFvec(input, &(self->freqs) )) {
134 return NULL;123 return NULL;
135 }124 }
136 125
137 err = aubio_filterbank_set_triangle_bands (self->o,126 err = aubio_filterbank_set_triangle_bands (self->o,
138 self->freqs, samplerate);127 &(self->freqs), samplerate);
139 if (err > 0) {128 if (err > 0) {
140 PyErr_SetString (PyExc_ValueError,129 PyErr_SetString (PyExc_ValueError,
141 "error when setting filter to A-weighting");130 "error when setting filter to A-weighting");
@@ -173,11 +162,11 @@ Py_filterbank_set_coeffs (Py_filterbank * self, PyObject *args) · 31 unmodified lines
173 return NULL;162 return NULL;
174 }163 }
175 164
176 if (!PyAubio_ArrayToCFmat(input, self->coeffs)) {165 if (!PyAubio_ArrayToCFmat(input, &(self->coeffs))) {
177 return NULL;166 return NULL;
178 }167 }
179 168
180 err = aubio_filterbank_set_coeffs (self->o, self->coeffs);169 err = aubio_filterbank_set_coeffs (self->o, &(self->coeffs));
181 170
182 if (err > 0) {171 if (err > 0) {
183 PyErr_SetString (PyExc_ValueError,172 PyErr_SetString (PyExc_ValueError,
python/ext/py-musicutils.c+12−24
@@ -25,7 +25,7 @@ PyObject * · 24 unmodified lines
25Py_aubio_level_lin(PyObject *self, PyObject *args)25Py_aubio_level_lin(PyObject *self, PyObject *args)
26{26{
27 PyObject *input;27 PyObject *input;
28 fvec_t *vec;28 fvec_t vec;
29 PyObject *level_lin;29 PyObject *level_lin;
30 30
31 if (!PyArg_ParseTuple (args, "O:level_lin", &input)) {31 if (!PyArg_ParseTuple (args, "O:level_lin", &input)) {
@@ -37,14 +37,11 @@ Py_aubio_level_lin(PyObject *self, PyObject *args) · 5 unmodified lines
37 return NULL;37 return NULL;
38 }38 }
39 39
40 vec = (fvec_t *)malloc(sizeof(fvec_t));40 if (!PyAubio_ArrayToCFvec(input, &vec)) {
41 if (!PyAubio_ArrayToCFvec(input, vec)) {
42 free(vec);
43 return NULL;41 return NULL;
44 }42 }
45 43
46 level_lin = Py_BuildValue("f", aubio_level_lin(vec));44 level_lin = Py_BuildValue("f", aubio_level_lin(&vec));
47 free(vec);
48 if (level_lin == NULL) {45 if (level_lin == NULL) {
49 PyErr_SetString (PyExc_ValueError, "failed computing level_lin");46 PyErr_SetString (PyExc_ValueError, "failed computing level_lin");
50 return NULL;47 return NULL;
@@ -57,7 +54,7 @@ PyObject * · 6 unmodified lines
57Py_aubio_db_spl(PyObject *self, PyObject *args)54Py_aubio_db_spl(PyObject *self, PyObject *args)
58{55{
59 PyObject *input;56 PyObject *input;
60 fvec_t *vec;57 fvec_t vec;
61 PyObject *db_spl;58 PyObject *db_spl;
62 59
63 if (!PyArg_ParseTuple (args, "O:db_spl", &input)) {60 if (!PyArg_ParseTuple (args, "O:db_spl", &input)) {
@@ -69,14 +66,11 @@ Py_aubio_db_spl(PyObject *self, PyObject *args) · 5 unmodified lines
69 return NULL;66 return NULL;
70 }67 }
71 68
72 vec = (fvec_t *)malloc(sizeof(fvec_t));69 if (!PyAubio_ArrayToCFvec(input, &vec)) {
73 if (!PyAubio_ArrayToCFvec(input, vec)) {
74 free(vec);
75 return NULL;70 return NULL;
76 }71 }
77 72
78 db_spl = Py_BuildValue("f", aubio_db_spl(vec));73 db_spl = Py_BuildValue("f", aubio_db_spl(&vec));
79 free(vec);
80 if (db_spl == NULL) {74 if (db_spl == NULL) {
81 PyErr_SetString (PyExc_ValueError, "failed computing db_spl");75 PyErr_SetString (PyExc_ValueError, "failed computing db_spl");
82 return NULL;76 return NULL;
@@ -89,7 +83,7 @@ PyObject * · 6 unmodified lines
89Py_aubio_silence_detection(PyObject *self, PyObject *args)83Py_aubio_silence_detection(PyObject *self, PyObject *args)
90{84{
91 PyObject *input;85 PyObject *input;
92 fvec_t *vec;86 fvec_t vec;
93 PyObject *silence_detection;87 PyObject *silence_detection;
94 smpl_t threshold;88 smpl_t threshold;
95 89
@@ -102,14 +96,11 @@ Py_aubio_silence_detection(PyObject *self, PyObject *args) · 6 unmodified lines
102 return NULL;96 return NULL;
103 }97 }
104 98
105 vec = (fvec_t *)malloc(sizeof(fvec_t));99 if (!PyAubio_ArrayToCFvec(input, &vec)) {
106 if (!PyAubio_ArrayToCFvec(input, vec)) {
107 free(vec);
108 return NULL;100 return NULL;
109 }101 }
110 102
111 silence_detection = Py_BuildValue("I", aubio_silence_detection(vec, threshold));103 silence_detection = Py_BuildValue("I", aubio_silence_detection(&vec, threshold));
112 free(vec);
113 if (silence_detection == NULL) {104 if (silence_detection == NULL) {
114 PyErr_SetString (PyExc_ValueError, "failed computing silence_detection");105 PyErr_SetString (PyExc_ValueError, "failed computing silence_detection");
115 return NULL;106 return NULL;
@@ -122,7 +113,7 @@ PyObject * · 6 unmodified lines
122Py_aubio_level_detection(PyObject *self, PyObject *args)113Py_aubio_level_detection(PyObject *self, PyObject *args)
123{114{
124 PyObject *input;115 PyObject *input;
125 fvec_t *vec;116 fvec_t vec;
126 PyObject *level_detection;117 PyObject *level_detection;
127 smpl_t threshold;118 smpl_t threshold;
128 119
@@ -135,14 +126,11 @@ Py_aubio_level_detection(PyObject *self, PyObject *args) · 6 unmodified lines
135 return NULL;126 return NULL;
136 }127 }
137 128
138 vec = (fvec_t *)malloc(sizeof(fvec_t));129 if (!PyAubio_ArrayToCFvec(input, &vec)) {
139 if (!PyAubio_ArrayToCFvec(input, vec)) {
140 free(vec);
141 return NULL;130 return NULL;
142 }131 }
143 132
144 level_detection = Py_BuildValue("f", aubio_level_detection(vec, threshold));133 level_detection = Py_BuildValue("f", aubio_level_detection(&vec, threshold));
145 free(vec);
146 if (level_detection == NULL) {134 if (level_detection == NULL) {
147 PyErr_SetString (PyExc_ValueError, "failed computing level_detection");135 PyErr_SetString (PyExc_ValueError, "failed computing level_detection");
148 return NULL;136 return NULL;
python/ext/py-phasevoc.c+6−13
@@ -1,17 +1,15 @@
1#include "aubio-types.h"1#include "aubio-types.h"
2 2
3static char Py_pvoc_doc[] = "pvoc object";
4
5typedef struct3typedef struct
6{4{
7 PyObject_HEAD5 PyObject_HEAD
8 aubio_pvoc_t * o;6 aubio_pvoc_t * o;
9 uint_t win_s;7 uint_t win_s;
10 uint_t hop_s;8 uint_t hop_s;
11 fvec_t *vecin;9 fvec_t vecin;
12 cvec_t *output;10 cvec_t *output;
13 Py_cvec *py_out;11 Py_cvec *py_out;
14 cvec_t *cvecin;12 cvec_t cvecin;
15 fvec_t *routput;13 fvec_t *routput;
16} Py_pvoc;14} Py_pvoc;
17 15
@@ -71,9 +69,6 @@ Py_pvoc_init (Py_pvoc * self, PyObject * args, PyObject * kwds) · 53 unmodified lines
71 return -1;69 return -1;
72 }70 }
73 71
74 self->cvecin = (cvec_t *)malloc(sizeof(cvec_t));
75 self->vecin = (fvec_t *)malloc(sizeof(fvec_t));
76
77 self->output = new_cvec(self->win_s);72 self->output = new_cvec(self->win_s);
78 self->py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);73 self->py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
79 self->routput = new_fvec(self->hop_s);74 self->routput = new_fvec(self->hop_s);
@@ -88,8 +83,6 @@ Py_pvoc_del (Py_pvoc *self, PyObject *unused) · 8 unmodified lines
88 del_aubio_pvoc(self->o);83 del_aubio_pvoc(self->o);
89 del_cvec(self->output);84 del_cvec(self->output);
90 del_fvec(self->routput);85 del_fvec(self->routput);
91 free(self->cvecin);
92 free(self->vecin);
93 Py_TYPE(self)->tp_free((PyObject *) self);86 Py_TYPE(self)->tp_free((PyObject *) self);
94}87}
95 88
@@ -103,12 +96,12 @@ Py_pvoc_do(Py_pvoc * self, PyObject * args) · 7 unmodified lines
103 return NULL;96 return NULL;
104 }97 }
105 98
106 if (!PyAubio_ArrayToCFvec (input, self->vecin)) {99 if (!PyAubio_ArrayToCFvec (input, &(self->vecin) )) {
107 return NULL;100 return NULL;
108 }101 }
109 102
110 // compute the function103 // compute the function
111 aubio_pvoc_do (self->o, self->vecin, self->output);104 aubio_pvoc_do (self->o, &(self->vecin), self->output);
112#if 0105#if 0
113 Py_cvec * py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);106 Py_cvec * py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
114 PyObject* output = PyAubio_CCvecToPyCvec(self->output, py_out);107 PyObject* output = PyAubio_CCvecToPyCvec(self->output, py_out);
@@ -135,12 +128,12 @@ Py_pvoc_rdo(Py_pvoc * self, PyObject * args) · 20 unmodified lines
135 return NULL;128 return NULL;
136 }129 }
137 130
138 if (!PyAubio_ArrayToCCvec (input, self->cvecin)) {131 if (!PyAubio_ArrayToCCvec (input, &(self->cvecin) )) {
139 return NULL;132 return NULL;
140 }133 }
141 134
142 // compute the function135 // compute the function
143 aubio_pvoc_rdo (self->o, self->cvecin, self->routput);136 aubio_pvoc_rdo (self->o, &(self->cvecin), self->routput);
144 return PyAubio_CFvecToArray(self->routput);137 return PyAubio_CFvecToArray(self->routput);
145}138}
146 139
python/ext/py-sink.c+7−13
@@ -7,8 +7,8 @@ typedef struct · 6 unmodified lines
7 char_t* uri;7 char_t* uri;
8 uint_t samplerate;8 uint_t samplerate;
9 uint_t channels;9 uint_t channels;
10 fvec_t *write_data;10 fvec_t write_data;
11 fmat_t *mwrite_data;11 fmat_t mwrite_data;
12} Py_sink;12} Py_sink;
13 13
14static char Py_sink_doc[] = ""14static char Py_sink_doc[] = ""
@@ -123,10 +123,6 @@ Py_sink_init (Py_sink * self, PyObject * args, PyObject * kwds) · 108 unmodified lines
123 self->samplerate = aubio_sink_get_samplerate ( self->o );123 self->samplerate = aubio_sink_get_samplerate ( self->o );
124 self->channels = aubio_sink_get_channels ( self->o );124 self->channels = aubio_sink_get_channels ( self->o );
125 125
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);
130 return 0;126 return 0;
131}127}
132 128
@@ -134,9 +130,7 @@ static void · 1 unmodified line
134Py_sink_del (Py_sink *self, PyObject *unused)130Py_sink_del (Py_sink *self, PyObject *unused)
135{131{
136 del_aubio_sink(self->o);132 del_aubio_sink(self->o);
137 free(self->write_data);133 free(self->mwrite_data.data);
138 free(self->mwrite_data->data);
139 free(self->mwrite_data);
140 Py_TYPE(self)->tp_free((PyObject *) self);134 Py_TYPE(self)->tp_free((PyObject *) self);
141}135}
142 136
@@ -156,13 +150,13 @@ Py_sink_do(Py_sink * self, PyObject * args) · 13 unmodified lines
156 }150 }
157 151
158 /* input vectors parsing */152 /* input vectors parsing */
159 if (!PyAubio_ArrayToCFvec(write_data_obj, self->write_data)) {153 if (!PyAubio_ArrayToCFvec(write_data_obj, &(self->write_data))) {
160 return NULL;154 return NULL;
161 }155 }
162 156
163 157
164 /* compute _do function */158 /* compute _do function */
165 aubio_sink_do (self->o, self->write_data, write);159 aubio_sink_do (self->o, &(self->write_data), write);
166 160
167 Py_RETURN_NONE;161 Py_RETURN_NONE;
168}162}
@@ -184,12 +178,12 @@ Py_sink_do_multi(Py_sink * self, PyObject * args) · 15 unmodified lines
184 178
185 179
186 /* input vectors parsing */180 /* input vectors parsing */
187 if (!PyAubio_ArrayToCFmat(write_data_obj, self->mwrite_data)) {181 if (!PyAubio_ArrayToCFmat(write_data_obj, &(self->mwrite_data))) {
188 return NULL;182 return NULL;
189 }183 }
190 184
191 /* compute _do function */185 /* compute _do function */
192 aubio_sink_do_multi (self->o, self->mwrite_data, write);186 aubio_sink_do_multi (self->o, &(self->mwrite_data), write);
193 Py_RETURN_NONE;187 Py_RETURN_NONE;
194}188}
195 189

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