Showing the changes to python (12 of 85 files). Show all
Unified · Split
File mode changed from 100644 to 100755.
| @@ -61,8 +61,9 @@ if 1: · 60 unmodified lines | |||
| 61 | ax.xaxis.set_visible(False) | 61 | ax.xaxis.set_visible(False) |
| 62 | ax.yaxis.set_visible(False) | 62 | ax.yaxis.set_visible(False) |
| 63 | ax.axis(xmax = all_desc_times[-1], xmin = all_desc_times[0]) | 63 | 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', |
| 65 | horizontalalignment='right', verticalalignment='bottom', | 65 | horizontalalignment='right', verticalalignment='bottom', |
| 66 | size = 'xx-small', | ||
| 66 | ) | 67 | ) |
| 67 | set_xlabels_sample2time( ax, all_desc_times[-1], samplerate) | 68 | set_xlabels_sample2time( ax, all_desc_times[-1], samplerate) |
| 68 | #plt.ylabel('spectral descriptor value') | 69 | #plt.ylabel('spectral descriptor value') |
| @@ -56,9 +56,11 @@ confidences = array(confidences[skip:]) · 55 unmodified lines | |||
| 56 | times = [t * hop_s for t in range(len(pitches))] | 56 | times = [t * hop_s for t in range(len(pitches))] |
| 57 | 57 | ||
| 58 | fig = plt.figure() | 58 | fig = plt.figure() |
| 59 | |||
| 59 | ax1 = fig.add_subplot(311) | 60 | ax1 = fig.add_subplot(311) |
| 60 | ax1 = get_waveform_plot(filename, samplerate = samplerate, block_size = hop_s, ax = ax1) | 61 | 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('') | ||
| 62 | 64 | ||
| 63 | def array_from_text_file(filename, dtype = 'float'): | 65 | def array_from_text_file(filename, dtype = 'float'): |
| 64 | import os.path | 66 | import os.path |
| @@ -87,7 +89,8 @@ cleaned_pitches = ma.masked_where(confidences < tolerance, cleaned_pitches) · 22 unmodified lines | |||
| 87 | ax2.plot(times, cleaned_pitches, '.-') | 89 | ax2.plot(times, cleaned_pitches, '.-') |
| 88 | #ax2.axis( ymin = 0.9 * cleaned_pitches.min(), ymax = 1.1 * cleaned_pitches.max() ) | 90 | #ax2.axis( ymin = 0.9 * cleaned_pitches.min(), ymax = 1.1 * cleaned_pitches.max() ) |
| 89 | #ax2.axis( ymin = 55, ymax = 70 ) | 91 | #ax2.axis( ymin = 55, ymax = 70 ) |
| 90 | ax2.set_xticklabels([]) | 92 | plt.setp(ax2.get_xticklabels(), visible = False) |
| 93 | ax2.set_ylabel('f0 (Hz)') | ||
| 91 | 94 | ||
| 92 | # plot confidence | 95 | # plot confidence |
| 93 | ax3 = fig.add_subplot(313, sharex = ax1) | 96 | ax3 = fig.add_subplot(313, sharex = ax1) |
| @@ -96,6 +99,7 @@ ax3.plot(times, confidences) · 2 unmodified lines | |||
| 96 | # draw a line at tolerance | 99 | # draw a line at tolerance |
| 97 | ax3.plot(times, [tolerance]*len(confidences)) | 100 | ax3.plot(times, [tolerance]*len(confidences)) |
| 98 | ax3.axis( xmin = times[0], xmax = times[-1]) | 101 | ax3.axis( xmin = times[0], xmax = times[-1]) |
| 99 | plt.show() | 102 | ax3.set_ylabel('condidence') |
| 100 | set_xlabels_sample2time(ax3, times[-1], samplerate) | 103 | 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') | ||
| @@ -71,7 +71,7 @@ if 1: · 70 unmodified lines | |||
| 71 | ax.xaxis.set_visible(False) | 71 | ax.xaxis.set_visible(False) |
| 72 | ax.yaxis.set_visible(False) | 72 | ax.yaxis.set_visible(False) |
| 73 | ax.axis(xmax = all_desc_times[-1], xmin = all_desc_times[0]) | 73 | 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', |
| 75 | horizontalalignment='right', verticalalignment='bottom', | 75 | horizontalalignment='right', verticalalignment='bottom', |
| 76 | ) | 76 | ) |
| 77 | set_xlabels_sample2time(ax, all_desc_times[-1], samplerate) | 77 | set_xlabels_sample2time(ax, all_desc_times[-1], samplerate) |
| @@ -68,3 +68,5 @@ extern PyTypeObject Py_fftType; · 67 unmodified lines | |||
| 68 | 68 | ||
| 69 | extern PyTypeObject Py_pvocType; | 69 | extern PyTypeObject Py_pvocType; |
| 70 | 70 | ||
| 71 | extern PyTypeObject Py_sourceType; | ||
| 72 | |||
| @@ -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 objects | 202 | // 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 objects | 233 | // add generated objects |
| 231 | add_generated_objects(m); | 234 | add_generated_objects(m); |
| @@ -35,7 +35,13 @@ PyAubio_ArrayToCFvec (PyObject *input) { · 34 unmodified lines | |||
| 35 | // vec = new_fvec (vec->length); | 35 | // vec = new_fvec (vec->length); |
| 36 | // no need to really allocate fvec, just its struct member | 36 | // no need to really allocate fvec, just its struct member |
| 37 | vec = (fvec_t *)malloc(sizeof(fvec_t)); | 37 | 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 | } | ||
| 39 | vec->data = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)array, 0); | 45 | vec->data = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)array, 0); |
| 40 | 46 | ||
| 41 | } else if (PyObject_TypeCheck (input, &PyList_Type)) { | 47 | } else if (PyObject_TypeCheck (input, &PyList_Type)) { |
| @@ -130,8 +136,20 @@ PyAubio_ArrayToCFmat (PyObject *input) { · 88 unmodified lines | |||
| 130 | 136 | ||
| 131 | // no need to really allocate fvec, just its struct member | 137 | // no need to really allocate fvec, just its struct member |
| 132 | mat = (fmat_t *)malloc(sizeof(fmat_t)); | 138 | mat = (fmat_t *)malloc(sizeof(fmat_t)); |
| 133 | mat->length = PyArray_DIM ((PyArrayObject *)array, 1); | 139 | long length = PyArray_DIM ((PyArrayObject *)array, 1); |
| 134 | mat->height = PyArray_DIM ((PyArrayObject *)array, 0); | 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 | } | ||
| 135 | mat->data = (smpl_t **)malloc(sizeof(smpl_t*) * mat->height); | 153 | mat->data = (smpl_t **)malloc(sizeof(smpl_t*) * mat->height); |
| 136 | for (i=0; i< mat->height; i++) { | 154 | for (i=0; i< mat->height; i++) { |
| 137 | mat->data[i] = (smpl_t*)PyArray_GETPTR1 ((PyArrayObject *)array, i); | 155 | mat->data[i] = (smpl_t*)PyArray_GETPTR1 ((PyArrayObject *)array, i); |
| @@ -25,10 +25,6 @@ Py_fft_new (PyTypeObject * type, PyObject * args, PyObject * kwds) · 24 unmodified lines | |||
| 25 | 25 | ||
| 26 | self->win_s = Py_default_vector_length; | 26 | self->win_s = Py_default_vector_length; |
| 27 | 27 | ||
| 28 | if (self == NULL) { | ||
| 29 | return NULL; | ||
| 30 | } | ||
| 31 | |||
| 32 | if (win_s > 0) { | 28 | if (win_s > 0) { |
| 33 | self->win_s = win_s; | 29 | self->win_s = win_s; |
| 34 | } else if (win_s < 0) { | 30 | } else if (win_s < 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") | ||
| @@ -239,9 +239,9 @@ Py_%(name)s_new (PyTypeObject * pytype, PyObject * args, PyObject * kwds) · 238 unmodified lines | |||
| 239 | s += """\ | 239 | s += """\ |
| 240 | 240 | ||
| 241 | self->%(pname)s = %(defval)s; | 241 | self->%(pname)s = %(defval)s; |
| 242 | if (%(pname)s > 0) { | 242 | if ((sint_t)%(pname)s > 0) { |
| 243 | self->%(pname)s = %(pname)s; | 243 | self->%(pname)s = %(pname)s; |
| 244 | } else if (%(pname)s < 0) { | 244 | } else if ((sint_t)%(pname)s < 0) { |
| 245 | PyErr_SetString (PyExc_ValueError, | 245 | PyErr_SetString (PyExc_ValueError, |
| 246 | "can not use negative value for %(pname)s"); | 246 | "can not use negative value for %(pname)s"); |
| 247 | return NULL; | 247 | return NULL; |
| @@ -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', |
| @@ -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 files | 57 | # generated files |
| 57 | ] + generated_object_files, | 58 | ] + generated_object_files, |
| 58 | include_dirs = include_dirs, | 59 | include_dirs = include_dirs, |