3 from numpy.testing import TestCase
4 from numpy.testing import assert_equal, assert_almost_equal
6 from aubio import cvec, filterbank, float_type
7 from utils import array_from_text_file
9 class aubio_filterbank_test_case(TestCase):
11 def test_members(self):
12 f = filterbank(40, 512)
13 assert_equal ([f.n_filters, f.win_s], [40, 512])
15 def test_set_coeffs(self):
16 f = filterbank(40, 512)
17 r = np.random.random([40, int(512 / 2) + 1]).astype(float_type)
19 assert_equal (r, f.get_coeffs())
22 f = filterbank(40, 512)
25 assert_equal( f(c), 0);
28 f = filterbank(40, 512)
31 assert_equal( f(c), 0);
33 def test_random_norm(self):
34 f = filterbank(40, 512)
36 c.norm[:] = np.random.random((int(512 / 2) + 1,)).astype(float_type)
37 assert_equal( f(c), 0)
39 def test_random_coeffs(self):
41 f = filterbank(40, win_s)
43 r = np.random.random([40, int(win_s / 2) + 1]).astype(float_type)
46 c.norm[:] = np.random.random((int(win_s / 2) + 1,)).astype(float_type)
47 assert_equal ( f(c) < 1., True )
48 assert_equal ( f(c) > 0., True )
50 def test_mfcc_coeffs(self):
51 f = filterbank(40, 512)
53 f.set_mel_coeffs_slaney(44100)
54 c.norm[:] = np.random.random((int(512 / 2) + 1,)).astype(float_type)
55 assert_equal ( f(c) < 1., True )
56 assert_equal ( f(c) > 0., True )
58 def test_mfcc_coeffs_16000(self):
59 expected = array_from_text_file('filterbank_mfcc_16000_512.expected')
60 f = filterbank(40, 512)
61 f.set_mel_coeffs_slaney(16000)
62 assert_almost_equal ( expected, f.get_coeffs() )
64 def test_filterbank_long_cvec(self):
65 f = filterbank(40, 512)
66 with self.assertRaises(ValueError):
69 def test_filterbank_short_cvec(self):
70 f = filterbank(40, 512)
71 with self.assertRaises(ValueError):
74 if __name__ == '__main__':
75 from nose2 import main