Ignore:
Timestamp:
Jun 22, 2016, 1:00:10 PM (9 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, 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.
Message:

Merge branch 'master' into notes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/ext/aubiomodule.c

    r60fc05b rf264b17  
    11#define PY_AUBIO_MODULE_MAIN
    22#include "aubio-types.h"
    3 #include "aubio-generated.h"
    43#include "py-musicutils.h"
    54
     
    8483{
    8584  PyObject *input;
    86   fvec_t *vec;
     85  fvec_t vec;
    8786  smpl_t alpha;
    8887  PyObject *result;
    8988
    90   if (!PyArg_ParseTuple (args, "Of:alpha_norm", &input, &alpha)) {
     89  if (!PyArg_ParseTuple (args, "O" AUBIO_NPY_SMPL_CHR ":alpha_norm", &input, &alpha)) {
    9190    return NULL;
    9291  }
     
    9695  }
    9796
    98   vec = PyAubio_ArrayToCFvec (input);
    99 
    100   if (vec == NULL) {
     97  if (!PyAubio_ArrayToCFvec(input, &vec)) {
    10198    return NULL;
    10299  }
    103100
    104101  // 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));
    106103  if (result == NULL) {
    107104    return NULL;
     
    117114  smpl_t output;
    118115
    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)) {
    120117    return NULL;
    121118  }
     
    132129  smpl_t output;
    133130
    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)) {
    135132    return NULL;
    136133  }
     
    147144  smpl_t output;
    148145
    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)) {
    150147    return NULL;
    151148  }
     
    162159  smpl_t output;
    163160
    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)) {
    165162    return NULL;
    166163  }
     
    175172{
    176173  PyObject *input;
    177   fvec_t *vec;
     174  fvec_t vec;
    178175  PyObject *result;
    179176
     
    186183  }
    187184
    188   vec = PyAubio_ArrayToCFvec (input);
    189 
    190   if (vec == NULL) {
     185  if (!PyAubio_ArrayToCFvec(input, &vec)) {
    191186    return NULL;
    192187  }
    193188
    194189  // 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));
    196191  if (result == NULL) {
    197192    return NULL;
     
    205200{
    206201  PyObject *input;
    207   fvec_t *vec;
     202  fvec_t vec;
    208203
    209204  if (!PyArg_ParseTuple (args, "O:min_removal", &input)) {
     
    215210  }
    216211
    217   vec = PyAubio_ArrayToCFvec (input);
    218 
    219   if (vec == NULL) {
     212  if (!PyAubio_ArrayToCFvec(input, &vec)) {
    220213    return NULL;
    221214  }
    222215
    223216  // compute the function
    224   fvec_min_removal (vec);
     217  fvec_min_removal (&vec);
    225218
    226219  // since this function does not return, we could return None
    227220  //Py_RETURN_NONE;
    228221  // however it is convenient to return the modified vector
    229   return (PyObject *) PyAubio_CFvecToArray(vec);
     222  return (PyObject *) PyAubio_CFvecToArray(&vec);
    230223  // or even without converting it back to an array
    231224  //Py_INCREF(vec);
     
    246239  {"level_detection", Py_aubio_level_detection, METH_VARARGS, Py_aubio_level_detection_doc},
    247240  {"window", Py_aubio_window, METH_VARARGS, Py_aubio_window_doc},
    248   {NULL, NULL} /* Sentinel */
     241  {NULL, NULL, 0, NULL} /* Sentinel */
    249242};
    250243
    251 PyMODINIT_FUNC
    252 init_aubio (void)
    253 {
    254   PyObject *m;
     244#if PY_MAJOR_VERSION >= 3
     245// Python3 module definition
     246static 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
     259static PyObject *
     260initaubio (void)
     261{
     262  PyObject *m = NULL;
    255263  int err;
    256264
     
    266274      || (generated_types_ready() < 0 )
    267275  ) {
    268     return;
    269   }
    270 
     276    return m;
     277  }
     278
     279#if PY_MAJOR_VERSION >= 3
     280  m = PyModule_Create(&moduledef);
     281#else
    271282  m = Py_InitModule3 ("_aubio", aubio_methods, aubio_module_doc);
     283#endif
    272284
    273285  if (m == NULL) {
    274     return;
     286    return m;
    275287  }
    276288
     
    296308  PyModule_AddObject (m, "sink", (PyObject *) & Py_sinkType);
    297309
     310  PyModule_AddStringConstant(m, "float_type", AUBIO_NPY_SMPL_STR);
     311
    298312  // add generated objects
    299313  add_generated_objects(m);
     
    301315  // add ufunc
    302316  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.