Showing the changes to python (6 of 6 files). Show all
Unified · Split
| @@ -33,10 +33,14 @@ · 32 unmodified lines | ||
| 33 | 33 | #define Py_aubio_default_samplerate 44100 |
| 34 | 34 | |
| 35 | 35 | #if HAVE_AUBIO_DOUBLE |
| 36 | −#error "Ouch! Python interface for aubio has not been much tested yet." | |
| 36 | +#warning "double mode needs love" | |
| 37 | 37 | #define AUBIO_NPY_SMPL NPY_DOUBLE |
| 38 | +#define AUBIO_NPY_SMPL_STR "float64" | |
| 39 | +#define AUBIO_NPY_SMPL_CHR "d" | |
| 38 | 40 | #else |
| 39 | 41 | #define AUBIO_NPY_SMPL NPY_FLOAT |
| 42 | +#define AUBIO_NPY_SMPL_STR "float32" | |
| 43 | +#define AUBIO_NPY_SMPL_CHR "f" | |
| 40 | 44 | #endif |
| 41 | 45 | |
| 42 | 46 | // compat with Python < 2.6 |
| @@ -87,7 +87,7 @@ Py_alpha_norm (PyObject * self, PyObject * args) · 86 unmodified lines | ||
| 87 | 87 | smpl_t alpha; |
| 88 | 88 | PyObject *result; |
| 89 | 89 | |
| 90 | − if (!PyArg_ParseTuple (args, "Of:alpha_norm", &input, &alpha)) { | |
| 90 | + if (!PyArg_ParseTuple (args, "O" AUBIO_NPY_SMPL_CHR ":alpha_norm", &input, &alpha)) { | |
| 91 | 91 | return NULL; |
| 92 | 92 | } |
| 93 | 93 | |
| @@ -100,7 +100,7 @@ Py_alpha_norm (PyObject * self, PyObject * args) · 6 unmodified lines | ||
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | // compute the function |
| 103 | − result = Py_BuildValue ("f", fvec_alpha_norm (&vec, alpha)); | |
| 103 | + result = Py_BuildValue (AUBIO_NPY_SMPL_CHR, fvec_alpha_norm (&vec, alpha)); | |
| 104 | 104 | if (result == NULL) { |
| 105 | 105 | return NULL; |
| 106 | 106 | } |
| @@ -114,7 +114,7 @@ Py_bintomidi (PyObject * self, PyObject * args) · 7 unmodified lines | ||
| 114 | 114 | smpl_t input, samplerate, fftsize; |
| 115 | 115 | smpl_t output; |
| 116 | 116 | |
| 117 | − if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) { | |
| 117 | + if (!PyArg_ParseTuple (args, "|" AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR , &input, &samplerate, &fftsize)) { | |
| 118 | 118 | return NULL; |
| 119 | 119 | } |
| 120 | 120 | |
| @@ -129,7 +129,7 @@ Py_miditobin (PyObject * self, PyObject * args) · 8 unmodified lines | ||
| 129 | 129 | smpl_t input, samplerate, fftsize; |
| 130 | 130 | smpl_t output; |
| 131 | 131 | |
| 132 | − if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) { | |
| 132 | + if (!PyArg_ParseTuple (args, "|" AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR , &input, &samplerate, &fftsize)) { | |
| 133 | 133 | return NULL; |
| 134 | 134 | } |
| 135 | 135 | |
| @@ -144,7 +144,7 @@ Py_bintofreq (PyObject * self, PyObject * args) · 8 unmodified lines | ||
| 144 | 144 | smpl_t input, samplerate, fftsize; |
| 145 | 145 | smpl_t output; |
| 146 | 146 | |
| 147 | − if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) { | |
| 147 | + if (!PyArg_ParseTuple (args, "|" AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR, &input, &samplerate, &fftsize)) { | |
| 148 | 148 | return NULL; |
| 149 | 149 | } |
| 150 | 150 | |
| @@ -159,7 +159,7 @@ Py_freqtobin (PyObject * self, PyObject * args) · 8 unmodified lines | ||
| 159 | 159 | smpl_t input, samplerate, fftsize; |
| 160 | 160 | smpl_t output; |
| 161 | 161 | |
| 162 | − if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) { | |
| 162 | + if (!PyArg_ParseTuple (args, "|" AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR, &input, &samplerate, &fftsize)) { | |
| 163 | 163 | return NULL; |
| 164 | 164 | } |
| 165 | 165 | |
| @@ -188,7 +188,7 @@ Py_zero_crossing_rate (PyObject * self, PyObject * args) · 22 unmodified lines | ||
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | // compute the function |
| 191 | − result = Py_BuildValue ("f", aubio_zero_crossing_rate (&vec)); | |
| 191 | + result = Py_BuildValue (AUBIO_NPY_SMPL_CHR, aubio_zero_crossing_rate (&vec)); | |
| 192 | 192 | if (result == NULL) { |
| 193 | 193 | return NULL; |
| 194 | 194 | } |
| @@ -308,6 +308,8 @@ initaubio (void) · 113 unmodified lines | ||
| 308 | 308 | Py_INCREF (&Py_sinkType); |
| 309 | 309 | PyModule_AddObject (m, "sink", (PyObject *) & Py_sinkType); |
| 310 | 310 | |
| 311 | + PyModule_AddStringConstant(m, "float_type", AUBIO_NPY_SMPL_STR); | |
| 312 | + | |
| 311 | 313 | // add generated objects |
| 312 | 314 | add_generated_objects(m); |
| 313 | 315 | |
| @@ -30,7 +30,7 @@ PyAubio_ArrayToCFvec (PyObject *input, fvec_t *out) { · 29 unmodified lines | ||
| 30 | 30 | PyErr_SetString (PyExc_ValueError, "input array should be float"); |
| 31 | 31 | return 0; |
| 32 | 32 | } else if (PyArray_TYPE ((PyArrayObject *)input) != AUBIO_NPY_SMPL) { |
| 33 | − PyErr_SetString (PyExc_ValueError, "input array should be float32"); | |
| 33 | + PyErr_SetString (PyExc_ValueError, "input array should be " AUBIO_NPY_SMPL_STR); | |
| 34 | 34 | return 0; |
| 35 | 35 | } |
| 36 | 36 | |
| @@ -73,7 +73,7 @@ PyAubio_ArrayToCCvec (PyObject *input, cvec_t *i) { · 36 unmodified lines | ||
| 73 | 73 | i->length = ((Py_cvec*)input)->o->length; |
| 74 | 74 | return 1; |
| 75 | 75 | } else { |
| 76 | − PyErr_SetString (PyExc_ValueError, "input array should be float32"); | |
| 76 | + PyErr_SetString (PyExc_ValueError, "input array should be aubio.cvec"); | |
| 77 | 77 | return 0; |
| 78 | 78 | } |
| 79 | 79 | } |
| @@ -119,7 +119,7 @@ PyAubio_ArrayToCFmat (PyObject *input, fmat_t *mat) { · 39 unmodified lines | ||
| 119 | 119 | PyErr_SetString (PyExc_ValueError, "input array should be float"); |
| 120 | 120 | return 0; |
| 121 | 121 | } else if (PyArray_TYPE ((PyArrayObject *)input) != AUBIO_NPY_SMPL) { |
| 122 | − PyErr_SetString (PyExc_ValueError, "input array should be float32"); | |
| 122 | + PyErr_SetString (PyExc_ValueError, "input array should be " AUBIO_NPY_SMPL_STR); | |
| 123 | 123 | return 0; |
| 124 | 124 | } |
| 125 | 125 | |
| @@ -93,7 +93,7 @@ PyObject * · 92 unmodified lines | ||
| 93 | 93 | PyAubio_CvecNormToArray (Py_cvec * self) |
| 94 | 94 | { |
| 95 | 95 | npy_intp dims[] = { self->o->length, 1 }; |
| 96 | − return PyArray_SimpleNewFromData (1, dims, NPY_FLOAT, self->o->norm); | |
| 96 | + return PyArray_SimpleNewFromData (1, dims, AUBIO_NPY_SMPL, self->o->norm); | |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
| @@ -101,7 +101,7 @@ PyObject * · 1 unmodified line | ||
| 101 | 101 | PyAubio_CvecPhasToArray (Py_cvec * self) |
| 102 | 102 | { |
| 103 | 103 | npy_intp dims[] = { self->o->length, 1 }; |
| 104 | − return PyArray_SimpleNewFromData (1, dims, NPY_FLOAT, self->o->phas); | |
| 104 | + return PyArray_SimpleNewFromData (1, dims, AUBIO_NPY_SMPL, self->o->phas); | |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | PyObject * |
| @@ -41,7 +41,7 @@ Py_aubio_level_lin(PyObject *self, PyObject *args) · 40 unmodified lines | ||
| 41 | 41 | return NULL; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | − level_lin = Py_BuildValue("f", aubio_level_lin(&vec)); | |
| 44 | + level_lin = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_lin(&vec)); | |
| 45 | 45 | if (level_lin == NULL) { |
| 46 | 46 | PyErr_SetString (PyExc_ValueError, "failed computing level_lin"); |
| 47 | 47 | return NULL; |
| @@ -70,7 +70,7 @@ Py_aubio_db_spl(PyObject *self, PyObject *args) · 22 unmodified lines | ||
| 70 | 70 | return NULL; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | − db_spl = Py_BuildValue("f", aubio_db_spl(&vec)); | |
| 73 | + db_spl = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_db_spl(&vec)); | |
| 74 | 74 | if (db_spl == NULL) { |
| 75 | 75 | PyErr_SetString (PyExc_ValueError, "failed computing db_spl"); |
| 76 | 76 | return NULL; |
| @@ -87,7 +87,7 @@ Py_aubio_silence_detection(PyObject *self, PyObject *args) · 10 unmodified lines | ||
| 87 | 87 | PyObject *silence_detection; |
| 88 | 88 | smpl_t threshold; |
| 89 | 89 | |
| 90 | − if (!PyArg_ParseTuple (args, "Of:silence_detection", &input, &threshold)) { | |
| 90 | + if (!PyArg_ParseTuple (args, "O" AUBIO_NPY_SMPL_CHR ":silence_detection", &input, &threshold)) { | |
| 91 | 91 | PyErr_SetString (PyExc_ValueError, "failed parsing arguments"); |
| 92 | 92 | return NULL; |
| 93 | 93 | } |
| @@ -117,7 +117,7 @@ Py_aubio_level_detection(PyObject *self, PyObject *args) · 23 unmodified lines | ||
| 117 | 117 | PyObject *level_detection; |
| 118 | 118 | smpl_t threshold; |
| 119 | 119 | |
| 120 | − if (!PyArg_ParseTuple (args, "Of:level_detection", &input, &threshold)) { | |
| 120 | + if (!PyArg_ParseTuple (args, "O" AUBIO_NPY_SMPL_CHR ":level_detection", &input, &threshold)) { | |
| 121 | 121 | PyErr_SetString (PyExc_ValueError, "failed parsing arguments"); |
| 122 | 122 | return NULL; |
| 123 | 123 | } |
| @@ -130,7 +130,7 @@ Py_aubio_level_detection(PyObject *self, PyObject *args) · 6 unmodified lines | ||
| 130 | 130 | return NULL; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | − level_detection = Py_BuildValue("f", aubio_level_detection(&vec, threshold)); | |
| 133 | + level_detection = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_detection(&vec, threshold)); | |
| 134 | 134 | if (level_detection == NULL) { |
| 135 | 135 | PyErr_SetString (PyExc_ValueError, "failed computing level_detection"); |
| 136 | 136 | return NULL; |
| @@ -25,7 +25,7 @@ member_types = { · 24 unmodified lines | ||
| 25 | 25 | 'name': 'type', |
| 26 | 26 | 'char_t*': 'T_STRING', |
| 27 | 27 | 'uint_t': 'T_INT', |
| 28 | − 'smpl_t': 'T_FLOAT', | |
| 28 | + 'smpl_t': 'AUBIO_NPY_SMPL', | |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | pyfromtype_fn = { |