Showing the changes to python (7 of 7 files). Show all
Unified · Split
| @@ -95,14 +95,15 @@ Py_alpha_norm (PyObject * self, PyObject * args) · 94 unmodified lines | ||
| 95 | 95 | return NULL; |
| 96 | 96 | } |
| 97 | 97 | |
| 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); | |
| 101 | 101 | return NULL; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // compute the function |
| 105 | 105 | result = Py_BuildValue ("f", fvec_alpha_norm (vec, alpha)); |
| 106 | + free(vec); | |
| 106 | 107 | if (result == NULL) { |
| 107 | 108 | return NULL; |
| 108 | 109 | } |
| @@ -185,14 +186,15 @@ Py_zero_crossing_rate (PyObject * self, PyObject * args) · 76 unmodified lines | ||
| 185 | 186 | return NULL; |
| 186 | 187 | } |
| 187 | 188 | |
| 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); | |
| 191 | 192 | return NULL; |
| 192 | 193 | } |
| 193 | 194 | |
| 194 | 195 | // compute the function |
| 195 | 196 | result = Py_BuildValue ("f", aubio_zero_crossing_rate (vec)); |
| 197 | + free(vec); | |
| 196 | 198 | if (result == NULL) { |
| 197 | 199 | return NULL; |
| 198 | 200 | } |
| @@ -214,9 +216,9 @@ Py_min_removal(PyObject * self, PyObject * args) · 15 unmodified lines | ||
| 214 | 216 | return NULL; |
| 215 | 217 | } |
| 216 | 218 | |
| 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); | |
| 220 | 222 | return NULL; |
| 221 | 223 | } |
| 222 | 224 | |
| @@ -7,7 +7,10 @@ typedef struct · 6 unmodified lines | ||
| 7 | 7 | PyObject_HEAD |
| 8 | 8 | aubio_fft_t * o; |
| 9 | 9 | uint_t win_s; |
| 10 | + fvec_t *vecin; | |
| 10 | 11 | cvec_t *out; |
| 12 | + Py_cvec *py_out; | |
| 13 | + cvec_t *cvecin; | |
| 11 | 14 | fvec_t *rout; |
| 12 | 15 | } Py_fft; |
| 13 | 16 | |
| @@ -52,7 +55,13 @@ Py_fft_init (Py_fft * self, PyObject * args, PyObject * kwds) · 38 unmodified lines | ||
| 52 | 55 | PyErr_SetString (PyExc_Exception, errstr); |
| 53 | 56 | return -1; |
| 54 | 57 | } |
| 58 | + | |
| 59 | + self->cvecin = (cvec_t *)malloc(sizeof(cvec_t)); | |
| 60 | + self->vecin = (fvec_t *)malloc(sizeof(fvec_t)); | |
| 61 | + | |
| 55 | 62 | 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); | |
| 56 | 65 | self->rout = new_fvec(self->win_s); |
| 57 | 66 | |
| 58 | 67 | return 0; |
| @@ -61,31 +70,38 @@ Py_fft_init (Py_fft * self, PyObject * args, PyObject * kwds) · 2 unmodified lines | ||
| 61 | 70 | static void |
| 62 | 71 | Py_fft_del (Py_fft *self, PyObject *unused) |
| 63 | 72 | { |
| 73 | + Py_XDECREF((PyObject*)(self->py_out)); | |
| 64 | 74 | del_aubio_fft(self->o); |
| 65 | 75 | del_cvec(self->out); |
| 66 | 76 | del_fvec(self->rout); |
| 77 | + free(self->cvecin); | |
| 78 | + free(self->vecin); | |
| 67 | 79 | Py_TYPE(self)->tp_free((PyObject *) self); |
| 68 | 80 | } |
| 69 | 81 | |
| 70 | −static PyObject * | |
| 82 | +static PyObject * | |
| 71 | 83 | Py_fft_do(Py_fft * self, PyObject * args) |
| 72 | 84 | { |
| 73 | 85 | PyObject *input; |
| 74 | − fvec_t *vec; | |
| 75 | 86 | |
| 76 | 87 | if (!PyArg_ParseTuple (args, "O", &input)) { |
| 77 | 88 | return NULL; |
| 78 | 89 | } |
| 79 | 90 | |
| 80 | − vec = PyAubio_ArrayToCFvec (input); | |
| 81 | − | |
| 82 | − if (vec == NULL) { | |
| 91 | + if (!PyAubio_ArrayToCFvec(input, self->vecin)) { | |
| 83 | 92 | return NULL; |
| 84 | 93 | } |
| 85 | 94 | |
| 86 | 95 | // 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 | |
| 89 | 105 | } |
| 90 | 106 | |
| 91 | 107 | static PyMemberDef Py_fft_members[] = { |
| @@ -94,25 +110,22 @@ static PyMemberDef Py_fft_members[] = { · 2 unmodified lines | ||
| 94 | 110 | {NULL} |
| 95 | 111 | }; |
| 96 | 112 | |
| 97 | −static PyObject * | |
| 113 | +static PyObject * | |
| 98 | 114 | Py_fft_rdo(Py_fft * self, PyObject * args) |
| 99 | 115 | { |
| 100 | 116 | PyObject *input; |
| 101 | − cvec_t *vec; | |
| 102 | 117 | |
| 103 | 118 | if (!PyArg_ParseTuple (args, "O", &input)) { |
| 104 | 119 | return NULL; |
| 105 | 120 | } |
| 106 | 121 | |
| 107 | − vec = PyAubio_ArrayToCCvec (input); | |
| 108 | − | |
| 109 | − if (vec == NULL) { | |
| 122 | + if (!PyAubio_ArrayToCCvec (input, self->cvecin) ) { | |
| 110 | 123 | return NULL; |
| 111 | 124 | } |
| 112 | 125 | |
| 113 | 126 | // 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); | |
| 116 | 129 | } |
| 117 | 130 | |
| 118 | 131 | static PyMethodDef Py_fft_methods[] = { |
| @@ -5,6 +5,7 @@ typedef struct · 4 unmodified lines | ||
| 5 | 5 | PyObject_HEAD |
| 6 | 6 | aubio_filter_t * o; |
| 7 | 7 | uint_t order; |
| 8 | + fvec_t *vec; | |
| 8 | 9 | fvec_t *out; |
| 9 | 10 | } Py_filter; |
| 10 | 11 | |
| @@ -49,6 +50,7 @@ Py_filter_init (Py_filter * self, PyObject * args, PyObject * kwds) · 38 unmodified lines | ||
| 49 | 50 | return -1; |
| 50 | 51 | } |
| 51 | 52 | self->out = new_fvec(Py_default_vector_length); |
| 53 | + self->vec = (fvec_t *)malloc(sizeof(fvec_t)); | |
| 52 | 54 | return 0; |
| 53 | 55 | } |
| 54 | 56 | |
| @@ -57,6 +59,7 @@ Py_filter_del (Py_filter * self) · 2 unmodified lines | ||
| 57 | 59 | { |
| 58 | 60 | del_fvec(self->out); |
| 59 | 61 | del_aubio_filter (self->o); |
| 62 | + free(self->vec); | |
| 60 | 63 | Py_TYPE(self)->tp_free ((PyObject *) self); |
| 61 | 64 | } |
| 62 | 65 | |
| @@ -64,7 +67,6 @@ static PyObject * · 1 unmodified line | ||
| 64 | 67 | Py_filter_do(Py_filter * self, PyObject * args) |
| 65 | 68 | { |
| 66 | 69 | PyObject *input; |
| 67 | − fvec_t *vec; | |
| 68 | 70 | |
| 69 | 71 | if (!PyArg_ParseTuple (args, "O:digital_filter.do", &input)) { |
| 70 | 72 | return NULL; |
| @@ -74,19 +76,17 @@ Py_filter_do(Py_filter * self, PyObject * args) · 3 unmodified lines | ||
| 74 | 76 | return NULL; |
| 75 | 77 | } |
| 76 | 78 | |
| 77 | − vec = PyAubio_ArrayToCFvec (input); | |
| 78 | − | |
| 79 | − if (vec == NULL) { | |
| 79 | + if (!PyAubio_ArrayToCFvec(input, self->vec)) { | |
| 80 | 80 | return NULL; |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | // reallocate the output if needed |
| 84 | − if (vec->length != self->out->length) { | |
| 84 | + if (self->vec->length != self->out->length) { | |
| 85 | 85 | del_fvec(self->out); |
| 86 | − self->out = new_fvec(vec->length); | |
| 86 | + self->out = new_fvec(self->vec->length); | |
| 87 | 87 | } |
| 88 | 88 | // compute the function |
| 89 | − aubio_filter_do_outplace (self->o, vec, self->out); | |
| 89 | + aubio_filter_do_outplace (self->o, self->vec, self->out); | |
| 90 | 90 | return PyAubio_CFvecToArray(self->out); |
| 91 | 91 | } |
| 92 | 92 | |
| @@ -8,7 +8,10 @@ typedef struct · 7 unmodified lines | ||
| 8 | 8 | aubio_filterbank_t * o; |
| 9 | 9 | uint_t n_filters; |
| 10 | 10 | uint_t win_s; |
| 11 | + cvec_t *vec; | |
| 11 | 12 | fvec_t *out; |
| 13 | + fvec_t *freqs; | |
| 14 | + fmat_t *coeffs; | |
| 12 | 15 | } Py_filterbank; |
| 13 | 16 | |
| 14 | 17 | static PyObject * |
| @@ -63,6 +66,14 @@ Py_filterbank_init (Py_filterbank * self, PyObject * args, PyObject * kwds) · 48 unmodified lines | ||
| 63 | 66 | } |
| 64 | 67 | self->out = new_fvec(self->n_filters); |
| 65 | 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 | + | |
| 66 | 77 | return 0; |
| 67 | 78 | } |
| 68 | 79 | |
| @@ -71,6 +82,10 @@ Py_filterbank_del (Py_filterbank *self, PyObject *unused) · 2 unmodified lines | ||
| 71 | 82 | { |
| 72 | 83 | del_aubio_filterbank(self->o); |
| 73 | 84 | del_fvec(self->out); |
| 85 | + free(self->vec); | |
| 86 | + free(self->freqs); | |
| 87 | + free(self->coeffs->data); | |
| 88 | + free(self->coeffs); | |
| 74 | 89 | Py_TYPE(self)->tp_free((PyObject *) self); |
| 75 | 90 | } |
| 76 | 91 | |
| @@ -78,20 +93,17 @@ static PyObject * · 1 unmodified line | ||
| 78 | 93 | Py_filterbank_do(Py_filterbank * self, PyObject * args) |
| 79 | 94 | { |
| 80 | 95 | PyObject *input; |
| 81 | − cvec_t *vec; | |
| 82 | 96 | |
| 83 | 97 | if (!PyArg_ParseTuple (args, "O", &input)) { |
| 84 | 98 | return NULL; |
| 85 | 99 | } |
| 86 | 100 | |
| 87 | − vec = PyAubio_ArrayToCCvec (input); | |
| 88 | − | |
| 89 | − if (vec == NULL) { | |
| 101 | + if (!PyAubio_ArrayToCCvec(input, self->vec)) { | |
| 90 | 102 | return NULL; |
| 91 | 103 | } |
| 92 | 104 | |
| 93 | 105 | // compute the function |
| 94 | − aubio_filterbank_do (self->o, vec, self->out); | |
| 106 | + aubio_filterbank_do (self->o, self->vec, self->out); | |
| 95 | 107 | return (PyObject *)PyAubio_CFvecToArray(self->out); |
| 96 | 108 | } |
| 97 | 109 | |
| @@ -110,7 +122,6 @@ Py_filterbank_set_triangle_bands (Py_filterbank * self, PyObject *args) · 12 unmodified lines | ||
| 110 | 122 | |
| 111 | 123 | PyObject *input; |
| 112 | 124 | uint_t samplerate; |
| 113 | − fvec_t *freqs; | |
| 114 | 125 | if (!PyArg_ParseTuple (args, "OI", &input, &samplerate)) { |
| 115 | 126 | return NULL; |
| 116 | 127 | } |
| @@ -119,14 +130,12 @@ Py_filterbank_set_triangle_bands (Py_filterbank * self, PyObject *args) · 2 unmodified lines | ||
| 119 | 130 | return NULL; |
| 120 | 131 | } |
| 121 | 132 | |
| 122 | − freqs = PyAubio_ArrayToCFvec (input); | |
| 123 | − | |
| 124 | − if (freqs == NULL) { | |
| 133 | + if (!PyAubio_ArrayToCFvec(input, self->freqs)) { | |
| 125 | 134 | return NULL; |
| 126 | 135 | } |
| 127 | 136 | |
| 128 | 137 | err = aubio_filterbank_set_triangle_bands (self->o, |
| 129 | − freqs, samplerate); | |
| 138 | + self->freqs, samplerate); | |
| 130 | 139 | if (err > 0) { |
| 131 | 140 | PyErr_SetString (PyExc_ValueError, |
| 132 | 141 | "error when setting filter to A-weighting"); |
| @@ -160,21 +169,15 @@ Py_filterbank_set_coeffs (Py_filterbank * self, PyObject *args) · 27 unmodified lines | ||
| 160 | 169 | uint_t err = 0; |
| 161 | 170 | |
| 162 | 171 | PyObject *input; |
| 163 | − fmat_t *coeffs; | |
| 164 | − | |
| 165 | 172 | if (!PyArg_ParseTuple (args, "O", &input)) { |
| 166 | 173 | return NULL; |
| 167 | 174 | } |
| 168 | 175 | |
| 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)) { | |
| 174 | 177 | return NULL; |
| 175 | 178 | } |
| 176 | 179 | |
| 177 | − err = aubio_filterbank_set_coeffs (self->o, coeffs); | |
| 180 | + err = aubio_filterbank_set_coeffs (self->o, self->coeffs); | |
| 178 | 181 | |
| 179 | 182 | if (err > 0) { |
| 180 | 183 | PyErr_SetString (PyExc_ValueError, |
| @@ -37,12 +37,14 @@ Py_aubio_level_lin(PyObject *self, PyObject *args) · 36 unmodified lines | ||
| 37 | 37 | return NULL; |
| 38 | 38 | } |
| 39 | 39 | |
| 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); | |
| 42 | 43 | return NULL; |
| 43 | 44 | } |
| 44 | 45 | |
| 45 | 46 | level_lin = Py_BuildValue("f", aubio_level_lin(vec)); |
| 47 | + free(vec); | |
| 46 | 48 | if (level_lin == NULL) { |
| 47 | 49 | PyErr_SetString (PyExc_ValueError, "failed computing level_lin"); |
| 48 | 50 | return NULL; |
| @@ -67,12 +69,14 @@ Py_aubio_db_spl(PyObject *self, PyObject *args) · 18 unmodified lines | ||
| 67 | 69 | return NULL; |
| 68 | 70 | } |
| 69 | 71 | |
| 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); | |
| 72 | 75 | return NULL; |
| 73 | 76 | } |
| 74 | 77 | |
| 75 | 78 | db_spl = Py_BuildValue("f", aubio_db_spl(vec)); |
| 79 | + free(vec); | |
| 76 | 80 | if (db_spl == NULL) { |
| 77 | 81 | PyErr_SetString (PyExc_ValueError, "failed computing db_spl"); |
| 78 | 82 | return NULL; |
| @@ -98,12 +102,14 @@ Py_aubio_silence_detection(PyObject *self, PyObject *args) · 19 unmodified lines | ||
| 98 | 102 | return NULL; |
| 99 | 103 | } |
| 100 | 104 | |
| 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); | |
| 103 | 108 | return NULL; |
| 104 | 109 | } |
| 105 | 110 | |
| 106 | 111 | silence_detection = Py_BuildValue("I", aubio_silence_detection(vec, threshold)); |
| 112 | + free(vec); | |
| 107 | 113 | if (silence_detection == NULL) { |
| 108 | 114 | PyErr_SetString (PyExc_ValueError, "failed computing silence_detection"); |
| 109 | 115 | return NULL; |
| @@ -129,12 +135,14 @@ Py_aubio_level_detection(PyObject *self, PyObject *args) · 19 unmodified lines | ||
| 129 | 135 | return NULL; |
| 130 | 136 | } |
| 131 | 137 | |
| 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); | |
| 134 | 141 | return NULL; |
| 135 | 142 | } |
| 136 | 143 | |
| 137 | 144 | level_detection = Py_BuildValue("f", aubio_level_detection(vec, threshold)); |
| 145 | + free(vec); | |
| 138 | 146 | if (level_detection == NULL) { |
| 139 | 147 | PyErr_SetString (PyExc_ValueError, "failed computing level_detection"); |
| 140 | 148 | return NULL; |
| @@ -8,7 +8,10 @@ typedef struct · 7 unmodified lines | ||
| 8 | 8 | aubio_pvoc_t * o; |
| 9 | 9 | uint_t win_s; |
| 10 | 10 | uint_t hop_s; |
| 11 | + fvec_t *vecin; | |
| 11 | 12 | cvec_t *output; |
| 13 | + Py_cvec *py_out; | |
| 14 | + cvec_t *cvecin; | |
| 12 | 15 | fvec_t *routput; |
| 13 | 16 | } Py_pvoc; |
| 14 | 17 | |
| @@ -68,7 +71,11 @@ Py_pvoc_init (Py_pvoc * self, PyObject * args, PyObject * kwds) · 53 unmodified lines | ||
| 68 | 71 | return -1; |
| 69 | 72 | } |
| 70 | 73 | |
| 74 | + self->cvecin = (cvec_t *)malloc(sizeof(cvec_t)); | |
| 75 | + self->vecin = (fvec_t *)malloc(sizeof(fvec_t)); | |
| 76 | + | |
| 71 | 77 | self->output = new_cvec(self->win_s); |
| 78 | + self->py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType); | |
| 72 | 79 | self->routput = new_fvec(self->hop_s); |
| 73 | 80 | |
| 74 | 81 | return 0; |
| @@ -81,29 +88,35 @@ Py_pvoc_del (Py_pvoc *self, PyObject *unused) · 6 unmodified lines | ||
| 81 | 88 | del_aubio_pvoc(self->o); |
| 82 | 89 | del_cvec(self->output); |
| 83 | 90 | del_fvec(self->routput); |
| 91 | + free(self->cvecin); | |
| 92 | + free(self->vecin); | |
| 84 | 93 | Py_TYPE(self)->tp_free((PyObject *) self); |
| 85 | 94 | } |
| 86 | 95 | |
| 87 | 96 | |
| 88 | −static PyObject * | |
| 97 | +static PyObject * | |
| 89 | 98 | Py_pvoc_do(Py_pvoc * self, PyObject * args) |
| 90 | 99 | { |
| 91 | 100 | PyObject *input; |
| 92 | − fvec_t *vec; | |
| 93 | 101 | |
| 94 | 102 | if (!PyArg_ParseTuple (args, "O", &input)) { |
| 95 | 103 | return NULL; |
| 96 | 104 | } |
| 97 | 105 | |
| 98 | − vec = PyAubio_ArrayToCFvec (input); | |
| 99 | − | |
| 100 | − if (vec == NULL) { | |
| 106 | + if (!PyAubio_ArrayToCFvec (input, self->vecin)) { | |
| 101 | 107 | return NULL; |
| 102 | 108 | } |
| 103 | 109 | |
| 104 | 110 | // 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 | |
| 107 | 120 | } |
| 108 | 121 | |
| 109 | 122 | static PyMemberDef Py_pvoc_members[] = { |
| @@ -118,20 +131,17 @@ static PyObject * · 8 unmodified lines | ||
| 118 | 131 | Py_pvoc_rdo(Py_pvoc * self, PyObject * args) |
| 119 | 132 | { |
| 120 | 133 | PyObject *input; |
| 121 | − cvec_t *vec; | |
| 122 | 134 | if (!PyArg_ParseTuple (args, "O", &input)) { |
| 123 | 135 | return NULL; |
| 124 | 136 | } |
| 125 | 137 | |
| 126 | − vec = PyAubio_ArrayToCCvec (input); | |
| 127 | − | |
| 128 | − if (vec == NULL) { | |
| 138 | + if (!PyAubio_ArrayToCCvec (input, self->cvecin)) { | |
| 129 | 139 | return NULL; |
| 130 | 140 | } |
| 131 | 141 | |
| 132 | 142 | // 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); | |
| 135 | 145 | } |
| 136 | 146 | |
| 137 | 147 | static PyMethodDef Py_pvoc_methods[] = { |
| @@ -7,6 +7,8 @@ typedef struct · 6 unmodified lines | ||
| 7 | 7 | char_t* uri; |
| 8 | 8 | uint_t samplerate; |
| 9 | 9 | uint_t channels; |
| 10 | + fvec_t *write_data; | |
| 11 | + fmat_t *mwrite_data; | |
| 10 | 12 | } Py_sink; |
| 11 | 13 | |
| 12 | 14 | static char Py_sink_doc[] = "" |
| @@ -121,6 +123,10 @@ Py_sink_init (Py_sink * self, PyObject * args, PyObject * kwds) · 108 unmodified lines | ||
| 121 | 123 | self->samplerate = aubio_sink_get_samplerate ( self->o ); |
| 122 | 124 | self->channels = aubio_sink_get_channels ( self->o ); |
| 123 | 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); | |
| 124 | 130 | return 0; |
| 125 | 131 | } |
| 126 | 132 | |
| @@ -128,6 +134,9 @@ static void · 1 unmodified line | ||
| 128 | 134 | Py_sink_del (Py_sink *self, PyObject *unused) |
| 129 | 135 | { |
| 130 | 136 | del_aubio_sink(self->o); |
| 137 | + free(self->write_data); | |
| 138 | + free(self->mwrite_data->data); | |
| 139 | + free(self->mwrite_data); | |
| 131 | 140 | Py_TYPE(self)->tp_free((PyObject *) self); |
| 132 | 141 | } |
| 133 | 142 | |
| @@ -139,7 +148,6 @@ Py_sink_do(Py_sink * self, PyObject * args) · 5 unmodified lines | ||
| 139 | 148 | PyObject * write_data_obj; |
| 140 | 149 | |
| 141 | 150 | /* input vectors prototypes */ |
| 142 | − fvec_t* write_data; | |
| 143 | 151 | uint_t write; |
| 144 | 152 | |
| 145 | 153 | |
| @@ -147,20 +155,14 @@ Py_sink_do(Py_sink * self, PyObject * args) · 1 unmodified line | ||
| 147 | 155 | return NULL; |
| 148 | 156 | } |
| 149 | 157 | |
| 150 | − | |
| 151 | 158 | /* 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)) { | |
| 155 | 160 | return NULL; |
| 156 | 161 | } |
| 157 | 162 | |
| 158 | 163 | |
| 159 | − | |
| 160 | − | |
| 161 | − | |
| 162 | 164 | /* compute _do function */ |
| 163 | − aubio_sink_do (self->o, write_data, write); | |
| 165 | + aubio_sink_do (self->o, self->write_data, write); | |
| 164 | 166 | |
| 165 | 167 | Py_RETURN_NONE; |
| 166 | 168 | } |
| @@ -173,7 +175,6 @@ Py_sink_do_multi(Py_sink * self, PyObject * args) · 6 unmodified lines | ||
| 173 | 175 | PyObject * write_data_obj; |
| 174 | 176 | |
| 175 | 177 | /* input vectors prototypes */ |
| 176 | − fmat_t * write_data; | |
| 177 | 178 | uint_t write; |
| 178 | 179 | |
| 179 | 180 | |
| @@ -183,18 +184,12 @@ Py_sink_do_multi(Py_sink * self, PyObject * args) · 3 unmodified lines | ||
| 183 | 184 | |
| 184 | 185 | |
| 185 | 186 | /* 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)) { | |
| 189 | 188 | return NULL; |
| 190 | 189 | } |
| 191 | 190 | |
| 192 | − | |
| 193 | − | |
| 194 | − | |
| 195 | − | |
| 196 | 191 | /* compute _do function */ |
| 197 | − aubio_sink_do_multi (self->o, write_data, write); | |
| 192 | + aubio_sink_do_multi (self->o, self->mwrite_data, write); | |
| 198 | 193 | Py_RETURN_NONE; |
| 199 | 194 | } |
| 200 | 195 | |