python/{ext,lib}: prepare for double precision
authorPaul Brossier <piem@piem.org>
Sun, 24 Apr 2016 21:45:45 +0000 (23:45 +0200)
committerPaul Brossier <piem@piem.org>
Sun, 24 Apr 2016 21:45:45 +0000 (23:45 +0200)
python/ext/aubio-types.h
python/ext/aubiomodule.c
python/ext/aubioproxy.c
python/ext/py-cvec.c
python/ext/py-musicutils.c
python/lib/gen_code.py

index b77abc6..b856ba4 100644 (file)
 #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
index 4c72497..2ab15fa 100644 (file)
@@ -87,7 +87,7 @@ Py_alpha_norm (PyObject * self, PyObject * args)
   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 @@ Py_alpha_norm (PyObject * self, PyObject * args)
   }
 
   // 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 @@ Py_bintomidi (PyObject * self, PyObject * args)
   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 @@ Py_miditobin (PyObject * self, PyObject * args)
   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 @@ Py_bintofreq (PyObject * self, PyObject * args)
   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 @@ Py_freqtobin (PyObject * self, PyObject * args)
   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 @@ Py_zero_crossing_rate (PyObject * self, PyObject * args)
   }
 
   // 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;
   }
@@ -308,6 +308,8 @@ initaubio (void)
   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);
 
index c6755b5..6ee61e9 100644 (file)
@@ -30,7 +30,7 @@ PyAubio_ArrayToCFvec (PyObject *input, fvec_t *out) {
       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 @@ PyAubio_ArrayToCCvec (PyObject *input, cvec_t *i) {
       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 @@ PyAubio_ArrayToCFmat (PyObject *input, fmat_t *mat) {
       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;
     }
 
index 6c70f05..dc7e71c 100644 (file)
@@ -93,7 +93,7 @@ PyObject *
 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 @@ PyObject *
 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 *
index ec26676..0f29697 100644 (file)
@@ -41,7 +41,7 @@ Py_aubio_level_lin(PyObject *self, PyObject *args)
     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 @@ Py_aubio_db_spl(PyObject *self, PyObject *args)
     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 @@ Py_aubio_silence_detection(PyObject *self, PyObject *args)
   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 @@ Py_aubio_level_detection(PyObject *self, PyObject *args)
   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 @@ Py_aubio_level_detection(PyObject *self, PyObject *args)
     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;
index d2f5459..7c8bc06 100644 (file)
@@ -25,7 +25,7 @@ member_types = {
         'name': 'type',
         'char_t*': 'T_STRING',
         'uint_t': 'T_INT',
-        'smpl_t': 'T_FLOAT',
+        'smpl_t': 'AUBIO_NPY_SMPL',
         }
 
 pyfromtype_fn = {