source: python/ext/py-phasevoc.c @ a41b1ef

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

python/ext/py-phasevoc.c: re-added Py_pvoc_doc

  • Property mode set to 100644
File size: 3.5 KB
Line 
1#include "aubio-types.h"
2
3static char Py_pvoc_doc[] = "pvoc object";
4
5typedef struct
6{
7  PyObject_HEAD
8  aubio_pvoc_t * o;
9  uint_t win_s;
10  uint_t hop_s;
11  fvec_t vecin;
12  cvec_t *output;
13  Py_cvec *py_out;
14  cvec_t cvecin;
15  fvec_t *routput;
16} Py_pvoc;
17
18
19static PyObject *
20Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
21{
22  int win_s = 0, hop_s = 0;
23  Py_pvoc *self;
24  static char *kwlist[] = { "win_s", "hop_s", NULL };
25
26  if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist,
27          &win_s, &hop_s)) {
28    return NULL;
29  }
30
31  self = (Py_pvoc *) type->tp_alloc (type, 0);
32
33  if (self == NULL) {
34    return NULL;
35  }
36
37  self->win_s = Py_default_vector_length;
38  self->hop_s = Py_default_vector_length/2;
39
40  if (self == NULL) {
41    return NULL;
42  }
43
44  if (win_s > 0) {
45    self->win_s = win_s;
46  } else if (win_s < 0) {
47    PyErr_SetString (PyExc_ValueError,
48        "can not use negative window size");
49    return NULL;
50  }
51
52  if (hop_s > 0) {
53    self->hop_s = hop_s;
54  } else if (hop_s < 0) {
55    PyErr_SetString (PyExc_ValueError,
56        "can not use negative hop size");
57    return NULL;
58  }
59
60  return (PyObject *) self;
61}
62
63static int
64Py_pvoc_init (Py_pvoc * self, PyObject * args, PyObject * kwds)
65{
66  self->o = new_aubio_pvoc ( self->win_s, self->hop_s);
67  if (self->o == NULL) {
68    char_t errstr[30];
69    sprintf(errstr, "error creating pvoc with %d, %d", self->win_s, self->hop_s);
70    PyErr_SetString (PyExc_RuntimeError, errstr);
71    return -1;
72  }
73
74  self->output = new_cvec(self->win_s);
75  self->py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
76  self->routput = new_fvec(self->hop_s);
77
78  return 0;
79}
80
81
82static void
83Py_pvoc_del (Py_pvoc *self, PyObject *unused)
84{
85  del_aubio_pvoc(self->o);
86  del_cvec(self->output);
87  del_fvec(self->routput);
88  Py_TYPE(self)->tp_free((PyObject *) self);
89}
90
91
92static PyObject *
93Py_pvoc_do(Py_pvoc * self, PyObject * args)
94{
95  PyObject *input;
96
97  if (!PyArg_ParseTuple (args, "O", &input)) {
98    return NULL;
99  }
100
101  if (!PyAubio_ArrayToCFvec (input, &(self->vecin) )) {
102    return NULL;
103  }
104
105  // compute the function
106  aubio_pvoc_do (self->o, &(self->vecin), self->output);
107#if 0
108  Py_cvec * py_out = (Py_cvec*) PyObject_New (Py_cvec, &Py_cvecType);
109  PyObject* output = PyAubio_CCvecToPyCvec(self->output, py_out);
110  return output;
111#else
112  // convert cvec to py_cvec, incrementing refcount to keep a copy
113  return PyAubio_CCvecToPyCvec(self->output, self->py_out);
114#endif
115}
116
117static PyMemberDef Py_pvoc_members[] = {
118  {"win_s", T_INT, offsetof (Py_pvoc, win_s), READONLY,
119    "size of the window"},
120  {"hop_s", T_INT, offsetof (Py_pvoc, hop_s), READONLY,
121    "size of the hop"},
122  { NULL } // sentinel
123};
124
125static PyObject * 
126Py_pvoc_rdo(Py_pvoc * self, PyObject * args)
127{
128  PyObject *input;
129  if (!PyArg_ParseTuple (args, "O", &input)) {
130    return NULL;
131  }
132
133  if (!PyAubio_ArrayToCCvec (input, &(self->cvecin) )) {
134    return NULL;
135  }
136
137  // compute the function
138  aubio_pvoc_rdo (self->o, &(self->cvecin), self->routput);
139  return PyAubio_CFvecToArray(self->routput);
140}
141
142static PyMethodDef Py_pvoc_methods[] = {
143  {"rdo", (PyCFunction) Py_pvoc_rdo, METH_VARARGS,
144    "synthesis of spectral grain"},
145  {NULL}
146};
147
148PyTypeObject Py_pvocType = {
149  PyVarObject_HEAD_INIT (NULL, 0)
150  "aubio.pvoc",
151  sizeof (Py_pvoc),
152  0,
153  (destructor) Py_pvoc_del,
154  0,
155  0,
156  0,
157  0,
158  0,
159  0,
160  0,
161  0,
162  0,
163  (ternaryfunc)Py_pvoc_do,
164  0,
165  0,
166  0,
167  0,
168  Py_TPFLAGS_DEFAULT,
169  Py_pvoc_doc,
170  0,
171  0,
172  0,
173  0,
174  0,
175  0,
176  Py_pvoc_methods,
177  Py_pvoc_members,
178  0,
179  0,
180  0,
181  0,
182  0,
183  0,
184  (initproc) Py_pvoc_init,
185  0,
186  Py_pvoc_new,
187};
Note: See TracBrowser for help on using the repository browser.