1 | import unittest |
---|
2 | |
---|
3 | from aubio.aubiowrapper import * |
---|
4 | |
---|
5 | buf_size = 1024 |
---|
6 | hop_size = 256 |
---|
7 | channels = 2 |
---|
8 | |
---|
9 | precision = 6 |
---|
10 | |
---|
11 | class phasevoc_unit(unittest.TestCase): |
---|
12 | |
---|
13 | def setUp(self): |
---|
14 | self.o = new_aubio_pvoc(buf_size, hop_size, channels) |
---|
15 | |
---|
16 | def tearDown(self): |
---|
17 | del_aubio_pvoc(self.o) |
---|
18 | |
---|
19 | def test_create(self): |
---|
20 | """ create and delete phasevoc object """ |
---|
21 | pass |
---|
22 | |
---|
23 | def test_zeroes(self): |
---|
24 | """ run phasevoc object on zeroes """ |
---|
25 | input = new_fvec(hop_size, channels) |
---|
26 | fftgrain = new_cvec(buf_size, channels) |
---|
27 | output = new_fvec(hop_size, channels) |
---|
28 | for index in range(hop_size): |
---|
29 | for channel in range(channels): |
---|
30 | self.assertEqual(0., fvec_read_sample(input, channel, index)) |
---|
31 | aubio_pvoc_do (self.o, input, fftgrain) |
---|
32 | aubio_pvoc_rdo(self.o, fftgrain, output) |
---|
33 | for index in range(hop_size): |
---|
34 | for channel in range(channels): |
---|
35 | self.assertEqual(0., fvec_read_sample(output, channel, index)) |
---|
36 | del input |
---|
37 | del fftgrain |
---|
38 | |
---|
39 | def test_ones(self): |
---|
40 | """ run phasevoc object on ones """ |
---|
41 | input = new_fvec(hop_size, channels) |
---|
42 | fftgrain = new_cvec(buf_size, channels) |
---|
43 | output = new_fvec(hop_size, channels) |
---|
44 | for index in range(hop_size): |
---|
45 | for channel in range(channels): |
---|
46 | fvec_write_sample(input, 1., channel, index) |
---|
47 | self.assertEqual(1., fvec_read_sample(input, channel, index)) |
---|
48 | # make sure the first buf_size-hop_size samples are zeroes |
---|
49 | for i in range(buf_size/hop_size - 1): |
---|
50 | aubio_pvoc_do (self.o, input, fftgrain) |
---|
51 | aubio_pvoc_rdo(self.o, fftgrain, output) |
---|
52 | for index in range(hop_size): |
---|
53 | for channel in range(channels): |
---|
54 | self.assertAlmostEqual(0., fvec_read_sample(output, channel, index), precision) |
---|
55 | # make sure the first non zero input is correctly resynthesised |
---|
56 | aubio_pvoc_do (self.o, input, fftgrain) |
---|
57 | aubio_pvoc_rdo(self.o, fftgrain, output) |
---|
58 | for index in range(hop_size): |
---|
59 | for channel in range(channels): |
---|
60 | self.assertAlmostEqual(1., fvec_read_sample(output, channel, index), precision) |
---|
61 | del input |
---|
62 | del fftgrain |
---|