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

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

python/: move source files to ext/

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[615ac7d]1#include "aubiowraphell.h"
2
3static char Py_pvoc_doc[] = "pvoc object";
4
[0f045b2]5AUBIO_DECLARE(pvoc, uint_t win_s; uint_t hop_s)
[615ac7d]6
7//AUBIO_NEW(pvoc)
8static PyObject *
9Py_pvoc_new (PyTypeObject * type, PyObject * args, PyObject * kwds)
10{
[0f045b2]11  int win_s = 0, hop_s = 0;
[615ac7d]12  Py_pvoc *self;
[0f045b2]13  static char *kwlist[] = { "win_s", "hop_s", NULL };
[615ac7d]14
[0f045b2]15  if (!PyArg_ParseTupleAndKeywords (args, kwds, "|II", kwlist,
16          &win_s, &hop_s)) {
[615ac7d]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
29  if (self == NULL) {
30    return NULL;
31  }
32
33  if (win_s > 0) {
34    self->win_s = win_s;
35  } else if (win_s < 0) {
36    PyErr_SetString (PyExc_ValueError,
37        "can not use negative window size");
38    return NULL;
39  }
40
41  if (hop_s > 0) {
42    self->hop_s = hop_s;
43  } else if (hop_s < 0) {
44    PyErr_SetString (PyExc_ValueError,
45        "can not use negative hop size");
46    return NULL;
47  }
48
49  return (PyObject *) self;
50}
51
52
[0f045b2]53AUBIO_INIT(pvoc, self->win_s, self->hop_s)
[615ac7d]54
55AUBIO_DEL(pvoc)
56
57static PyObject * 
[c04d250]58Py_pvoc_do(Py_pvoc * self, PyObject * args)
[615ac7d]59{
60  PyObject *input;
[c04d250]61  fvec_t *vec;
62  cvec_t *output;
[615ac7d]63
64  if (!PyArg_ParseTuple (args, "O", &input)) {
65    return NULL;
66  }
67
[c04d250]68  vec = PyAubio_ArrayToCFvec (input);
[615ac7d]69
70  if (vec == NULL) {
71    return NULL;
72  }
73
[c04d250]74  output = new_cvec(self->win_s);
[615ac7d]75
76  // compute the function
[c04d250]77  aubio_pvoc_do (self->o, vec, output);
78  return (PyObject *)PyAubio_CCvecToPyCvec(output);
[615ac7d]79}
80
81AUBIO_MEMBERS_START(pvoc) 
82  {"win_s", T_INT, offsetof (Py_pvoc, win_s), READONLY,
83    "size of the window"},
84  {"hop_s", T_INT, offsetof (Py_pvoc, hop_s), READONLY,
85    "size of the hop"},
86AUBIO_MEMBERS_STOP(pvoc)
87
88static PyObject * 
[c04d250]89Py_pvoc_rdo(Py_pvoc * self, PyObject * args)
[615ac7d]90{
91  PyObject *input;
[c04d250]92  cvec_t *vec;
93  fvec_t *output;
[615ac7d]94
95  if (!PyArg_ParseTuple (args, "O", &input)) {
96    return NULL;
97  }
98
[c04d250]99  vec = PyAubio_ArrayToCCvec (input);
[615ac7d]100
101  if (vec == NULL) {
102    return NULL;
103  }
104
[c04d250]105  output = new_fvec(self->hop_s);
[615ac7d]106
107  // compute the function
[c04d250]108  aubio_pvoc_rdo (self->o, vec, output);
109  return (PyObject *)PyAubio_CFvecToArray(output);
[615ac7d]110}
111
112static PyMethodDef Py_pvoc_methods[] = {
113  {"rdo", (PyCFunction) Py_pvoc_rdo, METH_VARARGS,
114    "synthesis of spectral grain"},
115  {NULL}
116};
117
118AUBIO_TYPEOBJECT(pvoc, "aubio.pvoc")
Note: See TracBrowser for help on using the repository browser.