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