source: python/tests/test_filter.py @ 7fc8406

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/timestretchfix/ffmpeg5
Last change on this file since 7fc8406 was b41672c, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[test] improve coverage of filters

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