source: tests/python/src/onset/peakpick.py @ 974dddc

feature/autosinkfeature/constantqfeature/pitchshiftfeature/pydocstringsfeature/timestretchpitchshiftsamplertimestretchyinfft+
Last change on this file since 974dddc was 974dddc, checked in by Paul Brossier <piem@piem.org>, 13 years ago

move tests/python/demo to tests/, add localaubio.py module helpers

  • 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(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. """
23    self.assertEqual(0., aubio_peakpick_pimrt_getval(self.o))
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)
33      #print "%2s" % index, aubio_peakpick_pimrt(input, self.o), "|",
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)
47      peak_pick_result = aubio_peakpick_pimrt(input, self.o)
48      if index == 2: self.assertEqual(1., peak_pick_result)
49      else: self.assertEqual(0., peak_pick_result)
50      #print "%2s" % index, peak_pick_result, "|",
51      #for i in range(buf_size): print fvec_read_sample(input, 0, i),
52      #print
53      del_fvec(input)
54    for index in range(buf_size-4,buf_size-1):
55      input = new_fvec(buf_size, channels)
56      fvec_write_sample(input, 1000./2, 0, index)
57      fvec_write_sample(input, 1000., 0, index+1)
58      #print "%2s" % index, aubio_peakpick_pimrt(input, self.o), "|",
59      #for i in range(buf_size): print fvec_read_sample(input, 0, i),
60      #print
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.