source: python/ext/py-phasevoc.c @ 5c1200a

feature/autosinkfeature/constantqfeature/pitchshiftfeature/pydocstringsfeature/timestretchpitchshiftsamplertimestretchyinfft+
Last change on this file since 5c1200a was 5c1200a, checked in by Paul Brossier <piem@piem.org>, 3 years ago

python/ext: continue preparing for python 3

  • Property mode set to 100644
File size: 2.5 KB
Line 
1#include "aubiowraphell.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
16//AUBIO_NEW(pvoc)
17static PyObject *
18Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
19{
20  int win_s = 0, hop_s = 0;
21  Py_pvoc *self;
22  static char *kwlist[] = { "win_s", "hop_s", NULL };
23
24  if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist,
25          &win_s, &hop_s)) {
26    return NULL;
27  }
28
29  self = (Py_pvoc *) type->tp_alloc (type, 0);
30
31  if (self == NULL) {
32    return NULL;
33  }
34
35  self->win_s = Py_default_vector_length;
36  self->hop_s = Py_default_vector_length/2;
37
38  if (self == NULL) {
39    return NULL;
40  }
41
42  if (win_s > 0) {
43    self->win_s = win_s;
44  } else if (win_s < 0) {
45    PyErr_SetString (PyExc_ValueError,
46        "can not use negative window size");
47    return NULL;
48  }
49
50  if (hop_s > 0) {
51    self->hop_s = hop_s;
52  } else if (hop_s < 0) {
53    PyErr_SetString (PyExc_ValueError,
54        "can not use negative hop size");
55    return NULL;
56  }
57
58  self->output = new_cvec(self->win_s);
59  self->routput = new_fvec(self->hop_s);
60
61  return (PyObject *) self;
62}
63
64
65AUBIO_INIT(pvoc, self->win_s, self->hop_s)
66
67static void
68Py_pvoc_del (Py_pvoc *self, PyObject *unused)
69{
70  del_aubio_pvoc(self->o);
71  del_cvec(self->output);
72  del_fvec(self->routput);
73  Py_TYPE(self)->tp_free((PyObject *) self);
74}
75
76
77static PyObject * 
78Py_pvoc_do(Py_pvoc * self, PyObject * args)
79{
80  PyObject *input;
81  fvec_t *vec;
82
83  if (!PyArg_ParseTuple (args, "O", &input)) {
84    return NULL;
85  }
86
87  vec = PyAubio_ArrayToCFvec (input);
88
89  if (vec == NULL) {
90    return NULL;
91  }
92
93  // compute the function
94  aubio_pvoc_do (self->o, vec, self->output);
95  return (PyObject *)PyAubio_CCvecToPyCvec(self->output);
96}
97
98AUBIO_MEMBERS_START(pvoc) 
99  {"win_s", T_INT, offsetof (Py_pvoc, win_s), READONLY,
100    "size of the window"},
101  {"hop_s", T_INT, offsetof (Py_pvoc, hop_s), READONLY,
102    "size of the hop"},
103AUBIO_MEMBERS_STOP(pvoc)
104
105static PyObject * 
106Py_pvoc_rdo(Py_pvoc * self, PyObject * args)
107{
108  PyObject *input;
109  cvec_t *vec;
110  if (!PyArg_ParseTuple (args, "O", &input)) {
111    return NULL;
112  }
113
114  vec = PyAubio_ArrayToCCvec (input);
115
116  if (vec == NULL) {
117    return NULL;
118  }
119
120  // compute the function
121  aubio_pvoc_rdo (self->o, vec, self->routput);
122  return (PyObject *)PyAubio_CFvecToArray(self->routput);
123}
124
125static PyMethodDef Py_pvoc_methods[] = {
126  {"rdo", (PyCFunction) Py_pvoc_rdo, METH_VARARGS,
127    "synthesis of spectral grain"},
128  {NULL}
129};
130
131AUBIO_TYPEOBJECT(pvoc, "aubio.pvoc")
Note: See TracBrowser for help on using the repository browser.