Changeset ccf8b77


Ignore:
Timestamp:
Oct 2, 2009, 3:39:33 PM (15 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:
f530f12
Parents:
146280a
Message:

python/aubiomodule.c: move PyAubio_ArrayToFvec to py-fvec.c

Location:
interfaces/python
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • interfaces/python/aubiomodule.c

    r146280a rccf8b77  
    44
    55#include "aubio-types.h"
    6 
    7 Py_fvec *
    8 PyAubio_ArrayToFvec (PyObject *input) {
    9   PyObject *array;
    10   Py_fvec *vec;
    11   uint_t i;
    12   // parsing input object into a Py_fvec
    13   if (PyObject_TypeCheck (input, &Py_fvecType)) {
    14     // input is an fvec, nothing else to do
    15     vec = (Py_fvec *) input;
    16   } else if (PyArray_Check(input)) {
    17 
    18     // we got an array, convert it to an fvec
    19     if (PyArray_NDIM (input) == 0) {
    20       PyErr_SetString (PyExc_ValueError, "input array is a scalar");
    21       goto fail;
    22     } else if (PyArray_NDIM (input) > 2) {
    23       PyErr_SetString (PyExc_ValueError,
    24           "input array has more than two dimensions");
    25       goto fail;
    26     }
    27 
    28     if (!PyArray_ISFLOAT (input)) {
    29       PyErr_SetString (PyExc_ValueError, "input array should be float");
    30       goto fail;
    31 #if AUBIO_DO_CASTING
    32     } else if (PyArray_TYPE (input) != AUBIO_FLOAT) {
    33       // input data type is not float32, casting
    34       array = PyArray_Cast ( (PyArrayObject*) input, AUBIO_FLOAT);
    35       if (array == NULL) {
    36         PyErr_SetString (PyExc_IndexError, "failed converting to NPY_FLOAT");
    37         goto fail;
    38       }
    39 #else
    40     } else if (PyArray_TYPE (input) != AUBIO_FLOAT) {
    41       PyErr_SetString (PyExc_ValueError, "input array should be float32");
    42       goto fail;
    43 #endif
    44     } else {
    45       // input data type is float32, nothing else to do
    46       array = input;
    47     }
    48 
    49     // create a new fvec object
    50     vec = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType);
    51     if (PyArray_NDIM (array) == 1) {
    52       vec->channels = 1;
    53       vec->length = PyArray_SIZE (array);
    54     } else {
    55       vec->channels = PyArray_DIM (array, 0);
    56       vec->length = PyArray_DIM (array, 1);
    57     }
    58 
    59     // no need to really allocate fvec, just its struct member
    60     // vec->o = new_fvec (vec->length, vec->channels);
    61     vec->o = (fvec_t *)malloc(sizeof(fvec_t));
    62     vec->o->length = vec->length; vec->o->channels = vec->channels;
    63     vec->o->data = (smpl_t**)malloc(vec->o->channels * sizeof(smpl_t*));
    64     // hat data[i] point to array line
    65     for (i = 0; i < vec->channels; i++) {
    66       vec->o->data[i] = (smpl_t *) PyArray_GETPTR1 (array, i);
    67     }
    68 
    69   } else {
    70     PyErr_SetString (PyExc_ValueError, "can only accept array or fvec as input");
    71     return NULL;
    72   }
    73 
    74   return vec;
    75 
    76 fail:
    77   return NULL;
    78 }
    79 
    80 
    816
    827static char Py_alpha_norm_doc[] = "compute alpha normalisation factor";
     
    15378  Py_fvec *vec;
    15479
    155   if (!PyArg_ParseTuple (args, "O:zero_crossing_rate", &input)) {
     80  if (!PyArg_ParseTuple (args, "O:min_removal", &input)) {
    15681    return NULL;
    15782  }
     
    186111    Py_zero_crossing_rate_doc},
    187112  {"min_removal", Py_min_removal, METH_VARARGS, Py_min_removal_doc},
    188   {NULL, NULL}                  /* Sentinel */
     113  {NULL, NULL} /* Sentinel */
    189114};
    190115
  • interfaces/python/py-fvec.c

    r146280a rccf8b77  
    104104  fvec_print (self->o);
    105105  return Py_None;
     106}
     107
     108Py_fvec *
     109PyAubio_ArrayToFvec (PyObject *input) {
     110  PyObject *array;
     111  Py_fvec *vec;
     112  uint_t i;
     113  // parsing input object into a Py_fvec
     114  if (PyObject_TypeCheck (input, &Py_fvecType)) {
     115    // input is an fvec, nothing else to do
     116    vec = (Py_fvec *) input;
     117  } else if (PyArray_Check(input)) {
     118
     119    // we got an array, convert it to an fvec
     120    if (PyArray_NDIM (input) == 0) {
     121      PyErr_SetString (PyExc_ValueError, "input array is a scalar");
     122      goto fail;
     123    } else if (PyArray_NDIM (input) > 2) {
     124      PyErr_SetString (PyExc_ValueError,
     125          "input array has more than two dimensions");
     126      goto fail;
     127    }
     128
     129    if (!PyArray_ISFLOAT (input)) {
     130      PyErr_SetString (PyExc_ValueError, "input array should be float");
     131      goto fail;
     132#if AUBIO_DO_CASTING
     133    } else if (PyArray_TYPE (input) != AUBIO_FLOAT) {
     134      // input data type is not float32, casting
     135      array = PyArray_Cast ( (PyArrayObject*) input, AUBIO_FLOAT);
     136      if (array == NULL) {
     137        PyErr_SetString (PyExc_IndexError, "failed converting to NPY_FLOAT");
     138        goto fail;
     139      }
     140#else
     141    } else if (PyArray_TYPE (input) != AUBIO_FLOAT) {
     142      PyErr_SetString (PyExc_ValueError, "input array should be float32");
     143      goto fail;
     144#endif
     145    } else {
     146      // input data type is float32, nothing else to do
     147      array = input;
     148    }
     149
     150    // create a new fvec object
     151    vec = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType);
     152    if (PyArray_NDIM (array) == 1) {
     153      vec->channels = 1;
     154      vec->length = PyArray_SIZE (array);
     155    } else {
     156      vec->channels = PyArray_DIM (array, 0);
     157      vec->length = PyArray_DIM (array, 1);
     158    }
     159
     160    // no need to really allocate fvec, just its struct member
     161    // vec->o = new_fvec (vec->length, vec->channels);
     162    vec->o = (fvec_t *)malloc(sizeof(fvec_t));
     163    vec->o->length = vec->length; vec->o->channels = vec->channels;
     164    vec->o->data = (smpl_t**)malloc(vec->o->channels * sizeof(smpl_t*));
     165    // hat data[i] point to array line
     166    for (i = 0; i < vec->channels; i++) {
     167      vec->o->data[i] = (smpl_t *) PyArray_GETPTR1 (array, i);
     168    }
     169
     170  } else {
     171    PyErr_SetString (PyExc_ValueError, "can only accept array or fvec as input");
     172    return NULL;
     173  }
     174
     175  return vec;
     176
     177fail:
     178  return NULL;
    106179}
    107180
Note: See TracChangeset for help on using the changeset viewer.