Changes in python/ext/aubiomodule.c [9c8c8a6:a159628]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/ext/aubiomodule.c
r9c8c8a6 ra159628 1 1 #define PY_AUBIO_MODULE_MAIN 2 2 #include "aubio-types.h" 3 #include "aubio-generated.h"4 3 #include "py-musicutils.h" 4 5 // this dummy macro is used to convince windows that a string passed as -D flag 6 // is just that, a string, and not a double. 7 #define REDEFINESTRING(x) #x 8 #define DEFINEDSTRING(x) REDEFINESTRING(x) 5 9 6 10 static char aubio_module_doc[] = "Python module for the aubio library"; … … 76 80 ">>> min_removal(a)"; 77 81 78 extern void add_generated_objects ( PyObject *m );79 82 extern void add_ufuncs ( PyObject *m ); 80 83 extern int generated_types_ready(void); … … 84 87 { 85 88 PyObject *input; 86 fvec_t *vec;89 fvec_t vec; 87 90 smpl_t alpha; 88 91 PyObject *result; 89 92 90 if (!PyArg_ParseTuple (args, "O f:alpha_norm", &input, &alpha)) {93 if (!PyArg_ParseTuple (args, "O" AUBIO_NPY_SMPL_CHR ":alpha_norm", &input, &alpha)) { 91 94 return NULL; 92 95 } … … 96 99 } 97 100 98 vec = PyAubio_ArrayToCFvec (input); 99 100 if (vec == NULL) { 101 if (!PyAubio_ArrayToCFvec(input, &vec)) { 101 102 return NULL; 102 103 } 103 104 104 105 // compute the function 105 result = Py_BuildValue ( "f", fvec_alpha_norm (vec, alpha));106 result = Py_BuildValue (AUBIO_NPY_SMPL_CHR, fvec_alpha_norm (&vec, alpha)); 106 107 if (result == NULL) { 107 108 return NULL; … … 117 118 smpl_t output; 118 119 119 if (!PyArg_ParseTuple (args, "| fff", &input, &samplerate, &fftsize)) {120 if (!PyArg_ParseTuple (args, "|" AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR , &input, &samplerate, &fftsize)) { 120 121 return NULL; 121 122 } … … 132 133 smpl_t output; 133 134 134 if (!PyArg_ParseTuple (args, "| fff", &input, &samplerate, &fftsize)) {135 if (!PyArg_ParseTuple (args, "|" AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR , &input, &samplerate, &fftsize)) { 135 136 return NULL; 136 137 } … … 147 148 smpl_t output; 148 149 149 if (!PyArg_ParseTuple (args, "| fff", &input, &samplerate, &fftsize)) {150 if (!PyArg_ParseTuple (args, "|" AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR, &input, &samplerate, &fftsize)) { 150 151 return NULL; 151 152 } … … 162 163 smpl_t output; 163 164 164 if (!PyArg_ParseTuple (args, "| fff", &input, &samplerate, &fftsize)) {165 if (!PyArg_ParseTuple (args, "|" AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR, &input, &samplerate, &fftsize)) { 165 166 return NULL; 166 167 } … … 175 176 { 176 177 PyObject *input; 177 fvec_t *vec;178 fvec_t vec; 178 179 PyObject *result; 179 180 … … 186 187 } 187 188 188 vec = PyAubio_ArrayToCFvec (input); 189 190 if (vec == NULL) { 189 if (!PyAubio_ArrayToCFvec(input, &vec)) { 191 190 return NULL; 192 191 } 193 192 194 193 // compute the function 195 result = Py_BuildValue ( "f", aubio_zero_crossing_rate (vec));194 result = Py_BuildValue (AUBIO_NPY_SMPL_CHR, aubio_zero_crossing_rate (&vec)); 196 195 if (result == NULL) { 197 196 return NULL; … … 205 204 { 206 205 PyObject *input; 207 fvec_t *vec;206 fvec_t vec; 208 207 209 208 if (!PyArg_ParseTuple (args, "O:min_removal", &input)) { … … 215 214 } 216 215 217 vec = PyAubio_ArrayToCFvec (input); 218 219 if (vec == NULL) { 216 if (!PyAubio_ArrayToCFvec(input, &vec)) { 220 217 return NULL; 221 218 } 222 219 223 220 // compute the function 224 fvec_min_removal ( vec);221 fvec_min_removal (&vec); 225 222 226 223 // since this function does not return, we could return None 227 224 //Py_RETURN_NONE; 228 225 // however it is convenient to return the modified vector 229 return (PyObject *) PyAubio_CFvecToArray( vec);226 return (PyObject *) PyAubio_CFvecToArray(&vec); 230 227 // or even without converting it back to an array 231 228 //Py_INCREF(vec); … … 246 243 {"level_detection", Py_aubio_level_detection, METH_VARARGS, Py_aubio_level_detection_doc}, 247 244 {"window", Py_aubio_window, METH_VARARGS, Py_aubio_window_doc}, 248 {NULL, NULL } /* Sentinel */245 {NULL, NULL, 0, NULL} /* Sentinel */ 249 246 }; 250 247 251 PyMODINIT_FUNC 252 init_aubio (void) 253 { 254 PyObject *m; 248 #if PY_MAJOR_VERSION >= 3 249 // Python3 module definition 250 static struct PyModuleDef moduledef = { 251 PyModuleDef_HEAD_INIT, 252 "_aubio", /* m_name */ 253 aubio_module_doc, /* m_doc */ 254 -1, /* m_size */ 255 aubio_methods, /* m_methods */ 256 NULL, /* m_reload */ 257 NULL, /* m_traverse */ 258 NULL, /* m_clear */ 259 NULL, /* m_free */ 260 }; 261 #endif 262 263 void 264 aubio_log_function(int level, const char *message, void *data) 265 { 266 // remove trailing \n 267 char *pos; 268 if ((pos=strchr(message, '\n')) != NULL) { 269 *pos = '\0'; 270 } 271 // warning or error 272 if (level == AUBIO_LOG_ERR) { 273 PyErr_Format(PyExc_RuntimeError, "%s", message); 274 } else { 275 PyErr_WarnEx(PyExc_UserWarning, message, 1); 276 } 277 } 278 279 static PyObject * 280 initaubio (void) 281 { 282 PyObject *m = NULL; 255 283 int err; 256 284 … … 266 294 || (generated_types_ready() < 0 ) 267 295 ) { 268 return; 269 } 270 296 return m; 297 } 298 299 #if PY_MAJOR_VERSION >= 3 300 m = PyModule_Create(&moduledef); 301 #else 271 302 m = Py_InitModule3 ("_aubio", aubio_methods, aubio_module_doc); 303 #endif 272 304 273 305 if (m == NULL) { 274 return ;306 return m; 275 307 } 276 308 … … 296 328 PyModule_AddObject (m, "sink", (PyObject *) & Py_sinkType); 297 329 330 PyModule_AddStringConstant(m, "float_type", AUBIO_NPY_SMPL_STR); 331 PyModule_AddStringConstant(m, "__version__", DEFINEDSTRING(AUBIO_VERSION)); 332 298 333 // add generated objects 299 334 add_generated_objects(m); … … 301 336 // add ufunc 302 337 add_ufuncs(m); 303 } 338 339 aubio_log_set_level_function(AUBIO_LOG_ERR, aubio_log_function, NULL); 340 aubio_log_set_level_function(AUBIO_LOG_WRN, aubio_log_function, NULL); 341 return m; 342 } 343 344 #if PY_MAJOR_VERSION >= 3 345 // Python3 init 346 PyMODINIT_FUNC PyInit__aubio(void) 347 { 348 return initaubio(); 349 } 350 #else 351 // Python 2 init 352 PyMODINIT_FUNC init_aubio(void) 353 { 354 initaubio(); 355 } 356 #endif
Note: See TracChangeset
for help on using the changeset viewer.