1 | from localaubio import * |
---|
2 | |
---|
3 | samplerate = 44100 |
---|
4 | buf_size = 1024 |
---|
5 | channels = 1 |
---|
6 | |
---|
7 | class a_weighting_unit (aubio_unit_template): |
---|
8 | |
---|
9 | def setUp(self): |
---|
10 | self.o = new_aubio_filter_a_weighting (samplerate, channels) |
---|
11 | |
---|
12 | def tearDown(self): |
---|
13 | del_aubio_filter (self.o) |
---|
14 | |
---|
15 | def test_creation(self): |
---|
16 | pass |
---|
17 | |
---|
18 | def test_filter_zeroes(self): |
---|
19 | """ check filter run on a vector full of zeroes returns zeros """ |
---|
20 | vec = new_fvec(buf_size, channels) |
---|
21 | aubio_filter_do (self.o, vec) |
---|
22 | for index in range(buf_size): |
---|
23 | for channel in range(channels): |
---|
24 | self.assertEqual(0., fvec_read_sample(vec,channel,index)) |
---|
25 | del_fvec(vec) |
---|
26 | |
---|
27 | def test_filter_ones(self): |
---|
28 | vec = new_fvec(buf_size, channels) |
---|
29 | for index in range(buf_size): |
---|
30 | for channel in range(channels): |
---|
31 | fvec_write_sample(vec, 1., channel, index) |
---|
32 | aubio_filter_do (self.o, vec) |
---|
33 | for index in range(buf_size): |
---|
34 | for channel in range(channels): |
---|
35 | self.assertNotEqual(0., fvec_read_sample(vec,channel,index)) |
---|
36 | del_fvec(vec) |
---|
37 | |
---|
38 | def test_filter_denormal(self): |
---|
39 | vec = new_fvec(buf_size, channels) |
---|
40 | for index in range(buf_size): |
---|
41 | for channel in range(channels): |
---|
42 | fvec_write_sample(vec, 2.e-42, channel, index) |
---|
43 | aubio_filter_do (self.o, vec) |
---|
44 | for index in range(buf_size): |
---|
45 | for channel in range(channels): |
---|
46 | self.assertEqual(0., fvec_read_sample(vec,channel,index)) |
---|
47 | del_fvec(vec) |
---|
48 | |
---|
49 | def test_simple(self): |
---|
50 | buf_size = 32 |
---|
51 | input = new_fvec (buf_size, 1) |
---|
52 | output = new_fvec (buf_size, 1) |
---|
53 | expected = array_from_text_file('src/temporal/a_weighting_test_simple.expected') |
---|
54 | fvec_write_sample (input, 0.5, 0, 12) |
---|
55 | for i in range(buf_size): |
---|
56 | for c in range(channels): |
---|
57 | self.assertEqual(expected[0][i], fvec_read_sample(input, c, i)) |
---|
58 | f = new_aubio_filter_a_weighting (samplerate, channels) |
---|
59 | aubio_filter_do_outplace (f, input, output) |
---|
60 | del_aubio_filter (f) |
---|
61 | for i in range(buf_size): |
---|
62 | for c in range(channels): |
---|
63 | self.assertCloseEnough(expected[1][i], fvec_read_sample(output, c, i)) |
---|
64 | |
---|
65 | if __name__ == '__main__': |
---|
66 | import unittest |
---|
67 | unittest.main() |
---|