source: tests/python/src/pitch/pitchdetection.py @ 41f4c5b

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

tests/python/src/pitch/pitchdetection.py: update prototypes

  • Property mode set to 100644
File size: 3.6 KB
Line 
1from template import aubio_unit_template
2from localaubio import *
3
4buf_size = 4096
5hop_size = 512
6channels = 1
7samplerate = 44100.
8
9class pitchdetection_test_case(unittest.TestCase):
10
11  def setUp(self, type = aubio_pitch_yinfft, mode = aubio_pitchm_freq):
12    self.create(type=type)
13 
14  def create(self, type = aubio_pitch_yinfft,
15      mode = aubio_pitchm_freq):
16    self.type = type
17    self.o = new_aubio_pitchdetection(buf_size, hop_size,
18        channels, int(samplerate), type, mode)
19
20  def tearDown(self):
21    del_aubio_pitchdetection(self.o)
22
23  def test_pitchdetection(self):
24    """ create and delete pitchdetection """
25    pass
26
27  def test_pitchdetection_run_zeroes(self):
28    """ run pitchdetection on an empty buffer """
29    vec = new_fvec(buf_size, channels)
30    for i in range(100):
31      self.assertEqual(aubio_pitchdetection_do(self.o,vec),0.)
32    del vec
33
34  def test_pitchdetection_run_4_impulses(self):
35    """ run pitchdetection on a train of 4 impulses """
36    vec = new_fvec(buf_size, channels)
37    fvec_write_sample(vec,-1.,0,  0)
38    fvec_write_sample(vec, 1.,0,  buf_size/4)
39    fvec_write_sample(vec,-1.,0,  buf_size/2)
40    fvec_write_sample(vec, 1.,0,3*buf_size/4)
41    frequency = samplerate/2*4/buf_size
42    for i in range(100):
43      self.assertEqual(aubio_pitchdetection_do(self.o,vec),frequency)
44    del vec
45
46  def test_pitchdetection_run_4_positive_impulses(self):
47    """ run pitchdetection on a train of 4 positive impulses of arbitrary size """
48    vec = new_fvec(buf_size, channels)
49    frequency = samplerate/2*8/buf_size
50    for i in range(100):
51      fvec_write_sample(vec, 2.-.01*i,0,  0)
52      fvec_write_sample(vec, 2.-.01*i,0,  buf_size/4)
53      fvec_write_sample(vec, 2.-.01*i,0,  buf_size/2)
54      fvec_write_sample(vec, 2.-.01*i,0,3*buf_size/4)
55      self.assertAlmostEqual(aubio_pitchdetection_do(self.o,vec),frequency,1)
56    del vec
57
58  def test_pitchdetection_run_4_negative_impulses(self):
59    """ run pitchdetection on a train of 4 negative impulses of arbitrary size """
60    vec = new_fvec(buf_size, channels)
61    frequency = samplerate/2*8/buf_size
62    for i in range(1,100):
63      fvec_write_sample(vec,-.01*i,0,  0)
64      fvec_write_sample(vec,-.01*i,0,  buf_size/4)
65      fvec_write_sample(vec,-.01*i,0,  buf_size/2)
66      fvec_write_sample(vec,-.01*i,0,3*buf_size/4)
67      self.assertAlmostEqual(aubio_pitchdetection_do(self.o,vec),frequency,1)
68    del vec
69
70  def test_pitchdetection_run_8_impulses(self):
71    """ run pitchdetection on a train of 8 impulses """
72    vec = new_fvec(buf_size, channels)
73    fvec_write_sample(vec, 1.,0,  0)
74    fvec_write_sample(vec,-1.,0,  buf_size/8)
75    fvec_write_sample(vec, 1.,0,  buf_size/4)
76    fvec_write_sample(vec,-1.,0,3*buf_size/8)
77    fvec_write_sample(vec, 1.,0,  buf_size/2)
78    fvec_write_sample(vec,-1.,0,5*buf_size/8)
79    fvec_write_sample(vec, 1.,0,3*buf_size/4)
80    fvec_write_sample(vec,-1.,0,7*buf_size/8)
81    for i in range(100):
82      self.assertAlmostEqual(aubio_pitchdetection_do(self.o,vec),
83        samplerate/2/buf_size*8, 1) 
84    del vec
85
86"""
87class pitchdetection_yin_test_case(pitchdetection_test_case):
88  def setUp(self, type = aubio_pitch_yin):
89    self.create(type=type)
90
91class pitchdetection_fcomb_test_case(pitchdetection_test_case):
92  def setUp(self, type = aubio_pitch_fcomb):
93    self.create(type=type)
94
95class pitchdetection_mcomb_test_case(pitchdetection_test_case):
96  def setUp(self, type = aubio_pitch_mcomb):
97    self.create(type=type)
98
99class pitchdetection_schmitt_test_case(pitchdetection_test_case):
100  def setUp(self, type = aubio_pitch_schmitt):
101    self.create(type=type)
102"""
103
104if __name__ == '__main__':
105  unittest.main()
Note: See TracBrowser for help on using the repository browser.