Changeset 6b1aafc for interfaces
- Timestamp:
- Oct 2, 2009, 11:20:31 AM (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:
- 207ed19
- Parents:
- 352fd5f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
interfaces/python/aubiomodule.c
r352fd5f r6b1aafc 5 5 #include "aubio-types.h" 6 6 7 static char Py_alpha_norm_doc[] = "compute alpha normalisation factor"; 8 9 static PyObject * 10 Py_alpha_norm (PyObject * self, PyObject * args) 11 { 12 PyObject *input; 7 Py_fvec * 8 PyAubio_ArrayToFvec (PyObject *input) { 9 PyObject *array; 13 10 Py_fvec *vec; 14 smpl_t alpha;15 PyObject *result;16 PyObject *array;17 11 uint_t i; 18 19 if (!PyArg_ParseTuple (args, "Of:alpha_norm", &input, &alpha)) {20 return NULL;21 }22 23 if (input == NULL) {24 return NULL;25 }26 27 12 // parsing input object into a Py_fvec 28 13 if (PyObject_TypeCheck (input, &Py_fvecType)) { … … 36 21 goto fail; 37 22 } else if (PyArray_NDIM (input) > 2) { 38 PyErr_SetString (PyExc_ValueError, "input array has more than two dimensions"); 23 PyErr_SetString (PyExc_ValueError, 24 "input array has more than two dimensions"); 39 25 goto fail; 40 26 } … … 43 29 PyErr_SetString (PyExc_ValueError, "input array should be float"); 44 30 goto fail; 45 } else if (PyArray_TYPE (input) != NPY_FLOAT) { 31 #if AUBIO_DO_CASTING 32 } else if (PyArray_TYPE (input) != AUBIO_FLOAT) { 46 33 // input data type is not float32, casting 47 array = PyArray_Cast ( (PyArrayObject*) input, NPY_FLOAT);34 array = PyArray_Cast ( (PyArrayObject*) input, AUBIO_FLOAT); 48 35 if (array == NULL) { 49 36 PyErr_SetString (PyExc_IndexError, "failed converting to NPY_FLOAT"); 50 37 goto fail; 51 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 52 44 } else { 53 45 // input data type is float32, nothing else to do … … 65 57 } 66 58 67 // FIXME should not need to allocate fvec 68 vec->o = new_fvec (vec->length, vec->channels); 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 69 65 for (i = 0; i < vec->channels; i++) { 70 66 vec->o->data[i] = (smpl_t *) PyArray_GETPTR1 (array, i); … … 76 72 } 77 73 74 return vec; 75 76 fail: 77 return NULL; 78 } 79 80 81 82 static char Py_alpha_norm_doc[] = "compute alpha normalisation factor"; 83 84 static PyObject * 85 Py_alpha_norm (PyObject * self, PyObject * args) 86 { 87 PyObject *input; 88 Py_fvec *vec; 89 smpl_t alpha; 90 PyObject *result; 91 92 if (!PyArg_ParseTuple (args, "Of:alpha_norm", &input, &alpha)) { 93 return NULL; 94 } 95 96 if (input == NULL) { 97 return NULL; 98 } 99 100 vec = PyAubio_ArrayToFvec (input); 101 102 if (vec == NULL) { 103 return NULL; 104 } 105 78 106 // compute the function 79 result = Py_BuildValue ("f", vec_alpha_norm (vec->o, alpha));107 result = Py_BuildValue ("f", fvec_alpha_norm (vec->o, alpha)); 80 108 if (result == NULL) { 81 109 return NULL; … … 83 111 84 112 return result; 85 86 fail:87 return NULL;88 113 } 89 114
Note: See TracChangeset
for help on using the changeset viewer.