Changeset 4a67c12
- Timestamp:
- Mar 6, 2013, 5:26:49 PM (12 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- b583c099
- Parents:
- 7606d23
- Location:
- python/ext
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/ext/aubiomodule.c
r7606d23 r4a67c12 39 39 } 40 40 41 static char Py_unwrap2pi_doc[] = "unwrap phase value to [-pi, pi]";42 43 static PyObject *44 Py_unwrap2pi (PyObject * self, PyObject * args)45 {46 smpl_t input;47 smpl_t output;48 49 if (!PyArg_ParseTuple (args, "|f", &input)) {50 return NULL;51 }52 53 output = aubio_unwrap2pi (input);54 55 return (PyObject *)PyFloat_FromDouble (output);56 }57 58 41 static char Py_bintomidi_doc[] = "convert bin to midi"; 59 42 … … 120 103 121 104 output = aubio_freqtobin (input, samplerate, fftsize); 122 123 return (PyObject *)PyFloat_FromDouble (output);124 }125 126 static char Py_freqtomidi_doc[] = "convert freq to midi";127 128 static PyObject *129 Py_freqtomidi (PyObject * self, PyObject * args)130 {131 smpl_t input;132 smpl_t output;133 134 if (!PyArg_ParseTuple (args, "|f", &input)) {135 return NULL;136 }137 138 output = aubio_freqtomidi (input);139 140 return (PyObject *)PyFloat_FromDouble (output);141 }142 143 static char Py_miditofreq_doc[] = "convert midi to freq";144 145 static PyObject *146 Py_miditofreq (PyObject * self, PyObject * args)147 {148 smpl_t input;149 smpl_t output;150 151 if (!PyArg_ParseTuple (args, "|f", &input)) {152 return NULL;153 }154 155 output = aubio_miditofreq (input);156 105 157 106 return (PyObject *)PyFloat_FromDouble (output); … … 225 174 226 175 static PyMethodDef aubio_methods[] = { 227 //{"unwrap2pi", Py_unwrap2pi, METH_VARARGS, Py_unwrap2pi_doc},228 176 {"bintomidi", Py_bintomidi, METH_VARARGS, Py_bintomidi_doc}, 229 177 {"miditobin", Py_miditobin, METH_VARARGS, Py_miditobin_doc}, 230 178 {"bintofreq", Py_bintofreq, METH_VARARGS, Py_bintofreq_doc}, 231 179 {"freqtobin", Py_freqtobin, METH_VARARGS, Py_freqtobin_doc}, 232 {"miditofreq", Py_miditofreq, METH_VARARGS, Py_miditofreq_doc},233 {"freqtomidi", Py_freqtomidi, METH_VARARGS, Py_freqtomidi_doc},234 180 {"alpha_norm", Py_alpha_norm, METH_VARARGS, Py_alpha_norm_doc}, 235 181 {"zero_crossing_rate", Py_zero_crossing_rate, METH_VARARGS, Py_zero_crossing_rate_doc}, -
python/ext/ufuncs.c
r7606d23 r4a67c12 2 2 #include "aubio-types.h" 3 3 4 static void unwrap2pi(char **args, npy_intp *dimensions, 4 typedef smpl_t (*aubio_unary_func_t)(smpl_t input); 5 6 static void aubio_PyUFunc_d_d(char **args, npy_intp *dimensions, 5 7 npy_intp* steps, void* data) 6 8 { … … 9 11 char *in = args[0], *out = args[1]; 10 12 npy_intp in_step = steps[0], out_step = steps[1]; 13 aubio_unary_func_t func = (aubio_unary_func_t)(data); 11 14 12 15 for (i = 0; i < n; i++) { 13 16 /*BEGIN main ufunc computation*/ 14 *((double *)out) = aubio_unwrap2pi(*(double *)in);17 *((double *)out) = func(*(double *)in); 15 18 /*END main ufunc computation*/ 16 19 … … 20 23 } 21 24 22 static void unwrap2pif(char **args, npy_intp *dimensions,25 static void aubio_PyUFunc_f_f_As_d_d(char **args, npy_intp *dimensions, 23 26 npy_intp* steps, void* data) 24 27 { … … 27 30 char *in = args[0], *out = args[1]; 28 31 npy_intp in_step = steps[0], out_step = steps[1]; 32 aubio_unary_func_t func = (aubio_unary_func_t)(data); 29 33 30 34 for (i = 0; i < n; i++) { 31 35 /*BEGIN main ufunc computation*/ 32 *((float *)out) = aubio_unwrap2pi(*(float *)in);36 *((float *)out) = func(*(float *)in); 33 37 /*END main ufunc computation*/ 34 38 … … 38 42 } 39 43 40 static char Py_unwrap2pi_doc[] = "map angle to unit circle [-pi, pi["; 41 42 PyUFuncGenericFunction unwrap2pi_functions[] = { 43 &unwrap2pif, &unwrap2pi, 44 static int Py_aubio_unary_n_types = 2; 45 static int Py_aubio_unary_n_inputs = 1; 46 static int Py_aubio_unary_n_outputs = 1; 47 PyUFuncGenericFunction Py_aubio_unary_functions[] = { 48 &aubio_PyUFunc_f_f_As_d_d, 49 &aubio_PyUFunc_d_d, 44 50 //PyUFunc_f_f_As_d_d, PyUFunc_d_d, 45 51 //PyUFunc_g_g, PyUFunc_OO_O_method, 46 52 }; 47 53 48 static void* unwrap2pi_data[] = { 54 static char Py_aubio_unary_types[] = { 55 NPY_FLOAT, NPY_FLOAT, 56 NPY_DOUBLE, NPY_DOUBLE, 57 //NPY_LONGDOUBLE, NPY_LONGDOUBLE, 58 //NPY_OBJECT, NPY_OBJECT, 59 }; 60 61 static char Py_unwrap2pi_doc[] = "map angle to unit circle [-pi, pi["; 62 63 static void* Py_unwrap2pi_data[] = { 49 64 (void *)aubio_unwrap2pi, 50 65 (void *)aubio_unwrap2pi, … … 53 68 }; 54 69 55 static char unwrap2pi_types[] = { 56 NPY_FLOAT, NPY_FLOAT, 57 NPY_DOUBLE, NPY_DOUBLE, 58 //NPY_LONGDOUBLE, NPY_LONGDOUBLE, 59 //NPY_OBJECT, NPY_OBJECT, 70 static char Py_freqtomidi_doc[] = "convert frequency to midi"; 71 72 static void* Py_freqtomidi_data[] = { 73 (void *)aubio_freqtomidi, 74 (void *)aubio_freqtomidi, 75 }; 76 77 static char Py_miditofreq_doc[] = "convert midi to frequency"; 78 79 static void* Py_miditofreq_data[] = { 80 (void *)aubio_miditofreq, 81 (void *)aubio_miditofreq, 60 82 }; 61 83 … … 72 94 PyObject *f, *dict; 73 95 dict = PyModule_GetDict(m); 74 f = PyUFunc_FromFuncAndData( unwrap2pi_functions,75 unwrap2pi_data, unwrap2pi_types, 2, 1, 1,96 f = PyUFunc_FromFuncAndData(Py_aubio_unary_functions, Py_unwrap2pi_data, Py_aubio_unary_types, 97 Py_aubio_unary_n_types, Py_aubio_unary_n_inputs, Py_aubio_unary_n_outputs, 76 98 PyUFunc_None, "unwrap2pi", Py_unwrap2pi_doc, 0); 77 99 PyDict_SetItemString(dict, "unwrap2pi", f); 78 100 Py_DECREF(f); 79 101 102 PyObject *g; 103 g = PyUFunc_FromFuncAndData(Py_aubio_unary_functions, Py_freqtomidi_data, Py_aubio_unary_types, 104 Py_aubio_unary_n_types, Py_aubio_unary_n_inputs, Py_aubio_unary_n_outputs, 105 PyUFunc_None, "freqtomidi", Py_freqtomidi_doc, 0); 106 PyDict_SetItemString(dict, "freqtomidi", g); 107 Py_DECREF(g); 108 109 PyObject *h; 110 h = PyUFunc_FromFuncAndData(Py_aubio_unary_functions, Py_miditofreq_data, Py_aubio_unary_types, 111 Py_aubio_unary_n_types, Py_aubio_unary_n_inputs, Py_aubio_unary_n_outputs, 112 PyUFunc_None, "miditofreq", Py_miditofreq_doc, 0); 113 PyDict_SetItemString(dict, "miditofreq", h); 114 Py_DECREF(h); 80 115 return; 81 116 }
Note: See TracChangeset
for help on using the changeset viewer.