- Timestamp:
- Mar 12, 2017, 11:26:24 AM (8 years ago)
- Branches:
- sampler
- Children:
- bde49c4a
- Parents:
- 71f2e5f (diff), 67b6618 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- python
- Files:
-
- 6 added
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
python/README.md
r71f2e5f r41b985f 36 36 ------------------------- 37 37 38 Python tests are in `python/tests` and use the [nose2 python package][nose2]. 39 38 40 To run the all the python tests, use the script: 39 41 … … 43 45 44 46 $ ./python/tests/test_note2midi.py -v 47 48 [nose2]: https://github.com/nose-devs/nose2 45 49 46 50 Install in a virtualenv -
python/demos/demo_timestretch_online.py
r71f2e5f r41b985f 12 12 import numpy as np 13 13 14 win_s = 102414 win_s = 512 15 15 hop_s = win_s // 8 # 87.5 % overlap 16 16 … … 93 93 old_grain.phas = np.copy(cur_grain.phas) 94 94 95 # until end of file 96 if read < hop_s: break 97 # increment block counter 95 98 block_read += 1 96 if read < hop_s: break97 99 98 100 for t in range(warmup + 2): # purge the last frames from the phase vocoder -
python/ext/aubio-types.h
r71f2e5f r41b985f 28 28 #include "aubio.h" 29 29 #else 30 #include "aubio/aubio.h"30 #include <aubio/aubio.h> 31 31 #endif 32 32 … … 45 45 #define AUBIO_NPY_SMPL_STR "float32" 46 46 #define AUBIO_NPY_SMPL_CHR "f" 47 #endif 48 49 #ifndef PATH_MAX 50 #ifdef MAX_PATH 51 #define PATH_MAX MAX_PATH 52 #else 53 #define PATH_MAX 1024 54 #endif 47 55 #endif 48 56 -
python/ext/aubiomodule.c
r71f2e5f r41b985f 2 2 #include "aubio-types.h" 3 3 #include "py-musicutils.h" 4 5 // this dummy macro is used to convince windows that a string passed as -D flag 6 // is just that, a string, and not a double. 7 #define REDEFINESTRING(x) #x 8 #define DEFINEDSTRING(x) REDEFINESTRING(x) 4 9 5 10 static char aubio_module_doc[] = "Python module for the aubio library"; … … 324 329 325 330 PyModule_AddStringConstant(m, "float_type", AUBIO_NPY_SMPL_STR); 331 PyModule_AddStringConstant(m, "__version__", DEFINEDSTRING(AUBIO_VERSION)); 326 332 327 333 // add generated objects -
python/ext/py-cvec.c
r71f2e5f r41b985f 148 148 if (length != vec->length) { 149 149 PyErr_Format (PyExc_ValueError, 150 "input array has length % ld, but cvec has length %d", length,150 "input array has length %" NPY_INTP_FMT ", but cvec has length %d", length, 151 151 vec->length); 152 152 return 1; … … 169 169 if (length != vec->length) { 170 170 PyErr_Format (PyExc_ValueError, 171 "input array has length % ld, but cvec has length %d", length,171 "input array has length %" NPY_INTP_FMT ", but cvec has length %d", length, 172 172 vec->length); 173 173 return 1; -
python/ext/py-sink.c
r71f2e5f r41b985f 81 81 } 82 82 83 self->uri = "none";83 self->uri = NULL; 84 84 if (uri != NULL) { 85 self->uri = uri; 85 self->uri = (char_t *)malloc(sizeof(char_t) * (strnlen(uri, PATH_MAX) + 1)); 86 strncpy(self->uri, uri, strnlen(uri, PATH_MAX) + 1); 86 87 } 87 88 88 89 self->samplerate = Py_aubio_default_samplerate; 89 if ( (sint_t)samplerate >0) {90 if (samplerate != 0) { 90 91 self->samplerate = samplerate; 91 } else if ((sint_t)samplerate < 0) {92 PyErr_SetString (PyExc_ValueError,93 "can not use negative value for samplerate");94 return NULL;95 92 } 96 93 97 94 self->channels = 1; 98 if ( (sint_t)channels >0) {95 if (channels != 0) { 99 96 self->channels = channels; 100 } else if ((sint_t)channels < 0) {101 PyErr_SetString (PyExc_ValueError,102 "can not use negative or null value for channels");103 return NULL;104 97 } 105 98 … … 110 103 Py_sink_init (Py_sink * self, PyObject * args, PyObject * kwds) 111 104 { 112 if (self->channels == 1) { 113 self->o = new_aubio_sink ( self->uri, self->samplerate ); 114 } else { 115 self->o = new_aubio_sink ( self->uri, 0 ); 116 aubio_sink_preset_channels ( self->o, self->channels ); 117 aubio_sink_preset_samplerate ( self->o, self->samplerate ); 118 } 105 self->o = new_aubio_sink ( self->uri, 0 ); 119 106 if (self->o == NULL) { 120 PyErr_SetString (PyExc_RuntimeError, "error creating sink with this uri");107 // error string was set in new_aubio_sink 121 108 return -1; 122 109 } 110 if (aubio_sink_preset_channels(self->o, self->channels) != 0) { 111 // error string was set in aubio_sink_preset_channels 112 return -1; 113 } 114 if (aubio_sink_preset_samplerate(self->o, self->samplerate) != 0) { 115 // error string was set in aubio_sink_preset_samplerate 116 return -1; 117 } 118 123 119 self->samplerate = aubio_sink_get_samplerate ( self->o ); 124 120 self->channels = aubio_sink_get_channels ( self->o ); … … 132 128 del_aubio_sink(self->o); 133 129 free(self->mwrite_data.data); 130 if (self->uri) { 131 free(self->uri); 132 } 134 133 Py_TYPE(self)->tp_free((PyObject *) self); 135 134 } … … 205 204 } 206 205 206 static char Pyaubio_sink_enter_doc[] = ""; 207 static PyObject* Pyaubio_sink_enter(Py_sink *self, PyObject *unused) { 208 Py_INCREF(self); 209 return (PyObject*)self; 210 } 211 212 static char Pyaubio_sink_exit_doc[] = ""; 213 static PyObject* Pyaubio_sink_exit(Py_sink *self, PyObject *unused) { 214 return Pyaubio_sink_close(self, unused); 215 } 216 207 217 static PyMethodDef Py_sink_methods[] = { 208 218 {"do", (PyCFunction) Py_sink_do, METH_VARARGS, Py_sink_do_doc}, 209 219 {"do_multi", (PyCFunction) Py_sink_do_multi, METH_VARARGS, Py_sink_do_multi_doc}, 210 220 {"close", (PyCFunction) Pyaubio_sink_close, METH_NOARGS, Py_sink_close_doc}, 221 {"__enter__", (PyCFunction)Pyaubio_sink_enter, METH_NOARGS, 222 Pyaubio_sink_enter_doc}, 223 {"__exit__", (PyCFunction)Pyaubio_sink_exit, METH_VARARGS, 224 Pyaubio_sink_exit_doc}, 211 225 {NULL} /* sentinel */ 212 226 }; -
python/ext/py-source.c
r71f2e5f r41b985f 101 101 } 102 102 103 self->uri = "none";103 self->uri = NULL; 104 104 if (uri != NULL) { 105 self->uri = uri; 105 self->uri = (char_t *)malloc(sizeof(char_t) * (strnlen(uri, PATH_MAX) + 1)); 106 strncpy(self->uri, uri, strnlen(uri, PATH_MAX) + 1); 106 107 } 107 108 … … 163 164 del_aubio_source(self->o); 164 165 free(self->c_mread_to.data); 166 } 167 if (self->uri) { 168 free(self->uri); 165 169 } 166 170 Py_XDECREF(self->read_to); … … 243 247 Pyaubio_source_close (Py_source *self, PyObject *unused) 244 248 { 245 aubio_source_close (self->o);249 if (aubio_source_close(self->o) != 0) return NULL; 246 250 Py_RETURN_NONE; 247 251 } … … 271 275 } 272 276 Py_RETURN_NONE; 277 } 278 279 static char Pyaubio_source_enter_doc[] = ""; 280 static PyObject* Pyaubio_source_enter(Py_source *self, PyObject *unused) { 281 Py_INCREF(self); 282 return (PyObject*)self; 283 } 284 285 static char Pyaubio_source_exit_doc[] = ""; 286 static PyObject* Pyaubio_source_exit(Py_source *self, PyObject *unused) { 287 return Pyaubio_source_close(self, unused); 288 } 289 290 static PyObject* Pyaubio_source_iter(PyObject *self) { 291 Py_INCREF(self); 292 return (PyObject*)self; 293 } 294 295 static PyObject* Pyaubio_source_iter_next(Py_source *self) { 296 PyObject *done, *size; 297 if (self->channels == 1) { 298 done = Py_source_do(self, NULL); 299 } else { 300 done = Py_source_do_multi(self, NULL); 301 } 302 if (!PyTuple_Check(done)) { 303 PyErr_Format(PyExc_ValueError, 304 "error when reading source: not opened?"); 305 return NULL; 306 } 307 size = PyTuple_GetItem(done, 1); 308 if (size != NULL && PyLong_Check(size)) { 309 if (PyLong_AsLong(size) == (long)self->hop_size) { 310 PyObject *vec = PyTuple_GetItem(done, 0); 311 return vec; 312 } else if (PyLong_AsLong(size) > 0) { 313 // short read, return a shorter array 314 PyArrayObject *shortread = (PyArrayObject*)PyTuple_GetItem(done, 0); 315 PyArray_Dims newdims; 316 PyObject *reshaped; 317 newdims.len = PyArray_NDIM(shortread); 318 newdims.ptr = PyArray_DIMS(shortread); 319 // mono or multiple channels? 320 if (newdims.len == 1) { 321 newdims.ptr[0] = PyLong_AsLong(size); 322 } else { 323 newdims.ptr[1] = PyLong_AsLong(size); 324 } 325 reshaped = PyArray_Newshape(shortread, &newdims, NPY_CORDER); 326 Py_DECREF(shortread); 327 return reshaped; 328 } else { 329 PyErr_SetNone(PyExc_StopIteration); 330 return NULL; 331 } 332 } else { 333 PyErr_SetNone(PyExc_StopIteration); 334 return NULL; 335 } 273 336 } 274 337 … … 286 349 {"seek", (PyCFunction) Pyaubio_source_seek, 287 350 METH_VARARGS, Py_source_seek_doc}, 351 {"__enter__", (PyCFunction)Pyaubio_source_enter, METH_NOARGS, 352 Pyaubio_source_enter_doc}, 353 {"__exit__", (PyCFunction)Pyaubio_source_exit, METH_VARARGS, 354 Pyaubio_source_exit_doc}, 288 355 {NULL} /* sentinel */ 289 356 }; … … 315 382 0, 316 383 0, 317 0,318 0,384 Pyaubio_source_iter, 385 (unaryfunc)Pyaubio_source_iter_next, 319 386 Py_source_methods, 320 387 Py_source_members, -
python/lib/aubio/__init__.py
r71f2e5f r41b985f 2 2 3 3 import numpy 4 from ._aubio import __version__ as version 5 from ._aubio import float_type 4 6 from ._aubio import * 5 from ._aubio import float_type6 7 from .midiconv import * 7 8 from .slicing import * -
python/lib/aubio/midiconv.py
r71f2e5f r41b985f 16 16 " convert note name to midi note number, e.g. [C-1, G9] -> [0, 127] " 17 17 _valid_notenames = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11} 18 _valid_modifiers = {None: 0, u'♮': 0, '#': +1, u'♯': +1, u'\udd2a': +2, 19 'b': -1, u'♭': -1, u'\ufffd': -2} 18 _valid_modifiers = { 19 u'𝄫': -2, # double flat 20 u'♭': -1, 'b': -1, '\u266d': -1, # simple flat 21 u'♮': 0, '\u266e': 0, None: 0, # natural 22 '#': +1, u'♯': +1, '\u266f': +1, # sharp 23 u'𝄪': +2, # double sharp 24 } 20 25 _valid_octaves = range(-1, 10) 21 26 if not isinstance(note, str_instances): -
python/lib/gen_external.py
r71f2e5f r41b985f 15 15 'filter', 16 16 'filterbank', 17 #'resampler',18 17 # AUBIO_UNSTABLE 19 18 'hist', … … 79 78 return cpp_cmd 80 79 81 def get_cpp_objects(header=header ):80 def get_cpp_objects(header=header, usedouble=False): 82 81 cpp_cmd = get_preprocessor() 83 82 84 83 macros = [('AUBIO_UNSTABLE', 1)] 84 if usedouble: 85 macros += [('HAVE_AUBIO_DOUBLE', 1)] 85 86 86 87 if not os.path.isfile(header): … … 180 181 elif not overwrite: return sorted(glob.glob(os.path.join(output_path, '*.c'))) 181 182 182 cpp_output, cpp_objects = get_cpp_objects(header )183 cpp_output, cpp_objects = get_cpp_objects(header, usedouble=usedouble) 183 184 184 185 lib = analyze_cpp_output(cpp_objects, cpp_output) … … 251 252 # no need to add header to list of sources 252 253 253 return so urces_list254 return sorted(sources_list) 254 255 255 256 if __name__ == '__main__': -
python/lib/moresetuptools.py
r71f2e5f r41b985f 4 4 import distutils, distutils.command.clean, distutils.dir_util 5 5 from .gen_external import generate_external, header, output_path 6 7 def get_aubio_version(): 8 # read from VERSION 9 this_file_dir = os.path.dirname(os.path.abspath(__file__)) 10 version_file = os.path.join(this_file_dir, '..', '..', 'VERSION') 11 12 if not os.path.isfile(version_file): 13 raise SystemError("VERSION file not found.") 14 15 for l in open(version_file).readlines(): 16 #exec (l.strip()) 17 if l.startswith('AUBIO_MAJOR_VERSION'): 18 AUBIO_MAJOR_VERSION = int(l.split('=')[1]) 19 if l.startswith('AUBIO_MINOR_VERSION'): 20 AUBIO_MINOR_VERSION = int(l.split('=')[1]) 21 if l.startswith('AUBIO_PATCH_VERSION'): 22 AUBIO_PATCH_VERSION = int(l.split('=')[1]) 23 if l.startswith('AUBIO_VERSION_STATUS'): 24 AUBIO_VERSION_STATUS = l.split('=')[1].strip()[1:-1] 25 26 if AUBIO_MAJOR_VERSION is None or AUBIO_MINOR_VERSION is None \ 27 or AUBIO_PATCH_VERSION is None: 28 raise SystemError("Failed parsing VERSION file.") 29 30 verstr = '.'.join(map(str, [AUBIO_MAJOR_VERSION, 31 AUBIO_MINOR_VERSION, 32 AUBIO_PATCH_VERSION])) 33 34 if AUBIO_VERSION_STATUS is not None: 35 verstr += AUBIO_VERSION_STATUS 36 return verstr 37 38 def get_aubio_pyversion(): 39 # convert to version for python according to pep 440 40 # see https://www.python.org/dev/peps/pep-0440/ 41 verstr = get_aubio_version() 42 if '~alpha' in verstr: 43 verstr = verstr.split('~')[0] + 'a1' 44 # TODO: add rc, .dev, and .post suffixes, add numbering 45 return verstr 6 46 7 47 # inspired from https://gist.github.com/abergmeier/9488990 … … 22 62 23 63 for package in packages: 64 print("checking for {:s}".format(package)) 24 65 cmd = ['pkg-config', '--libs', '--cflags', package] 25 66 try: … … 53 94 ext.libraries += ['aubio'] 54 95 55 def add_local_aubio_sources(ext ):96 def add_local_aubio_sources(ext, usedouble = False): 56 97 """ build aubio inside python module instead of linking against libaubio """ 57 print("Warning: libaubio was not built with waf, adding src/") 58 # create an empty header, macros will be passed on the command line 59 fake_config_header = os.path.join('python', 'ext', 'config.h') 60 distutils.file_util.write_file(fake_config_header, "") 98 print("Info: libaubio was not installed or built locally with waf, adding src/") 61 99 aubio_sources = sorted(glob.glob(os.path.join('src', '**.c'))) 62 100 aubio_sources += sorted(glob.glob(os.path.join('src', '*', '**.c'))) 63 101 ext.sources += aubio_sources 102 103 def add_local_macros(ext, usedouble = False): 64 104 # define macros (waf puts them in build/src/config.h) 65 105 for define_macro in ['HAVE_STDLIB_H', 'HAVE_STDIO_H', … … 70 110 ext.define_macros += [(define_macro, 1)] 71 111 112 def add_external_deps(ext, usedouble = False): 72 113 # loof for additional packages 73 114 print("Info: looking for *optional* additional packages") 74 115 packages = ['libavcodec', 'libavformat', 'libavutil', 'libavresample', 75 116 'jack', 76 'sndfile', 'samplerate', 117 'sndfile', 118 'samplerate', 77 119 'rubberband', 78 120 #'fftw3f', 79 121 ] 122 # samplerate only works with float 123 if usedouble is False: 124 packages += ['samplerate'] 125 else: 126 print("Info: not adding libsamplerate in double precision mode") 80 127 add_packages(packages, ext=ext) 81 128 if 'avcodec' in ext.libraries \ … … 116 163 def add_system_aubio(ext): 117 164 # use pkg-config to find aubio's location 118 add_packages(['aubio'], ext) 165 aubio_version = get_aubio_version() 166 add_packages(['aubio = ' + aubio_version], ext) 119 167 if 'aubio' not in ext.libraries: 120 print("Error: libaubio not found") 168 print("Info: aubio " + aubio_version + " was not found by pkg-config") 169 else: 170 print("Info: using system aubio " + aubio_version + " found in " + ' '.join(ext.library_dirs)) 121 171 122 172 class CleanGenerated(distutils.command.clean.clean): 123 173 def run(self): 124 distutils.dir_util.remove_tree(output_path)125 distutils.command.clean.clean.run(self)174 if os.path.isdir(output_path): 175 distutils.dir_util.remove_tree(output_path) 126 176 127 177 from distutils.command.build_ext import build_ext as _build_ext … … 145 195 146 196 def build_extension(self, extension): 147 if self.enable_double :197 if self.enable_double or 'HAVE_AUBIO_DOUBLE' in os.environ: 148 198 extension.define_macros += [('HAVE_AUBIO_DOUBLE', 1)] 149 if os.path.isfile('src/aubio.h'): 150 # if aubio headers are found in this directory 151 add_local_aubio_header(extension) 152 # was waf used to build the shared lib? 153 if os.path.isdir(os.path.join('build','src')): 154 # link against build/src/libaubio, built with waf 199 enable_double = True 200 else: 201 enable_double = False 202 # seack for aubio headers and lib in PKG_CONFIG_PATH 203 add_system_aubio(extension) 204 # the lib was not installed on this system 205 if 'aubio' not in extension.libraries: 206 # use local src/aubio.h 207 if os.path.isfile(os.path.join('src', 'aubio.h')): 208 add_local_aubio_header(extension) 209 add_local_macros(extension) 210 # look for a local waf build 211 if os.path.isfile(os.path.join('build','src', 'fvec.c.1.o')): 155 212 add_local_aubio_lib(extension) 156 213 else: 214 # check for external dependencies 215 add_external_deps(extension, usedouble=enable_double) 157 216 # add libaubio sources and look for optional deps with pkg-config 158 add_local_aubio_sources(extension, usedouble=self.enable_double) 159 else: 160 # look for aubio headers and lib using pkg-config 161 add_system_aubio(extension) 217 add_local_aubio_sources(extension, usedouble=enable_double) 162 218 # generate files python/gen/*.c, python/gen/aubio-generated.h 163 219 extension.sources += generate_external(header, output_path, overwrite = False, 164 usedouble= self.enable_double)220 usedouble=enable_double) 165 221 return _build_ext.build_extension(self, extension) -
python/scripts/aubiocut
r71f2e5f r41b985f 6 6 7 7 import sys 8 #from aubio.task import *9 8 10 9 usage = "usage: %s [options] -i soundfile" % sys.argv[0] … … 118 117 action = "store", dest = "cut_until_nsamples", default = None, 119 118 help="how many extra samples should be added at the end of each slice") 119 parser.add_option("--cut-every-nslices", type = int, 120 metavar = "<samples>", 121 action = "store", dest = "cut_every_nslices", default = None, 122 help="how many slices should be groupped together at each cut") 120 123 parser.add_option("--cut-until-nslices", type = int, 121 124 metavar = "<slices>", … … 188 191 from aubio.slicing import slice_source_at_stamps 189 192 timestamps_end = None 193 if options.cut_every_nslices: 194 timestamps = timestamps[::options.cut_every_nslices] 195 nstamps = len(timestamps) 190 196 if options.cut_until_nslices and options.cut_until_nsamples: 191 197 print ("warning: using cut_until_nslices, but cut_until_nsamples is set") -
python/tests/eval_pitch
r71f2e5f r41b985f 25 25 import os.path 26 26 import numpy 27 from utils import array_from_text_file, array_from_yaml_file27 from .utils import array_from_text_file, array_from_yaml_file 28 28 from aubio import source, pitch, freqtomidi 29 29 -
python/tests/test_aubio.py
r71f2e5f r41b985f 10 10 import aubio 11 11 12 def test_version(self): 13 """ test aubio.version """ 14 import aubio 15 self.assertEqual('0', aubio.version[0]) 16 12 17 if __name__ == '__main__': 13 18 main() -
python/tests/test_fft.py
r71f2e5f r41b985f 34 34 fftgrain = f (timegrain) 35 35 assert_equal ( fftgrain.norm, 0 ) 36 assert_equal ( fftgrain.phas, 0 ) 36 try: 37 assert_equal ( fftgrain.phas, 0 ) 38 except AssertionError: 39 assert_equal (fftgrain.phas[fftgrain.phas > 0], +pi) 40 assert_equal (fftgrain.phas[fftgrain.phas < 0], -pi) 41 assert_equal (np.abs(fftgrain.phas[np.abs(fftgrain.phas) != pi]), 0) 42 self.skipTest('fft(fvec(%d)).phas != +0, ' % win_s \ 43 + 'This is expected when using fftw3 on powerpc.') 37 44 38 45 def test_impulse(self): -
python/tests/test_filter.py
r71f2e5f r41b985f 4 4 from numpy.testing import TestCase, assert_equal, assert_almost_equal 5 5 from aubio import fvec, digital_filter 6 from utils import array_from_text_file6 from .utils import array_from_text_file 7 7 8 8 class aubio_filter_test_case(TestCase): -
python/tests/test_filterbank.py
r71f2e5f r41b985f 6 6 import numpy as np 7 7 from aubio import cvec, filterbank, float_type 8 from utils import array_from_text_file8 from .utils import array_from_text_file 9 9 10 10 class aubio_filterbank_test_case(TestCase): -
python/tests/test_midi2note.py
r71f2e5f r41b985f 3 3 4 4 from aubio import midi2note 5 from nose2.tools import params 5 6 import unittest 6 7 … … 17 18 class midi2note_good_values(unittest.TestCase): 18 19 19 def test_midi2note_known_values(self): 20 @params(*list_of_known_midis) 21 def test_midi2note_known_values(self, midi, note): 20 22 " known values are correctly converted " 21 for midi, note in list_of_known_midis: 22 self.assertEqual ( midi2note(midi), note ) 23 self.assertEqual ( midi2note(midi), note ) 23 24 24 25 class midi2note_wrong_values(unittest.TestCase): … … 41 42 42 43 if __name__ == '__main__': 43 unittest.main() 44 import nose2 45 nose2.main() -
python/tests/test_note2midi.py
r71f2e5f r41b985f 5 5 6 6 from aubio import note2midi, freq2note 7 from nose2.tools import params 7 8 import unittest 8 9 … … 14 15 ( 'B3', 59 ), 15 16 ( 'B#3', 60 ), 17 ( 'C♯4', 61 ), 16 18 ( 'A4', 69 ), 17 19 ( 'A#4', 70 ), 20 ( 'A♯4', 70 ), 21 ( 'A\u266f4', 70 ), 18 22 ( 'Bb4', 70 ), 19 23 ( 'B♭4', 70 ), 24 ( 'B\u266d4', 70 ), 20 25 ( 'G8', 115 ), 21 26 ( 'G♯8', 116 ), 22 27 ( 'G9', 127 ), 23 ( 'G\udd2a2', 45 ),24 ( 'B\ufffd2', 45 ),25 28 ( 'A♮2', 45 ), 29 ) 30 31 list_of_known_notes_with_unicode_issues = ( 32 ('C𝄪4', 62 ), 33 ('E𝄫4', 62 ), 34 ) 35 36 list_of_unknown_notes = ( 37 ( 'G\udd2a2' ), 38 ( 'B\ufffd2' ), 39 ( 'B\u266e\u266e2' ), 40 ( 'B\u266f\u266d3' ), 41 ( 'B33' ), 42 ( 'C.3' ), 43 ( 'A' ), 44 ( '2' ), 26 45 ) 27 46 28 47 class note2midi_good_values(unittest.TestCase): 29 48 30 def test_note2midi_known_values(self): 49 @params(*list_of_known_notes) 50 def test_note2midi_known_values(self, note, midi): 31 51 " known values are correctly converted " 32 for note, midi in list_of_known_notes: 52 self.assertEqual ( note2midi(note), midi ) 53 54 @params(*list_of_known_notes_with_unicode_issues) 55 def test_note2midi_known_values_with_unicode_issues(self, note, midi): 56 " known values are correctly converted, unless decoding is expected to fail" 57 try: 33 58 self.assertEqual ( note2midi(note), midi ) 59 except UnicodeEncodeError as e: 60 import sys 61 strfmt = "len(u'\\U0001D12A') != 1, excpected decoding failure | {:s} | {:s} {:s}" 62 strres = strfmt.format(e, sys.platform, sys.version) 63 # happens with: darwin 2.7.10, windows 2.7.12 64 if len('\U0001D12A') != 1 and sys.version[0] == '2': 65 self.skipTest(strres + " | upgrade to Python 3 to fix") 66 else: 67 raise 34 68 35 69 class note2midi_wrong_values(unittest.TestCase): … … 67 101 self.assertRaises(TypeError, note2midi, 123) 68 102 103 def test_note2midi_wrong_data_too_long(self): 104 " fails when passed a note with a note name longer than expected" 105 self.assertRaises(ValueError, note2midi, 'CB+-3') 106 107 @params(*list_of_unknown_notes) 108 def test_note2midi_unknown_values(self, note): 109 " unknown values throw out an error " 110 self.assertRaises(ValueError, note2midi, note) 69 111 70 112 class freq2note_simple_test(unittest.TestCase): … … 75 117 76 118 if __name__ == '__main__': 77 unittest.main() 119 import nose2 120 nose2.main() -
python/tests/test_phasevoc.py
r71f2e5f r41b985f 47 47 assert_equal ( t, 0.) 48 48 assert_equal ( s.norm, 0.) 49 assert_equal ( s.phas, 0.) 49 try: 50 assert_equal ( s.phas, 0 ) 51 except AssertionError: 52 assert_equal (s.phas[s.phas > 0], +np.pi) 53 assert_equal (s.phas[s.phas < 0], -np.pi) 54 assert_equal (np.abs(s.phas[np.abs(s.phas) != np.pi]), 0) 55 self.skipTest('pvoc(fvec(%d)).phas != +0, ' % win_s \ 56 + 'This is expected when using fftw3 on powerpc.') 50 57 assert_equal ( r, 0.) 51 58 -
python/tests/test_sink.py
r71f2e5f r41b985f 5 5 from numpy.testing import TestCase 6 6 from aubio import fvec, source, sink 7 from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path 7 from .utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path 8 9 import warnings 10 warnings.filterwarnings('ignore', category=UserWarning, append=True) 8 11 9 12 list_of_sounds = list_all_sounds('sounds') … … 26 29 if not len(list_of_sounds): 27 30 self.skipTest('add some sound files in \'python/tests/sounds\'') 31 32 def test_wrong_filename(self): 33 with self.assertRaises(RuntimeError): 34 sink('') 35 36 def test_wrong_samplerate(self): 37 with self.assertRaises(RuntimeError): 38 sink(get_tmp_sink_path(), -1) 39 40 def test_wrong_samplerate_too_large(self): 41 with self.assertRaises(RuntimeError): 42 sink(get_tmp_sink_path(), 1536001, 2) 43 44 def test_wrong_channels(self): 45 with self.assertRaises(RuntimeError): 46 sink(get_tmp_sink_path(), 44100, -1) 47 48 def test_wrong_channels_too_large(self): 49 with self.assertRaises(RuntimeError): 50 sink(get_tmp_sink_path(), 44100, 202020) 28 51 29 52 def test_many_sinks(self): … … 94 117 del_tmp_sink_path(sink_path) 95 118 119 def test_read_with(self): 120 sink_path =get_tmp_sink_path() 121 vec = fvec(128) 122 with sink(sink_path, samplerate) as g: 123 for i in range(10): 124 g(vec, 128) 125 96 126 if __name__ == '__main__': 97 127 main() -
python/tests/test_slicing.py
r71f2e5f r41b985f 4 4 from numpy.testing import TestCase, assert_equal 5 5 from aubio import slice_source_at_stamps 6 from utils import count_files_in_directory, get_default_test_sound7 from utils import count_samples_in_directory, count_samples_in_file6 from .utils import count_files_in_directory, get_default_test_sound 7 from .utils import count_samples_in_directory, count_samples_in_file 8 8 9 9 import tempfile -
python/tests/test_source.py
r71f2e5f r41b985f 5 5 from numpy.testing import TestCase, assert_equal 6 6 from aubio import source 7 from utils import list_all_sounds7 from .utils import list_all_sounds 8 8 import numpy as np 9 9 … … 57 57 if read < f.hop_size: 58 58 assert_equal(samples[read:], 0) 59 if 'brownnoise' in f.uri:60 self.assertEquals(np.count_nonzero(samples[:read]), read)61 59 break 62 60 #result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}" … … 72 70 self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e))) 73 71 assert f.samplerate != 0 74 self.read_from_source(f) 72 read_frames = self.read_from_source(f) 73 if 'f_' in soundfile and samplerate == 0: 74 import re 75 f = re.compile('.*_\([0:9]*f\)_.*') 76 match_f = re.findall('([0-9]*)f_', soundfile) 77 if len(match_f) == 1: 78 expected_frames = int(match_f[0]) 79 self.assertEqual(expected_frames, read_frames) 75 80 76 81 @params(*list_of_sounds) … … 159 164 if read < f.hop_size: 160 165 assert_equal(samples[:,read:], 0) 161 if 'brownnoise' in f.uri:162 self.assertEquals(np.count_nonzero(samples[:,:read]), read)163 166 break 164 167 #result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}" … … 167 170 return total_frames 168 171 172 class aubio_source_with(aubio_source_test_case_base): 173 174 #@params(*list_of_sounds) 175 @params(*list_of_sounds) 176 def test_read_from_mono(self, filename): 177 total_frames = 0 178 hop_size = 2048 179 with source(filename, 0, hop_size) as input_source: 180 assert_equal(input_source.hop_size, hop_size) 181 #assert_equal(input_source.samplerate, samplerate) 182 total_frames = 0 183 for frames in input_source: 184 total_frames += frames.shape[-1] 185 # check we read as many samples as we expected 186 assert_equal(total_frames, input_source.duration) 187 169 188 if __name__ == '__main__': 170 189 main()
Note: See TracChangeset
for help on using the changeset viewer.