source: python/tests/test_filter.py @ 6f330f12

feature/crepe_org
Last change on this file since 6f330f12 was d06c9a4, checked in by Paul Brossier <piem@piem.org>, 6 years ago

Merge branch 'master' into feature/pytest

  • Property mode set to 100755
File size: 3.1 KB
Line 
1#! /usr/bin/env python
2
3from numpy.testing import TestCase, assert_equal, assert_almost_equal
4from aubio import fvec, digital_filter
5from utils import array_from_text_file
6
7class aubio_filter_test_case(TestCase):
8
9    def test_members(self):
10        f = digital_filter()
11        assert_equal (f.order, 7)
12        f = digital_filter(5)
13        assert_equal (f.order, 5)
14        f(fvec())
15
16    def test_cweighting_error(self):
17        f = digital_filter (2)
18        self.assertRaises ( ValueError, f.set_c_weighting, 44100 )
19        f = digital_filter (8)
20        self.assertRaises ( ValueError, f.set_c_weighting, 44100 )
21        f = digital_filter (5)
22        self.assertRaises ( ValueError, f.set_c_weighting, 4000 )
23        f = digital_filter (5)
24        self.assertRaises ( ValueError, f.set_c_weighting, 193000 )
25        f = digital_filter (7)
26        self.assertRaises ( ValueError, f.set_a_weighting, 193000 )
27        f = digital_filter (5)
28        self.assertRaises ( ValueError, f.set_a_weighting, 192000 )
29
30    def test_c_weighting(self):
31        expected = array_from_text_file('c_weighting_test_simple.expected')
32        f = digital_filter(5)
33        f.set_c_weighting(44100)
34        v = fvec(32)
35        v[12] = .5
36        u = f(v)
37        assert_almost_equal (expected[1], u)
38
39    def test_c_weighting_8000(self):
40        expected = array_from_text_file('c_weighting_test_simple_8000.expected')
41        f = digital_filter(5)
42        f.set_c_weighting(8000)
43        v = fvec(32)
44        v[12] = .5
45        u = f(v)
46        assert_almost_equal (expected[1], u)
47
48    def test_a_weighting(self):
49        expected = array_from_text_file('a_weighting_test_simple.expected')
50        f = digital_filter(7)
51        f.set_a_weighting(44100)
52        v = fvec(32)
53        v[12] = .5
54        u = f(v)
55        assert_almost_equal (expected[1], u)
56
57    def test_a_weighting_parted(self):
58        expected = array_from_text_file('a_weighting_test_simple.expected')
59        f = digital_filter(7)
60        f.set_a_weighting(44100)
61        v = fvec(16)
62        v[12] = .5
63        u = f(v)
64        assert_almost_equal (expected[1][:16], u)
65        # one more time
66        v = fvec(16)
67        u = f(v)
68        assert_almost_equal (expected[1][16:], u)
69
70    def test_set_biquad(self):
71        f = digital_filter(3)
72        f.set_biquad(0., 0., 0, 0., 0.)
73
74    def test_set_biquad_wrong_order(self):
75        f = digital_filter(4)
76        with self.assertRaises(ValueError):
77            f.set_biquad(0., 0., 0, 0., 0.)
78
79    def test_all_available_presets(self):
80        f = digital_filter(7)
81        for sr in [8000, 11025, 16000, 22050, 24000, 32000,
82                44100, 48000, 88200, 96000, 192000]:
83            f.set_a_weighting(sr)
84        f = digital_filter(5)
85        for sr in [8000, 11025, 16000, 22050, 24000, 32000,
86                44100, 48000, 88200, 96000, 192000]:
87            f.set_c_weighting(sr)
88
89class aubio_filter_wrong_params(TestCase):
90
91    def test_negative_order(self):
92        with self.assertRaises(ValueError):
93            digital_filter(-1)
94
95if __name__ == '__main__':
96    from unittest import main
97    main()
Note: See TracBrowser for help on using the repository browser.