Changeset f264b17 for python/ext/py-phasevoc.c
- Timestamp:
- Jun 22, 2016, 1:00:10 PM (8 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:
- 4b9443c4
- Parents:
- 60fc05b (diff), 6769586 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/ext/py-phasevoc.c
r60fc05b rf264b17 1 #include "aubio wraphell.h"1 #include "aubio-types.h" 2 2 3 3 static char Py_pvoc_doc[] = "pvoc object"; 4 4 5 AUBIO_DECLARE(pvoc, uint_t win_s; uint_t hop_s) 6 7 //AUBIO_NEW(pvoc) 5 typedef struct 6 { 7 PyObject_HEAD 8 aubio_pvoc_t * o; 9 uint_t win_s; 10 uint_t hop_s; 11 fvec_t vecin; 12 cvec_t cvecin; 13 PyObject *output; 14 cvec_t c_output; 15 PyObject *routput; 16 fvec_t c_routput; 17 } Py_pvoc; 18 19 8 20 static PyObject * 9 21 Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds) … … 50 62 } 51 63 52 53 AUBIO_INIT(pvoc, self->win_s, self->hop_s) 54 55 AUBIO_DEL(pvoc) 56 57 static PyObject * 64 static int 65 Py_pvoc_init (Py_pvoc * self, PyObject * args, PyObject * kwds) 66 { 67 self->o = new_aubio_pvoc ( self->win_s, self->hop_s); 68 if (self->o == NULL) { 69 PyErr_Format(PyExc_RuntimeError, 70 "failed creating pvoc with win_s=%d, hop_s=%d", 71 self->win_s, self->hop_s); 72 return -1; 73 } 74 75 self->output = new_py_cvec(self->win_s); 76 self->routput = new_py_fvec(self->hop_s); 77 78 return 0; 79 } 80 81 82 static void 83 Py_pvoc_del (Py_pvoc *self, PyObject *unused) 84 { 85 Py_XDECREF(self->output); 86 Py_XDECREF(self->routput); 87 if (self->o) { 88 del_aubio_pvoc(self->o); 89 } 90 Py_TYPE(self)->tp_free((PyObject *) self); 91 } 92 93 94 static PyObject * 58 95 Py_pvoc_do(Py_pvoc * self, PyObject * args) 59 96 { 60 97 PyObject *input; 61 fvec_t *vec;62 cvec_t *output;63 98 64 99 if (!PyArg_ParseTuple (args, "O", &input)) { … … 66 101 } 67 102 68 vec = PyAubio_ArrayToCFvec (input); 69 70 if (vec == NULL) { 71 return NULL; 72 } 73 74 output = new_cvec(self->win_s); 75 103 if (!PyAubio_ArrayToCFvec (input, &(self->vecin) )) { 104 return NULL; 105 } 106 107 if (self->vecin.length != self->hop_s) { 108 PyErr_Format(PyExc_ValueError, 109 "input fvec has length %d, but pvoc expects length %d", 110 self->vecin.length, self->hop_s); 111 return NULL; 112 } 113 114 Py_INCREF(self->output); 115 if (!PyAubio_PyCvecToCCvec (self->output, &(self->c_output))) { 116 return NULL; 117 } 76 118 // compute the function 77 aubio_pvoc_do (self->o, vec, output);78 return (PyObject *)PyAubio_CCvecToPyCvec(output);79 } 80 81 AUBIO_MEMBERS_START(pvoc) 119 aubio_pvoc_do (self->o, &(self->vecin), &(self->c_output)); 120 return self->output; 121 } 122 123 static PyMemberDef Py_pvoc_members[] = { 82 124 {"win_s", T_INT, offsetof (Py_pvoc, win_s), READONLY, 83 125 "size of the window"}, 84 126 {"hop_s", T_INT, offsetof (Py_pvoc, hop_s), READONLY, 85 127 "size of the hop"}, 86 AUBIO_MEMBERS_STOP(pvoc) 87 88 static PyObject * 128 { NULL } // sentinel 129 }; 130 131 static PyObject * 89 132 Py_pvoc_rdo(Py_pvoc * self, PyObject * args) 90 133 { 91 134 PyObject *input; 92 cvec_t *vec;93 fvec_t *output;94 95 135 if (!PyArg_ParseTuple (args, "O", &input)) { 96 136 return NULL; 97 137 } 98 138 99 vec = PyAubio_ArrayToCCvec (input); 100 101 if (vec == NULL) { 102 return NULL; 103 } 104 105 output = new_fvec(self->hop_s); 106 139 if (!PyAubio_PyCvecToCCvec (input, &(self->cvecin) )) { 140 return NULL; 141 } 142 143 if (self->cvecin.length != self->win_s / 2 + 1) { 144 PyErr_Format(PyExc_ValueError, 145 "input cvec has length %d, but pvoc expects length %d", 146 self->cvecin.length, self->win_s / 2 + 1); 147 return NULL; 148 } 149 150 Py_INCREF(self->routput); 151 if (!PyAubio_ArrayToCFvec(self->routput, &(self->c_routput)) ) { 152 return NULL; 153 } 107 154 // compute the function 108 aubio_pvoc_rdo (self->o, vec, output);109 return (PyObject *)PyAubio_CFvecToArray(output);155 aubio_pvoc_rdo (self->o, &(self->cvecin), &(self->c_routput)); 156 return self->routput; 110 157 } 111 158 … … 116 163 }; 117 164 118 AUBIO_TYPEOBJECT(pvoc, "aubio.pvoc") 165 PyTypeObject Py_pvocType = { 166 PyVarObject_HEAD_INIT (NULL, 0) 167 "aubio.pvoc", 168 sizeof (Py_pvoc), 169 0, 170 (destructor) Py_pvoc_del, 171 0, 172 0, 173 0, 174 0, 175 0, 176 0, 177 0, 178 0, 179 0, 180 (ternaryfunc)Py_pvoc_do, 181 0, 182 0, 183 0, 184 0, 185 Py_TPFLAGS_DEFAULT, 186 Py_pvoc_doc, 187 0, 188 0, 189 0, 190 0, 191 0, 192 0, 193 Py_pvoc_methods, 194 Py_pvoc_members, 195 0, 196 0, 197 0, 198 0, 199 0, 200 0, 201 (initproc) Py_pvoc_init, 202 0, 203 Py_pvoc_new, 204 0, 205 0, 206 0, 207 0, 208 0, 209 0, 210 0, 211 0, 212 0, 213 };
Note: See TracChangeset
for help on using the changeset viewer.