source: tests/python/src/onset/peakpicker.py @ be65de4

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

tests/: move file around to match src/

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