[5652a8c] | 1 | #include "aubio-types.h" |
---|
[615ac7d] | 2 | |
---|
[51b9c83] | 3 | static char Py_pvoc_doc[] = "pvoc object"; |
---|
| 4 | |
---|
[202697a] | 5 | typedef struct |
---|
| 6 | { |
---|
| 7 | PyObject_HEAD |
---|
| 8 | aubio_pvoc_t * o; |
---|
| 9 | uint_t win_s; |
---|
| 10 | uint_t hop_s; |
---|
[569b363] | 11 | fvec_t vecin; |
---|
[202697a] | 12 | cvec_t *output; |
---|
[569b363] | 13 | cvec_t cvecin; |
---|
[202697a] | 14 | fvec_t *routput; |
---|
| 15 | } Py_pvoc; |
---|
| 16 | |
---|
[615ac7d] | 17 | |
---|
| 18 | static PyObject * |
---|
| 19 | Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds) |
---|
| 20 | { |
---|
[0f045b2] | 21 | int win_s = 0, hop_s = 0; |
---|
[615ac7d] | 22 | Py_pvoc *self; |
---|
[0f045b2] | 23 | static char *kwlist[] = { "win_s", "hop_s", NULL }; |
---|
[615ac7d] | 24 | |
---|
[0f045b2] | 25 | if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist, |
---|
| 26 | &win_s, &hop_s)) { |
---|
[615ac7d] | 27 | return NULL; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | self = (Py_pvoc *) type->tp_alloc (type, 0); |
---|
| 31 | |
---|
| 32 | if (self == NULL) { |
---|
| 33 | return NULL; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | self->win_s = Py_default_vector_length; |
---|
| 37 | self->hop_s = Py_default_vector_length/2; |
---|
| 38 | |
---|
| 39 | if (self == NULL) { |
---|
| 40 | return NULL; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | if (win_s > 0) { |
---|
| 44 | self->win_s = win_s; |
---|
| 45 | } else if (win_s < 0) { |
---|
| 46 | PyErr_SetString (PyExc_ValueError, |
---|
| 47 | "can not use negative window size"); |
---|
| 48 | return NULL; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | if (hop_s > 0) { |
---|
| 52 | self->hop_s = hop_s; |
---|
| 53 | } else if (hop_s < 0) { |
---|
| 54 | PyErr_SetString (PyExc_ValueError, |
---|
| 55 | "can not use negative hop size"); |
---|
| 56 | return NULL; |
---|
| 57 | } |
---|
| 58 | |
---|
[5652a8c] | 59 | return (PyObject *) self; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | static int |
---|
| 63 | Py_pvoc_init (Py_pvoc * self, PyObject * args, PyObject * kwds) |
---|
| 64 | { |
---|
| 65 | self->o = new_aubio_pvoc ( self->win_s, self->hop_s); |
---|
| 66 | if (self->o == NULL) { |
---|
| 67 | char_t errstr[30]; |
---|
| 68 | sprintf(errstr, "error creating pvoc with %d, %d", self->win_s, self->hop_s); |
---|
| 69 | PyErr_SetString (PyExc_RuntimeError, errstr); |
---|
| 70 | return -1; |
---|
| 71 | } |
---|
| 72 | |
---|
[202697a] | 73 | self->output = new_cvec(self->win_s); |
---|
| 74 | self->routput = new_fvec(self->hop_s); |
---|
| 75 | |
---|
[5652a8c] | 76 | return 0; |
---|
[615ac7d] | 77 | } |
---|
| 78 | |
---|
| 79 | |
---|
[202697a] | 80 | static void |
---|
| 81 | Py_pvoc_del (Py_pvoc *self, PyObject *unused) |
---|
| 82 | { |
---|
| 83 | del_aubio_pvoc(self->o); |
---|
| 84 | del_cvec(self->output); |
---|
| 85 | del_fvec(self->routput); |
---|
[5c1200a] | 86 | Py_TYPE(self)->tp_free((PyObject *) self); |
---|
[202697a] | 87 | } |
---|
| 88 | |
---|
[615ac7d] | 89 | |
---|
[b5bef11] | 90 | static PyObject * |
---|
[c04d250] | 91 | Py_pvoc_do(Py_pvoc * self, PyObject * args) |
---|
[615ac7d] | 92 | { |
---|
| 93 | PyObject *input; |
---|
| 94 | |
---|
| 95 | if (!PyArg_ParseTuple (args, "O", &input)) { |
---|
| 96 | return NULL; |
---|
| 97 | } |
---|
| 98 | |
---|
[569b363] | 99 | if (!PyAubio_ArrayToCFvec (input, &(self->vecin) )) { |
---|
[615ac7d] | 100 | return NULL; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | // compute the function |
---|
[569b363] | 104 | aubio_pvoc_do (self->o, &(self->vecin), self->output); |
---|
[92a8800] | 105 | // convert cvec to py_cvec |
---|
| 106 | return PyAubio_CCvecToPyCvec(self->output); |
---|
[615ac7d] | 107 | } |
---|
| 108 | |
---|
[5652a8c] | 109 | static PyMemberDef Py_pvoc_members[] = { |
---|
[615ac7d] | 110 | {"win_s", T_INT, offsetof (Py_pvoc, win_s), READONLY, |
---|
| 111 | "size of the window"}, |
---|
| 112 | {"hop_s", T_INT, offsetof (Py_pvoc, hop_s), READONLY, |
---|
| 113 | "size of the hop"}, |
---|
[5652a8c] | 114 | { NULL } // sentinel |
---|
| 115 | }; |
---|
[615ac7d] | 116 | |
---|
| 117 | static PyObject * |
---|
[c04d250] | 118 | Py_pvoc_rdo(Py_pvoc * self, PyObject * args) |
---|
[615ac7d] | 119 | { |
---|
| 120 | PyObject *input; |
---|
| 121 | if (!PyArg_ParseTuple (args, "O", &input)) { |
---|
| 122 | return NULL; |
---|
| 123 | } |
---|
| 124 | |
---|
[92a8800] | 125 | if (!PyAubio_PyCvecToCCvec (input, &(self->cvecin) )) { |
---|
[615ac7d] | 126 | return NULL; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | // compute the function |
---|
[569b363] | 130 | aubio_pvoc_rdo (self->o, &(self->cvecin), self->routput); |
---|
[b5bef11] | 131 | return PyAubio_CFvecToArray(self->routput); |
---|
[615ac7d] | 132 | } |
---|
| 133 | |
---|
| 134 | static PyMethodDef Py_pvoc_methods[] = { |
---|
| 135 | {"rdo", (PyCFunction) Py_pvoc_rdo, METH_VARARGS, |
---|
| 136 | "synthesis of spectral grain"}, |
---|
| 137 | {NULL} |
---|
| 138 | }; |
---|
| 139 | |
---|
[5652a8c] | 140 | PyTypeObject Py_pvocType = { |
---|
| 141 | PyVarObject_HEAD_INIT (NULL, 0) |
---|
| 142 | "aubio.pvoc", |
---|
| 143 | sizeof (Py_pvoc), |
---|
| 144 | 0, |
---|
| 145 | (destructor) Py_pvoc_del, |
---|
| 146 | 0, |
---|
| 147 | 0, |
---|
| 148 | 0, |
---|
| 149 | 0, |
---|
| 150 | 0, |
---|
| 151 | 0, |
---|
| 152 | 0, |
---|
| 153 | 0, |
---|
| 154 | 0, |
---|
| 155 | (ternaryfunc)Py_pvoc_do, |
---|
| 156 | 0, |
---|
| 157 | 0, |
---|
| 158 | 0, |
---|
| 159 | 0, |
---|
| 160 | Py_TPFLAGS_DEFAULT, |
---|
| 161 | Py_pvoc_doc, |
---|
| 162 | 0, |
---|
| 163 | 0, |
---|
| 164 | 0, |
---|
| 165 | 0, |
---|
| 166 | 0, |
---|
| 167 | 0, |
---|
| 168 | Py_pvoc_methods, |
---|
| 169 | Py_pvoc_members, |
---|
| 170 | 0, |
---|
| 171 | 0, |
---|
| 172 | 0, |
---|
| 173 | 0, |
---|
| 174 | 0, |
---|
| 175 | 0, |
---|
| 176 | (initproc) Py_pvoc_init, |
---|
| 177 | 0, |
---|
| 178 | Py_pvoc_new, |
---|
| 179 | }; |
---|