[db62622] | 1 | from template import aubio_unit_template |
---|
| 2 | from localaubio import * |
---|
[647a2d8] | 3 | |
---|
| 4 | buf_size = 4096 |
---|
| 5 | hop_size = 512 |
---|
| 6 | channels = 1 |
---|
| 7 | samplerate = 44100. |
---|
| 8 | |
---|
[ca1abdd] | 9 | class pitch_test_case(unittest.TestCase): |
---|
[647a2d8] | 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 |
---|
[ca1abdd] | 17 | self.o = new_aubio_pitch(buf_size, hop_size, |
---|
[647a2d8] | 18 | channels, int(samplerate), type, mode) |
---|
| 19 | |
---|
| 20 | def tearDown(self): |
---|
[ca1abdd] | 21 | del_aubio_pitch(self.o) |
---|
[647a2d8] | 22 | |
---|
[ca1abdd] | 23 | def test_pitch(self): |
---|
| 24 | """ create and delete pitch """ |
---|
[647a2d8] | 25 | pass |
---|
| 26 | |
---|
[ca1abdd] | 27 | def test_pitch_run_zeroes(self): |
---|
| 28 | """ run pitch on an empty buffer """ |
---|
[647a2d8] | 29 | vec = new_fvec(buf_size, channels) |
---|
[8802f92] | 30 | out = new_fvec(1, channels) |
---|
[647a2d8] | 31 | for i in range(100): |
---|
[ca1abdd] | 32 | aubio_pitch_do(self.o,vec, out) |
---|
[8802f92] | 33 | self.assertEqual(fvec_read_sample(out, 0, 0),0.) |
---|
[647a2d8] | 34 | del vec |
---|
| 35 | |
---|
[ca1abdd] | 36 | def test_pitch_run_4_impulses(self): |
---|
| 37 | """ run pitch on a train of 4 impulses """ |
---|
[647a2d8] | 38 | vec = new_fvec(buf_size, channels) |
---|
[8802f92] | 39 | out = new_fvec(1, channels) |
---|
[647a2d8] | 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): |
---|
[ca1abdd] | 46 | aubio_pitch_do(self.o,vec, out) |
---|
[8802f92] | 47 | self.assertEqual(fvec_read_sample(out, 0, 0),frequency) |
---|
[647a2d8] | 48 | del vec |
---|
| 49 | |
---|
[ca1abdd] | 50 | def test_pitch_run_4_positive_impulses(self): |
---|
| 51 | """ run pitch on a train of 4 positive impulses of arbitrary size """ |
---|
[647a2d8] | 52 | vec = new_fvec(buf_size, channels) |
---|
[8802f92] | 53 | out = new_fvec(1, channels) |
---|
[647a2d8] | 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) |
---|
[ca1abdd] | 60 | aubio_pitch_do(self.o,vec, out) |
---|
[8802f92] | 61 | self.assertAlmostEqual(fvec_read_sample(out, 0, 0),frequency,1) |
---|
[647a2d8] | 62 | del vec |
---|
| 63 | |
---|
[ca1abdd] | 64 | def test_pitch_run_4_negative_impulses(self): |
---|
| 65 | """ run pitch on a train of 4 negative impulses of arbitrary size """ |
---|
[647a2d8] | 66 | vec = new_fvec(buf_size, channels) |
---|
[8802f92] | 67 | out = new_fvec(1, channels) |
---|
[647a2d8] | 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) |
---|
[ca1abdd] | 74 | aubio_pitch_do(self.o,vec, out) |
---|
[8802f92] | 75 | self.assertAlmostEqual(fvec_read_sample(out, 0, 0),frequency,1) |
---|
[647a2d8] | 76 | del vec |
---|
| 77 | |
---|
[ca1abdd] | 78 | def test_pitch_run_8_impulses(self): |
---|
| 79 | """ run pitch on a train of 8 impulses """ |
---|
[647a2d8] | 80 | vec = new_fvec(buf_size, channels) |
---|
[8802f92] | 81 | out = new_fvec(1, channels) |
---|
[647a2d8] | 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): |
---|
[ca1abdd] | 91 | aubio_pitch_do(self.o,vec, out) |
---|
[8802f92] | 92 | self.assertAlmostEqual(fvec_read_sample(out, 0, 0), |
---|
[647a2d8] | 93 | samplerate/2/buf_size*8, 1) |
---|
| 94 | del vec |
---|
| 95 | |
---|
| 96 | """ |
---|
[b14107f] | 97 | class pitch_yin_test_case(pitch_test_case): |
---|
[647a2d8] | 98 | def setUp(self, type = aubio_pitch_yin): |
---|
| 99 | self.create(type=type) |
---|
| 100 | |
---|
[b14107f] | 101 | class pitch_fcomb_test_case(pitch_test_case): |
---|
[647a2d8] | 102 | def setUp(self, type = aubio_pitch_fcomb): |
---|
| 103 | self.create(type=type) |
---|
| 104 | |
---|
[b14107f] | 105 | class pitch_mcomb_test_case(pitch_test_case): |
---|
[647a2d8] | 106 | def setUp(self, type = aubio_pitch_mcomb): |
---|
| 107 | self.create(type=type) |
---|
| 108 | |
---|
[b14107f] | 109 | class pitch_schmitt_test_case(pitch_test_case): |
---|
[647a2d8] | 110 | def setUp(self, type = aubio_pitch_schmitt): |
---|
| 111 | self.create(type=type) |
---|
| 112 | """ |
---|
| 113 | |
---|
| 114 | if __name__ == '__main__': |
---|
| 115 | unittest.main() |
---|