1 #include "aubio-types.h"
3 static char Py_pvoc_doc[] = "pvoc object";
21 Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
23 int win_s = 0, hop_s = 0;
25 static char *kwlist[] = { "win_s", "hop_s", NULL };
27 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist,
32 self = (Py_pvoc *) type->tp_alloc (type, 0);
38 self->win_s = Py_default_vector_length;
39 self->hop_s = Py_default_vector_length/2;
47 } else if (win_s < 0) {
48 PyErr_SetString (PyExc_ValueError,
49 "can not use negative window size");
55 } else if (hop_s < 0) {
56 PyErr_SetString (PyExc_ValueError,
57 "can not use negative hop size");
61 return (PyObject *) self;
65 Py_pvoc_init (Py_pvoc * self, PyObject * args, PyObject * kwds)
67 self->o = new_aubio_pvoc ( self->win_s, self->hop_s);
68 if (self->o == NULL) {
69 // PyErr_Format(PyExc_RuntimeError, ...) was set above by new_ which called
70 // AUBIO_ERR when failing
74 self->output = new_py_cvec(self->win_s);
75 self->routput = new_py_fvec(self->hop_s);
82 Py_pvoc_del (Py_pvoc *self, PyObject *unused)
84 Py_XDECREF(self->output);
85 Py_XDECREF(self->routput);
87 del_aubio_pvoc(self->o);
89 Py_TYPE(self)->tp_free((PyObject *) self);
94 Py_pvoc_do(Py_pvoc * self, PyObject * args)
98 if (!PyArg_ParseTuple (args, "O", &input)) {
102 if (!PyAubio_ArrayToCFvec (input, &(self->vecin) )) {
106 if (self->vecin.length != self->hop_s) {
107 PyErr_Format(PyExc_ValueError,
108 "input fvec has length %d, but pvoc expects length %d",
109 self->vecin.length, self->hop_s);
113 Py_INCREF(self->output);
114 if (!PyAubio_PyCvecToCCvec (self->output, &(self->c_output))) {
117 // compute the function
118 aubio_pvoc_do (self->o, &(self->vecin), &(self->c_output));
122 static PyMemberDef Py_pvoc_members[] = {
123 {"win_s", T_INT, offsetof (Py_pvoc, win_s), READONLY,
124 "size of the window"},
125 {"hop_s", T_INT, offsetof (Py_pvoc, hop_s), READONLY,
131 Py_pvoc_rdo(Py_pvoc * self, PyObject * args)
134 if (!PyArg_ParseTuple (args, "O", &input)) {
138 if (!PyAubio_PyCvecToCCvec (input, &(self->cvecin) )) {
142 if (self->cvecin.length != self->win_s / 2 + 1) {
143 PyErr_Format(PyExc_ValueError,
144 "input cvec has length %d, but pvoc expects length %d",
145 self->cvecin.length, self->win_s / 2 + 1);
149 Py_INCREF(self->routput);
150 if (!PyAubio_ArrayToCFvec(self->routput, &(self->c_routput)) ) {
153 // compute the function
154 aubio_pvoc_rdo (self->o, &(self->cvecin), &(self->c_routput));
155 return self->routput;
159 Pyaubio_pvoc_set_window (Py_pvoc *self, PyObject *args)
162 char_t *window = NULL;
164 if (!PyArg_ParseTuple (args, "s", &window)) {
167 err = aubio_pvoc_set_window (self->o, window);
170 PyErr_SetString (PyExc_ValueError, "error running aubio_pvoc_set_window");
176 static PyMethodDef Py_pvoc_methods[] = {
177 {"rdo", (PyCFunction) Py_pvoc_rdo, METH_VARARGS,
178 "synthesis of spectral grain"},
179 {"set_window", (PyCFunction) Pyaubio_pvoc_set_window, METH_VARARGS, ""},
183 PyTypeObject Py_pvocType = {
184 PyVarObject_HEAD_INIT (NULL, 0)
188 (destructor) Py_pvoc_del,
198 (ternaryfunc)Py_pvoc_do,
219 (initproc) Py_pvoc_init,