source: tests/python/src/temporal/zero_crossing_rate.py @ 05a3479

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 05a3479 was db62622, checked in by Paul Brossier <piem@piem.org>, 15 years ago

tests/python: update imports

  • Property mode set to 100644
File size: 1.8 KB
Line 
1from template import aubio_unit_template
2from localaubio import *
3
4buf_size = 2048
5channels = 1
6
7class 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
52if __name__ == '__main__':
53  unittest.main()
Note: See TracBrowser for help on using the repository browser.