[615ac7d] | 1 | #include "aubiowraphell.h" |
---|
| 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 | //AUBIO_NEW(pvoc) |
---|
| 17 | static PyObject * |
---|
| 18 | Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds) |
---|
| 19 | { |
---|
[0f045b2] | 20 | int win_s = 0, hop_s = 0; |
---|
[615ac7d] | 21 | Py_pvoc *self; |
---|
[0f045b2] | 22 | static char *kwlist[] = { "win_s", "hop_s", NULL }; |
---|
[615ac7d] | 23 | |
---|
[0f045b2] | 24 | if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist, |
---|
| 25 | &win_s, &hop_s)) { |
---|
[615ac7d] | 26 | return NULL; |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | self = (Py_pvoc *) type->tp_alloc (type, 0); |
---|
| 30 | |
---|
| 31 | if (self == NULL) { |
---|
| 32 | return NULL; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | self->win_s = Py_default_vector_length; |
---|
| 36 | self->hop_s = Py_default_vector_length/2; |
---|
| 37 | |
---|
| 38 | if (self == NULL) { |
---|
| 39 | return NULL; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | if (win_s > 0) { |
---|
| 43 | self->win_s = win_s; |
---|
| 44 | } else if (win_s < 0) { |
---|
| 45 | PyErr_SetString (PyExc_ValueError, |
---|
| 46 | "can not use negative window size"); |
---|
| 47 | return NULL; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | if (hop_s > 0) { |
---|
| 51 | self->hop_s = hop_s; |
---|
| 52 | } else if (hop_s < 0) { |
---|
| 53 | PyErr_SetString (PyExc_ValueError, |
---|
| 54 | "can not use negative hop size"); |
---|
| 55 | return NULL; |
---|
| 56 | } |
---|
| 57 | |
---|
[202697a] | 58 | self->output = new_cvec(self->win_s); |
---|
| 59 | self->routput = new_fvec(self->hop_s); |
---|
| 60 | |
---|
[615ac7d] | 61 | return (PyObject *) self; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | |
---|
[0f045b2] | 65 | AUBIO_INIT(pvoc, self->win_s, self->hop_s) |
---|
[615ac7d] | 66 | |
---|
[202697a] | 67 | static void |
---|
| 68 | Py_pvoc_del (Py_pvoc *self, PyObject *unused) |
---|
| 69 | { |
---|
| 70 | del_aubio_pvoc(self->o); |
---|
| 71 | del_cvec(self->output); |
---|
| 72 | del_fvec(self->routput); |
---|
| 73 | self->ob_type->tp_free((PyObject *) self); |
---|
| 74 | } |
---|
| 75 | |
---|
[615ac7d] | 76 | |
---|
| 77 | static PyObject * |
---|
[c04d250] | 78 | Py_pvoc_do(Py_pvoc * self, PyObject * args) |
---|
[615ac7d] | 79 | { |
---|
| 80 | PyObject *input; |
---|
[c04d250] | 81 | fvec_t *vec; |
---|
[615ac7d] | 82 | |
---|
| 83 | if (!PyArg_ParseTuple (args, "O", &input)) { |
---|
| 84 | return NULL; |
---|
| 85 | } |
---|
| 86 | |
---|
[c04d250] | 87 | vec = PyAubio_ArrayToCFvec (input); |
---|
[615ac7d] | 88 | |
---|
| 89 | if (vec == NULL) { |
---|
| 90 | return NULL; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | // compute the function |
---|
[202697a] | 94 | aubio_pvoc_do (self->o, vec, self->output); |
---|
| 95 | return (PyObject *)PyAubio_CCvecToPyCvec(self->output); |
---|
[615ac7d] | 96 | } |
---|
| 97 | |
---|
| 98 | AUBIO_MEMBERS_START(pvoc) |
---|
| 99 | {"win_s", T_INT, offsetof (Py_pvoc, win_s), READONLY, |
---|
| 100 | "size of the window"}, |
---|
| 101 | {"hop_s", T_INT, offsetof (Py_pvoc, hop_s), READONLY, |
---|
| 102 | "size of the hop"}, |
---|
| 103 | AUBIO_MEMBERS_STOP(pvoc) |
---|
| 104 | |
---|
| 105 | static PyObject * |
---|
[c04d250] | 106 | Py_pvoc_rdo(Py_pvoc * self, PyObject * args) |
---|
[615ac7d] | 107 | { |
---|
| 108 | PyObject *input; |
---|
[c04d250] | 109 | cvec_t *vec; |
---|
[615ac7d] | 110 | if (!PyArg_ParseTuple (args, "O", &input)) { |
---|
| 111 | return NULL; |
---|
| 112 | } |
---|
| 113 | |
---|
[c04d250] | 114 | vec = PyAubio_ArrayToCCvec (input); |
---|
[615ac7d] | 115 | |
---|
| 116 | if (vec == NULL) { |
---|
| 117 | return NULL; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | // compute the function |
---|
[202697a] | 121 | aubio_pvoc_rdo (self->o, vec, self->routput); |
---|
| 122 | return (PyObject *)PyAubio_CFvecToArray(self->routput); |
---|
[615ac7d] | 123 | } |
---|
| 124 | |
---|
| 125 | static PyMethodDef Py_pvoc_methods[] = { |
---|
| 126 | {"rdo", (PyCFunction) Py_pvoc_rdo, METH_VARARGS, |
---|
| 127 | "synthesis of spectral grain"}, |
---|
| 128 | {NULL} |
---|
| 129 | }; |
---|
| 130 | |
---|
| 131 | AUBIO_TYPEOBJECT(pvoc, "aubio.pvoc") |
---|