source: tests/python/src/pitch/pitchdetection.py @ 4e3723d

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

examples/aubiopitch.c: added c version of aubiopitch, more renaming

  • Property mode set to 100644
File size: 3.7 KB
Line 
1from template import aubio_unit_template
2from localaubio import *
3
4buf_size = 4096
5hop_size = 512
6channels = 1
7samplerate = 44100.
8
9class pitch_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_pitch(buf_size, hop_size,
18        channels, int(samplerate), type, mode)
19
20  def tearDown(self):
21    del_aubio_pitch(self.o)
22
23  def test_pitch(self):
24    """ create and delete pitch """
25    pass
26
27  def test_pitch_run_zeroes(self):
28    """ run pitch on an empty buffer """
29    vec = new_fvec(buf_size, channels)
30    out = new_fvec(1, channels)
31    for i in range(100):
32      aubio_pitch_do(self.o,vec, out)
33      self.assertEqual(fvec_read_sample(out, 0, 0),0.)
34    del vec
35
36  def test_pitch_run_4_impulses(self):
37    """ run pitch on a train of 4 impulses """
38    vec = new_fvec(buf_size, channels)
39    out = new_fvec(1, channels)
40    fvec_write_sample(vec,-1.,0,  0)
41    fvec_write_sample(vec, 1.,0,  buf_size/4)
42    fvec_write_sample(vec,-1.,0,  buf_size/2)
43    fvec_write_sample(vec, 1.,0,3*buf_size/4)
44    frequency = samplerate/2*4/buf_size
45    for i in range(100):
46      aubio_pitch_do(self.o,vec, out)
47      self.assertEqual(fvec_read_sample(out, 0, 0),frequency)
48    del vec
49
50  def test_pitch_run_4_positive_impulses(self):
51    """ run pitch on a train of 4 positive impulses of arbitrary size """
52    vec = new_fvec(buf_size, channels)
53    out = new_fvec(1, channels)
54    frequency = samplerate/2*8/buf_size
55    for i in range(100):
56      fvec_write_sample(vec, 2.-.01*i,0,  0)
57      fvec_write_sample(vec, 2.-.01*i,0,  buf_size/4)
58      fvec_write_sample(vec, 2.-.01*i,0,  buf_size/2)
59      fvec_write_sample(vec, 2.-.01*i,0,3*buf_size/4)
60      aubio_pitch_do(self.o,vec, out)
61      self.assertAlmostEqual(fvec_read_sample(out, 0, 0),frequency,1)
62    del vec
63
64  def test_pitch_run_4_negative_impulses(self):
65    """ run pitch on a train of 4 negative impulses of arbitrary size """
66    vec = new_fvec(buf_size, channels)
67    out = new_fvec(1, channels)
68    frequency = samplerate/2*8/buf_size
69    for i in range(1,100):
70      fvec_write_sample(vec,-.01*i,0,  0)
71      fvec_write_sample(vec,-.01*i,0,  buf_size/4)
72      fvec_write_sample(vec,-.01*i,0,  buf_size/2)
73      fvec_write_sample(vec,-.01*i,0,3*buf_size/4)
74      aubio_pitch_do(self.o,vec, out)
75      self.assertAlmostEqual(fvec_read_sample(out, 0, 0),frequency,1)
76    del vec
77
78  def test_pitch_run_8_impulses(self):
79    """ run pitch on a train of 8 impulses """
80    vec = new_fvec(buf_size, channels)
81    out = new_fvec(1, channels)
82    fvec_write_sample(vec, 1.,0,  0)
83    fvec_write_sample(vec,-1.,0,  buf_size/8)
84    fvec_write_sample(vec, 1.,0,  buf_size/4)
85    fvec_write_sample(vec,-1.,0,3*buf_size/8)
86    fvec_write_sample(vec, 1.,0,  buf_size/2)
87    fvec_write_sample(vec,-1.,0,5*buf_size/8)
88    fvec_write_sample(vec, 1.,0,3*buf_size/4)
89    fvec_write_sample(vec,-1.,0,7*buf_size/8)
90    for i in range(100):
91      aubio_pitch_do(self.o,vec, out)
92      self.assertAlmostEqual(fvec_read_sample(out, 0, 0),
93        samplerate/2/buf_size*8, 1) 
94    del vec
95
96"""
97class pitch_yin_test_case(pitch_test_case):
98  def setUp(self, type = aubio_pitch_yin):
99    self.create(type=type)
100
101class pitch_fcomb_test_case(pitch_test_case):
102  def setUp(self, type = aubio_pitch_fcomb):
103    self.create(type=type)
104
105class pitch_mcomb_test_case(pitch_test_case):
106  def setUp(self, type = aubio_pitch_mcomb):
107    self.create(type=type)
108
109class pitch_schmitt_test_case(pitch_test_case):
110  def setUp(self, type = aubio_pitch_schmitt):
111    self.create(type=type)
112"""
113
114if __name__ == '__main__':
115  unittest.main()
Note: See TracBrowser for help on using the repository browser.