ref: c6388f4affa69eb201fa5de663dd8d27fef12b74
parent: 81984a7ad7ed58837b0ca07cdd6098b1838ca2b8
author: Paul Brossier <piem@piem.org>
date: Sun Apr 24 19:45:45 EDT 2016
python/{ext,lib}: prepare for double precision
--- a/python/ext/aubio-types.h
+++ b/python/ext/aubio-types.h
@@ -33,10 +33,14 @@
#define Py_aubio_default_samplerate 44100
#if HAVE_AUBIO_DOUBLE
-#error "Ouch! Python interface for aubio has not been much tested yet."
+#warning "double mode needs love"
#define AUBIO_NPY_SMPL NPY_DOUBLE
+#define AUBIO_NPY_SMPL_STR "float64"
+#define AUBIO_NPY_SMPL_CHR "d"
#else
#define AUBIO_NPY_SMPL NPY_FLOAT
+#define AUBIO_NPY_SMPL_STR "float32"
+#define AUBIO_NPY_SMPL_CHR "f"
#endif
// compat with Python < 2.6
--- a/python/ext/aubiomodule.c
+++ b/python/ext/aubiomodule.c
@@ -87,7 +87,7 @@
smpl_t alpha;
PyObject *result;
- if (!PyArg_ParseTuple (args, "Of:alpha_norm", &input, &alpha)) {
+ if (!PyArg_ParseTuple (args, "O" AUBIO_NPY_SMPL_CHR ":alpha_norm", &input, &alpha)) {
return NULL;
}
@@ -100,7 +100,7 @@
}
// compute the function
- result = Py_BuildValue ("f", fvec_alpha_norm (&vec, alpha));
+ result = Py_BuildValue (AUBIO_NPY_SMPL_CHR, fvec_alpha_norm (&vec, alpha));
if (result == NULL) {
return NULL;
}
@@ -114,7 +114,7 @@
smpl_t input, samplerate, fftsize;
smpl_t output;
- if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) {
+ if (!PyArg_ParseTuple (args, "|" AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR , &input, &samplerate, &fftsize)) {
return NULL;
}
@@ -129,7 +129,7 @@
smpl_t input, samplerate, fftsize;
smpl_t output;
- if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) {
+ if (!PyArg_ParseTuple (args, "|" AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR , &input, &samplerate, &fftsize)) {
return NULL;
}
@@ -144,7 +144,7 @@
smpl_t input, samplerate, fftsize;
smpl_t output;
- if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) {
+ if (!PyArg_ParseTuple (args, "|" AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR, &input, &samplerate, &fftsize)) {
return NULL;
}
@@ -159,7 +159,7 @@
smpl_t input, samplerate, fftsize;
smpl_t output;
- if (!PyArg_ParseTuple (args, "|fff", &input, &samplerate, &fftsize)) {
+ if (!PyArg_ParseTuple (args, "|" AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR AUBIO_NPY_SMPL_CHR, &input, &samplerate, &fftsize)) {
return NULL;
}
@@ -188,7 +188,7 @@
}
// compute the function
- result = Py_BuildValue ("f", aubio_zero_crossing_rate (&vec));
+ result = Py_BuildValue (AUBIO_NPY_SMPL_CHR, aubio_zero_crossing_rate (&vec));
if (result == NULL) {
return NULL;
}
@@ -307,6 +307,8 @@
PyModule_AddObject (m, "source", (PyObject *) & Py_sourceType);
Py_INCREF (&Py_sinkType);
PyModule_AddObject (m, "sink", (PyObject *) & Py_sinkType);
+
+ PyModule_AddStringConstant(m, "float_type", AUBIO_NPY_SMPL_STR);
// add generated objects
add_generated_objects(m);
--- a/python/ext/aubioproxy.c
+++ b/python/ext/aubioproxy.c
@@ -30,7 +30,7 @@
PyErr_SetString (PyExc_ValueError, "input array should be float");
return 0;
} else if (PyArray_TYPE ((PyArrayObject *)input) != AUBIO_NPY_SMPL) {
- PyErr_SetString (PyExc_ValueError, "input array should be float32");
+ PyErr_SetString (PyExc_ValueError, "input array should be " AUBIO_NPY_SMPL_STR);
return 0;
}
@@ -73,7 +73,7 @@
i->length = ((Py_cvec*)input)->o->length;
return 1;
} else {
- PyErr_SetString (PyExc_ValueError, "input array should be float32");
+ PyErr_SetString (PyExc_ValueError, "input array should be aubio.cvec");
return 0;
}
}
@@ -119,7 +119,7 @@
PyErr_SetString (PyExc_ValueError, "input array should be float");
return 0;
} else if (PyArray_TYPE ((PyArrayObject *)input) != AUBIO_NPY_SMPL) {
- PyErr_SetString (PyExc_ValueError, "input array should be float32");
+ PyErr_SetString (PyExc_ValueError, "input array should be " AUBIO_NPY_SMPL_STR);
return 0;
}
--- a/python/ext/py-cvec.c
+++ b/python/ext/py-cvec.c
@@ -93,7 +93,7 @@
PyAubio_CvecNormToArray (Py_cvec * self)
{
npy_intp dims[] = { self->o->length, 1 };
- return PyArray_SimpleNewFromData (1, dims, NPY_FLOAT, self->o->norm);
+ return PyArray_SimpleNewFromData (1, dims, AUBIO_NPY_SMPL, self->o->norm);
}
@@ -101,7 +101,7 @@
PyAubio_CvecPhasToArray (Py_cvec * self)
{
npy_intp dims[] = { self->o->length, 1 };
- return PyArray_SimpleNewFromData (1, dims, NPY_FLOAT, self->o->phas);
+ return PyArray_SimpleNewFromData (1, dims, AUBIO_NPY_SMPL, self->o->phas);
}
PyObject *
--- a/python/ext/py-musicutils.c
+++ b/python/ext/py-musicutils.c
@@ -41,7 +41,7 @@
return NULL;
}
- level_lin = Py_BuildValue("f", aubio_level_lin(&vec));
+ level_lin = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_lin(&vec));
if (level_lin == NULL) {
PyErr_SetString (PyExc_ValueError, "failed computing level_lin");
return NULL;
@@ -70,7 +70,7 @@
return NULL;
}
- db_spl = Py_BuildValue("f", aubio_db_spl(&vec));
+ db_spl = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_db_spl(&vec));
if (db_spl == NULL) {
PyErr_SetString (PyExc_ValueError, "failed computing db_spl");
return NULL;
@@ -87,7 +87,7 @@
PyObject *silence_detection;
smpl_t threshold;
- if (!PyArg_ParseTuple (args, "Of:silence_detection", &input, &threshold)) {
+ if (!PyArg_ParseTuple (args, "O" AUBIO_NPY_SMPL_CHR ":silence_detection", &input, &threshold)) {
PyErr_SetString (PyExc_ValueError, "failed parsing arguments");
return NULL;
}
@@ -117,7 +117,7 @@
PyObject *level_detection;
smpl_t threshold;
- if (!PyArg_ParseTuple (args, "Of:level_detection", &input, &threshold)) {
+ if (!PyArg_ParseTuple (args, "O" AUBIO_NPY_SMPL_CHR ":level_detection", &input, &threshold)) {
PyErr_SetString (PyExc_ValueError, "failed parsing arguments");
return NULL;
}
@@ -130,7 +130,7 @@
return NULL;
}
- level_detection = Py_BuildValue("f", aubio_level_detection(&vec, threshold));
+ level_detection = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_detection(&vec, threshold));
if (level_detection == NULL) {
PyErr_SetString (PyExc_ValueError, "failed computing level_detection");
return NULL;
--- a/python/lib/gen_code.py
+++ b/python/lib/gen_code.py
@@ -25,7 +25,7 @@
'name': 'type',
'char_t*': 'T_STRING',
'uint_t': 'T_INT',
- 'smpl_t': 'T_FLOAT',
+ 'smpl_t': 'AUBIO_NPY_SMPL',
}
pyfromtype_fn = {