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(TestCase):
14 if not len(list_of_sounds): self.skipTest('add some sound files in \'python/tests/sounds\'')
16 def read_from_sink(self, f):
21 if read < f.hop_size: break
22 print "read", "%.2fs" % (total_frames / float(f.samplerate) ),
23 print "(", total_frames, "frames", "in",
24 print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",
27 def test_samplerate_hopsize(self):
28 for p in list_of_sounds:
29 for samplerate, hop_size in zip([0, 44100, 8000, 32000], [ 512, 512, 64, 256]):
30 f = source(p, samplerate, hop_size)
31 assert f.samplerate != 0
32 self.read_from_sink(f)
34 def test_samplerate_none(self):
35 for p in list_of_sounds:
37 assert f.samplerate != 0
38 self.read_from_sink(f)
40 def test_samplerate_0(self):
41 for p in list_of_sounds:
43 assert f.samplerate != 0
44 self.read_from_sink(f)
46 def test_wrong_samplerate(self):
47 for p in list_of_sounds:
53 self.fail('does not fail with wrong samplerate')
55 def test_wrong_hop_size(self):
56 for p in list_of_sounds:
60 def test_zero_hop_size(self):
61 for p in list_of_sounds:
63 assert f.samplerate != 0
64 assert f.hop_size != 0
65 self.read_from_sink(f)
67 if __name__ == '__main__':
68 from unittest import main