Changeset 84e0606


Ignore:
Timestamp:
Dec 25, 2009, 4:56:48 AM (14 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:
1a6ef2c
Parents:
3e882a8
Message:

py-cvec.c: remove obsolete proxy functions

Location:
interfaces/python
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • interfaces/python/aubio-types.h

    r3e882a8 r84e0606  
    2727} Py_cvec;
    2828extern PyTypeObject Py_cvecType;
    29 extern PyObject *PyAubio_CvecToArray (Py_cvec * self);
    30 extern Py_cvec *PyAubio_ArrayToCvec (PyObject * self);
    3129
    3230// defined in aubio-proxy.c
  • interfaces/python/py-cvec.c

    r3e882a8 r84e0606  
    8888
    8989  return result;
    90 }
    91 
    92 Py_cvec *
    93 PyAubio_ArrayToCvec (PyObject *input) {
    94   PyObject *array;
    95   Py_cvec *vec;
    96   if (input == NULL) {
    97     PyErr_SetString (PyExc_ValueError, "input array is not a python object");
    98     goto fail;
    99   }
    100   // parsing input object into a Py_cvec
    101   if (PyObject_TypeCheck (input, &Py_cvecType)) {
    102     // input is an cvec, nothing else to do
    103     vec = (Py_cvec *) input;
    104   } else if (PyArray_Check(input)) {
    105 
    106     // we got an array, convert it to an cvec
    107     if (PyArray_NDIM (input) == 0) {
    108       PyErr_SetString (PyExc_ValueError, "input array is a scalar");
    109       goto fail;
    110     } else if (PyArray_NDIM (input) > 1) {
    111       PyErr_SetString (PyExc_ValueError,
    112           "input array has more than one dimensions");
    113       goto fail;
    114     }
    115 
    116     if (!PyArray_ISFLOAT (input)) {
    117       PyErr_SetString (PyExc_ValueError, "input array should be float");
    118       goto fail;
    119     } else if (PyArray_TYPE (input) != AUBIO_NPY_SMPL) {
    120       PyErr_SetString (PyExc_ValueError, "input array should be float32");
    121       goto fail;
    122     } else {
    123       // input data type is float32, nothing else to do
    124       array = input;
    125     }
    126 
    127     // create a new cvec object
    128     vec = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
    129     if (PyArray_NDIM (array) != 2) {
    130       PyErr_SetString (PyExc_ValueError,
    131           "input array should be have exactly two rows for norm and phas");
    132       goto fail;
    133     } else {
    134       vec->length = PyArray_SIZE (array);
    135     }
    136 
    137     // no need to really allocate cvec, just its struct member
    138     // vec->o = new_cvec (vec->length);
    139     vec->o = (cvec_t *)malloc(sizeof(cvec_t));
    140     vec->o->length = vec->length;
    141     // have norm and phas point to array rows
    142     vec->o->norm = (smpl_t *) PyArray_GETPTR1 (array, 0);
    143     vec->o->phas = (smpl_t *) PyArray_GETPTR1 (array, 1);
    144 
    145   } else {
    146     PyErr_SetString (PyExc_ValueError, "can only accept array or cvec as input");
    147     return NULL;
    148   }
    149 
    150   return vec;
    151 
    152 fail:
    153   return NULL;
    154 }
    155 
    156 PyObject *
    157 PyAubio_CvecToArray (Py_cvec * self)
    158 {
    159   PyObject *array = NULL;
    160   npy_intp dims[] = { self->o->length, 1 };
    161   PyObject *concat = PyList_New (0), *tmp = NULL;
    162   tmp = PyArray_SimpleNewFromData (1, dims, NPY_FLOAT, self->o->norm);
    163   PyList_Append (concat, tmp);
    164   Py_DECREF (tmp);
    165   tmp = PyArray_SimpleNewFromData (1, dims, NPY_FLOAT, self->o->phas);
    166   PyList_Append (concat, tmp);
    167   Py_DECREF (tmp);
    168   array = PyArray_FromObject (concat, NPY_FLOAT, 2, 2);
    169   Py_DECREF (concat);
    170   return array;
    17190}
    17291
     
    328247
    329248static PyMethodDef Py_cvec_methods[] = {
    330   {"__array__", (PyCFunction) PyAubio_CvecToArray, METH_NOARGS,
    331       "Returns the content of this cvec as a numpy array"},
    332249  {NULL}
    333250};
Note: See TracChangeset for help on using the changeset viewer.