1 from template import aubio_unit_template
2 from localaubio import *
7 class peakpick_unit(aubio_unit_template):
10 self.o = new_aubio_peakpicker(1)
11 aubio_peakpicker_set_threshold (0.1)
15 del_aubio_peakpicker(self.o)
18 def test_peakpick(self):
19 """ create and delete peakpick """
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))
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. """
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),
39 def test_peakpick_consecutive_peaks(self):
40 """ check two consecutive peaks are detected as one. """
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)
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)
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)
64 def test_peakpick_set_threshold(self):
65 """ test aubio_peakpicker_set_threshold """
67 aubio_peakpicker_set_threshold(self.o, new_threshold)
68 self.assertCloseEnough(new_threshold, aubio_peakpicker_get_threshold(self.o))
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))
76 if __name__ == '__main__':