Changeset 96fe713
- Timestamp:
- Dec 5, 2009, 1:44:11 AM (15 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:
- 0f045b2
- Parents:
- 7a7b00f
- Location:
- interfaces/python
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
interfaces/python/aubio-types.h
r7a7b00f r96fe713 6 6 #include <aubio.h> 7 7 8 #define Py_default_vector_length 9 #define Py_default_vector_ channels18 #define Py_default_vector_length 1024 9 #define Py_default_vector_height 1 10 10 11 11 #define Py_aubio_default_samplerate 44100 … … 25 25 26 26 */ 27 #define AUBIO_DO_CASTING 028 27 29 28 typedef struct … … 32 31 fvec_t * o; 33 32 uint_t length; 34 uint_t channels;35 33 } Py_fvec; 36 34 extern PyTypeObject Py_fvecType; … … 38 36 extern PyObject *PyAubio_CFvecToArray (fvec_t * self); 39 37 extern Py_fvec *PyAubio_ArrayToFvec (PyObject * self); 38 39 typedef struct 40 { 41 PyObject_HEAD 42 fmat_t * o; 43 uint_t length; 44 uint_t height; 45 } Py_fmat; 46 extern PyTypeObject Py_fmatType; 47 extern PyObject *PyAubio_FmatToArray (Py_fmat * self); 48 extern PyObject *PyAubio_CFmatToArray (fmat_t * self); 49 extern Py_fmat *PyAubio_ArrayToFmat (PyObject * self); 40 50 41 51 typedef struct -
interfaces/python/aubiomodule.c
r7a7b00f r96fe713 122 122 123 123 if ((PyType_Ready (&Py_fvecType) < 0) 124 || (PyType_Ready (&Py_fmatType) < 0) 124 125 || (PyType_Ready (&Py_cvecType) < 0) 125 126 || (PyType_Ready (&Py_filterType) < 0) … … 148 149 Py_INCREF (&Py_fvecType); 149 150 PyModule_AddObject (m, "fvec", (PyObject *) & Py_fvecType); 151 Py_INCREF (&Py_fmatType); 152 PyModule_AddObject (m, "fmat", (PyObject *) & Py_fmatType); 150 153 Py_INCREF (&Py_cvecType); 151 154 PyModule_AddObject (m, "cvec", (PyObject *) & Py_cvecType); -
interfaces/python/aubiowraphell.h
r7a7b00f r96fe713 94 94 95 95 // some more helpers 96 #define AUBIO_NEW_VEC(name, type, lengthval , channelsval) \96 #define AUBIO_NEW_VEC(name, type, lengthval) \ 97 97 name = (type *) PyObject_New (type, & type ## Type); \ 98 name->channels = channelsval; \99 98 name->length = lengthval; -
interfaces/python/gen_pyobject.py
r7a7b00f r96fe713 69 69 # move into the C library at some point. 70 70 defaultsizes = { 71 'resampler': ('input->length * self->ratio', 'input->channels'),72 'specdesc': ('1', 'fftgrain->channels'),73 'onset': ('1', 'self->channels'),74 'pitchyin': ('1', 'in->channels'),75 'pitchyinfft': ('1', 'in->channels'),76 'pitchschmitt': ('1', 'in->channels'),77 'pitchmcomb': ('1', 'self->channels'),78 'pitchfcomb': ('1', 'self->channels'),79 'pitch': ('1', 'self->channels'),80 'tss': ('self->hop_size', 'self->channels'),81 'mfcc': ('self->n_coeffs', 'in->channels'),82 'beattracking': ('self->hop_size', 'self->channels'),83 'tempo': ('1', 'self->channels'),84 'peakpicker': ('1', 'self->channels'),71 'resampler': 'input->length * self->ratio', 72 'specdesc': '1', 73 'onset': '1', 74 'pitchyin': '1', 75 'pitchyinfft': '1', 76 'pitchschmitt': '1', 77 'pitchmcomb': '1', 78 'pitchfcomb': '1', 79 'pitch': '1', 80 'tss': 'self->hop_size', 81 'mfcc': 'self->n_coeffs', 82 'beattracking': 'self->hop_size', 83 'tempo': '1', 84 'peakpicker': '1', 85 85 } 86 86 … … 99 99 'hop_size': 'Py_default_vector_length / 2', 100 100 # these should be alright 101 'channels': 'Py_default_vector_channels',102 101 'samplerate': 'Py_aubio_default_samplerate', 103 102 # now for the non obvious ones … … 151 150 newparams = get_params_types_names(newfunc) 152 151 # self->param1, self->param2, self->param3 153 selfparams = ', self->'.join([p[1] for p in newparams]) 152 if len(newparams): 153 selfparams = ', self->'+', self->'.join([p[1] for p in newparams]) 154 else: 155 selfparams = '' 154 156 # "param1", "param2", "param3" 155 157 paramnames = ", ".join(["\""+p[1]+"\"" for p in newparams]) … … 179 181 Py_%(name)s_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds) 180 182 { 183 Py_%(name)s *self; 181 184 """ % locals() 182 185 for ptype, pname in newparams: … … 186 189 """ % locals() 187 190 # now the actual PyArg_Parse 188 s += """\189 Py_%(name)s *self;191 if len(paramnames): 192 s += """\ 190 193 static char *kwlist[] = { %(paramnames)s, NULL }; 191 194 … … 194 197 return NULL; 195 198 } 199 """ % locals() 200 s += """\ 196 201 197 202 self = (Py_%(name)s *) pytype->tp_alloc (pytype, 0); … … 238 243 } 239 244 240 AUBIO_INIT(%(name)s , self->%(selfparams)s)245 AUBIO_INIT(%(name)s %(selfparams)s) 241 246 242 247 AUBIO_DEL(%(name)s) … … 287 292 outputvecs = "\n ".join([aubio2pyaubio[p[0]]+" * " + p[-1] + ";" for p in outputparams]) 288 293 outputcreate = "\n ".join(["""\ 289 AUBIO_NEW_VEC(%(name)s, %(pytype)s, %(length)s , %(channels)s)290 %(name)s->o = new_%(autype)s (%(length)s , %(channels)s);""" % \294 AUBIO_NEW_VEC(%(name)s, %(pytype)s, %(length)s) 295 %(name)s->o = new_%(autype)s (%(length)s);""" % \ 291 296 {'name': p[-1], 'pytype': aubio2pyaubio[p[0]], 'autype': p[0][:-3], 292 'length': defaultsizes[name] [0], 'channels': defaultsizes[name][1]} \297 'length': defaultsizes[name]} \ 293 298 for p in outputparams]) 294 299 if len(outputparams) > 1: -
interfaces/python/py-fft.c
r7a7b00f r96fe713 3 3 static char Py_fft_doc[] = "fft object"; 4 4 5 AUBIO_DECLARE(fft, uint_t win_s ; uint_t channels)5 AUBIO_DECLARE(fft, uint_t win_s) 6 6 7 7 //AUBIO_NEW(fft) … … 9 9 Py_fft_new (PyTypeObject * type, PyObject * args, PyObject * kwds) 10 10 { 11 int win_s = 0 , channels = 0;11 int win_s = 0; 12 12 Py_fft *self; 13 static char *kwlist[] = { "win_s", "channels",NULL };13 static char *kwlist[] = { "win_s", NULL }; 14 14 15 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|I I", kwlist,16 &win_s , &channels)) {15 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|I", kwlist, 16 &win_s)) { 17 17 return NULL; 18 18 } … … 25 25 26 26 self->win_s = Py_default_vector_length; 27 self->channels = Py_default_vector_channels;28 27 29 28 if (self == NULL) { … … 39 38 } 40 39 41 if (channels > 0) {42 self->channels = channels;43 } else if (channels < 0) {44 PyErr_SetString (PyExc_ValueError,45 "can not use negative number of filters");46 return NULL;47 }48 49 40 return (PyObject *) self; 50 41 } 51 42 52 43 53 AUBIO_INIT(fft, self->win_s , self->channels)44 AUBIO_INIT(fft, self->win_s) 54 45 55 46 AUBIO_DEL(fft) … … 73 64 74 65 output = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType); 75 output->channels = vec->channels;76 66 output->length = ((Py_fft *) self)->win_s; 77 output->o = new_cvec(((Py_fft *) self)->win_s , vec->channels);67 output->o = new_cvec(((Py_fft *) self)->win_s); 78 68 79 69 // compute the function … … 87 77 {"win_s", T_INT, offsetof (Py_fft, win_s), READONLY, 88 78 "size of the window"}, 89 {"channels", T_INT, offsetof (Py_fft, channels), READONLY,90 "number of channels"},91 79 AUBIO_MEMBERS_STOP(fft) 92 80 … … 109 97 110 98 output = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType); 111 output->channels = vec->channels;112 99 output->length = ((Py_fft *) self)->win_s; 113 output->o = new_fvec(output->length , output->channels);100 output->o = new_fvec(output->length); 114 101 115 102 // compute the function -
interfaces/python/py-filter.c
r7a7b00f r96fe713 6 6 aubio_filter_t * o; 7 7 uint_t order; 8 uint_t channels;9 8 } Py_filter; 10 9 … … 14 13 Py_filter_new (PyTypeObject * type, PyObject * args, PyObject * kwds) 15 14 { 16 int order= 0 , channels = 0;15 int order= 0; 17 16 Py_filter *self; 18 static char *kwlist[] = { "order", "channels",NULL };17 static char *kwlist[] = { "order", NULL }; 19 18 20 19 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist, 21 &order , &channels)) {20 &order)) { 22 21 return NULL; 23 22 } … … 30 29 31 30 self->order = 7; 32 self->channels = Py_default_vector_channels;33 31 34 32 if (order > 0) { … … 40 38 } 41 39 42 if (channels > 0) {43 self->channels = channels;44 } else if (channels < 0) {45 PyErr_SetString (PyExc_ValueError,46 "can not use negative number of channels");47 return NULL;48 }49 50 40 return (PyObject *) self; 51 41 } … … 54 44 Py_filter_init (Py_filter * self, PyObject * args, PyObject * kwds) 55 45 { 56 self->o = new_aubio_filter (self->order , self->channels);46 self->o = new_aubio_filter (self->order); 57 47 if (self->o == NULL) { 58 48 return -1; … … 92 82 #if 1 93 83 aubio_filter_do (((Py_filter *)self)->o, vec->o); 94 Py _INCREF(vec);84 PyArray_INCREF((PyArrayObject*)vec); 95 85 return (PyObject *)vec; 96 86 #else 97 87 Py_fvec *copy = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType); 98 copy->o = new_fvec(vec->o->length , vec->o->channels);88 copy->o = new_fvec(vec->o->length); 99 89 aubio_filter_do_outplace (((Py_filter *)self)->o, vec->o, copy->o); 100 90 return (PyObject *)copy; … … 142 132 {"order", T_INT, offsetof (Py_filter, order), READONLY, 143 133 "order of the filter"}, 144 {"channels", T_INT, offsetof (Py_filter, channels), READONLY,145 "number of channels"},146 134 {NULL} /* Sentinel */ 147 135 }; -
interfaces/python/py-filterbank.c
r7a7b00f r96fe713 68 68 69 69 output = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType); 70 output->channels = vec->channels;71 70 output->length = self->n_filters; 72 output->o = new_fvec(self->n_filters , vec->channels);71 output->o = new_fvec(self->n_filters); 73 72 74 73 // compute the function … … 138 137 Py_filterbank_get_coeffs (Py_filterbank * self, PyObject *unused) 139 138 { 140 Py_fvec *output = (Py_fvec *) PyObject_New (Py_fvec, &Py_fvecType); 141 output->channels = self->n_filters; 142 output->length = self->win_s / 2 + 1; 139 Py_fmat *output = (Py_fmat *) PyObject_New (Py_fmat, &Py_fvecType); 143 140 output->o = aubio_filterbank_get_coeffs (self->o); 144 return (PyObject *)PyAubio_F vecToArray(output);141 return (PyObject *)PyAubio_FmatToArray(output); 145 142 } 146 143
Note: See TracChangeset
for help on using the changeset viewer.