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

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

ext/: no more hell, use plain c

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