1 #include "aubio-types.h"
18 Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
20 int win_s = 0, hop_s = 0;
22 static char *kwlist[] = { "win_s", "hop_s", NULL };
24 if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist,
29 self = (Py_pvoc *) type->tp_alloc (type, 0);
35 self->win_s = Py_default_vector_length;
36 self->hop_s = Py_default_vector_length/2;
44 } else if (win_s < 0) {
45 PyErr_SetString (PyExc_ValueError,
46 "can not use negative window size");
52 } else if (hop_s < 0) {
53 PyErr_SetString (PyExc_ValueError,
54 "can not use negative hop size");
58 return (PyObject *) self;
62 Py_pvoc_init (Py_pvoc * self, PyObject * args, PyObject * kwds)
64 self->o = new_aubio_pvoc ( self->win_s, self->hop_s);
65 if (self->o == NULL) {
67 sprintf(errstr, "error creating pvoc with %d, %d", self->win_s, self->hop_s);
68 PyErr_SetString (PyExc_RuntimeError, errstr);
72 self->output = new_cvec(self->win_s);
73 self->py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
74 self->routput = new_fvec(self->hop_s);
81 Py_pvoc_del (Py_pvoc *self, PyObject *unused)
83 del_aubio_pvoc(self->o);
84 del_cvec(self->output);
85 del_fvec(self->routput);
86 Py_TYPE(self)->tp_free((PyObject *) self);
91 Py_pvoc_do(Py_pvoc * self, PyObject * args)
95 if (!PyArg_ParseTuple (args, "O", &input)) {
99 if (!PyAubio_ArrayToCFvec (input, &(self->vecin) )) {
103 // compute the function
104 aubio_pvoc_do (self->o, &(self->vecin), self->output);
106 Py_cvec * py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
107 PyObject* output = PyAubio_CCvecToPyCvec(self->output, py_out);
110 // convert cvec to py_cvec, incrementing refcount to keep a copy
111 return PyAubio_CCvecToPyCvec(self->output, self->py_out);
115 static PyMemberDef Py_pvoc_members[] = {
116 {"win_s", T_INT, offsetof (Py_pvoc, win_s), READONLY,
117 "size of the window"},
118 {"hop_s", T_INT, offsetof (Py_pvoc, hop_s), READONLY,
124 Py_pvoc_rdo(Py_pvoc * self, PyObject * args)
127 if (!PyArg_ParseTuple (args, "O", &input)) {
131 if (!PyAubio_ArrayToCCvec (input, &(self->cvecin) )) {
135 // compute the function
136 aubio_pvoc_rdo (self->o, &(self->cvecin), self->routput);
137 return PyAubio_CFvecToArray(self->routput);
140 static PyMethodDef Py_pvoc_methods[] = {
141 {"rdo", (PyCFunction) Py_pvoc_rdo, METH_VARARGS,
142 "synthesis of spectral grain"},
146 PyTypeObject Py_pvocType = {
147 PyVarObject_HEAD_INIT (NULL, 0)
151 (destructor) Py_pvoc_del,
161 (ternaryfunc)Py_pvoc_do,
182 (initproc) Py_pvoc_init,