Changeset 569b363
- Timestamp:
- Apr 24, 2016, 6:23:14 PM (9 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 51b9c83
- Parents:
- a35db12
- Location:
- python
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
python/ext/aubiomodule.c
ra35db12 r569b363 84 84 { 85 85 PyObject *input; 86 fvec_t *vec;86 fvec_t vec; 87 87 smpl_t alpha; 88 88 PyObject *result; … … 96 96 } 97 97 98 vec = (fvec_t *)malloc(sizeof(fvec_t)); 99 if (!PyAubio_ArrayToCFvec(input, vec)) { 100 free(vec); 98 if (!PyAubio_ArrayToCFvec(input, &vec)) { 101 99 return NULL; 102 100 } 103 101 104 102 // compute the function 105 result = Py_BuildValue ("f", fvec_alpha_norm (vec, alpha)); 106 free(vec); 103 result = Py_BuildValue ("f", fvec_alpha_norm (&vec, alpha)); 107 104 if (result == NULL) { 108 105 return NULL; … … 176 173 { 177 174 PyObject *input; 178 fvec_t *vec;175 fvec_t vec; 179 176 PyObject *result; 180 177 … … 187 184 } 188 185 189 vec = (fvec_t *)malloc(sizeof(fvec_t)); 190 if (!PyAubio_ArrayToCFvec(input, vec)) { 191 free(vec); 186 if (!PyAubio_ArrayToCFvec(input, &vec)) { 192 187 return NULL; 193 188 } 194 189 195 190 // compute the function 196 result = Py_BuildValue ("f", aubio_zero_crossing_rate (vec)); 197 free(vec); 191 result = Py_BuildValue ("f", aubio_zero_crossing_rate (&vec)); 198 192 if (result == NULL) { 199 193 return NULL; … … 207 201 { 208 202 PyObject *input; 209 fvec_t *vec;203 fvec_t vec; 210 204 211 205 if (!PyArg_ParseTuple (args, "O:min_removal", &input)) { … … 217 211 } 218 212 219 vec = (fvec_t *)malloc(sizeof(fvec_t)); 220 if (!PyAubio_ArrayToCFvec(input, vec)) { 221 free(vec); 213 if (!PyAubio_ArrayToCFvec(input, &vec)) { 222 214 return NULL; 223 215 } 224 216 225 217 // compute the function 226 fvec_min_removal ( vec);218 fvec_min_removal (&vec); 227 219 228 220 // since this function does not return, we could return None 229 221 //Py_RETURN_NONE; 230 222 // however it is convenient to return the modified vector 231 return (PyObject *) PyAubio_CFvecToArray( vec);223 return (PyObject *) PyAubio_CFvecToArray(&vec); 232 224 // or even without converting it back to an array 233 225 //Py_INCREF(vec); -
python/ext/aubioproxy.c
ra35db12 r569b363 144 144 } 145 145 146 if (mat->height != (uint_t)PyArray_DIM ((PyArrayObject *)input, 0)) { 147 /* 148 free(mat->data); 149 mat->height = (uint_t)PyArray_DIM ((PyArrayObject *)input, 0); 150 mat->data = (smpl_t **)malloc(sizeof(smpl_t*) * mat->height); 151 */ 152 PyErr_Format(PyExc_ValueError, "too many rows, %d but %ld expected", 153 mat->height, PyArray_DIM ((PyArrayObject *)input, 0) ); 154 return 0; 146 uint_t new_height = (uint_t)PyArray_DIM ((PyArrayObject *)input, 0); 147 if (mat->height != new_height) { 148 if (mat->data) { 149 free(mat->data); 150 } 151 mat->data = (smpl_t **)malloc(sizeof(smpl_t*) * new_height); 155 152 } 156 153 154 mat->height = new_height; 157 155 mat->length = (uint_t)PyArray_DIM ((PyArrayObject *)input, 1); 158 156 for (i=0; i< mat->height; i++) { -
python/ext/py-fft.c
ra35db12 r569b363 8 8 aubio_fft_t * o; 9 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 14 cvec_t *out; 15 fvec_t *rout; 16 // bridge for cvec output 12 17 Py_cvec *py_out; 13 cvec_t *cvecin;14 fvec_t *rout;15 18 } Py_fft; 16 19 … … 57 60 } 58 61 59 self->cvecin = (cvec_t *)malloc(sizeof(cvec_t));60 self->vecin = (fvec_t *)malloc(sizeof(fvec_t));61 62 62 self->out = new_cvec(self->win_s); 63 63 self->py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType); … … 75 75 del_cvec(self->out); 76 76 del_fvec(self->rout); 77 free(self->cvecin);78 free(self->vecin);79 77 Py_TYPE(self)->tp_free((PyObject *) self); 80 78 } … … 89 87 } 90 88 91 if (!PyAubio_ArrayToCFvec(input, self->vecin)) {89 if (!PyAubio_ArrayToCFvec(input, &(self->vecin))) { 92 90 return NULL; 93 91 } 94 92 95 93 // 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 95 #if 0 98 96 Py_cvec * py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType); … … 120 118 } 121 119 122 if (!PyAubio_ArrayToCCvec (input, self->cvecin) ) {120 if (!PyAubio_ArrayToCCvec (input, &(self->cvecin)) ) { 123 121 return NULL; 124 122 } 125 123 126 124 // compute the function 127 aubio_fft_rdo (self->o, self->cvecin, self->rout);125 aubio_fft_rdo (self->o, &(self->cvecin), self->rout); 128 126 return PyAubio_CFvecToArray(self->rout); 129 127 } -
python/ext/py-filter.c
ra35db12 r569b363 6 6 aubio_filter_t * o; 7 7 uint_t order; 8 fvec_t *vec;8 fvec_t vec; 9 9 fvec_t *out; 10 10 } Py_filter; … … 51 51 } 52 52 self->out = new_fvec(Py_default_vector_length); 53 self->vec = (fvec_t *)malloc(sizeof(fvec_t));54 53 return 0; 55 54 } … … 60 59 del_fvec(self->out); 61 60 del_aubio_filter (self->o); 62 free(self->vec);63 61 Py_TYPE(self)->tp_free ((PyObject *) self); 64 62 } … … 77 75 } 78 76 79 if (!PyAubio_ArrayToCFvec(input, self->vec)) {77 if (!PyAubio_ArrayToCFvec(input, &(self->vec))) { 80 78 return NULL; 81 79 } 82 80 83 81 // reallocate the output if needed 84 if (self->vec ->length != self->out->length) {82 if (self->vec.length != self->out->length) { 85 83 del_fvec(self->out); 86 self->out = new_fvec(self->vec ->length);84 self->out = new_fvec(self->vec.length); 87 85 } 88 86 // 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 88 return PyAubio_CFvecToArray(self->out); 91 89 } -
python/ext/py-filterbank.c
ra35db12 r569b363 9 9 uint_t n_filters; 10 10 uint_t win_s; 11 cvec_t *vec; 11 cvec_t vec; 12 fvec_t freqs; 13 fmat_t coeffs; 12 14 fvec_t *out; 13 fvec_t *freqs;14 fmat_t *coeffs;15 15 } Py_filterbank; 16 16 … … 67 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 69 return 0; 78 70 } … … 83 75 del_aubio_filterbank(self->o); 84 76 del_fvec(self->out); 85 free(self->vec); 86 free(self->freqs); 87 free(self->coeffs->data); 88 free(self->coeffs); 77 free(self->coeffs.data); 89 78 Py_TYPE(self)->tp_free((PyObject *) self); 90 79 } … … 99 88 } 100 89 101 if (!PyAubio_ArrayToCCvec(input, self->vec)) {90 if (!PyAubio_ArrayToCCvec(input, &(self->vec) )) { 102 91 return NULL; 103 92 } 104 93 105 94 // compute the function 106 aubio_filterbank_do (self->o, self->vec, self->out);95 aubio_filterbank_do (self->o, &(self->vec), self->out); 107 96 return (PyObject *)PyAubio_CFvecToArray(self->out); 108 97 } … … 131 120 } 132 121 133 if (!PyAubio_ArrayToCFvec(input, self->freqs)) {122 if (!PyAubio_ArrayToCFvec(input, &(self->freqs) )) { 134 123 return NULL; 135 124 } 136 125 137 126 err = aubio_filterbank_set_triangle_bands (self->o, 138 self->freqs, samplerate);127 &(self->freqs), samplerate); 139 128 if (err > 0) { 140 129 PyErr_SetString (PyExc_ValueError, … … 174 163 } 175 164 176 if (!PyAubio_ArrayToCFmat(input, self->coeffs)) {177 return NULL; 178 } 179 180 err = aubio_filterbank_set_coeffs (self->o, self->coeffs);165 if (!PyAubio_ArrayToCFmat(input, &(self->coeffs))) { 166 return NULL; 167 } 168 169 err = aubio_filterbank_set_coeffs (self->o, &(self->coeffs)); 181 170 182 171 if (err > 0) { -
python/ext/py-musicutils.c
ra35db12 r569b363 26 26 { 27 27 PyObject *input; 28 fvec_t *vec;28 fvec_t vec; 29 29 PyObject *level_lin; 30 30 … … 38 38 } 39 39 40 vec = (fvec_t *)malloc(sizeof(fvec_t)); 41 if (!PyAubio_ArrayToCFvec(input, vec)) { 42 free(vec); 40 if (!PyAubio_ArrayToCFvec(input, &vec)) { 43 41 return NULL; 44 42 } 45 43 46 level_lin = Py_BuildValue("f", aubio_level_lin(vec)); 47 free(vec); 44 level_lin = Py_BuildValue("f", aubio_level_lin(&vec)); 48 45 if (level_lin == NULL) { 49 46 PyErr_SetString (PyExc_ValueError, "failed computing level_lin"); … … 58 55 { 59 56 PyObject *input; 60 fvec_t *vec;57 fvec_t vec; 61 58 PyObject *db_spl; 62 59 … … 70 67 } 71 68 72 vec = (fvec_t *)malloc(sizeof(fvec_t)); 73 if (!PyAubio_ArrayToCFvec(input, vec)) { 74 free(vec); 69 if (!PyAubio_ArrayToCFvec(input, &vec)) { 75 70 return NULL; 76 71 } 77 72 78 db_spl = Py_BuildValue("f", aubio_db_spl(vec)); 79 free(vec); 73 db_spl = Py_BuildValue("f", aubio_db_spl(&vec)); 80 74 if (db_spl == NULL) { 81 75 PyErr_SetString (PyExc_ValueError, "failed computing db_spl"); … … 90 84 { 91 85 PyObject *input; 92 fvec_t *vec;86 fvec_t vec; 93 87 PyObject *silence_detection; 94 88 smpl_t threshold; … … 103 97 } 104 98 105 vec = (fvec_t *)malloc(sizeof(fvec_t)); 106 if (!PyAubio_ArrayToCFvec(input, vec)) { 107 free(vec); 99 if (!PyAubio_ArrayToCFvec(input, &vec)) { 108 100 return NULL; 109 101 } 110 102 111 silence_detection = Py_BuildValue("I", aubio_silence_detection(vec, threshold)); 112 free(vec); 103 silence_detection = Py_BuildValue("I", aubio_silence_detection(&vec, threshold)); 113 104 if (silence_detection == NULL) { 114 105 PyErr_SetString (PyExc_ValueError, "failed computing silence_detection"); … … 123 114 { 124 115 PyObject *input; 125 fvec_t *vec;116 fvec_t vec; 126 117 PyObject *level_detection; 127 118 smpl_t threshold; … … 136 127 } 137 128 138 vec = (fvec_t *)malloc(sizeof(fvec_t)); 139 if (!PyAubio_ArrayToCFvec(input, vec)) { 140 free(vec); 129 if (!PyAubio_ArrayToCFvec(input, &vec)) { 141 130 return NULL; 142 131 } 143 132 144 level_detection = Py_BuildValue("f", aubio_level_detection(vec, threshold)); 145 free(vec); 133 level_detection = Py_BuildValue("f", aubio_level_detection(&vec, threshold)); 146 134 if (level_detection == NULL) { 147 135 PyErr_SetString (PyExc_ValueError, "failed computing level_detection"); -
python/ext/py-phasevoc.c
ra35db12 r569b363 1 1 #include "aubio-types.h" 2 3 static char Py_pvoc_doc[] = "pvoc object";4 2 5 3 typedef struct … … 9 7 uint_t win_s; 10 8 uint_t hop_s; 11 fvec_t *vecin;9 fvec_t vecin; 12 10 cvec_t *output; 13 11 Py_cvec *py_out; 14 cvec_t *cvecin;12 cvec_t cvecin; 15 13 fvec_t *routput; 16 14 } Py_pvoc; … … 72 70 } 73 71 74 self->cvecin = (cvec_t *)malloc(sizeof(cvec_t));75 self->vecin = (fvec_t *)malloc(sizeof(fvec_t));76 77 72 self->output = new_cvec(self->win_s); 78 73 self->py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType); … … 89 84 del_cvec(self->output); 90 85 del_fvec(self->routput); 91 free(self->cvecin);92 free(self->vecin);93 86 Py_TYPE(self)->tp_free((PyObject *) self); 94 87 } … … 104 97 } 105 98 106 if (!PyAubio_ArrayToCFvec (input, self->vecin)) {99 if (!PyAubio_ArrayToCFvec (input, &(self->vecin) )) { 107 100 return NULL; 108 101 } 109 102 110 103 // compute the function 111 aubio_pvoc_do (self->o, self->vecin, self->output);104 aubio_pvoc_do (self->o, &(self->vecin), self->output); 112 105 #if 0 113 106 Py_cvec * py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType); … … 136 129 } 137 130 138 if (!PyAubio_ArrayToCCvec (input, self->cvecin)) {131 if (!PyAubio_ArrayToCCvec (input, &(self->cvecin) )) { 139 132 return NULL; 140 133 } 141 134 142 135 // compute the function 143 aubio_pvoc_rdo (self->o, self->cvecin, self->routput);136 aubio_pvoc_rdo (self->o, &(self->cvecin), self->routput); 144 137 return PyAubio_CFvecToArray(self->routput); 145 138 } -
python/ext/py-sink.c
ra35db12 r569b363 8 8 uint_t samplerate; 9 9 uint_t channels; 10 fvec_t *write_data;11 fmat_t *mwrite_data;10 fvec_t write_data; 11 fmat_t mwrite_data; 12 12 } Py_sink; 13 13 … … 124 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 126 return 0; 131 127 } … … 135 131 { 136 132 del_aubio_sink(self->o); 137 free(self->write_data); 138 free(self->mwrite_data->data); 139 free(self->mwrite_data); 133 free(self->mwrite_data.data); 140 134 Py_TYPE(self)->tp_free((PyObject *) self); 141 135 } … … 157 151 158 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 154 return NULL; 161 155 } … … 163 157 164 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 161 Py_RETURN_NONE; … … 185 179 186 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 182 return NULL; 189 183 } 190 184 191 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 187 Py_RETURN_NONE; 194 188 } -
python/lib/gen_code.py
ra35db12 r569b363 203 203 }} Py_{shortname}; 204 204 """ 205 return out.format(do_inputs_list = "; ".join(get_input_params(self.do_proto)), **self.__dict__) 205 # fmat_t* / fvec_t* / cvec_t* inputs -> full fvec_t /.. struct in Py_{shortname} 206 do_inputs_list = "; ".join(get_input_params(self.do_proto)).replace('fvec_t *','fvec_t').replace('fmat_t *', 'fmat_t').replace('cvec_t *', 'cvec_t') 207 return out.format(do_inputs_list = do_inputs_list, **self.__dict__) 206 208 207 209 def gen_doc(self): … … 311 313 // TODO get internal params after actual object creation? 312 314 """ 313 for input_param in self.do_inputs:314 out += """315 self->{0} = ({1})malloc(sizeof({2}));""".format(input_param['name'], input_param['type'], input_param['type'][:-1])316 315 out += """ 317 316 // create outputs{output_create} … … 343 342 {{""".format(**self.__dict__) 344 343 for input_param in self.do_inputs: 345 out += """ 346 free(self->{0[name]});""".format(input_param) 344 if input_param['type'] == 'fmat_t *': 345 out += """ 346 free(self->{0[name]}.data);""".format(input_param) 347 347 for o in self.outputs: 348 348 name = o['name'] … … 380 380 for p in input_params: 381 381 out += """ 382 if (!{pytoaubio}(py_{0[name]}, self->{0[name]})) {{382 if (!{pytoaubio}(py_{0[name]}, &(self->{0[name]}))) {{ 383 383 return NULL; 384 384 }}""".format(input_param, pytoaubio = pytoaubio_fn[input_param['type']]) 385 385 do_fn = get_name(self.do_proto) 386 inputs = ", ".join([' self->'+p['name']for p in input_params])386 inputs = ", ".join(['&(self->'+p['name']+')' for p in input_params]) 387 387 outputs = ", ".join(["self->%s" % p['name'] for p in self.do_outputs]) 388 388 out += """
Note: See TracChangeset
for help on using the changeset viewer.