Ignore:
Timestamp:
Mar 10, 2017, 2:26:32 PM (7 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, sampler
Children:
ee8a57c
Parents:
00d0275 (diff), 67b6618 (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.
Message:

Merge branch 'master' into awhitening

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/ext/aubiomodule.c

    r00d0275 r155cc10  
    11#define PY_AUBIO_MODULE_MAIN
    22#include "aubio-types.h"
    3 #include "aubio-generated.h"
    43#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)
    59
    610static char aubio_module_doc[] = "Python module for the aubio library";
     
    7680">>> min_removal(a)";
    7781
    78 extern void add_generated_objects ( PyObject *m );
    7982extern void add_ufuncs ( PyObject *m );
    8083extern int generated_types_ready(void);
     
    8487{
    8588  PyObject *input;
    86   fvec_t *vec;
     89  fvec_t vec;
    8790  smpl_t alpha;
    8891  PyObject *result;
    8992
    90   if (!PyArg_ParseTuple (args, "Of:alpha_norm", &input, &alpha)) {
     93  if (!PyArg_ParseTuple (args, "O" AUBIO_NPY_SMPL_CHR ":alpha_norm", &input, &alpha)) {
    9194    return NULL;
    9295  }
     
    9699  }
    97100
    98   vec = PyAubio_ArrayToCFvec (input);
    99 
    100   if (vec == NULL) {
     101  if (!PyAubio_ArrayToCFvec(input, &vec)) {
    101102    return NULL;
    102103  }
    103104
    104105  // 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));
    106107  if (result == NULL) {
    107108    return NULL;
     
    117118  smpl_t output;
    118119
    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)) {
    120121    return NULL;
    121122  }
     
    132133  smpl_t output;
    133134
    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)) {
    135136    return NULL;
    136137  }
     
    147148  smpl_t output;
    148149
    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)) {
    150151    return NULL;
    151152  }
     
    162163  smpl_t output;
    163164
    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)) {
    165166    return NULL;
    166167  }
     
    175176{
    176177  PyObject *input;
    177   fvec_t *vec;
     178  fvec_t vec;
    178179  PyObject *result;
    179180
     
    186187  }
    187188
    188   vec = PyAubio_ArrayToCFvec (input);
    189 
    190   if (vec == NULL) {
     189  if (!PyAubio_ArrayToCFvec(input, &vec)) {
    191190    return NULL;
    192191  }
    193192
    194193  // 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));
    196195  if (result == NULL) {
    197196    return NULL;
     
    205204{
    206205  PyObject *input;
    207   fvec_t *vec;
     206  fvec_t vec;
    208207
    209208  if (!PyArg_ParseTuple (args, "O:min_removal", &input)) {
     
    215214  }
    216215
    217   vec = PyAubio_ArrayToCFvec (input);
    218 
    219   if (vec == NULL) {
     216  if (!PyAubio_ArrayToCFvec(input, &vec)) {
    220217    return NULL;
    221218  }
    222219
    223220  // compute the function
    224   fvec_min_removal (vec);
     221  fvec_min_removal (&vec);
    225222
    226223  // since this function does not return, we could return None
    227224  //Py_RETURN_NONE;
    228225  // however it is convenient to return the modified vector
    229   return (PyObject *) PyAubio_CFvecToArray(vec);
     226  return (PyObject *) PyAubio_CFvecToArray(&vec);
    230227  // or even without converting it back to an array
    231228  //Py_INCREF(vec);
     
    246243  {"level_detection", Py_aubio_level_detection, METH_VARARGS, Py_aubio_level_detection_doc},
    247244  {"window", Py_aubio_window, METH_VARARGS, Py_aubio_window_doc},
    248   {NULL, NULL} /* Sentinel */
     245  {NULL, NULL, 0, NULL} /* Sentinel */
    249246};
    250247
    251 PyMODINIT_FUNC
    252 init_aubio (void)
    253 {
    254   PyObject *m;
     248#if PY_MAJOR_VERSION >= 3
     249// Python3 module definition
     250static 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
     263void
     264aubio_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
     279static PyObject *
     280initaubio (void)
     281{
     282  PyObject *m = NULL;
    255283  int err;
    256284
     
    266294      || (generated_types_ready() < 0 )
    267295  ) {
    268     return;
    269   }
    270 
     296    return m;
     297  }
     298
     299#if PY_MAJOR_VERSION >= 3
     300  m = PyModule_Create(&moduledef);
     301#else
    271302  m = Py_InitModule3 ("_aubio", aubio_methods, aubio_module_doc);
     303#endif
    272304
    273305  if (m == NULL) {
    274     return;
     306    return m;
    275307  }
    276308
     
    296328  PyModule_AddObject (m, "sink", (PyObject *) & Py_sinkType);
    297329
     330  PyModule_AddStringConstant(m, "float_type", AUBIO_NPY_SMPL_STR);
     331  PyModule_AddStringConstant(m, "__version__", DEFINEDSTRING(AUBIO_VERSION));
     332
    298333  // add generated objects
    299334  add_generated_objects(m);
     
    301336  // add ufunc
    302337  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.