4 from nose2.tools import params
5 from numpy.testing import TestCase
6 from aubio import fvec, source, sink
7 from .utils import list_all_sounds, get_tmp_sink_path, del_tmp_sink_path
10 warnings.filterwarnings('ignore', category=UserWarning, append=True)
12 list_of_sounds = list_all_sounds('sounds')
13 samplerates = [0, 44100, 8000, 32000]
14 hop_sizes = [512, 1024, 64]
18 many_files = 300 # 256 opened files is too much
21 for soundfile in list_of_sounds:
22 for hop_size in hop_sizes:
23 for samplerate in samplerates:
24 all_params.append((hop_size, samplerate, soundfile))
26 class aubio_sink_test_case(TestCase):
29 if not len(list_of_sounds):
30 self.skipTest('add some sound files in \'python/tests/sounds\'')
32 def test_wrong_filename(self):
33 with self.assertRaises(RuntimeError):
36 def test_wrong_samplerate(self):
37 with self.assertRaises(RuntimeError):
38 sink(get_tmp_sink_path(), -1)
40 def test_wrong_samplerate_too_large(self):
41 with self.assertRaises(RuntimeError):
42 sink(get_tmp_sink_path(), 1536001, 2)
44 def test_wrong_channels(self):
45 with self.assertRaises(RuntimeError):
46 sink(get_tmp_sink_path(), 44100, -1)
48 def test_wrong_channels_too_large(self):
49 with self.assertRaises(RuntimeError):
50 sink(get_tmp_sink_path(), 44100, 202020)
52 def test_many_sinks(self):
53 from tempfile import mkdtemp
58 for i in range(many_files):
59 path = os.path.join(tmpdir, 'f-' + str(i) + '.wav')
70 def test_read_and_write(self, hop_size, samplerate, path):
73 f = source(path, samplerate, hop_size)
74 except RuntimeError as e:
75 self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
76 if samplerate == 0: samplerate = f.samplerate
77 sink_path = get_tmp_sink_path()
78 g = sink(sink_path, samplerate)
84 if read < f.hop_size: break
85 del_tmp_sink_path(sink_path)
88 def test_read_and_write_multi(self, hop_size, samplerate, path):
90 f = source(path, samplerate, hop_size)
91 except RuntimeError as e:
92 self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
93 if samplerate == 0: samplerate = f.samplerate
94 sink_path = get_tmp_sink_path()
95 g = sink(sink_path, samplerate, channels = f.channels)
98 vec, read = f.do_multi()
101 if read < f.hop_size: break
102 del_tmp_sink_path(sink_path)
104 def test_close_file(self):
106 sink_path = get_tmp_sink_path()
107 g = sink(sink_path, samplerate)
109 del_tmp_sink_path(sink_path)
111 def test_close_file_twice(self):
113 sink_path = get_tmp_sink_path()
114 g = sink(sink_path, samplerate)
117 del_tmp_sink_path(sink_path)
119 def test_read_with(self):
121 sink_path = get_tmp_sink_path()
123 with sink(sink_path, samplerate) as g:
127 if __name__ == '__main__':