source: tests/python/src/onset/peakpick.py @ b63b322

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

added first tests for peakpicker

  • Property mode set to 100644
File size: 2.7 KB
Line 
1from template import aubio_unit_template
2
3from aubio.aubiowrapper import *
4
5buf_size = 7 
6channels = 1
7
8class peakpick_unit(aubio_unit_template):
9
10  def setUp(self):
11    self.o = new_aubio_peakpicker(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_peakpick_pimrt_getval(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_peakpick_pimrt(input, self.o), "|",
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_peakpick_pimrt(input, self.o)
49      if index == 2: self.assertEqual(1., peak_pick_result)
50      else: self.assertEqual(0., peak_pick_result)
51      #print "%2s" % index, peak_pick_result, "|",
52      #for i in range(buf_size): print fvec_read_sample(input, 0, i),
53      #print
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)
59      #print "%2s" % index, aubio_peakpick_pimrt(input, self.o), "|",
60      #for i in range(buf_size): print fvec_read_sample(input, 0, i),
61      #print
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.