source: python/tests/utils.py @ aee840b

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since aee840b was aee840b, checked in by Paul Brossier <piem@piem.org>, 11 years ago

python/lib/aubio/slicing.py: error checking, add more tests, use get_default_sound

  • Property mode set to 100644
File size: 1.4 KB
Line 
1#! /usr/bin/env python
2
3def array_from_text_file(filename, dtype = 'float'):
4    import os.path
5    from numpy import array
6    filename = os.path.join(os.path.dirname(__file__), filename)
7    return array([line.split() for line in open(filename).readlines()],
8        dtype = dtype)
9
10def list_all_sounds(rel_dir):
11    import os.path, glob
12    datadir = os.path.join(os.path.dirname(__file__), rel_dir)
13    return glob.glob(os.path.join(datadir,'*.*'))
14
15def get_default_test_sound(TestCase, rel_dir = 'sounds'):
16    all_sounds = list_all_sounds(rel_dir)
17    if len(all_sounds) == 0:
18        TestCase.skipTest("please add some sounds in \'python/tests/sounds\'")
19    else:
20        return all_sounds[0]
21
22def array_from_yaml_file(filename):
23    import yaml
24    f = open(filename)
25    yaml_data = yaml.safe_load(f)
26    f.close()
27    return yaml_data
28
29def count_samples_in_file(file_path):
30    from aubio import source
31    hopsize = 256
32    s = source(file_path, 0, hopsize)
33    total_frames = 0
34    while True:
35        samples, read = s()
36        total_frames += read
37        if read < hopsize: break
38    return total_frames
39
40def count_samples_in_directory(samples_dir):
41    import os
42    total_frames = 0
43    for f in os.walk(samples_dir):
44        if len(f[2]):
45            for each in f[2]:
46                file_path = os.path.join(f[0], each)
47                if file_path:
48                    total_frames += count_samples_in_file(file_path)
49    return total_frames
Note: See TracBrowser for help on using the repository browser.