1 | from localaubio import * |
---|
2 | |
---|
3 | class c_weighting_unit(aubio_unit_template): |
---|
4 | |
---|
5 | def test_simple(self): |
---|
6 | expected = array_from_text_file('src/temporal/c_weighting_test_simple.expected') |
---|
7 | samplerate = 44100 |
---|
8 | channels = 1 |
---|
9 | buf_size = 32 |
---|
10 | |
---|
11 | # prepare input |
---|
12 | input = new_fvec (buf_size, 1) |
---|
13 | output = new_fvec (buf_size, 1) |
---|
14 | fvec_write_sample (input, 0.5, 0, 12) |
---|
15 | |
---|
16 | # check input |
---|
17 | for i in range(buf_size): |
---|
18 | for c in range(channels): |
---|
19 | self.assertEqual(expected[0][i], fvec_read_sample(input, c, i)) |
---|
20 | |
---|
21 | # filter |
---|
22 | f = new_aubio_filter_c_weighting (samplerate, channels) |
---|
23 | aubio_filter_do_outplace (f, input, output) |
---|
24 | del_aubio_filter (f) |
---|
25 | |
---|
26 | # check output |
---|
27 | for i in range(buf_size): |
---|
28 | for c in range(channels): |
---|
29 | self.assertAlmostEqual(expected[1][i], fvec_read_sample(output, c, i)) |
---|
30 | |
---|
31 | def test_simple_8000(self): |
---|
32 | expected = array_from_text_file('src/temporal/c_weighting_test_simple_8000.expected') |
---|
33 | samplerate = 8000 |
---|
34 | channels = 1 |
---|
35 | buf_size = 32 |
---|
36 | |
---|
37 | # prepare input |
---|
38 | input = new_fvec (buf_size, 1) |
---|
39 | output = new_fvec (buf_size, 1) |
---|
40 | fvec_write_sample (input, 0.5, 0, 12) |
---|
41 | |
---|
42 | # check input |
---|
43 | for i in range(buf_size): |
---|
44 | for c in range(channels): |
---|
45 | self.assertEqual(expected[0][i], fvec_read_sample(input, c, i)) |
---|
46 | |
---|
47 | # filter |
---|
48 | f = new_aubio_filter_c_weighting (samplerate, channels) |
---|
49 | aubio_filter_do_outplace (f, input, output) |
---|
50 | del_aubio_filter (f) |
---|
51 | |
---|
52 | # check output |
---|
53 | for i in range(buf_size): |
---|
54 | for c in range(channels): |
---|
55 | self.assertAlmostEqual(expected[1][i], fvec_read_sample(output, c, i)) |
---|
56 | |
---|
57 | if __name__ == '__main__': |
---|
58 | import unittest |
---|
59 | unittest.main() |
---|