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; uint_t channels) |
---|
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, channels = 0; |
---|
12 | Py_pvoc *self; |
---|
13 | static char *kwlist[] = { "win_s", "hop_s", "channels", NULL }; |
---|
14 | |
---|
15 | if (!PyArg_ParseTupleAndKeywords (args, kwds, "|III", kwlist, |
---|
16 | &win_s, &hop_s, &channels)) { |
---|
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 | self->channels = Py_default_vector_channels; |
---|
29 | |
---|
30 | if (self == NULL) { |
---|
31 | return NULL; |
---|
32 | } |
---|
33 | |
---|
34 | if (win_s > 0) { |
---|
35 | self->win_s = win_s; |
---|
36 | } else if (win_s < 0) { |
---|
37 | PyErr_SetString (PyExc_ValueError, |
---|
38 | "can not use negative window size"); |
---|
39 | return NULL; |
---|
40 | } |
---|
41 | |
---|
42 | if (hop_s > 0) { |
---|
43 | self->hop_s = hop_s; |
---|
44 | } else if (hop_s < 0) { |
---|
45 | PyErr_SetString (PyExc_ValueError, |
---|
46 | "can not use negative hop size"); |
---|
47 | return NULL; |
---|
48 | } |
---|
49 | |
---|
50 | if (channels > 0) { |
---|
51 | self->channels = channels; |
---|
52 | } else if (channels < 0) { |
---|
53 | PyErr_SetString (PyExc_ValueError, |
---|
54 | "can not use negative number of filters"); |
---|
55 | return NULL; |
---|
56 | } |
---|
57 | |
---|
58 | return (PyObject *) self; |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | AUBIO_INIT(pvoc, self->win_s, self->hop_s, self->channels) |
---|
63 | |
---|
64 | AUBIO_DEL(pvoc) |
---|
65 | |
---|
66 | static PyObject * |
---|
67 | Py_pvoc_do(PyObject * self, PyObject * args) |
---|
68 | { |
---|
69 | PyObject *input; |
---|
70 | Py_fvec *vec; |
---|
71 | Py_cvec *output; |
---|
72 | |
---|
73 | if (!PyArg_ParseTuple (args, "O", &input)) { |
---|
74 | return NULL; |
---|
75 | } |
---|
76 | |
---|
77 | vec = PyAubio_ArrayToFvec (input); |
---|
78 | |
---|
79 | if (vec == NULL) { |
---|
80 | return NULL; |
---|
81 | } |
---|
82 | |
---|
83 | output = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType); |
---|
84 | output->channels = vec->channels; |
---|
85 | output->length = ((Py_pvoc *) self)->win_s; |
---|
86 | output->o = new_cvec(((Py_pvoc *) self)->win_s, vec->channels); |
---|
87 | |
---|
88 | // compute the function |
---|
89 | aubio_pvoc_do (((Py_pvoc *)self)->o, vec->o, output->o); |
---|
90 | Py_INCREF(output); |
---|
91 | return (PyObject *)output; |
---|
92 | //return (PyObject *)PyAubio_CvecToArray(output); |
---|
93 | } |
---|
94 | |
---|
95 | AUBIO_MEMBERS_START(pvoc) |
---|
96 | {"win_s", T_INT, offsetof (Py_pvoc, win_s), READONLY, |
---|
97 | "size of the window"}, |
---|
98 | {"hop_s", T_INT, offsetof (Py_pvoc, hop_s), READONLY, |
---|
99 | "size of the hop"}, |
---|
100 | {"channels", T_INT, offsetof (Py_pvoc, channels), READONLY, |
---|
101 | "number of channels"}, |
---|
102 | AUBIO_MEMBERS_STOP(pvoc) |
---|
103 | |
---|
104 | static PyObject * |
---|
105 | Py_pvoc_rdo(PyObject * self, PyObject * args) |
---|
106 | { |
---|
107 | PyObject *input; |
---|
108 | Py_cvec *vec; |
---|
109 | Py_fvec *output; |
---|
110 | |
---|
111 | if (!PyArg_ParseTuple (args, "O", &input)) { |
---|
112 | return NULL; |
---|
113 | } |
---|
114 | |
---|
115 | vec = PyAubio_ArrayToCvec (input); |
---|
116 | |
---|
117 | if (vec == NULL) { |
---|
118 | return NULL; |
---|
119 | } |
---|
120 | |
---|
121 | output = (Py_fvec*) PyObject_New (Py_fvec, &Py_fvecType); |
---|
122 | output->channels = vec->channels; |
---|
123 | output->length = ((Py_pvoc *) self)->hop_s; |
---|
124 | output->o = new_fvec(output->length, output->channels); |
---|
125 | |
---|
126 | // compute the function |
---|
127 | aubio_pvoc_rdo (((Py_pvoc *)self)->o, vec->o, output->o); |
---|
128 | return (PyObject *)PyAubio_FvecToArray(output); |
---|
129 | } |
---|
130 | |
---|
131 | static PyMethodDef Py_pvoc_methods[] = { |
---|
132 | {"rdo", (PyCFunction) Py_pvoc_rdo, METH_VARARGS, |
---|
133 | "synthesis of spectral grain"}, |
---|
134 | {NULL} |
---|
135 | }; |
---|
136 | |
---|
137 | AUBIO_TYPEOBJECT(pvoc, "aubio.pvoc") |
---|