1 | import unittest |
---|
2 | |
---|
3 | from template import aubio_unit_template |
---|
4 | from aubio.aubiowrapper import * |
---|
5 | |
---|
6 | buf_size = 2000 |
---|
7 | channels = 2 |
---|
8 | |
---|
9 | ilow = .40 |
---|
10 | ihig = 40.00 |
---|
11 | olow = 100.0 |
---|
12 | ohig = 1000. |
---|
13 | |
---|
14 | class scale_unit(aubio_unit_template): |
---|
15 | |
---|
16 | def setUp(self): |
---|
17 | self.o = new_aubio_scale(ilow, ihig, olow, ohig) |
---|
18 | |
---|
19 | def tearDown(self): |
---|
20 | del_aubio_scale(self.o) |
---|
21 | |
---|
22 | def test(self): |
---|
23 | """ create and delete scale """ |
---|
24 | pass |
---|
25 | |
---|
26 | def test_zeroes(self): |
---|
27 | """ test scale on zeroes """ |
---|
28 | input = new_fvec(buf_size, channels) |
---|
29 | aubio_scale_do(self.o, input) |
---|
30 | for index in range(buf_size): |
---|
31 | for channel in range(channels): |
---|
32 | expval = (- ilow) * (ohig - olow) / \ |
---|
33 | (ihig - ilow) + olow |
---|
34 | val = fvec_read_sample(input, channel, index) |
---|
35 | self.assertCloseEnough(expval, val) |
---|
36 | del_fvec(input) |
---|
37 | |
---|
38 | def test_ilow(self): |
---|
39 | """ test scale on ilow """ |
---|
40 | input = new_fvec(buf_size, channels) |
---|
41 | for index in range(buf_size): |
---|
42 | for channel in range(channels): |
---|
43 | fvec_write_sample(input, ilow, channel, index) |
---|
44 | aubio_scale_do(self.o, input) |
---|
45 | for index in range(buf_size): |
---|
46 | for channel in range(channels): |
---|
47 | val = fvec_read_sample(input, channel, index) |
---|
48 | self.assertAlmostEqual(olow, val) |
---|
49 | del_fvec(input) |
---|
50 | |
---|
51 | def test_ihig(self): |
---|
52 | """ test scale on ihig """ |
---|
53 | input = new_fvec(buf_size, channels) |
---|
54 | for index in range(buf_size): |
---|
55 | for channel in range(channels): |
---|
56 | fvec_write_sample(input, ihig, channel, index) |
---|
57 | aubio_scale_do(self.o, input) |
---|
58 | for index in range(buf_size): |
---|
59 | for channel in range(channels): |
---|
60 | val = fvec_read_sample(input, channel, index) |
---|
61 | self.assertCloseEnough(ohig, val) |
---|
62 | del_fvec(input) |
---|
63 | |
---|
64 | def test_climbing_ramp(self): |
---|
65 | """ test scale on climbing ramp """ |
---|
66 | input = new_fvec(buf_size, channels) |
---|
67 | for index in range(buf_size): |
---|
68 | for channel in range(channels): |
---|
69 | rampval = index*(ihig-ilow)/buf_size + ilow |
---|
70 | fvec_write_sample(input, rampval, channel, index) |
---|
71 | aubio_scale_do(self.o, input) |
---|
72 | for index in range(buf_size): |
---|
73 | for channel in range(channels): |
---|
74 | expval = index*(ohig-olow)/buf_size + olow |
---|
75 | self.assertCloseEnough(expval, \ |
---|
76 | fvec_read_sample(input, channel, index)) |
---|
77 | del_fvec(input) |
---|
78 | |
---|
79 | def test_falling_ramp(self): |
---|
80 | """ test scale on falling ramp """ |
---|
81 | input = new_fvec(buf_size, channels) |
---|
82 | for index in range(buf_size): |
---|
83 | for channel in range(channels): |
---|
84 | fvec_write_sample(input, ihig \ |
---|
85 | - index*(ihig-ilow)/buf_size, \ |
---|
86 | channel, index) |
---|
87 | aubio_scale_do(self.o, input) |
---|
88 | for index in range(buf_size): |
---|
89 | for channel in range(channels): |
---|
90 | expval = ohig - index*(ohig-olow)/buf_size |
---|
91 | self.assertCloseEnough(expval, \ |
---|
92 | fvec_read_sample(input, channel, index)) |
---|
93 | del_fvec(input) |
---|
94 | |
---|
95 | if __name__ == '__main__': unittest.main() |
---|