3 from numpy.testing import TestCase, assert_equal, assert_almost_equal
4 from aubio import fvec, source
5 from numpy import array
6 from utils import list_all_sounds
8 list_of_sounds = list_all_sounds('sounds')
11 class aubio_source_test_case_base(TestCase):
14 if not len(list_of_sounds): self.skipTest('add some sound files in \'python/tests/sounds\'')
16 class aubio_source_test_case(aubio_source_test_case_base):
18 def test_close_file(self):
19 samplerate = 0 # use native samplerate
21 for p in list_of_sounds:
22 f = source(p, samplerate, hop_size)
25 def test_close_file_twice(self):
26 samplerate = 0 # use native samplerate
28 for p in list_of_sounds:
29 f = source(p, samplerate, hop_size)
33 class aubio_source_read_test_case(aubio_source_test_case_base):
35 def read_from_sink(self, f):
40 if read < f.hop_size: break
41 print "read", "%.2fs" % (total_frames / float(f.samplerate) ),
42 print "(", total_frames, "frames", "in",
43 print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",
46 def test_samplerate_hopsize(self):
47 for p in list_of_sounds:
48 for samplerate, hop_size in zip([0, 44100, 8000, 32000], [ 512, 512, 64, 256]):
49 f = source(p, samplerate, hop_size)
50 assert f.samplerate != 0
51 self.read_from_sink(f)
53 def test_samplerate_none(self):
54 for p in list_of_sounds:
56 assert f.samplerate != 0
57 self.read_from_sink(f)
59 def test_samplerate_0(self):
60 for p in list_of_sounds:
62 assert f.samplerate != 0
63 self.read_from_sink(f)
65 def test_wrong_samplerate(self):
66 for p in list_of_sounds:
72 self.fail('negative samplerate does not raise ValueError')
74 def test_wrong_hop_size(self):
75 for p in list_of_sounds:
81 self.fail('negative hop_size does not raise ValueError')
83 def test_zero_hop_size(self):
84 for p in list_of_sounds:
86 assert f.samplerate != 0
87 assert f.hop_size != 0
88 self.read_from_sink(f)
90 class aubio_source_readmulti_test_case(aubio_source_read_test_case):
92 def read_from_sink(self, f):
95 vec, read = f.do_multi()
97 if read < f.hop_size: break
98 print "read", "%.2fs" % (total_frames / float(f.samplerate) ),
99 print "(", total_frames, "frames", "in",
100 print f.channels, "channels and",
101 print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",
104 if __name__ == '__main__':
105 from unittest import main