source: interfaces/python/test_filter.py @ 84e0606

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 84e0606 was 07bf04e6, checked in by Paul Brossier <piem@piem.org>, 15 years ago

python/: update to new filter, test_filter.py py-filter.c

  • Property mode set to 100644
File size: 2.0 KB
Line 
1from numpy.testing import TestCase, run_module_suite
2from numpy.testing import assert_equal, assert_almost_equal
3from _aubio import *
4from numpy import array
5
6def array_from_text_file(filename, dtype = 'float'):
7  return array([line.split() for line in open(filename).readlines()], 
8      dtype = dtype)
9
10class aubio_filter_test_case(TestCase):
11
12  def test_members(self):
13    f = digital_filter()
14    assert_equal ([f.channels, f.order], [1, 7])
15    f = digital_filter(5, 2)
16    assert_equal ([f.channels, f.order], [2, 5])
17    f(fvec())
18 
19  def test_cweighting_error(self):
20    f = digital_filter (2, 1)
21    self.assertRaises ( ValueError, f.set_c_weighting, 44100 )
22    f = digital_filter (8, 1)
23    self.assertRaises ( ValueError, f.set_c_weighting, 44100 )
24    f = digital_filter (5, 1)
25    self.assertRaises ( ValueError, f.set_c_weighting, 4000 )
26    f = digital_filter (5, 1)
27    self.assertRaises ( ValueError, f.set_c_weighting, 193000 )
28    f = digital_filter (7, 1)
29    self.assertRaises ( ValueError, f.set_a_weighting, 193000 )
30    f = digital_filter (5, 1)
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, 1)
36    f.set_c_weighting(44100)
37    v = fvec(32)
38    v[0][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, 1)
45    f.set_a_weighting(44100)
46    v = fvec(32)
47    v[0][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, 1)
54    f.set_a_weighting(44100)
55    v = fvec(16)
56    v[0][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
64if __name__ == '__main__':
65  from unittest import main
66  main()
67
Note: See TracBrowser for help on using the repository browser.