Changeset 92a8800
- Timestamp:
- Apr 28, 2016, 6:59:55 PM (9 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:
- 6937842
- Parents:
- 1f4d932
- Location:
- python
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
python/ext/aubio-types.h
r1f4d932 r92a8800 51 51 #endif 52 52 53 // special python type for cvec54 typedef struct55 {56 PyObject_HEAD57 cvec_t * o;58 uint_t length;59 } Py_cvec;60 53 extern PyTypeObject Py_cvecType; 61 54 … … 64 57 extern int PyAubio_ArrayToCFvec (PyObject * self, fvec_t *out); 65 58 66 extern PyObject * PyAubio_CCvecToPyCvec (cvec_t * self , Py_cvec *out);67 extern int PyAubio_ ArrayToCCvec (PyObject *input, cvec_t *i);59 extern PyObject * PyAubio_CCvecToPyCvec (cvec_t * self); 60 extern int PyAubio_PyCvecToCCvec (PyObject *input, cvec_t *i); 68 61 69 62 extern PyObject *PyAubio_CFmatToArray (fmat_t * self); -
python/ext/aubioproxy.c
r1f4d932 r92a8800 54 54 out->data = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)input, 0); 55 55 return 1; 56 }57 58 PyObject *59 PyAubio_CCvecToPyCvec (cvec_t * input, Py_cvec *vec) {60 vec->length = input->length;61 vec->o = input;62 // keep a reference to re-use after returning it63 Py_INCREF(vec);64 return (PyObject *)vec;65 }66 67 int68 PyAubio_ArrayToCCvec (PyObject *input, cvec_t *i) {69 if (PyObject_TypeCheck (input, &Py_cvecType)) {70 //*i = *(((Py_cvec*)input)->o);71 i->norm = ((Py_cvec*)input)->o->norm;72 i->phas = ((Py_cvec*)input)->o->phas;73 i->length = ((Py_cvec*)input)->o->length;74 return 1;75 } else {76 PyErr_SetString (PyExc_ValueError, "input array should be aubio.cvec");77 return 0;78 }79 56 } 80 57 -
python/ext/py-cvec.c
r1f4d932 r92a8800 1 1 #include "aubio-types.h" 2 2 3 /* cvec type definition 3 /* cvec type definition 4 4 5 5 class cvec(): 6 def __ init__(self, length = 1024):7 self.length = length 8 self.norm = array(length)9 self.phas = array(length)6 def __new__(self, length = 1024): 7 self.length = length / 2 + 1 8 self.norm = np.zeros(length / 2 + 1) 9 self.phas = np.zeros(length / 2 + 1) 10 10 11 11 */ 12 12 13 // special python type for cvec 14 typedef struct 15 { 16 PyObject_HEAD 17 PyObject *norm; 18 PyObject *phas; 19 uint_t length; 20 } Py_cvec; 21 13 22 static char Py_cvec_doc[] = "cvec object"; 23 24 PyObject * 25 PyAubio_CCvecToPyCvec (cvec_t * input) { 26 if (input == NULL) { 27 PyErr_SetString (PyExc_ValueError, "PyAubio_CCvecToPyCvec got a null cvec!"); 28 return NULL; 29 } 30 Py_cvec* vec = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType); 31 npy_intp dims[] = { input->length, 1 }; 32 vec->norm = PyArray_SimpleNewFromData (1, dims, AUBIO_NPY_SMPL, input->norm); 33 vec->phas = PyArray_SimpleNewFromData (1, dims, AUBIO_NPY_SMPL, input->phas); 34 vec->length = input->length; 35 return (PyObject *)vec; 36 } 37 38 int 39 PyAubio_PyCvecToCCvec (PyObject *input, cvec_t *i) { 40 if (PyObject_TypeCheck (input, &Py_cvecType)) { 41 Py_cvec * in = (Py_cvec *)input; 42 if (in->norm == NULL) { 43 npy_intp dims[] = { in->length, 1 }; 44 in->norm = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0); 45 } 46 if (in->phas == NULL) { 47 npy_intp dims[] = { in->length, 1 }; 48 in->phas = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0); 49 } 50 i->norm = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)(in->norm), 0); 51 i->phas = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)(in->phas), 0); 52 i->length = ((Py_cvec*)input)->length; 53 return 1; 54 } else { 55 PyErr_SetString (PyExc_ValueError, "input array should be aubio.cvec"); 56 return 0; 57 } 58 } 14 59 15 60 static PyObject * … … 24 69 return NULL; 25 70 } 26 27 71 28 72 self = (Py_cvec *) type->tp_alloc (type, 0); … … 48 92 Py_cvec_init (Py_cvec * self, PyObject * args, PyObject * kwds) 49 93 { 50 self->o = new_cvec ((self->length - 1) * 2); 51 if (self->o == NULL) { 52 return -1; 53 } 54 94 self->norm = NULL; 95 self->phas = NULL; 55 96 return 0; 56 97 } … … 59 100 Py_cvec_del (Py_cvec * self) 60 101 { 61 del_cvec (self->o); 102 Py_XDECREF(self->norm); 103 Py_XDECREF(self->phas); 62 104 Py_TYPE(self)->tp_free ((PyObject *) self); 63 105 } … … 79 121 goto fail; 80 122 } 81 cvec_print ( self->o );123 // hide actual norm / phas content 82 124 83 125 result = PyUnicode_Format (format, args); … … 91 133 92 134 PyObject * 93 PyAubio_CvecNormToArray (Py_cvec * self)94 {95 npy_intp dims[] = { self->o->length, 1 };96 return PyArray_SimpleNewFromData (1, dims, AUBIO_NPY_SMPL, self->o->norm);97 }98 99 100 PyObject *101 PyAubio_CvecPhasToArray (Py_cvec * self)102 {103 npy_intp dims[] = { self->o->length, 1 };104 return PyArray_SimpleNewFromData (1, dims, AUBIO_NPY_SMPL, self->o->phas);105 }106 107 PyObject *108 PyAubio_ArrayToCvecPhas (PyObject * self)109 {110 return NULL;111 }112 113 PyObject *114 135 Py_cvec_get_norm (Py_cvec * self, void *closure) 115 136 { 116 return PyAubio_CvecNormToArray(self); 137 // if it norm hasn't been created, create it now 138 if (self->norm == NULL) { 139 npy_intp dims[] = { self->length, 1 }; 140 self->norm = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0); 141 } 142 Py_INCREF(self->norm); 143 return (PyObject*)(self->norm); 117 144 } 118 145 … … 120 147 Py_cvec_get_phas (Py_cvec * self, void *closure) 121 148 { 122 return PyAubio_CvecPhasToArray(self); 149 // if it phas hasn't been created, create it now 150 if (self->phas == NULL) { 151 npy_intp dims[] = { self->length, 1 }; 152 self->phas = PyArray_ZEROS(1, dims, AUBIO_NPY_SMPL, 0); 153 } 154 Py_INCREF(self->phas); 155 return (PyObject *)(self->phas); 123 156 } 124 157 … … 132 165 } 133 166 if (PyArray_Check(input)) { 134 135 // we got an array, convert it to a cvec.norm 167 // we got an array, convert it to a cvec.norm 136 168 if (PyArray_NDIM ((PyArrayObject *)input) == 0) { 137 169 PyErr_SetString (PyExc_ValueError, "input array is a scalar"); … … 159 191 goto fail; 160 192 } else { 161 if (vec-> o->length != PyArray_SIZE (array)) {193 if (vec->length != PyArray_SIZE (array)) { 162 194 PyErr_Format (PyExc_ValueError, 163 195 "input array has length %d, but cvec has length %d", 164 (int)PyArray_SIZE (array), vec-> o->length);196 (int)PyArray_SIZE (array), vec->length); 165 197 goto fail; 166 198 } 167 199 } 168 200 169 vec->o->norm = (smpl_t *) PyArray_GETPTR1 (array, 0); 201 Py_XDECREF(vec->norm); 202 vec->norm = input; 203 Py_INCREF(vec->norm); 170 204 171 205 } else { … … 174 208 } 175 209 176 Py_INCREF(array);177 210 return 0; 178 211 … … 217 250 goto fail; 218 251 } else { 219 if (vec-> o->length != PyArray_SIZE (array)) {252 if (vec->length != PyArray_SIZE (array)) { 220 253 PyErr_Format (PyExc_ValueError, 221 254 "input array has length %d, but cvec has length %d", 222 (int)PyArray_SIZE (array), vec-> o->length);255 (int)PyArray_SIZE (array), vec->length); 223 256 goto fail; 224 257 } 225 258 } 226 259 227 vec->o->phas = (smpl_t *) PyArray_GETPTR1 (array, 0); 260 Py_XDECREF(vec->phas); 261 vec->phas = input; 262 Py_INCREF(vec->phas); 228 263 229 264 } else { … … 232 267 } 233 268 234 Py_INCREF(array);235 269 return 0; 236 270 -
python/ext/py-fft.c
r1f4d932 r92a8800 14 14 cvec_t *out; 15 15 fvec_t *rout; 16 // bridge for cvec output17 Py_cvec *py_out;18 16 } Py_fft; 19 17 … … 61 59 62 60 self->out = new_cvec(self->win_s); 63 self->py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);64 Py_XINCREF(self->py_out);65 61 self->rout = new_fvec(self->win_s); 66 62 … … 71 67 Py_fft_del (Py_fft *self, PyObject *unused) 72 68 { 73 Py_XDECREF((PyObject*)(self->py_out));74 69 del_aubio_fft(self->o); 75 70 del_cvec(self->out); … … 93 88 // compute the function 94 89 aubio_fft_do (((Py_fft *)self)->o, &(self->vecin), self->out); 95 #if 0 96 Py_cvec * py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType); 97 PyObject* output = PyAubio_CCvecToPyCvec(self->out, py_out); 98 return output; 99 #else 100 // convert cvec to py_cvec, incrementing refcount to keep a copy 101 return PyAubio_CCvecToPyCvec(self->out, self->py_out); 102 #endif 90 // convert cvec to py_cvec 91 return PyAubio_CCvecToPyCvec(self->out); 103 92 } 104 93 … … 118 107 } 119 108 120 if (!PyAubio_ ArrayToCCvec (input, &(self->cvecin)) ) {109 if (!PyAubio_PyCvecToCCvec (input, &(self->cvecin)) ) { 121 110 return NULL; 122 111 } -
python/ext/py-filterbank.c
r1f4d932 r92a8800 88 88 } 89 89 90 if (!PyAubio_ ArrayToCCvec(input, &(self->vec) )) {90 if (!PyAubio_PyCvecToCCvec(input, &(self->vec) )) { 91 91 return NULL; 92 92 } -
python/ext/py-phasevoc.c
r1f4d932 r92a8800 11 11 fvec_t vecin; 12 12 cvec_t *output; 13 Py_cvec *py_out;14 13 cvec_t cvecin; 15 14 fvec_t *routput; … … 73 72 74 73 self->output = new_cvec(self->win_s); 75 self->py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);76 74 self->routput = new_fvec(self->hop_s); 77 75 … … 105 103 // compute the function 106 104 aubio_pvoc_do (self->o, &(self->vecin), self->output); 107 #if 0 108 Py_cvec * py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType); 109 PyObject* output = PyAubio_CCvecToPyCvec(self->output, py_out); 110 return output; 111 #else 112 // convert cvec to py_cvec, incrementing refcount to keep a copy 113 return PyAubio_CCvecToPyCvec(self->output, self->py_out); 114 #endif 105 // convert cvec to py_cvec 106 return PyAubio_CCvecToPyCvec(self->output); 115 107 } 116 108 … … 131 123 } 132 124 133 if (!PyAubio_ ArrayToCCvec (input, &(self->cvecin) )) {125 if (!PyAubio_PyCvecToCCvec (input, &(self->cvecin) )) { 134 126 return NULL; 135 127 } -
python/lib/gen_code.py
r1f4d932 r92a8800 38 38 pytoaubio_fn = { 39 39 'fvec_t*': 'PyAubio_ArrayToCFvec', 40 'cvec_t*': 'PyAubio_ ArrayToCCvec',40 'cvec_t*': 'PyAubio_PyCvecToCCvec', 41 41 #'fmat_t*': 'PyAubio_ArrayToCFmat', 42 42 }
Note: See TracChangeset
for help on using the changeset viewer.