1 #include "aubio-types.h"
3 static char Py_pvoc_doc[] = "pvoc object";
20 Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
22 int win_s = 0, hop_s = 0;
24 static char *kwlist[] = { "win_s", "hop_s", NULL };
26 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist,
31 self = (Py_pvoc *) type->tp_alloc (type, 0);
37 self->win_s = Py_default_vector_length;
38 self->hop_s = Py_default_vector_length/2;
46 } else if (win_s < 0) {
47 PyErr_SetString (PyExc_ValueError,
48 "can not use negative window size");
54 } else if (hop_s < 0) {
55 PyErr_SetString (PyExc_ValueError,
56 "can not use negative hop size");
60 return (PyObject *) self;
64 Py_pvoc_init (Py_pvoc * self, PyObject * args, PyObject * kwds)
66 self->o = new_aubio_pvoc ( self->win_s, self->hop_s);
67 if (self->o == NULL) {
69 sprintf(errstr, "error creating pvoc with %d, %d", self->win_s, self->hop_s);
70 PyErr_SetString (PyExc_RuntimeError, errstr);
74 self->cvecin = (cvec_t *)malloc(sizeof(cvec_t));
75 self->vecin = (fvec_t *)malloc(sizeof(fvec_t));
77 self->output = new_cvec(self->win_s);
78 self->py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
79 self->routput = new_fvec(self->hop_s);
86 Py_pvoc_del (Py_pvoc *self, PyObject *unused)
88 del_aubio_pvoc(self->o);
89 del_cvec(self->output);
90 del_fvec(self->routput);
93 Py_TYPE(self)->tp_free((PyObject *) self);
98 Py_pvoc_do(Py_pvoc * self, PyObject * args)
102 if (!PyArg_ParseTuple (args, "O", &input)) {
106 if (!PyAubio_ArrayToCFvec (input, self->vecin)) {
110 // compute the function
111 aubio_pvoc_do (self->o, self->vecin, self->output);
113 Py_cvec * py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
114 PyObject* output = PyAubio_CCvecToPyCvec(self->output, py_out);
117 // convert cvec to py_cvec, incrementing refcount to keep a copy
118 return PyAubio_CCvecToPyCvec(self->output, self->py_out);
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_ArrayToCCvec (input, self->cvecin)) {
142 // compute the function
143 aubio_pvoc_rdo (self->o, self->cvecin, self->routput);
144 return PyAubio_CFvecToArray(self->routput);
147 static PyMethodDef Py_pvoc_methods[] = {
148 {"rdo", (PyCFunction) Py_pvoc_rdo, METH_VARARGS,
149 "synthesis of spectral grain"},
153 PyTypeObject Py_pvocType = {
154 PyVarObject_HEAD_INIT (NULL, 0)
158 (destructor) Py_pvoc_del,
168 (ternaryfunc)Py_pvoc_do,
189 (initproc) Py_pvoc_init,