Changeset f264b17 for python/ext/aubiomodule.c
- Timestamp:
- Jun 22, 2016, 1:00: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:
- 4b9443c4
- Parents:
- 60fc05b (diff), 6769586 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/ext/aubiomodule.c
r60fc05b rf264b17 1 1 #define PY_AUBIO_MODULE_MAIN 2 2 #include "aubio-types.h" 3 #include "aubio-generated.h"4 3 #include "py-musicutils.h" 5 4 … … 84 83 { 85 84 PyObject *input; 86 fvec_t *vec;85 fvec_t vec; 87 86 smpl_t alpha; 88 87 PyObject *result; 89 88 90 if (!PyArg_ParseTuple (args, "O f:alpha_norm", &input, &alpha)) {89 if (!PyArg_ParseTuple (args, "O" AUBIO_NPY_SMPL_CHR ":alpha_norm", &input, &alpha)) { 91 90 return NULL; 92 91 } … … 96 95 } 97 96 98 vec = PyAubio_ArrayToCFvec (input); 99 100 if (vec == NULL) { 97 if (!PyAubio_ArrayToCFvec(input, &vec)) { 101 98 return NULL; 102 99 } 103 100 104 101 // compute the function 105 result = Py_BuildValue ( "f", fvec_alpha_norm (vec, alpha));102 result = Py_BuildValue (AUBIO_NPY_SMPL_CHR, fvec_alpha_norm (&vec, alpha)); 106 103 if (result == NULL) { 107 104 return NULL; … … 117 114 smpl_t output; 118 115 119 if (!PyArg_ParseTuple (args, "| fff", &input, &samplerate, &fftsize)) {116 if (!PyArg_ParseTuple (args, "|" AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR , &input, &samplerate, &fftsize)) { 120 117 return NULL; 121 118 } … … 132 129 smpl_t output; 133 130 134 if (!PyArg_ParseTuple (args, "| fff", &input, &samplerate, &fftsize)) {131 if (!PyArg_ParseTuple (args, "|" AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR , &input, &samplerate, &fftsize)) { 135 132 return NULL; 136 133 } … … 147 144 smpl_t output; 148 145 149 if (!PyArg_ParseTuple (args, "| fff", &input, &samplerate, &fftsize)) {146 if (!PyArg_ParseTuple (args, "|" AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR, &input, &samplerate, &fftsize)) { 150 147 return NULL; 151 148 } … … 162 159 smpl_t output; 163 160 164 if (!PyArg_ParseTuple (args, "| fff", &input, &samplerate, &fftsize)) {161 if (!PyArg_ParseTuple (args, "|" AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR, &input, &samplerate, &fftsize)) { 165 162 return NULL; 166 163 } … … 175 172 { 176 173 PyObject *input; 177 fvec_t *vec;174 fvec_t vec; 178 175 PyObject *result; 179 176 … … 186 183 } 187 184 188 vec = PyAubio_ArrayToCFvec (input); 189 190 if (vec == NULL) { 185 if (!PyAubio_ArrayToCFvec(input, &vec)) { 191 186 return NULL; 192 187 } 193 188 194 189 // compute the function 195 result = Py_BuildValue ( "f", aubio_zero_crossing_rate (vec));190 result = Py_BuildValue (AUBIO_NPY_SMPL_CHR, aubio_zero_crossing_rate (&vec)); 196 191 if (result == NULL) { 197 192 return NULL; … … 205 200 { 206 201 PyObject *input; 207 fvec_t *vec;202 fvec_t vec; 208 203 209 204 if (!PyArg_ParseTuple (args, "O:min_removal", &input)) { … … 215 210 } 216 211 217 vec = PyAubio_ArrayToCFvec (input); 218 219 if (vec == NULL) { 212 if (!PyAubio_ArrayToCFvec(input, &vec)) { 220 213 return NULL; 221 214 } 222 215 223 216 // compute the function 224 fvec_min_removal ( vec);217 fvec_min_removal (&vec); 225 218 226 219 // since this function does not return, we could return None 227 220 //Py_RETURN_NONE; 228 221 // however it is convenient to return the modified vector 229 return (PyObject *) PyAubio_CFvecToArray( vec);222 return (PyObject *) PyAubio_CFvecToArray(&vec); 230 223 // or even without converting it back to an array 231 224 //Py_INCREF(vec); … … 246 239 {"level_detection", Py_aubio_level_detection, METH_VARARGS, Py_aubio_level_detection_doc}, 247 240 {"window", Py_aubio_window, METH_VARARGS, Py_aubio_window_doc}, 248 {NULL, NULL } /* Sentinel */241 {NULL, NULL, 0, NULL} /* Sentinel */ 249 242 }; 250 243 251 PyMODINIT_FUNC 252 init_aubio (void) 253 { 254 PyObject *m; 244 #if PY_MAJOR_VERSION >= 3 245 // Python3 module definition 246 static struct PyModuleDef moduledef = { 247 PyModuleDef_HEAD_INIT, 248 "_aubio", /* m_name */ 249 aubio_module_doc, /* m_doc */ 250 -1, /* m_size */ 251 aubio_methods, /* m_methods */ 252 NULL, /* m_reload */ 253 NULL, /* m_traverse */ 254 NULL, /* m_clear */ 255 NULL, /* m_free */ 256 }; 257 #endif 258 259 static PyObject * 260 initaubio (void) 261 { 262 PyObject *m = NULL; 255 263 int err; 256 264 … … 266 274 || (generated_types_ready() < 0 ) 267 275 ) { 268 return; 269 } 270 276 return m; 277 } 278 279 #if PY_MAJOR_VERSION >= 3 280 m = PyModule_Create(&moduledef); 281 #else 271 282 m = Py_InitModule3 ("_aubio", aubio_methods, aubio_module_doc); 283 #endif 272 284 273 285 if (m == NULL) { 274 return ;286 return m; 275 287 } 276 288 … … 296 308 PyModule_AddObject (m, "sink", (PyObject *) & Py_sinkType); 297 309 310 PyModule_AddStringConstant(m, "float_type", AUBIO_NPY_SMPL_STR); 311 298 312 // add generated objects 299 313 add_generated_objects(m); … … 301 315 // add ufunc 302 316 add_ufuncs(m); 303 } 317 318 return m; 319 } 320 321 #if PY_MAJOR_VERSION >= 3 322 // Python3 init 323 PyMODINIT_FUNC PyInit__aubio(void) 324 { 325 return initaubio(); 326 } 327 #else 328 // Python 2 init 329 PyMODINIT_FUNC init_aubio(void) 330 { 331 initaubio(); 332 } 333 #endif
Note: See TracChangeset
for help on using the changeset viewer.