feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change
on this file since 7e9c67d was
376d5e9,
checked in by Paul Brossier <piem@piem.org>, 9 years ago
|
tests/: continue python3 preparation
|
-
Property mode set to
100644
|
File size:
2.0 KB
|
Rev | Line | |
---|
[a4cc8e5] | 1 | #! /usr/bin/env python |
---|
| 2 | |
---|
| 3 | def array_from_text_file(filename, dtype = 'float'): |
---|
[e1bfde5] | 4 | import os.path |
---|
| 5 | from numpy import array |
---|
| 6 | filename = os.path.join(os.path.dirname(__file__), filename) |
---|
[376d5e9] | 7 | with open(filename) as f: |
---|
| 8 | lines = f.readlines() |
---|
| 9 | return array([line.split() for line in lines], |
---|
| 10 | dtype = dtype) |
---|
[a4cc8e5] | 11 | |
---|
[e1bfde5] | 12 | def list_all_sounds(rel_dir): |
---|
| 13 | import os.path, glob |
---|
| 14 | datadir = os.path.join(os.path.dirname(__file__), rel_dir) |
---|
| 15 | return glob.glob(os.path.join(datadir,'*.*')) |
---|
[2693655] | 16 | |
---|
[aee840b] | 17 | def get_default_test_sound(TestCase, rel_dir = 'sounds'): |
---|
| 18 | all_sounds = list_all_sounds(rel_dir) |
---|
| 19 | if len(all_sounds) == 0: |
---|
| 20 | TestCase.skipTest("please add some sounds in \'python/tests/sounds\'") |
---|
| 21 | else: |
---|
| 22 | return all_sounds[0] |
---|
| 23 | |
---|
[ab35262] | 24 | def get_tmp_sink_path(): |
---|
[18d8bef] | 25 | from tempfile import mkstemp |
---|
| 26 | import os |
---|
[ab35262] | 27 | fd, path = mkstemp() |
---|
[18d8bef] | 28 | os.close(fd) |
---|
[ab35262] | 29 | return path |
---|
| 30 | |
---|
| 31 | def del_tmp_sink_path(path): |
---|
| 32 | import os |
---|
| 33 | os.unlink(path) |
---|
[18d8bef] | 34 | |
---|
[2693655] | 35 | def array_from_yaml_file(filename): |
---|
| 36 | import yaml |
---|
| 37 | f = open(filename) |
---|
| 38 | yaml_data = yaml.safe_load(f) |
---|
| 39 | f.close() |
---|
| 40 | return yaml_data |
---|
[88432a9] | 41 | |
---|
| 42 | def count_samples_in_file(file_path): |
---|
| 43 | from aubio import source |
---|
| 44 | hopsize = 256 |
---|
| 45 | s = source(file_path, 0, hopsize) |
---|
| 46 | total_frames = 0 |
---|
| 47 | while True: |
---|
| 48 | samples, read = s() |
---|
| 49 | total_frames += read |
---|
| 50 | if read < hopsize: break |
---|
| 51 | return total_frames |
---|
| 52 | |
---|
| 53 | def count_samples_in_directory(samples_dir): |
---|
| 54 | import os |
---|
| 55 | total_frames = 0 |
---|
| 56 | for f in os.walk(samples_dir): |
---|
| 57 | if len(f[2]): |
---|
| 58 | for each in f[2]: |
---|
| 59 | file_path = os.path.join(f[0], each) |
---|
| 60 | if file_path: |
---|
| 61 | total_frames += count_samples_in_file(file_path) |
---|
| 62 | return total_frames |
---|
[f36ecea] | 63 | |
---|
| 64 | def count_files_in_directory(samples_dir): |
---|
| 65 | import os |
---|
| 66 | total_files = 0 |
---|
| 67 | for f in os.walk(samples_dir): |
---|
| 68 | if len(f[2]): |
---|
| 69 | for each in f[2]: |
---|
| 70 | file_path = os.path.join(f[0], each) |
---|
| 71 | if file_path: |
---|
| 72 | total_files += 1 |
---|
| 73 | return total_files |
---|
Note: See
TracBrowser
for help on using the repository browser.