source: tests/python/src/pitch/pitchdetection.py @ 66a150a2

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

move around files in tests/python according to src/ changes

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