Changeset ccf8b77
- Timestamp:
- Oct 2, 2009, 3:39:33 PM (15 years ago)
- 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
- Location:
- interfaces/python
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
interfaces/python/aubiomodule.c
r146280a rccf8b77 4 4 5 5 #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_fvec13 if (PyObject_TypeCheck (input, &Py_fvecType)) {14 // input is an fvec, nothing else to do15 vec = (Py_fvec *) input;16 } else if (PyArray_Check(input)) {17 18 // we got an array, convert it to an fvec19 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_CASTING32 } else if (PyArray_TYPE (input) != AUBIO_FLOAT) {33 // input data type is not float32, casting34 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 #else40 } else if (PyArray_TYPE (input) != AUBIO_FLOAT) {41 PyErr_SetString (PyExc_ValueError, "input array should be float32");42 goto fail;43 #endif44 } else {45 // input data type is float32, nothing else to do46 array = input;47 }48 49 // create a new fvec object50 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 member60 // 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 line65 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 81 6 82 7 static char Py_alpha_norm_doc[] = "compute alpha normalisation factor"; … … 153 78 Py_fvec *vec; 154 79 155 if (!PyArg_ParseTuple (args, "O: zero_crossing_rate", &input)) {80 if (!PyArg_ParseTuple (args, "O:min_removal", &input)) { 156 81 return NULL; 157 82 } … … 186 111 Py_zero_crossing_rate_doc}, 187 112 {"min_removal", Py_min_removal, METH_VARARGS, Py_min_removal_doc}, 188 {NULL, NULL} 113 {NULL, NULL} /* Sentinel */ 189 114 }; 190 115 -
interfaces/python/py-fvec.c
r146280a rccf8b77 104 104 fvec_print (self->o); 105 105 return Py_None; 106 } 107 108 Py_fvec * 109 PyAubio_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 177 fail: 178 return NULL; 106 179 } 107 180
Note: See TracChangeset
for help on using the changeset viewer.