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);
88 del_aubio_pvoc(self->o);
90 Py_TYPE(self)->tp_free((PyObject *) self);
95 Py_pvoc_do(Py_pvoc * self, PyObject * args)
99 if (!PyArg_ParseTuple (args, "O", &input)) {
103 if (!PyAubio_ArrayToCFvec (input, &(self->vecin) )) {
107 if (self->vecin.length != self->hop_s) {
108 PyErr_Format(PyExc_ValueError,
109 "input fvec has length %d, but pvoc expects length %d",
110 self->vecin.length, self->hop_s);
114 Py_INCREF(self->output);
115 if (!PyAubio_PyCvecToCCvec (self->output, &(self->c_output))) {
118 // compute the function
119 aubio_pvoc_do (self->o, &(self->vecin), &(self->c_output));
123 static PyMemberDef Py_pvoc_members[] = {
124 {"win_s", T_INT, offsetof (Py_pvoc, win_s), READONLY,
125 "size of the window"},
126 {"hop_s", T_INT, offsetof (Py_pvoc, hop_s), READONLY,
132 Py_pvoc_rdo(Py_pvoc * self, PyObject * args)
135 if (!PyArg_ParseTuple (args, "O", &input)) {
139 if (!PyAubio_PyCvecToCCvec (input, &(self->cvecin) )) {
143 if (self->cvecin.length != self->win_s / 2 + 1) {
144 PyErr_Format(PyExc_ValueError,
145 "input cvec has length %d, but pvoc expects length %d",
146 self->cvecin.length, self->win_s / 2 + 1);
150 Py_INCREF(self->routput);
151 if (!PyAubio_ArrayToCFvec(self->routput, &(self->c_routput)) ) {
154 // compute the function
155 aubio_pvoc_rdo (self->o, &(self->cvecin), &(self->c_routput));
156 return self->routput;
159 static PyMethodDef Py_pvoc_methods[] = {
160 {"rdo", (PyCFunction) Py_pvoc_rdo, METH_VARARGS,
161 "synthesis of spectral grain"},
165 PyTypeObject Py_pvocType = {
166 PyVarObject_HEAD_INIT (NULL, 0)
170 (destructor) Py_pvoc_del,
180 (ternaryfunc)Py_pvoc_do,
201 (initproc) Py_pvoc_init,