Showing the changes to python (8 of 40 files). Show all
Unified · Split
| @@ -63,7 +63,7 @@ while True: · 62 unmodified lines | |||
| 63 | delta = frames2tick(total_frames) - last_time | 63 | delta = frames2tick(total_frames) - last_time |
| 64 | if new_note[2] > 0: | 64 | if new_note[2] > 0: |
| 65 | track.append(Message('note_off', note=int(new_note[2]), | 65 | track.append(Message('note_off', note=int(new_note[2]), |
| 66 | velocity=127, time=0) | 66 | velocity=127, time=delta) |
| 67 | ) | 67 | ) |
| 68 | track.append(Message('note_on', | 68 | track.append(Message('note_on', |
| 69 | note=int(new_note[0]), | 69 | note=int(new_note[0]), |
| @@ -109,7 +109,8 @@ static void · 108 unmodified lines | |||
| 109 | Py_filter_del (Py_filter * self) | 109 | Py_filter_del (Py_filter * self) |
| 110 | { | 110 | { |
| 111 | Py_XDECREF(self->out); | 111 | Py_XDECREF(self->out); |
| 112 | del_aubio_filter (self->o); | 112 | if (self->o) |
| 113 | del_aubio_filter (self->o); | ||
| 113 | Py_TYPE(self)->tp_free ((PyObject *) self); | 114 | Py_TYPE(self)->tp_free ((PyObject *) self); |
| 114 | } | 115 | } |
| 115 | 116 | ||
| @@ -150,8 +150,10 @@ Py_sink_init (Py_sink * self, PyObject * args, PyObject * kwds) · 149 unmodified lines | |||
| 150 | static void | 150 | static void |
| 151 | Py_sink_del (Py_sink *self, PyObject *unused) | 151 | Py_sink_del (Py_sink *self, PyObject *unused) |
| 152 | { | 152 | { |
| 153 | del_aubio_sink(self->o); | 153 | if (self->o) { |
| 154 | free(self->mwrite_data.data); | 154 | del_aubio_sink(self->o); |
| 155 | free(self->mwrite_data.data); | ||
| 156 | } | ||
| 155 | if (self->uri) { | 157 | if (self->uri) { |
| 156 | free(self->uri); | 158 | free(self->uri); |
| 157 | } | 159 | } |
| @@ -436,6 +436,10 @@ Py_source_do(Py_source * self, PyObject * args) · 435 unmodified lines | |||
| 436 | /* compute _do function */ | 436 | /* compute _do function */ |
| 437 | aubio_source_do (self->o, &(self->c_read_to), &read); | 437 | aubio_source_do (self->o, &(self->c_read_to), &read); |
| 438 | 438 | ||
| 439 | if (PyErr_Occurred() != NULL) { | ||
| 440 | return NULL; | ||
| 441 | } | ||
| 442 | |||
| 439 | outputs = PyTuple_New(2); | 443 | outputs = PyTuple_New(2); |
| 440 | PyTuple_SetItem( outputs, 0, self->read_to ); | 444 | PyTuple_SetItem( outputs, 0, self->read_to ); |
| 441 | PyTuple_SetItem( outputs, 1, (PyObject *)PyLong_FromLong(read)); | 445 | PyTuple_SetItem( outputs, 1, (PyObject *)PyLong_FromLong(read)); |
| @@ -457,6 +461,10 @@ Py_source_do_multi(Py_source * self, PyObject * args) · 15 unmodified lines | |||
| 457 | /* compute _do function */ | 461 | /* compute _do function */ |
| 458 | aubio_source_do_multi (self->o, &(self->c_mread_to), &read); | 462 | aubio_source_do_multi (self->o, &(self->c_mread_to), &read); |
| 459 | 463 | ||
| 464 | if (PyErr_Occurred() != NULL) { | ||
| 465 | return NULL; | ||
| 466 | } | ||
| 467 | |||
| 460 | outputs = PyTuple_New(2); | 468 | outputs = PyTuple_New(2); |
| 461 | PyTuple_SetItem( outputs, 0, self->mread_to); | 469 | PyTuple_SetItem( outputs, 0, self->mread_to); |
| 462 | PyTuple_SetItem( outputs, 1, (PyObject *)PyLong_FromLong(read)); | 470 | PyTuple_SetItem( outputs, 1, (PyObject *)PyLong_FromLong(read)); |
| @@ -573,7 +581,10 @@ static PyObject* Pyaubio_source_iter_next(Py_source *self) { · 110 unmodified lines | |||
| 573 | return vec; | 581 | return vec; |
| 574 | } else if (PyLong_AsLong(size) > 0) { | 582 | } else if (PyLong_AsLong(size) > 0) { |
| 575 | // short read, return a shorter array | 583 | // short read, return a shorter array |
| 576 | PyArrayObject *shortread = (PyArrayObject*)PyTuple_GetItem(done, 0); | 584 | PyObject *vec = PyTuple_GetItem(done, 0); |
| 585 | // take a copy to prevent resizing internal arrays | ||
| 586 | PyArrayObject *shortread = (PyArrayObject*)PyArray_FROM_OTF(vec, | ||
| 587 | NPY_NOTYPE, NPY_ARRAY_ENSURECOPY); | ||
| 577 | PyArray_Dims newdims; | 588 | PyArray_Dims newdims; |
| 578 | PyObject *reshaped; | 589 | PyObject *reshaped; |
| 579 | newdims.len = PyArray_NDIM(shortread); | 590 | newdims.len = PyArray_NDIM(shortread); |
| @@ -586,6 +597,7 @@ static PyObject* Pyaubio_source_iter_next(Py_source *self) { · 6 unmodified lines | |||
| 586 | } | 597 | } |
| 587 | reshaped = PyArray_Newshape(shortread, &newdims, NPY_CORDER); | 598 | reshaped = PyArray_Newshape(shortread, &newdims, NPY_CORDER); |
| 588 | Py_DECREF(shortread); | 599 | Py_DECREF(shortread); |
| 600 | Py_DECREF(vec); | ||
| 589 | return reshaped; | 601 | return reshaped; |
| 590 | } else { | 602 | } else { |
| 591 | PyErr_SetNone(PyExc_StopIteration); | 603 | PyErr_SetNone(PyExc_StopIteration); |
| @@ -68,7 +68,7 @@ def add_local_macros(ext, usedouble = False): · 67 unmodified lines | |||
| 68 | # define macros (waf puts them in build/src/config.h) | 68 | # define macros (waf puts them in build/src/config.h) |
| 69 | for define_macro in ['HAVE_STDLIB_H', 'HAVE_STDIO_H', | 69 | for define_macro in ['HAVE_STDLIB_H', 'HAVE_STDIO_H', |
| 70 | 'HAVE_MATH_H', 'HAVE_STRING_H', | 70 | 'HAVE_MATH_H', 'HAVE_STRING_H', |
| 71 | 'HAVE_C99_VARARGS_MACROS', | 71 | 'HAVE_ERRNO_H', 'HAVE_C99_VARARGS_MACROS', |
| 72 | 'HAVE_LIMITS_H', 'HAVE_STDARG_H', | 72 | 'HAVE_LIMITS_H', 'HAVE_STDARG_H', |
| 73 | 'HAVE_MEMCPY_HACKS']: | 73 | 'HAVE_MEMCPY_HACKS']: |
| 74 | ext.define_macros += [(define_macro, 1)] | 74 | ext.define_macros += [(define_macro, 1)] |
| @@ -3,7 +3,8 @@ · 2 unmodified lines | |||
| 3 | from numpy.testing import TestCase | 3 | from numpy.testing import TestCase |
| 4 | from aubio import fvec, source, sink | 4 | from aubio import fvec, source, sink |
| 5 | from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path | 5 | from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path |
| 6 | from _tools import parametrize, skipTest, assert_raises | 6 | from utils import parse_file_samplerate |
| 7 | from _tools import parametrize, skipTest, assert_raises, assert_warns | ||
| 7 | 8 | ||
| 8 | list_of_sounds = list_all_sounds('sounds') | 9 | list_of_sounds = list_all_sounds('sounds') |
| 9 | samplerates = [0, 44100, 8000, 32000] | 10 | samplerates = [0, 44100, 8000, 32000] |
| @@ -60,8 +61,14 @@ class Test_aubio_sink(object): · 50 unmodified lines | |||
| 60 | 61 | ||
| 61 | @parametrize('hop_size, samplerate, path', all_params) | 62 | @parametrize('hop_size, samplerate, path', all_params) |
| 62 | def test_read_and_write(self, hop_size, samplerate, path): | 63 | def test_read_and_write(self, hop_size, samplerate, path): |
| 64 | orig_samplerate = parse_file_samplerate(soundfile) | ||
| 63 | try: | 65 | try: |
| 64 | f = source(path, samplerate, hop_size) | 66 | if orig_samplerate is not None and orig_samplerate < samplerate: |
| 67 | # upsampling should emit a warning | ||
| 68 | with assert_warns(UserWarning): | ||
| 69 | f = source(soundfile, samplerate, hop_size) | ||
| 70 | else: | ||
| 71 | f = source(soundfile, samplerate, hop_size) | ||
| 65 | except RuntimeError as e: | 72 | except RuntimeError as e: |
| 66 | err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})' | 73 | err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})' |
| 67 | skipTest(err_msg.format(str(e), hop_size, samplerate)) | 74 | skipTest(err_msg.format(str(e), hop_size, samplerate)) |
| @@ -78,8 +85,14 @@ class Test_aubio_sink(object): · 10 unmodified lines | |||
| 78 | 85 | ||
| 79 | @parametrize('hop_size, samplerate, path', all_params) | 86 | @parametrize('hop_size, samplerate, path', all_params) |
| 80 | def test_read_and_write_multi(self, hop_size, samplerate, path): | 87 | def test_read_and_write_multi(self, hop_size, samplerate, path): |
| 88 | orig_samplerate = parse_file_samplerate(soundfile) | ||
| 81 | try: | 89 | try: |
| 82 | f = source(path, samplerate, hop_size) | 90 | if orig_samplerate is not None and orig_samplerate < samplerate: |
| 91 | # upsampling should emit a warning | ||
| 92 | with assert_warns(UserWarning): | ||
| 93 | f = source(soundfile, samplerate, hop_size) | ||
| 94 | else: | ||
| 95 | f = source(soundfile, samplerate, hop_size) | ||
| 83 | except RuntimeError as e: | 96 | except RuntimeError as e: |
| 84 | err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})' | 97 | err_msg = '{:s} (hop_s = {:d}, samplerate = {:d})' |
| 85 | skipTest(err_msg.format(str(e), hop_size, samplerate)) | 98 | skipTest(err_msg.format(str(e), hop_size, samplerate)) |
| @@ -3,9 +3,10 @@ · 2 unmodified lines | |||
| 3 | 3 | ||
| 4 | from numpy.testing import TestCase, assert_equal | 4 | from numpy.testing import TestCase, assert_equal |
| 5 | from aubio import source | 5 | from aubio import source |
| 6 | from utils import list_all_sounds | 6 | from utils import list_all_sounds, parse_file_samplerate |
| 7 | import unittest | 7 | import unittest |
| 8 | from _tools import parametrize, assert_raises, assert_equal, skipTest | 8 | from _tools import assert_raises, assert_equal, assert_warns |
| 9 | from _tools import parametrize, skipTest | ||
| 9 | 10 | ||
| 10 | list_of_sounds = list_all_sounds('sounds') | 11 | list_of_sounds = list_all_sounds('sounds') |
| 11 | samplerates = [0, 44100, 8000, 32000] | 12 | samplerates = [0, 44100, 8000, 32000] |
| @@ -23,23 +24,38 @@ no_sounds_msg = "no test sounds, add some in 'python/tests/sounds/'!" · 11 unmodified lines | |||
| 23 | 24 | ||
| 24 | _debug = False | 25 | _debug = False |
| 25 | 26 | ||
| 26 | class Test_aubio_source_test_case(object): | ||
| 27 | 27 | ||
| 28 | @parametrize('filename', list_of_sounds) | 28 | class Test_aubio_source_test_case(TestCase): |
| 29 | def test_close_file(self, filename): | 29 | |
| 30 | def setUp(self): | ||
| 31 | if not default_test_sound: | ||
| 32 | skipTest(no_sounds_msg) | ||
| 33 | |||
| 34 | def test_close_file(self): | ||
| 30 | samplerate = 0 # use native samplerate | 35 | samplerate = 0 # use native samplerate |
| 31 | hop_size = 256 | 36 | hop_size = 256 |
| 32 | f = source(filename, samplerate, hop_size) | 37 | f = source(default_test_sound, samplerate, hop_size) |
| 33 | f.close() | 38 | f.close() |
| 34 | 39 | ||
| 35 | @parametrize('filename', list_of_sounds) | 40 | def test_close_file_twice(self): |
| 36 | def test_close_file_twice(self, filename): | ||
| 37 | samplerate = 0 # use native samplerate | 41 | samplerate = 0 # use native samplerate |
| 38 | hop_size = 256 | 42 | hop_size = 256 |
| 39 | f = source(filename, samplerate, hop_size) | 43 | f = source(default_test_sound, samplerate, hop_size) |
| 40 | f.close() | 44 | f.close() |
| 41 | f.close() | 45 | f.close() |
| 42 | 46 | ||
| 47 | def test_read_after_close(self): | ||
| 48 | samplerate = 0 # use native samplerate | ||
| 49 | hop_size = 256 | ||
| 50 | f = source(default_test_sound, samplerate, hop_size) | ||
| 51 | read, frames = f() | ||
| 52 | f.close() | ||
| 53 | with assert_raises(RuntimeError): | ||
| 54 | read, frames = f() | ||
| 55 | with assert_raises(RuntimeError): | ||
| 56 | read, frames = f.do_multi() | ||
| 57 | |||
| 58 | |||
| 43 | class Test_aubio_source_read(object): | 59 | class Test_aubio_source_read(object): |
| 44 | 60 | ||
| 45 | def read_from_source(self, f): | 61 | def read_from_source(self, f): |
| @@ -60,8 +76,14 @@ class Test_aubio_source_read(object): · 14 unmodified lines | |||
| 60 | 76 | ||
| 61 | @parametrize('hop_size, samplerate, soundfile', all_params) | 77 | @parametrize('hop_size, samplerate, soundfile', all_params) |
| 62 | def test_samplerate_hopsize(self, hop_size, samplerate, soundfile): | 78 | def test_samplerate_hopsize(self, hop_size, samplerate, soundfile): |
| 79 | orig_samplerate = parse_file_samplerate(soundfile) | ||
| 63 | try: | 80 | try: |
| 64 | f = source(soundfile, samplerate, hop_size) | 81 | if orig_samplerate is not None and orig_samplerate < samplerate: |
| 82 | # upsampling should emit a warning | ||
| 83 | with assert_warns(UserWarning): | ||
| 84 | f = source(soundfile, samplerate, hop_size) | ||
| 85 | else: | ||
| 86 | f = source(soundfile, samplerate, hop_size) | ||
| 65 | except RuntimeError as e: | 87 | except RuntimeError as e: |
| 66 | err_msg = 'failed opening with hop_s={:d}, samplerate={:d} ({:s})' | 88 | err_msg = 'failed opening with hop_s={:d}, samplerate={:d} ({:s})' |
| 67 | skipTest(err_msg.format(hop_size, samplerate, str(e))) | 89 | skipTest(err_msg.format(hop_size, samplerate, str(e))) |
| @@ -1,6 +1,7 @@ | |||
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | 2 | ||
| 3 | import os | 3 | import os |
| 4 | import re | ||
| 4 | import glob | 5 | import glob |
| 5 | import numpy as np | 6 | import numpy as np |
| 6 | from tempfile import mkstemp | 7 | from tempfile import mkstemp |
| @@ -77,3 +78,16 @@ def count_files_in_directory(samples_dir): · 70 unmodified lines | |||
| 77 | if file_path: | 78 | if file_path: |
| 78 | total_files += 1 | 79 | total_files += 1 |
| 79 | return total_files | 80 | return total_files |
| 81 | |||
| 82 | def parse_file_samplerate(soundfile): | ||
| 83 | samplerate = None | ||
| 84 | # parse samplerate | ||
| 85 | re_sr = re.compile(r'/([0-9]{4,})Hz_.*') | ||
| 86 | match_samplerate = re_sr.findall(soundfile) | ||
| 87 | if match_samplerate: | ||
| 88 | samplerate = int(match_samplerate[0]) | ||
| 89 | else: | ||
| 90 | import warnings | ||
| 91 | warnings.warn(UserWarning("could not parse samplerate for {:s}" | ||
| 92 | .format(soundfile))) | ||
| 93 | return samplerate | ||