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