History

Merge branch 'master' of aubio.org:/git/aubio/aubio into develop

Paul Brossier committed 12 years ago

Commit 21234ee2 parents 1573b16 c3c630585 files · +603 −934Browse files

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

Unified · Split

12 files
  1. python/demos/demo_bpm_extract.py +0 −0
  2. python/demos/demo_mel-energy.py +2 −1
  3. python/demos/demo_pitch.py +8 −4
  4. python/demos/demo_specdesc.py +1 −1
  5. python/ext/aubio-types.h +2 −0
  6. python/ext/aubiomodule.c +3 −0
  7. python/ext/aubioproxy.c +21 −3
  8. python/ext/py-fft.c +0 −4
  9. python/ext/py-source.c +137 −0
  10. python/lib/gen_pyobject.py +2 −2
  11. python/lib/generator.py +1 −0
  12. python/setup.py +1 −0
python/demos/demo_bpm_extract.py+0−0

File mode changed from 100644 to 100755.

python/demos/demo_mel-energy.py+2−1
@@ -61,8 +61,9 @@ if 1: · 60 unmodified lines
6161 ax.xaxis.set_visible(False)
6262 ax.yaxis.set_visible(False)
6363 ax.axis(xmax = all_desc_times[-1], xmin = all_desc_times[0])
64− ax.annotate('band %d' % i, xy=(-10, 10), xycoords='axes points',
64+ ax.annotate('band %d' % i, xy=(-10, 0), xycoords='axes points',
6565 horizontalalignment='right', verticalalignment='bottom',
66+ size = 'xx-small',
6667 )
6768 set_xlabels_sample2time( ax, all_desc_times[-1], samplerate)
6869 #plt.ylabel('spectral descriptor value')
python/demos/demo_pitch.py+8−4
@@ -56,9 +56,11 @@ confidences = array(confidences[skip:]) · 55 unmodified lines
5656 times = [t * hop_s for t in range(len(pitches))]
5757
5858 fig = plt.figure()
59+
5960 ax1 = fig.add_subplot(311)
6061 ax1 = get_waveform_plot(filename, samplerate = samplerate, block_size = hop_s, ax = ax1)
61−ax1.set_xticklabels([])
62+plt.setp(ax1.get_xticklabels(), visible = False)
63+ax1.set_xlabel('')
6264
6365 def array_from_text_file(filename, dtype = 'float'):
6466 import os.path
@@ -87,7 +89,8 @@ cleaned_pitches = ma.masked_where(confidences < tolerance, cleaned_pitches) · 22 unmodified lines
8789 ax2.plot(times, cleaned_pitches, '.-')
8890 #ax2.axis( ymin = 0.9 * cleaned_pitches.min(), ymax = 1.1 * cleaned_pitches.max() )
8991 #ax2.axis( ymin = 55, ymax = 70 )
90−ax2.set_xticklabels([])
92+plt.setp(ax2.get_xticklabels(), visible = False)
93+ax2.set_ylabel('f0 (Hz)')
9194
9295 # plot confidence
9396 ax3 = fig.add_subplot(313, sharex = ax1)
@@ -96,6 +99,7 @@ ax3.plot(times, confidences) · 2 unmodified lines
9699 # draw a line at tolerance
97100 ax3.plot(times, [tolerance]*len(confidences))
98101 ax3.axis( xmin = times[0], xmax = times[-1])
99−plt.show()
102+ax3.set_ylabel('condidence')
100103 set_xlabels_sample2time(ax3, times[-1], samplerate)
101−#plt.savefig(os.path.basename(filename) + '.png', dpi=200)
104+plt.show()
105+#plt.savefig(os.path.basename(filename) + '.svg')
python/demos/demo_specdesc.py+1−1
@@ -71,7 +71,7 @@ if 1: · 70 unmodified lines
7171 ax.xaxis.set_visible(False)
7272 ax.yaxis.set_visible(False)
7373 ax.axis(xmax = all_desc_times[-1], xmin = all_desc_times[0])
74− ax.annotate(method, xy=(-10, 10), xycoords='axes points',
74+ ax.annotate(method, xy=(-10, 0), xycoords='axes points',
7575 horizontalalignment='right', verticalalignment='bottom',
7676 )
7777 set_xlabels_sample2time(ax, all_desc_times[-1], samplerate)
python/ext/aubio-types.h+2−0
@@ -68,3 +68,5 @@ extern PyTypeObject Py_fftType; · 67 unmodified lines
6868
6969 extern PyTypeObject Py_pvocType;
7070
71+extern PyTypeObject Py_sourceType;
72+
python/ext/aubiomodule.c+3−0
@@ -198,6 +198,7 @@ init_aubio (void) · 197 unmodified lines
198198 || (PyType_Ready (&Py_filterbankType) < 0)
199199 || (PyType_Ready (&Py_fftType) < 0)
200200 || (PyType_Ready (&Py_pvocType) < 0)
201+ || (PyType_Ready (&Py_sourceType) < 0)
201202 // generated objects
202203 || (generated_types_ready() < 0 )
203204 ) {
@@ -226,6 +227,8 @@ init_aubio (void) · 22 unmodified lines
226227 PyModule_AddObject (m, "fft", (PyObject *) & Py_fftType);
227228 Py_INCREF (&Py_pvocType);
228229 PyModule_AddObject (m, "pvoc", (PyObject *) & Py_pvocType);
230+ Py_INCREF (&Py_sourceType);
231+ PyModule_AddObject (m, "source", (PyObject *) & Py_sourceType);
229232
230233 // add generated objects
231234 add_generated_objects(m);
python/ext/aubioproxy.c+21−3
@@ -35,7 +35,13 @@ PyAubio_ArrayToCFvec (PyObject *input) { · 34 unmodified lines
3535 // vec = new_fvec (vec->length);
3636 // no need to really allocate fvec, just its struct member
3737 vec = (fvec_t *)malloc(sizeof(fvec_t));
38− vec->length = PyArray_SIZE ((PyArrayObject *)array);
38+ long length = PyArray_SIZE ((PyArrayObject *)array);
39+ if (length > 0) {
40+ vec->length = (uint_t)length;
41+ } else {
42+ PyErr_SetString (PyExc_ValueError, "input array size should be greater than 0");
43+ goto fail;
44+ }
3945 vec->data = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)array, 0);
4046
4147 } else if (PyObject_TypeCheck (input, &PyList_Type)) {
@@ -130,8 +136,20 @@ PyAubio_ArrayToCFmat (PyObject *input) { · 88 unmodified lines
130136
131137 // no need to really allocate fvec, just its struct member
132138 mat = (fmat_t *)malloc(sizeof(fmat_t));
133− mat->length = PyArray_DIM ((PyArrayObject *)array, 1);
134− mat->height = PyArray_DIM ((PyArrayObject *)array, 0);
139+ long length = PyArray_DIM ((PyArrayObject *)array, 1);
140+ if (length > 0) {
141+ mat->length = (uint_t)length;
142+ } else {
143+ PyErr_SetString (PyExc_ValueError, "input array dimension 1 should be greater than 0");
144+ goto fail;
145+ }
146+ long height = PyArray_DIM ((PyArrayObject *)array, 0);
147+ if (height > 0) {
148+ mat->height = (uint_t)height;
149+ } else {
150+ PyErr_SetString (PyExc_ValueError, "input array dimension 0 should be greater than 0");
151+ goto fail;
152+ }
135153 mat->data = (smpl_t **)malloc(sizeof(smpl_t*) * mat->height);
136154 for (i=0; i< mat->height; i++) {
137155 mat->data[i] = (smpl_t*)PyArray_GETPTR1 ((PyArrayObject *)array, i);
python/ext/py-fft.c+0−4
@@ -25,10 +25,6 @@ Py_fft_new (PyTypeObject * type, PyObject * args, PyObject * kwds) · 24 unmodified lines
2525
2626 self->win_s = Py_default_vector_length;
2727
28− if (self == NULL) {
29− return NULL;
30− }
31−
3228 if (win_s > 0) {
3329 self->win_s = win_s;
3430 } else if (win_s < 0) {
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+
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")
python/lib/gen_pyobject.py+2−2
@@ -239,9 +239,9 @@ Py_%(name)s_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds) · 238 unmodified lines
239239 s += """\
240240
241241 self->%(pname)s = %(defval)s;
242− if (%(pname)s > 0) {
242+ if ((sint_t)%(pname)s > 0) {
243243 self->%(pname)s = %(pname)s;
244− } else if (%(pname)s < 0) {
244+ } else if ((sint_t)%(pname)s < 0) {
245245 PyErr_SetString (PyExc_ValueError,
246246 "can not use negative value for %(pname)s");
247247 return NULL;
python/lib/generator.py+1−0
@@ -56,6 +56,7 @@ def generate_object_files(output_path): · 55 unmodified lines
5656 'pitchyinfft',
5757 'sink_apple_audio',
5858 'sink_sndfile',
59+ 'source',
5960 'source_apple_audio',
6061 'source_sndfile',
6162 'source_avcodec',
python/setup.py+1−0
@@ -53,6 +53,7 @@ aubio_extension = Extension("aubio._aubio", [ · 52 unmodified lines
5353 "ext/py-filterbank.c",
5454 "ext/py-fft.c",
5555 "ext/py-phasevoc.c",
56+ "ext/py-source.c",
5657 # generated files
5758 ] + generated_object_files,
5859 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