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 (6 of 6 files). Show all

Unified · Split

6 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
  6. python/lib/gen_code.py +1 −1
python/ext/aubio-types.h+5−1
@@ -33,10 +33,14 @@ · 32 unmodified lines
33#define Py_aubio_default_samplerate 4410033#define Py_aubio_default_samplerate 44100
34 34
35#if HAVE_AUBIO_DOUBLE35#if HAVE_AUBIO_DOUBLE
36#error "Ouch! Python interface for aubio has not been much tested yet."36#warning "double mode needs love"
37#define AUBIO_NPY_SMPL NPY_DOUBLE37#define AUBIO_NPY_SMPL NPY_DOUBLE
38#define AUBIO_NPY_SMPL_STR "float64"
39#define AUBIO_NPY_SMPL_CHR "d"
38#else40#else
39#define AUBIO_NPY_SMPL NPY_FLOAT41#define AUBIO_NPY_SMPL NPY_FLOAT
42#define AUBIO_NPY_SMPL_STR "float32"
43#define AUBIO_NPY_SMPL_CHR "f"
40#endif44#endif
41 45
42// compat with Python < 2.646// 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
87 smpl_t alpha;87 smpl_t alpha;
88 PyObject *result;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 return NULL;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 // compute the function102 // 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 if (result == NULL) {104 if (result == NULL) {
105 return NULL;105 return NULL;
106 }106 }
@@ -114,7 +114,7 @@ Py_bintomidi (PyObject * self, PyObject * args) · 7 unmodified lines
114 smpl_t input, samplerate, fftsize;114 smpl_t input, samplerate, fftsize;
115 smpl_t output;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 return NULL;118 return NULL;
119 }119 }
120 120
@@ -129,7 +129,7 @@ Py_miditobin (PyObject * self, PyObject * args) · 8 unmodified lines
129 smpl_t input, samplerate, fftsize;129 smpl_t input, samplerate, fftsize;
130 smpl_t output;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 return NULL;133 return NULL;
134 }134 }
135 135
@@ -144,7 +144,7 @@ Py_bintofreq (PyObject * self, PyObject * args) · 8 unmodified lines
144 smpl_t input, samplerate, fftsize;144 smpl_t input, samplerate, fftsize;
145 smpl_t output;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 return NULL;148 return NULL;
149 }149 }
150 150
@@ -159,7 +159,7 @@ Py_freqtobin (PyObject * self, PyObject * args) · 8 unmodified lines
159 smpl_t input, samplerate, fftsize;159 smpl_t input, samplerate, fftsize;
160 smpl_t output;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 return NULL;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 // compute the function190 // 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 if (result == NULL) {192 if (result == NULL) {
193 return NULL;193 return NULL;
194 }194 }
@@ -308,6 +308,8 @@ initaubio (void) · 113 unmodified lines
308 Py_INCREF (&Py_sinkType);308 Py_INCREF (&Py_sinkType);
309 PyModule_AddObject (m, "sink", (PyObject *) & Py_sinkType);309 PyModule_AddObject (m, "sink", (PyObject *) & Py_sinkType);
310 310
311 PyModule_AddStringConstant(m, "float_type", AUBIO_NPY_SMPL_STR);
312
311 // add generated objects313 // add generated objects
312 add_generated_objects(m);314 add_generated_objects(m);
313 315
python/ext/aubioproxy.c+3−3
@@ -30,7 +30,7 @@ PyAubio_ArrayToCFvec (PyObject *input, fvec_t *out) { · 29 unmodified lines
30 PyErr_SetString (PyExc_ValueError, "input array should be float");30 PyErr_SetString (PyExc_ValueError, "input array should be float");
31 return 0;31 return 0;
32 } else if (PyArray_TYPE ((PyArrayObject *)input) != AUBIO_NPY_SMPL) {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 return 0;34 return 0;
35 }35 }
36 36
@@ -73,7 +73,7 @@ PyAubio_ArrayToCCvec (PyObject *input, cvec_t *i) { · 36 unmodified lines
73 i->length = ((Py_cvec*)input)->o->length;73 i->length = ((Py_cvec*)input)->o->length;
74 return 1;74 return 1;
75 } else {75 } else {
76 PyErr_SetString (PyExc_ValueError, "input array should be float32");76 PyErr_SetString (PyExc_ValueError, "input array should be aubio.cvec");
77 return 0;77 return 0;
78 }78 }
79}79}
@@ -119,7 +119,7 @@ PyAubio_ArrayToCFmat (PyObject *input, fmat_t *mat) { · 39 unmodified lines
119 PyErr_SetString (PyExc_ValueError, "input array should be float");119 PyErr_SetString (PyExc_ValueError, "input array should be float");
120 return 0;120 return 0;
121 } else if (PyArray_TYPE ((PyArrayObject *)input) != AUBIO_NPY_SMPL) {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 return 0;123 return 0;
124 }124 }
125 125
python/ext/py-cvec.c+2−2
@@ -93,7 +93,7 @@ PyObject * · 92 unmodified lines
93PyAubio_CvecNormToArray (Py_cvec * self)93PyAubio_CvecNormToArray (Py_cvec * self)
94{94{
95 npy_intp dims[] = { self->o->length, 1 };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
101PyAubio_CvecPhasToArray (Py_cvec * self)101PyAubio_CvecPhasToArray (Py_cvec * self)
102{102{
103 npy_intp dims[] = { self->o->length, 1 };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
107PyObject *107PyObject *
python/ext/py-musicutils.c+5−5
@@ -41,7 +41,7 @@ Py_aubio_level_lin(PyObject *self, PyObject *args) · 40 unmodified lines
41 return NULL;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 if (level_lin == NULL) {45 if (level_lin == NULL) {
46 PyErr_SetString (PyExc_ValueError, "failed computing level_lin");46 PyErr_SetString (PyExc_ValueError, "failed computing level_lin");
47 return NULL;47 return NULL;
@@ -70,7 +70,7 @@ Py_aubio_db_spl(PyObject *self, PyObject *args) · 22 unmodified lines
70 return NULL;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 if (db_spl == NULL) {74 if (db_spl == NULL) {
75 PyErr_SetString (PyExc_ValueError, "failed computing db_spl");75 PyErr_SetString (PyExc_ValueError, "failed computing db_spl");
76 return NULL;76 return NULL;
@@ -87,7 +87,7 @@ Py_aubio_silence_detection(PyObject *self, PyObject *args) · 10 unmodified lines
87 PyObject *silence_detection;87 PyObject *silence_detection;
88 smpl_t threshold;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 PyErr_SetString (PyExc_ValueError, "failed parsing arguments");91 PyErr_SetString (PyExc_ValueError, "failed parsing arguments");
92 return NULL;92 return NULL;
93 }93 }
@@ -117,7 +117,7 @@ Py_aubio_level_detection(PyObject *self, PyObject *args) · 23 unmodified lines
117 PyObject *level_detection;117 PyObject *level_detection;
118 smpl_t threshold;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 PyErr_SetString (PyExc_ValueError, "failed parsing arguments");121 PyErr_SetString (PyExc_ValueError, "failed parsing arguments");
122 return NULL;122 return NULL;
123 }123 }
@@ -130,7 +130,7 @@ Py_aubio_level_detection(PyObject *self, PyObject *args) · 6 unmodified lines
130 return NULL;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 if (level_detection == NULL) {134 if (level_detection == NULL) {
135 PyErr_SetString (PyExc_ValueError, "failed computing level_detection");135 PyErr_SetString (PyExc_ValueError, "failed computing level_detection");
136 return NULL;136 return NULL;
python/lib/gen_code.py+1−1
@@ -25,7 +25,7 @@ member_types = { · 24 unmodified lines
25 'name': 'type',25 'name': 'type',
26 'char_t*': 'T_STRING',26 'char_t*': 'T_STRING',
27 'uint_t': 'T_INT',27 'uint_t': 'T_INT',
28 'smpl_t': 'T_FLOAT',28 'smpl_t': 'AUBIO_NPY_SMPL',
29 }29 }
30 30
31pyfromtype_fn = {31pyfromtype_fn = {

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