History

python/ext/py-source.c: not generated, modified init to get samplerate from aubio_source_t

Paul Brossier committed 12 years ago

Commit d27634d1 parent d7019c45 files · +145 −1Browse files

Showing the changes to python (5 of 5 files). Show all

Unified · Split

5 files
  1. python/ext/aubio-types.h +3 −1
  2. python/ext/aubiomodule.c +3 −0
  3. python/ext/py-source.c +137 −0
  4. python/lib/generator.py +1 −0
  5. python/setup.py +1 −0
python/ext/aubio-types.h+3−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
30 30
31#define Py_default_vector_length 102431#define Py_default_vector_length 1024
32 32
33#define Py_aubio_default_samplerate 4410033#define Py_aubio_default_samplerate 0
34 34
35#if HAVE_AUBIO_DOUBLE35#if HAVE_AUBIO_DOUBLE
36#error "Ouch! Python interface for aubio has not been much tested yet."36#error "Ouch! Python interface for aubio has not been much tested yet."
@@ -68,3 +68,5 @@ extern PyTypeObject Py_fftType; · 31 unmodified lines
68 68
69extern PyTypeObject Py_pvocType;69extern PyTypeObject Py_pvocType;
70 70
71extern PyTypeObject Py_sourceType;
72
python/ext/aubiomodule.c+3−0
@@ -198,6 +198,7 @@ init_aubio (void) · 197 unmodified lines
198 || (PyType_Ready (&Py_filterbankType) < 0)198 || (PyType_Ready (&Py_filterbankType) < 0)
199 || (PyType_Ready (&Py_fftType) < 0)199 || (PyType_Ready (&Py_fftType) < 0)
200 || (PyType_Ready (&Py_pvocType) < 0)200 || (PyType_Ready (&Py_pvocType) < 0)
201 || (PyType_Ready (&Py_sourceType) < 0)
201 // generated objects202 // generated objects
202 || (generated_types_ready() < 0 )203 || (generated_types_ready() < 0 )
203 ) {204 ) {
@@ -226,6 +227,8 @@ init_aubio (void) · 22 unmodified lines
226 PyModule_AddObject (m, "fft", (PyObject *) & Py_fftType);227 PyModule_AddObject (m, "fft", (PyObject *) & Py_fftType);
227 Py_INCREF (&Py_pvocType);228 Py_INCREF (&Py_pvocType);
228 PyModule_AddObject (m, "pvoc", (PyObject *) & Py_pvocType);229 PyModule_AddObject (m, "pvoc", (PyObject *) & Py_pvocType);
230 Py_INCREF (&Py_sourceType);
231 PyModule_AddObject (m, "source", (PyObject *) & Py_sourceType);
229 232
230 // add generated objects233 // add generated objects
231 add_generated_objects(m);234 add_generated_objects(m);
python/ext/py-source.c+137−0
@@ -0,0 +1,137 @@
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
6typedef 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
15static char Py_source_doc[] = "source object";
16
17static PyObject *
18Py_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 = Py_aubio_default_samplerate;
43 if (samplerate > 0) {
44 self->samplerate = samplerate;
45 //} else if (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 (hop_size > 0) {
53 self->hop_size = hop_size;
54 //} else if (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
63static int
64Py_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
76AUBIO_DEL(source)
77
78/* function Py_source_do */
79static PyObject *
80Py_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
108AUBIO_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, ""},
112AUBIO_MEMBERS_STOP(source)
113
114
115static PyObject *
116Pyaubio_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
122static PyObject *
123Pyaubio_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
129static 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
137AUBIO_TYPEOBJECT(source, "aubio.source")
python/lib/generator.py+1−0
@@ -56,6 +56,7 @@ def generate_object_files(output_path): · 55 unmodified lines
56 'pitchyinfft',56 'pitchyinfft',
57 'sink_apple_audio',57 'sink_apple_audio',
58 'sink_sndfile',58 'sink_sndfile',
59 'source',
59 'source_apple_audio',60 'source_apple_audio',
60 'source_sndfile',61 'source_sndfile',
61 'source_avcodec',62 'source_avcodec',
python/setup.py+1−0
@@ -53,6 +53,7 @@ aubio_extension = Extension("aubio._aubio", [ · 52 unmodified lines
53 "ext/py-filterbank.c",53 "ext/py-filterbank.c",
54 "ext/py-fft.c",54 "ext/py-fft.c",
55 "ext/py-phasevoc.c",55 "ext/py-phasevoc.c",
56 "ext/py-source.c",
56 # generated files57 # generated files
57 ] + generated_object_files,58 ] + generated_object_files,
58 include_dirs = include_dirs,59 include_dirs = include_dirs,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t