1 | #include "aubiowraphell.h" |
---|
2 | |
---|
3 | static char Py_pvoc_doc[] = "pvoc object"; |
---|
4 | |
---|
5 | AUBIO_DECLARE(pvoc, uint_t win_s; uint_t hop_s) |
---|
6 | |
---|
7 | //AUBIO_NEW(pvoc) |
---|
8 | static PyObject * |
---|
9 | Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds) |
---|
10 | { |
---|
11 | int win_s = 0, hop_s = 0; |
---|
12 | Py_pvoc *self; |
---|
13 | static char *kwlist[] = { "win_s", "hop_s", NULL }; |
---|
14 | |
---|
15 | if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist, |
---|
16 | &win_s, &hop_s)) { |
---|
17 | return NULL; |
---|
18 | } |
---|
19 | |
---|
20 | self = (Py_pvoc *) type->tp_alloc (type, 0); |
---|
21 | |
---|
22 | if (self == NULL) { |
---|
23 | return NULL; |
---|
24 | } |
---|
25 | |
---|
26 | self->win_s = Py_default_vector_length; |
---|
27 | self->hop_s = Py_default_vector_length/2; |
---|
28 | |
---|
29 | if (self == NULL) { |
---|
30 | return NULL; |
---|
31 | } |
---|
32 | |
---|
33 | if (win_s > 0) { |
---|
34 | self->win_s = win_s; |
---|
35 | } else if (win_s < 0) { |
---|
36 | PyErr_SetString (PyExc_ValueError, |
---|
37 | "can not use negative window size"); |
---|
38 | return NULL; |
---|
39 | } |
---|
40 | |
---|
41 | if (hop_s > 0) { |
---|
42 | self->hop_s = hop_s; |
---|
43 | } else if (hop_s < 0) { |
---|
44 | PyErr_SetString (PyExc_ValueError, |
---|
45 | "can not use negative hop size"); |
---|
46 | return NULL; |
---|
47 | } |
---|
48 | |
---|
49 | return (PyObject *) self; |
---|
50 | } |
---|
51 | |
---|
52 | |
---|
53 | AUBIO_INIT(pvoc, self->win_s, self->hop_s) |
---|
54 | |
---|
55 | AUBIO_DEL(pvoc) |
---|
56 | |
---|
57 | static PyObject * |
---|
58 | Py_pvoc_do(PyObject * self, PyObject * args) |
---|
59 | { |
---|
60 | PyObject *input; |
---|
61 | Py_fvec *vec; |
---|
62 | Py_cvec *output; |
---|
63 | |
---|
64 | if (!PyArg_ParseTuple (args, "O", &input)) { |
---|
65 | return NULL; |
---|
66 | } |
---|
67 | |
---|
68 | vec = PyAubio_ArrayToFvec (input); |
---|
69 | |
---|
70 | if (vec == NULL) { |
---|
71 | return NULL; |
---|
72 | } |
---|
73 | |
---|
74 | output = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType); |
---|
75 | output->length = ((Py_pvoc *) self)->win_s; |
---|
76 | output->o = new_cvec(((Py_pvoc *) self)->win_s); |
---|
77 | |
---|
78 | // compute the function |
---|
79 | aubio_pvoc_do (((Py_pvoc *)self)->o, vec->o, output->o); |
---|
80 | Py_INCREF(output); |
---|
81 | return (PyObject *)output; |
---|
82 | //return (PyObject *)PyAubio_CvecToArray(output); |
---|
83 | } |
---|
84 | |
---|
85 | AUBIO_MEMBERS_START(pvoc) |
---|
86 | {"win_s", T_INT, offsetof (Py_pvoc, win_s), READONLY, |
---|
87 | "size of the window"}, |
---|
88 | {"hop_s", T_INT, offsetof (Py_pvoc, hop_s), READONLY, |
---|
89 | "size of the hop"}, |
---|
90 | AUBIO_MEMBERS_STOP(pvoc) |
---|
91 | |
---|
92 | static PyObject * |
---|
93 | Py_pvoc_rdo(PyObject * self, PyObject * args) |
---|
94 | { |
---|
95 | PyObject *input; |
---|
96 | Py_cvec *vec; |
---|
97 | Py_fvec *output; |
---|
98 | |
---|
99 | if (!PyArg_ParseTuple (args, "O", &input)) { |
---|
100 | return NULL; |
---|
101 | } |
---|
102 | |
---|
103 | vec = PyAubio_ArrayToCvec (input); |
---|
104 | |
---|
105 | if (vec == NULL) { |
---|
106 | return NULL; |
---|
107 | } |
---|
108 | |
---|
109 | output = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType); |
---|
110 | output->length = ((Py_pvoc *) self)->hop_s; |
---|
111 | output->o = new_fvec(output->length); |
---|
112 | |
---|
113 | // compute the function |
---|
114 | aubio_pvoc_rdo (((Py_pvoc *)self)->o, vec->o, output->o); |
---|
115 | return (PyObject *)PyAubio_FvecToArray(output); |
---|
116 | } |
---|
117 | |
---|
118 | static PyMethodDef Py_pvoc_methods[] = { |
---|
119 | {"rdo", (PyCFunction) Py_pvoc_rdo, METH_VARARGS, |
---|
120 | "synthesis of spectral grain"}, |
---|
121 | {NULL} |
---|
122 | }; |
---|
123 | |
---|
124 | AUBIO_TYPEOBJECT(pvoc, "aubio.pvoc") |
---|