[7e204d01] | 1 | import unittest |
---|
| 2 | |
---|
| 3 | from aubio.aubiowrapper import * |
---|
| 4 | |
---|
| 5 | buf_size = 2048 |
---|
| 6 | channels = 1 |
---|
| 7 | |
---|
| 8 | class zero_crossing_rate_unit(unittest.TestCase): |
---|
| 9 | |
---|
| 10 | def setUp(self): |
---|
| 11 | self.vector = new_fvec(buf_size, channels) |
---|
| 12 | |
---|
| 13 | def tearDown(self): |
---|
| 14 | del_fvec(self.vector) |
---|
| 15 | |
---|
| 16 | def test(self): |
---|
| 17 | """ create and delete fvec """ |
---|
| 18 | pass |
---|
| 19 | |
---|
| 20 | def test_zeroes(self): |
---|
| 21 | """ check zero crossing rate on a buffer of 0. """ |
---|
| 22 | self.assertEqual(0., aubio_zero_crossing_rate(self.vector)) |
---|
| 23 | |
---|
| 24 | def test_ones(self): |
---|
| 25 | """ check zero crossing rate on a buffer of 1. """ |
---|
| 26 | for index in range(buf_size): |
---|
| 27 | for channel in range(channels): |
---|
| 28 | fvec_write_sample(self.vector, 1., channel, index) |
---|
| 29 | self.assertEqual(0., aubio_zero_crossing_rate(self.vector)) |
---|
| 30 | |
---|
| 31 | def test_impulse(self): |
---|
| 32 | """ check zero crossing rate on a buffer with an impulse """ |
---|
| 33 | fvec_write_sample(self.vector, 1., 0, buf_size / 2) |
---|
| 34 | self.assertEqual(0., aubio_zero_crossing_rate(self.vector)) |
---|
| 35 | |
---|
| 36 | def test_negative_impulse(self): |
---|
| 37 | """ check zero crossing rate on a buffer with a negative impulse """ |
---|
| 38 | fvec_write_sample(self.vector, -1., 0, buf_size / 2) |
---|
| 39 | self.assertEqual(2./buf_size, aubio_zero_crossing_rate(self.vector)) |
---|
| 40 | |
---|
| 41 | def test_single(self): |
---|
| 42 | """ check zero crossing rate on single crossing """ |
---|
| 43 | fvec_write_sample(self.vector, +1., 0, buf_size / 2 - 1) |
---|
| 44 | fvec_write_sample(self.vector, -1., 0, buf_size / 2) |
---|
| 45 | self.assertEqual(2./buf_size, aubio_zero_crossing_rate(self.vector)) |
---|
| 46 | |
---|
| 47 | def test_single_with_gap(self): |
---|
| 48 | """ check zero crossing rate on single crossing with a gap""" |
---|
| 49 | fvec_write_sample(self.vector, +1., 0, buf_size / 2 - 2) |
---|
| 50 | fvec_write_sample(self.vector, -1., 0, buf_size / 2) |
---|
| 51 | self.assertEqual(2./buf_size, aubio_zero_crossing_rate(self.vector)) |
---|
| 52 | |
---|
| 53 | if __name__ == '__main__': |
---|
| 54 | unittest.main() |
---|