source: python/ext/py-phasevoc.c @ 2f4d9b7

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 2f4d9b7 was 0e70ef9, checked in by Paul Brossier <piem@piem.org>, 9 years ago

python/{ext/*.c,lib/gen_code.py}: complete PyTypeObject? definitions

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[5652a8c]1#include "aubio-types.h"
[615ac7d]2
[51b9c83]3static char Py_pvoc_doc[] = "pvoc object";
4
[202697a]5typedef struct
6{
7  PyObject_HEAD
8  aubio_pvoc_t * o;
9  uint_t win_s;
10  uint_t hop_s;
[569b363]11  fvec_t vecin;
12  cvec_t cvecin;
[307fdfc]13  PyObject *output;
14  cvec_t c_output;
15  PyObject *routput;
16  fvec_t c_routput;
[202697a]17} Py_pvoc;
18
[615ac7d]19
20static PyObject *
21Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
22{
[0f045b2]23  int win_s = 0, hop_s = 0;
[615ac7d]24  Py_pvoc *self;
[0f045b2]25  static char *kwlist[] = { "win_s", "hop_s", NULL };
[615ac7d]26
[0f045b2]27  if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist,
28          &win_s, &hop_s)) {
[615ac7d]29    return NULL;
30  }
31
32  self = (Py_pvoc *) type->tp_alloc (type, 0);
33
34  if (self == NULL) {
35    return NULL;
36  }
37
38  self->win_s = Py_default_vector_length;
39  self->hop_s = Py_default_vector_length/2;
40
41  if (self == NULL) {
42    return NULL;
43  }
44
45  if (win_s > 0) {
46    self->win_s = win_s;
47  } else if (win_s < 0) {
48    PyErr_SetString (PyExc_ValueError,
49        "can not use negative window size");
50    return NULL;
51  }
52
53  if (hop_s > 0) {
54    self->hop_s = hop_s;
55  } else if (hop_s < 0) {
56    PyErr_SetString (PyExc_ValueError,
57        "can not use negative hop size");
58    return NULL;
59  }
60
[5652a8c]61  return (PyObject *) self;
62}
63
64static int
65Py_pvoc_init (Py_pvoc * self, PyObject * args, PyObject * kwds)
66{
67  self->o = new_aubio_pvoc ( self->win_s, self->hop_s);
68  if (self->o == NULL) {
[ad9f999]69    PyErr_Format(PyExc_RuntimeError,
70        "failed creating pvoc with win_s=%d, hop_s=%d",
71        self->win_s, self->hop_s);
[5652a8c]72    return -1;
73  }
74
[307fdfc]75  self->output = new_py_cvec(self->win_s);
76  self->routput = new_py_fvec(self->hop_s);
[202697a]77
[5652a8c]78  return 0;
[615ac7d]79}
80
81
[202697a]82static void
83Py_pvoc_del (Py_pvoc *self, PyObject *unused)
84{
[307fdfc]85  Py_XDECREF(self->output);
86  Py_XDECREF(self->routput);
[8cf51c4]87  if (self->o) {
88    del_aubio_pvoc(self->o);
89  }
[5c1200a]90  Py_TYPE(self)->tp_free((PyObject *) self);
[202697a]91}
92
[615ac7d]93
[b5bef11]94static PyObject *
[c04d250]95Py_pvoc_do(Py_pvoc * self, PyObject * args)
[615ac7d]96{
97  PyObject *input;
98
99  if (!PyArg_ParseTuple (args, "O", &input)) {
100    return NULL;
101  }
102
[569b363]103  if (!PyAubio_ArrayToCFvec (input, &(self->vecin) )) {
[615ac7d]104    return NULL;
105  }
106
[99aa353]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);
111    return NULL;
112  }
113
[307fdfc]114  Py_INCREF(self->output);
115  if (!PyAubio_PyCvecToCCvec (self->output, &(self->c_output))) {
116    return NULL;
117  }
[615ac7d]118  // compute the function
[307fdfc]119  aubio_pvoc_do (self->o, &(self->vecin), &(self->c_output));
120  return self->output;
[615ac7d]121}
122
[5652a8c]123static PyMemberDef Py_pvoc_members[] = {
[615ac7d]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,
127    "size of the hop"},
[5652a8c]128  { NULL } // sentinel
129};
[615ac7d]130
[307fdfc]131static PyObject *
[c04d250]132Py_pvoc_rdo(Py_pvoc * self, PyObject * args)
[615ac7d]133{
134  PyObject *input;
135  if (!PyArg_ParseTuple (args, "O", &input)) {
136    return NULL;
137  }
138
[92a8800]139  if (!PyAubio_PyCvecToCCvec (input, &(self->cvecin) )) {
[615ac7d]140    return NULL;
141  }
142
[99aa353]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);
147    return NULL;
148  }
149
[307fdfc]150  Py_INCREF(self->routput);
151  if (!PyAubio_ArrayToCFvec(self->routput, &(self->c_routput)) ) {
152    return NULL;
153  }
[615ac7d]154  // compute the function
[307fdfc]155  aubio_pvoc_rdo (self->o, &(self->cvecin), &(self->c_routput));
156  return self->routput;
[615ac7d]157}
158
159static PyMethodDef Py_pvoc_methods[] = {
160  {"rdo", (PyCFunction) Py_pvoc_rdo, METH_VARARGS,
161    "synthesis of spectral grain"},
162  {NULL}
163};
164
[5652a8c]165PyTypeObject Py_pvocType = {
166  PyVarObject_HEAD_INIT (NULL, 0)
167  "aubio.pvoc",
168  sizeof (Py_pvoc),
169  0,
170  (destructor) Py_pvoc_del,
171  0,
172  0,
173  0,
174  0,
175  0,
176  0,
177  0,
178  0,
179  0,
180  (ternaryfunc)Py_pvoc_do,
181  0,
182  0,
183  0,
184  0,
185  Py_TPFLAGS_DEFAULT,
186  Py_pvoc_doc,
187  0,
188  0,
189  0,
190  0,
191  0,
192  0,
193  Py_pvoc_methods,
194  Py_pvoc_members,
195  0,
196  0,
197  0,
198  0,
199  0,
200  0,
201  (initproc) Py_pvoc_init,
202  0,
203  Py_pvoc_new,
[0e70ef9]204  0,
205  0,
206  0,
207  0,
208  0,
209  0,
210  0,
211  0,
212  0,
[5652a8c]213};
Note: See TracBrowser for help on using the repository browser.