History

python/{ext,lib}: prepare for double precision

Paul Brossier committed 10 years ago

Commit c6388f41 parent 81984a76 files · +25 −19Browse files

Showing the changes to python/ext (5 of 6 files). Show all

Unified · Split

5 files
  1. python/ext/aubio-types.h +5 −1
  2. python/ext/aubiomodule.c +9 −7
  3. python/ext/aubioproxy.c +3 −3
  4. python/ext/py-cvec.c +2 −2
  5. python/ext/py-musicutils.c +5 −5
python/ext/aubio-types.h+5−1
@@ -33,10 +33,14 @@ · 32 unmodified lines
3333 #define Py_aubio_default_samplerate 44100
3434
3535 #if HAVE_AUBIO_DOUBLE
36−#error "Ouch! Python interface for aubio has not been much tested yet."
36+#warning "double mode needs love"
3737 #define AUBIO_NPY_SMPL NPY_DOUBLE
38+#define AUBIO_NPY_SMPL_STR "float64"
39+#define AUBIO_NPY_SMPL_CHR "d"
3840 #else
3941 #define AUBIO_NPY_SMPL NPY_FLOAT
42+#define AUBIO_NPY_SMPL_STR "float32"
43+#define AUBIO_NPY_SMPL_CHR "f"
4044 #endif
4145
4246 // compat with Python < 2.6
python/ext/aubiomodule.c+9−7
@@ -87,7 +87,7 @@ Py_alpha_norm (PyObject * self, PyObject * args) · 86 unmodified lines
8787 smpl_t alpha;
8888 PyObject *result;
8989
90− if (!PyArg_ParseTuple (args, "Of:alpha_norm", &input, &alpha)) {
90+ if (!PyArg_ParseTuple (args, "O" AUBIO_NPY_SMPL_CHR ":alpha_norm", &input, &alpha)) {
9191 return NULL;
9292 }
9393
@@ -100,7 +100,7 @@ Py_alpha_norm (PyObject * self, PyObject * args) · 6 unmodified lines
100100 }
101101
102102 // 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));
104104 if (result == NULL) {
105105 return NULL;
106106 }
@@ -114,7 +114,7 @@ Py_bintomidi (PyObject * self, PyObject * args) · 7 unmodified lines
114114 smpl_t input, samplerate, fftsize;
115115 smpl_t output;
116116
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)) {
118118 return NULL;
119119 }
120120
@@ -129,7 +129,7 @@ Py_miditobin (PyObject * self, PyObject * args) · 8 unmodified lines
129129 smpl_t input, samplerate, fftsize;
130130 smpl_t output;
131131
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)) {
133133 return NULL;
134134 }
135135
@@ -144,7 +144,7 @@ Py_bintofreq (PyObject * self, PyObject * args) · 8 unmodified lines
144144 smpl_t input, samplerate, fftsize;
145145 smpl_t output;
146146
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)) {
148148 return NULL;
149149 }
150150
@@ -159,7 +159,7 @@ Py_freqtobin (PyObject * self, PyObject * args) · 8 unmodified lines
159159 smpl_t input, samplerate, fftsize;
160160 smpl_t output;
161161
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)) {
163163 return NULL;
164164 }
165165
@@ -188,7 +188,7 @@ Py_zero_crossing_rate (PyObject * self, PyObject * args) · 22 unmodified lines
188188 }
189189
190190 // 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));
192192 if (result == NULL) {
193193 return NULL;
194194 }
@@ -308,6 +308,8 @@ initaubio (void) · 113 unmodified lines
308308 Py_INCREF (&Py_sinkType);
309309 PyModule_AddObject (m, "sink", (PyObject *) & Py_sinkType);
310310
311+ PyModule_AddStringConstant(m, "float_type", AUBIO_NPY_SMPL_STR);
312+
311313 // add generated objects
312314 add_generated_objects(m);
313315
python/ext/aubioproxy.c+3−3
@@ -30,7 +30,7 @@ PyAubio_ArrayToCFvec (PyObject *input, fvec_t *out) { · 29 unmodified lines
3030 PyErr_SetString (PyExc_ValueError, "input array should be float");
3131 return 0;
3232 } 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);
3434 return 0;
3535 }
3636
@@ -73,7 +73,7 @@ PyAubio_ArrayToCCvec (PyObject *input, cvec_t *i) { · 36 unmodified lines
7373 i->length = ((Py_cvec*)input)->o->length;
7474 return 1;
7575 } else {
76− PyErr_SetString (PyExc_ValueError, "input array should be float32");
76+ PyErr_SetString (PyExc_ValueError, "input array should be aubio.cvec");
7777 return 0;
7878 }
7979 }
@@ -119,7 +119,7 @@ PyAubio_ArrayToCFmat (PyObject *input, fmat_t *mat) { · 39 unmodified lines
119119 PyErr_SetString (PyExc_ValueError, "input array should be float");
120120 return 0;
121121 } 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);
123123 return 0;
124124 }
125125
python/ext/py-cvec.c+2−2
@@ -93,7 +93,7 @@ PyObject * · 92 unmodified lines
9393 PyAubio_CvecNormToArray (Py_cvec * self)
9494 {
9595 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);
9797 }
9898
9999
@@ -101,7 +101,7 @@ PyObject * · 1 unmodified line
101101 PyAubio_CvecPhasToArray (Py_cvec * self)
102102 {
103103 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);
105105 }
106106
107107 PyObject *
python/ext/py-musicutils.c+5−5
@@ -41,7 +41,7 @@ Py_aubio_level_lin(PyObject *self, PyObject *args) · 40 unmodified lines
4141 return NULL;
4242 }
4343
44− level_lin = Py_BuildValue("f", aubio_level_lin(&vec));
44+ level_lin = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_lin(&vec));
4545 if (level_lin == NULL) {
4646 PyErr_SetString (PyExc_ValueError, "failed computing level_lin");
4747 return NULL;
@@ -70,7 +70,7 @@ Py_aubio_db_spl(PyObject *self, PyObject *args) · 22 unmodified lines
7070 return NULL;
7171 }
7272
73− db_spl = Py_BuildValue("f", aubio_db_spl(&vec));
73+ db_spl = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_db_spl(&vec));
7474 if (db_spl == NULL) {
7575 PyErr_SetString (PyExc_ValueError, "failed computing db_spl");
7676 return NULL;
@@ -87,7 +87,7 @@ Py_aubio_silence_detection(PyObject *self, PyObject *args) · 10 unmodified lines
8787 PyObject *silence_detection;
8888 smpl_t threshold;
8989
90− if (!PyArg_ParseTuple (args, "Of:silence_detection", &input, &threshold)) {
90+ if (!PyArg_ParseTuple (args, "O" AUBIO_NPY_SMPL_CHR ":silence_detection", &input, &threshold)) {
9191 PyErr_SetString (PyExc_ValueError, "failed parsing arguments");
9292 return NULL;
9393 }
@@ -117,7 +117,7 @@ Py_aubio_level_detection(PyObject *self, PyObject *args) · 23 unmodified lines
117117 PyObject *level_detection;
118118 smpl_t threshold;
119119
120− if (!PyArg_ParseTuple (args, "Of:level_detection", &input, &threshold)) {
120+ if (!PyArg_ParseTuple (args, "O" AUBIO_NPY_SMPL_CHR ":level_detection", &input, &threshold)) {
121121 PyErr_SetString (PyExc_ValueError, "failed parsing arguments");
122122 return NULL;
123123 }
@@ -130,7 +130,7 @@ Py_aubio_level_detection(PyObject *self, PyObject *args) · 6 unmodified lines
130130 return NULL;
131131 }
132132
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));
134134 if (level_detection == NULL) {
135135 PyErr_SetString (PyExc_ValueError, "failed computing level_detection");
136136 return NULL;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t