ref: dd9e6f959f2fe238c7882d86a06ce6835801e99b
dir: /tests/python/src/temporal/zero_crossing_rate.py/
from template import aubio_unit_template from localaubio import * buf_size = 2048 channels = 1 class zero_crossing_rate_unit(unittest.TestCase): def setUp(self): self.vector = new_fvec(buf_size, channels) def tearDown(self): del_fvec(self.vector) def test(self): """ create and delete fvec """ pass def test_zeroes(self): """ check zero crossing rate on a buffer of 0. """ self.assertEqual(0., aubio_zero_crossing_rate(self.vector)) def test_ones(self): """ check zero crossing rate on a buffer of 1. """ for index in range(buf_size): for channel in range(channels): fvec_write_sample(self.vector, 1., channel, index) self.assertEqual(0., aubio_zero_crossing_rate(self.vector)) def test_impulse(self): """ check zero crossing rate on a buffer with an impulse """ fvec_write_sample(self.vector, 1., 0, buf_size / 2) self.assertEqual(0., aubio_zero_crossing_rate(self.vector)) def test_negative_impulse(self): """ check zero crossing rate on a buffer with a negative impulse """ fvec_write_sample(self.vector, -1., 0, buf_size / 2) self.assertEqual(2./buf_size, aubio_zero_crossing_rate(self.vector)) def test_single(self): """ check zero crossing rate on single crossing """ fvec_write_sample(self.vector, +1., 0, buf_size / 2 - 1) fvec_write_sample(self.vector, -1., 0, buf_size / 2) self.assertEqual(2./buf_size, aubio_zero_crossing_rate(self.vector)) def test_single_with_gap(self): """ check zero crossing rate on single crossing with a gap""" fvec_write_sample(self.vector, +1., 0, buf_size / 2 - 2) fvec_write_sample(self.vector, -1., 0, buf_size / 2) self.assertEqual(2./buf_size, aubio_zero_crossing_rate(self.vector)) if __name__ == '__main__': unittest.main()