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,
70 "failed creating pvoc with win_s=%d, hop_s=%d",
71 self->win_s, self->hop_s);
75 self->output = new_py_cvec(self->win_s);
76 self->routput = new_py_fvec(self->hop_s);
83 Py_pvoc_del (Py_pvoc *self, PyObject *unused)
85 Py_XDECREF(self->output);
86 Py_XDECREF(self->routput);
87 del_aubio_pvoc(self->o);
88 Py_TYPE(self)->tp_free((PyObject *) self);
93 Py_pvoc_do(Py_pvoc * self, PyObject * args)
97 if (!PyArg_ParseTuple (args, "O", &input)) {
101 if (!PyAubio_ArrayToCFvec (input, &(self->vecin) )) {
105 if (self->vecin.length != self->hop_s) {
106 PyErr_Format(PyExc_ValueError,
107 "input fvec has length %d, but pvoc expects length %d",
108 self->vecin.length, self->hop_s);
112 Py_INCREF(self->output);
113 if (!PyAubio_PyCvecToCCvec (self->output, &(self->c_output))) {
116 // compute the function
117 aubio_pvoc_do (self->o, &(self->vecin), &(self->c_output));
121 static PyMemberDef Py_pvoc_members[] = {
122 {"win_s", T_INT, offsetof (Py_pvoc, win_s), READONLY,
123 "size of the window"},
124 {"hop_s", T_INT, offsetof (Py_pvoc, hop_s), READONLY,
130 Py_pvoc_rdo(Py_pvoc * self, PyObject * args)
133 if (!PyArg_ParseTuple (args, "O", &input)) {
137 if (!PyAubio_PyCvecToCCvec (input, &(self->cvecin) )) {
141 if (self->cvecin.length != self->win_s / 2 + 1) {
142 PyErr_Format(PyExc_ValueError,
143 "input cvec has length %d, but pvoc expects length %d",
144 self->cvecin.length, self->win_s / 2 + 1);
148 Py_INCREF(self->routput);
149 if (!PyAubio_ArrayToCFvec(self->routput, &(self->c_routput)) ) {
152 // compute the function
153 aubio_pvoc_rdo (self->o, &(self->cvecin), &(self->c_routput));
154 return self->routput;
157 static PyMethodDef Py_pvoc_methods[] = {
158 {"rdo", (PyCFunction) Py_pvoc_rdo, METH_VARARGS,
159 "synthesis of spectral grain"},
163 PyTypeObject Py_pvocType = {
164 PyVarObject_HEAD_INIT (NULL, 0)
168 (destructor) Py_pvoc_del,
178 (ternaryfunc)Py_pvoc_do,
199 (initproc) Py_pvoc_init,