source: python/ext/py-sink.c @ 3cc3fd8

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

python/ext/py-{source,sink}.c: use _close in .close()

  • Property mode set to 100644
File size: 2.0 KB
Line 
1#include "aubiowraphell.h"
2
3typedef struct
4{
5  PyObject_HEAD
6  aubio_sink_t * o;
7  char_t* uri;
8  uint_t samplerate;
9} Py_sink;
10
11static char Py_sink_doc[] = "sink object";
12
13static PyObject *
14Py_sink_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds)
15{
16  Py_sink *self;
17  char_t* uri = NULL;
18  uint_t samplerate = 0;
19  static char *kwlist[] = { "uri", "samplerate", NULL };
20
21  if (!PyArg_ParseTupleAndKeywords (args, kwds, "|sI", kwlist,
22          &uri, &samplerate)) {
23    return NULL;
24  }
25
26  self = (Py_sink *) pytype->tp_alloc (pytype, 0);
27
28  if (self == NULL) {
29    return NULL;
30  }
31
32  self->uri = "none";
33  if (uri != NULL) {
34    self->uri = uri;
35  }
36
37  self->samplerate = Py_aubio_default_samplerate;
38  if ((sint_t)samplerate > 0) {
39    self->samplerate = samplerate;
40  } else if ((sint_t)samplerate < 0) {
41    PyErr_SetString (PyExc_ValueError,
42        "can not use negative value for samplerate");
43    return NULL;
44  }
45
46  return (PyObject *) self;
47}
48
49AUBIO_INIT(sink , self->uri, self->samplerate)
50
51AUBIO_DEL(sink)
52
53/* function Py_sink_do */
54static PyObject * 
55Py_sink_do(Py_sink * self, PyObject * args)
56{
57  /* input vectors python prototypes */
58  PyObject * write_data_obj;
59
60  /* input vectors prototypes */
61  fvec_t* write_data;
62  uint_t write;
63
64
65  if (!PyArg_ParseTuple (args, "OI", &write_data_obj, &write)) {
66    return NULL;
67  }
68
69
70  /* input vectors parsing */
71  write_data = PyAubio_ArrayToCFvec (write_data_obj);
72
73  if (write_data == NULL) {
74    return NULL;
75  }
76
77 
78 
79
80
81  /* compute _do function */
82  aubio_sink_do (self->o, write_data, write);
83
84  Py_RETURN_NONE;
85}
86
87AUBIO_MEMBERS_START(sink)
88  {"uri", T_STRING, offsetof (Py_sink, uri), READONLY, ""},
89  {"samplerate", T_INT, offsetof (Py_sink, samplerate), READONLY, ""},
90AUBIO_MEMBERS_STOP(sink)
91
92static PyObject *
93Pyaubio_sink_close (Py_sink *self, PyObject *unused)
94{
95  aubio_sink_close (self->o);
96  Py_RETURN_NONE;
97}
98
99static PyMethodDef Py_sink_methods[] = {
100  {"close", (PyCFunction) Pyaubio_sink_close,
101    METH_NOARGS, ""},
102  {NULL} /* sentinel */
103};
104
105AUBIO_TYPEOBJECT(sink, "aubio.sink")
Note: See TracBrowser for help on using the repository browser.