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