Merge branch 'master' of aubio.org:/git/aubio/aubio into develop
[aubio.git] / python / ext / py-source.c
1 // WARNING: this file is generated, DO NOT EDIT
2
3 // WARNING: if you haven't read the first line yet, please do so
4 #include "aubiowraphell.h"
5
6 typedef struct
7 {
8   PyObject_HEAD
9   aubio_source_t * o;
10   char_t* uri;
11   uint_t samplerate;
12   uint_t hop_size;
13 } Py_source;
14
15 static char Py_source_doc[] = "source object";
16
17 static PyObject *
18 Py_source_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds)
19 {
20   Py_source *self;
21   char_t* uri = NULL;
22   uint_t samplerate = 0;
23   uint_t hop_size = 0;
24   static char *kwlist[] = { "uri", "samplerate", "hop_size", NULL };
25
26   if (!PyArg_ParseTupleAndKeywords (args, kwds, "|sII", kwlist,
27           &uri, &samplerate, &hop_size)) {
28     return NULL;
29   }
30
31   self = (Py_source *) pytype->tp_alloc (pytype, 0);
32
33   if (self == NULL) {
34     return NULL;
35   }
36
37   self->uri = "none";
38   if (uri != NULL) {
39     self->uri = uri;
40   }
41
42   self->samplerate = 0;
43   if ((sint_t)samplerate > 0) {
44     self->samplerate = samplerate;
45   } else if ((sint_t)samplerate < 0) {
46     PyErr_SetString (PyExc_ValueError,
47         "can not use negative value for samplerate");
48     return NULL;
49   }
50
51   self->hop_size = Py_default_vector_length / 2;
52   if ((sint_t)hop_size > 0) {
53     self->hop_size = hop_size;
54   } else if ((sint_t)hop_size < 0) {
55     PyErr_SetString (PyExc_ValueError,
56         "can not use negative value for hop_size");
57     return NULL;
58   }
59
60   return (PyObject *) self;
61 }
62
63 static int
64 Py_source_init (Py_source * self, PyObject * args, PyObject * kwds)
65 {
66   self->o = new_aubio_source ( self->uri, self->samplerate, self->hop_size );
67   if (self->o == NULL) {
68     PyErr_SetString (PyExc_StandardError, "error creating object");
69     return -1;
70   }
71   self->samplerate = aubio_source_get_samplerate ( self->o );
72
73   return 0;
74 }
75
76 AUBIO_DEL(source)
77
78 /* function Py_source_do */
79 static PyObject * 
80 Py_source_do(Py_source * self, PyObject * args)
81 {
82
83
84   /* output vectors prototypes */
85   fvec_t* read_to;
86   uint_t read;
87
88
89
90
91
92   
93   /* creating output read_to as a new_fvec of length self->hop_size */
94   read_to = new_fvec (self->hop_size);
95   read = 0;
96
97
98   /* compute _do function */
99   aubio_source_do (self->o, read_to, &read);
100
101   PyObject *outputs = PyList_New(0);
102   PyList_Append( outputs, (PyObject *)PyAubio_CFvecToArray (read_to));
103   //del_fvec (read_to);
104   PyList_Append( outputs, (PyObject *)PyInt_FromLong (read));
105   return outputs;
106 }
107
108 AUBIO_MEMBERS_START(source)
109   {"uri", T_STRING, offsetof (Py_source, uri), READONLY, ""},
110   {"samplerate", T_INT, offsetof (Py_source, samplerate), READONLY, ""},
111   {"hop_size", T_INT, offsetof (Py_source, hop_size), READONLY, ""},
112 AUBIO_MEMBERS_STOP(source)
113
114
115 static PyObject *
116 Pyaubio_source_get_samplerate (Py_source *self, PyObject *unused)
117 {
118   uint_t tmp = aubio_source_get_samplerate (self->o);
119   return (PyObject *)PyInt_FromLong (tmp);
120 }
121
122 static PyObject *
123 Pyaubio_source_get_channels (Py_source *self, PyObject *unused)
124 {
125   uint_t tmp = aubio_source_get_channels (self->o);
126   return (PyObject *)PyInt_FromLong (tmp);
127 }
128
129 static PyMethodDef Py_source_methods[] = {
130   {"get_samplerate", (PyCFunction) Pyaubio_source_get_samplerate,
131     METH_NOARGS, ""},
132   {"get_channels", (PyCFunction) Pyaubio_source_get_channels,
133     METH_NOARGS, ""},
134   {NULL} /* sentinel */
135 };
136
137 AUBIO_TYPEOBJECT(source, "aubio.source")