1 | from numpy.testing import TestCase, run_module_suite |
---|
2 | from numpy.testing import assert_equal, assert_almost_equal |
---|
3 | from aubio import fvec, digital_filter |
---|
4 | from numpy import array |
---|
5 | |
---|
6 | def array_from_text_file(filename, dtype = 'float'): |
---|
7 | return array([line.split() for line in open(filename).readlines()], |
---|
8 | dtype = dtype) |
---|
9 | |
---|
10 | class aubio_filter_test_case(TestCase): |
---|
11 | |
---|
12 | def test_members(self): |
---|
13 | f = digital_filter() |
---|
14 | assert_equal (f.order, 7) |
---|
15 | f = digital_filter(5) |
---|
16 | assert_equal (f.order, 5) |
---|
17 | f(fvec()) |
---|
18 | |
---|
19 | def test_cweighting_error(self): |
---|
20 | f = digital_filter (2) |
---|
21 | self.assertRaises ( ValueError, f.set_c_weighting, 44100 ) |
---|
22 | f = digital_filter (8) |
---|
23 | self.assertRaises ( ValueError, f.set_c_weighting, 44100 ) |
---|
24 | f = digital_filter (5) |
---|
25 | self.assertRaises ( ValueError, f.set_c_weighting, 4000 ) |
---|
26 | f = digital_filter (5) |
---|
27 | self.assertRaises ( ValueError, f.set_c_weighting, 193000 ) |
---|
28 | f = digital_filter (7) |
---|
29 | self.assertRaises ( ValueError, f.set_a_weighting, 193000 ) |
---|
30 | f = digital_filter (5) |
---|
31 | self.assertRaises ( ValueError, f.set_a_weighting, 192000 ) |
---|
32 | |
---|
33 | def test_c_weighting(self): |
---|
34 | expected = array_from_text_file('c_weighting_test_simple.expected') |
---|
35 | f = digital_filter(5) |
---|
36 | f.set_c_weighting(44100) |
---|
37 | v = fvec(32) |
---|
38 | v[12] = .5 |
---|
39 | u = f(v) |
---|
40 | assert_almost_equal (expected[1], u) |
---|
41 | |
---|
42 | def test_a_weighting(self): |
---|
43 | expected = array_from_text_file('a_weighting_test_simple.expected') |
---|
44 | f = digital_filter(7) |
---|
45 | f.set_a_weighting(44100) |
---|
46 | v = fvec(32) |
---|
47 | v[12] = .5 |
---|
48 | u = f(v) |
---|
49 | assert_almost_equal (expected[1], u) |
---|
50 | |
---|
51 | def test_a_weighting_parted(self): |
---|
52 | expected = array_from_text_file('a_weighting_test_simple.expected') |
---|
53 | f = digital_filter(7) |
---|
54 | f.set_a_weighting(44100) |
---|
55 | v = fvec(16) |
---|
56 | v[12] = .5 |
---|
57 | u = f(v) |
---|
58 | assert_almost_equal (expected[1][:16], u) |
---|
59 | # one more time |
---|
60 | v = fvec(16) |
---|
61 | u = f(v) |
---|
62 | assert_almost_equal (expected[1][16:], u) |
---|
63 | |
---|
64 | if __name__ == '__main__': |
---|
65 | from unittest import main |
---|
66 | main() |
---|
67 | |
---|