3 from numpy.testing import TestCase, assert_equal, assert_almost_equal
4 from nose2.tools import params
5 from aubio import fvec, source, sink
6 from numpy import array
7 from utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
9 list_of_sounds = list_all_sounds('sounds')
10 samplerates = [0, 44100, 8000, 32000]
11 hop_sizes = [512, 1024, 64]
15 many_files = 300 # 256 opened files is too much
18 for soundfile in list_of_sounds:
19 for hop_size in hop_sizes:
20 for samplerate in samplerates:
21 all_params.append((hop_size, samplerate, soundfile))
23 class aubio_sink_test_case(TestCase):
26 if not len(list_of_sounds):
27 self.skipTest('add some sound files in \'python/tests/sounds\'')
29 def test_many_sinks(self):
30 from tempfile import mkdtemp
35 for i in range(many_files):
36 path = os.path.join(tmpdir, 'f-' + str(i) + '.wav')
47 def test_read_and_write(self, hop_size, samplerate, path):
50 f = source(path, samplerate, hop_size)
51 except RuntimeError as e:
52 self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
53 if samplerate == 0: samplerate = f.samplerate
54 sink_path = get_tmp_sink_path()
55 g = sink(sink_path, samplerate)
61 if read < f.hop_size: break
62 del_tmp_sink_path(sink_path)
65 def test_read_and_write_multi(self, hop_size, samplerate, path):
67 f = source(path, samplerate, hop_size)
68 except RuntimeError as e:
69 self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
70 if samplerate == 0: samplerate = f.samplerate
71 sink_path = get_tmp_sink_path()
72 g = sink(sink_path, samplerate, channels = f.channels)
75 vec, read = f.do_multi()
78 if read < f.hop_size: break
79 del_tmp_sink_path(sink_path)
81 def test_close_file(self):
83 sink_path = get_tmp_sink_path()
84 g = sink(sink_path, samplerate)
86 del_tmp_sink_path(sink_path)
88 def test_close_file_twice(self):
90 sink_path = get_tmp_sink_path()
91 g = sink(sink_path, samplerate)
94 del_tmp_sink_path(sink_path)
96 if __name__ == '__main__':
97 from nose2 import main