3 from unittest import main
4 from numpy.testing import TestCase
5 from numpy.testing import assert_equal, assert_almost_equal
7 from aubio import cvec, filterbank, float_type
8 from utils import array_from_text_file
10 class aubio_filterbank_test_case(TestCase):
12 def test_members(self):
13 f = filterbank(40, 512)
14 assert_equal ([f.n_filters, f.win_s], [40, 512])
16 def test_set_coeffs(self):
17 f = filterbank(40, 512)
18 r = np.random.random([40, int(512 / 2) + 1]).astype(float_type)
20 assert_equal (r, f.get_coeffs())
23 f = filterbank(40, 512)
26 assert_equal( f(c), 0);
29 f = filterbank(40, 512)
32 assert_equal( f(c), 0);
34 def test_random_norm(self):
35 f = filterbank(40, 512)
37 c.norm[:] = np.random.random((int(512 / 2) + 1,)).astype(float_type)
38 assert_equal( f(c), 0)
40 def test_random_coeffs(self):
42 f = filterbank(40, win_s)
44 r = np.random.random([40, int(win_s / 2) + 1]).astype(float_type)
47 c.norm[:] = np.random.random((int(win_s / 2) + 1,)).astype(float_type)
48 assert_equal ( f(c) < 1., True )
49 assert_equal ( f(c) > 0., True )
51 def test_mfcc_coeffs(self):
52 f = filterbank(40, 512)
54 f.set_mel_coeffs_slaney(44100)
55 c.norm[:] = np.random.random((int(512 / 2) + 1,)).astype(float_type)
56 assert_equal ( f(c) < 1., True )
57 assert_equal ( f(c) > 0., True )
59 def test_mfcc_coeffs_16000(self):
60 expected = array_from_text_file('filterbank_mfcc_16000_512.expected')
61 f = filterbank(40, 512)
62 f.set_mel_coeffs_slaney(16000)
63 assert_almost_equal ( expected, f.get_coeffs() )
65 class aubio_filterbank_wrong_values(TestCase):
67 def test_negative_window(self):
68 self.assertRaises(ValueError, filterbank, 40, -20)
70 def test_negative_filters(self):
71 self.assertRaises(ValueError, filterbank, -40, 1024)
73 def test_filterbank_long_cvec(self):
74 f = filterbank(40, 512)
75 with self.assertRaises(ValueError):
78 def test_filterbank_short_cvec(self):
79 f = filterbank(40, 512)
80 with self.assertRaises(ValueError):
83 if __name__ == '__main__':