Changeset b5bef11
- Timestamp:
- Apr 21, 2016, 9:31:10 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:
- a7f398d
- Parents:
- bfe8256
- Location:
- python/ext
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
python/ext/aubiomodule.c
rbfe8256 rb5bef11 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 } … … 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; … … 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 } … … 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; … … 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 } -
python/ext/py-fft.c
rbfe8256 rb5bef11 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; … … 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 … … 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)) { … … 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 … … 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)) { … … 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 -
python/ext/py-filter.c
rbfe8256 rb5bef11 6 6 aubio_filter_t * o; 7 7 uint_t order; 8 fvec_t *vec; 8 9 fvec_t *out; 9 10 } Py_filter; … … 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 } … … 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 } … … 65 68 { 66 69 PyObject *input; 67 fvec_t *vec;68 70 69 71 if (!PyArg_ParseTuple (args, "O:digital_filter.do", &input)) { … … 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 } -
python/ext/py-filterbank.c
rbfe8256 rb5bef11 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 … … 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 } … … 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 } … … 79 94 { 80 95 PyObject *input; 81 cvec_t *vec;82 96 83 97 if (!PyArg_ParseTuple (args, "O", &input)) { … … 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 } … … 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; … … 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, … … 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"); 174 return NULL; 175 } 176 177 err = aubio_filterbank_set_coeffs (self->o, coeffs); 176 if (!PyAubio_ArrayToCFmat(input, self->coeffs)) { 177 return NULL; 178 } 179 180 err = aubio_filterbank_set_coeffs (self->o, self->coeffs); 178 181 179 182 if (err > 0) { -
python/ext/py-musicutils.c
rbfe8256 rb5bef11 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"); … … 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"); … … 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"); … … 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"); -
python/ext/py-phasevoc.c
rbfe8256 rb5bef11 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; … … 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 … … 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)) { … … 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 … … 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 -
python/ext/py-sink.c
rbfe8256 rb5bef11 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 … … 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 } … … 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 } … … 140 149 141 150 /* input vectors prototypes */ 142 fvec_t* write_data;143 151 uint_t write; 144 152 … … 148 156 } 149 157 150 151 158 /* input vectors parsing */ 152 write_data = PyAubio_ArrayToCFvec (write_data_obj); 153 154 if (write_data == NULL) { 155 return NULL; 156 } 157 158 159 159 if (!PyAubio_ArrayToCFvec(write_data_obj, self->write_data)) { 160 return NULL; 161 } 160 162 161 163 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; … … 174 176 175 177 /* input vectors prototypes */ 176 fmat_t * write_data;177 178 uint_t write; 178 179 … … 184 185 185 186 /* input vectors parsing */ 186 write_data = PyAubio_ArrayToCFmat (write_data_obj); 187 188 if (write_data == NULL) { 189 return NULL; 190 } 191 192 193 194 187 if (!PyAubio_ArrayToCFmat(write_data_obj, self->mwrite_data)) { 188 return NULL; 189 } 195 190 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 }
Note: See TracChangeset
for help on using the changeset viewer.