source: tests/python/src/onset/peakpick.py @ 61316a6

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

tests/python/src/onset/peakpick.py: update to interpolated peak position

  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[5d012d0]1from template import aubio_unit_template
[974dddc]2from localaubio import *
[5d012d0]3
4buf_size = 7 
5channels = 1
6
7class peakpick_unit(aubio_unit_template):
8
9  def setUp(self):
10    self.o = new_aubio_peakpicker(0.1)
11    pass
12
13  def tearDown(self):
14    del_aubio_peakpicker(self.o)
15    pass
16
17  def test_peakpick(self):
18    """ create and delete peakpick """
19    pass
20
21  def test_peakpick_zeroes(self):
22    """ check peakpick run on a vector full of zero returns no peak. """
[5a93302]23    self.assertEqual(0., aubio_peakpicker_get_thresholded_input(self.o))
[5d012d0]24
25  def test_peakpick_impulse(self):
26    """ check peakpick detects a single impulse as a peak. """
27    """ check two consecutive peaks are detected as one. """
28    #print
29    for index in range(0,buf_size-1):
30      input = new_fvec(buf_size, channels)
31      fvec_write_sample(input, 1000., 0, index)
32      fvec_write_sample(input, 1000./2, 0, index+1)
[5a93302]33      #print "%2s" % index, aubio_peakpicker_do(self.o, input), "|",
[5d012d0]34      #for i in range(buf_size): print fvec_read_sample(input, 0, i),
35      #print
36      del_fvec(input)
37
38  def test_peakpick_consecutive_peaks(self):
39    """ check two consecutive peaks are detected as one. """
40    #print
41    for index in range(0,buf_size-4):
42      input = new_fvec(buf_size, channels)
43      fvec_write_sample(input, 1000./2, 0, index)
44      fvec_write_sample(input, 1000., 0, index+1)
45      fvec_write_sample(input, 1000., 0, index+3)
46      fvec_write_sample(input, 1000./2, 0, index+4)
[5a93302]47      peak_pick_result = aubio_peakpicker_do(self.o, input)
48      if index == 2:
49        # we are at the peak. check the result is after current sample,
50        # and not after next one
51        self.failIf( 1. >= peak_pick_result )
52        self.failIf( 2. < peak_pick_result )
[5d012d0]53      else: self.assertEqual(0., peak_pick_result)
54      del_fvec(input)
55    for index in range(buf_size-4,buf_size-1):
56      input = new_fvec(buf_size, channels)
57      fvec_write_sample(input, 1000./2, 0, index)
58      fvec_write_sample(input, 1000., 0, index+1)
[5a93302]59      peak_pick_result = aubio_peakpicker_do(self.o, input)
60      self.assertEqual(0., peak_pick_result)
[5d012d0]61      del_fvec(input)
62
63  def test_peakpick_set_threshold(self):
64    """ test aubio_peakpicker_set_threshold """
65    new_threshold = 0.1
66    aubio_peakpicker_set_threshold(self.o, new_threshold)
67    self.assertCloseEnough(new_threshold, aubio_peakpicker_get_threshold(self.o))
68
69  def test_peakpick_get_threshold(self):
70    """ test aubio_peakpicker_get_threshold """
71    new_threshold = aubio_peakpicker_get_threshold(self.o) 
72    aubio_peakpicker_set_threshold(self.o, new_threshold)
73    self.assertCloseEnough(new_threshold, aubio_peakpicker_get_threshold(self.o))
74
75if __name__ == '__main__':
76  unittest.main()
Note: See TracBrowser for help on using the repository browser.