Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -2,18 +2,86 @@ · 1 unmodified line | |||
| 2 | 2 | ||
| 3 | from numpy.testing import TestCase, run_module_suite | 3 | from numpy.testing import TestCase, run_module_suite |
| 4 | from numpy.testing import assert_equal, assert_almost_equal | 4 | from numpy.testing import assert_equal, assert_almost_equal |
| 5 | # WARNING: numpy also has an fft object | 5 | from aubio import onset |
| 6 | from aubio import onset, cvec | ||
| 7 | from numpy import array, shape, arange, zeros, log | ||
| 8 | from math import pi | ||
| 9 | 6 | ||
| 10 | class aubio_onset(TestCase): | 7 | class aubio_onset_default(TestCase): |
| 11 | 8 | ||
| 12 | def test_members(self): | 9 | def test_members(self): |
| 13 | o = onset() | 10 | o = onset() |
| 14 | assert_equal ([o.buf_size, o.hop_size, o.method, o.samplerate], | 11 | assert_equal ([o.buf_size, o.hop_size, o.method, o.samplerate], |
| 15 | [1024,512,'default',44100]) | 12 | [1024,512,'default',44100]) |
| 16 | 13 | ||
| 14 | class aubio_onset_params(TestCase): | ||
| 15 | |||
| 16 | samplerate = 44100 | ||
| 17 | |||
| 18 | def setUp(self): | ||
| 19 | self.o = onset(samplerate = self.samplerate) | ||
| 20 | |||
| 21 | def test_get_delay(self): | ||
| 22 | assert_equal (self.o.get_delay(), int(4.3 * self.o.hop_size)) | ||
| 23 | |||
| 24 | def test_get_delay_s(self): | ||
| 25 | assert_almost_equal (self.o.get_delay_s(), self.o.get_delay() / float(self.samplerate)) | ||
| 26 | |||
| 27 | def test_get_delay_ms(self): | ||
| 28 | assert_almost_equal (self.o.get_delay_ms(), self.o.get_delay() * 1000. / self.samplerate, 5) | ||
| 29 | |||
| 30 | def test_get_minioi(self): | ||
| 31 | assert_almost_equal (self.o.get_minioi(), 0.02 * self.samplerate) | ||
| 32 | |||
| 33 | def test_get_minioi_s(self): | ||
| 34 | assert_almost_equal (self.o.get_minioi_s(), 0.02) | ||
| 35 | |||
| 36 | def test_get_minioi_ms(self): | ||
| 37 | assert_equal (self.o.get_minioi_ms(), 20.) | ||
| 38 | |||
| 39 | def test_get_threshold(self): | ||
| 40 | assert_almost_equal (self.o.get_threshold(), 0.3) | ||
| 41 | |||
| 42 | def test_set_delay(self): | ||
| 43 | val = 256 | ||
| 44 | self.o.set_delay(val) | ||
| 45 | assert_equal (self.o.get_delay(), val) | ||
| 46 | |||
| 47 | def test_set_delay_s(self): | ||
| 48 | val = .05 | ||
| 49 | self.o.set_delay_s(val) | ||
| 50 | assert_almost_equal (self.o.get_delay_s(), val) | ||
| 51 | |||
| 52 | def test_set_delay_ms(self): | ||
| 53 | val = 50. | ||
| 54 | self.o.set_delay_ms(val) | ||
| 55 | assert_almost_equal (self.o.get_delay_ms(), val) | ||
| 56 | |||
| 57 | def test_set_minioi(self): | ||
| 58 | val = 200 | ||
| 59 | self.o.set_minioi(val) | ||
| 60 | assert_equal (self.o.get_minioi(), val) | ||
| 61 | |||
| 62 | def test_set_minioi_s(self): | ||
| 63 | val = 0.04 | ||
| 64 | self.o.set_minioi_s(val) | ||
| 65 | assert_almost_equal (self.o.get_minioi_s(), val) | ||
| 66 | |||
| 67 | def test_set_minioi_ms(self): | ||
| 68 | val = 40. | ||
| 69 | self.o.set_minioi_ms(val) | ||
| 70 | assert_almost_equal (self.o.get_minioi_ms(), val) | ||
| 71 | |||
| 72 | def test_set_threshold(self): | ||
| 73 | val = 0.2 | ||
| 74 | self.o.set_threshold(val) | ||
| 75 | assert_almost_equal (self.o.get_threshold(), val) | ||
| 76 | |||
| 77 | class aubio_onset_96000(aubio_onset_params): | ||
| 78 | samplerate = 96000 | ||
| 79 | |||
| 80 | class aubio_onset_32000(aubio_onset_params): | ||
| 81 | samplerate = 32000 | ||
| 82 | |||
| 83 | class aubio_onset_8000(aubio_onset_params): | ||
| 84 | samplerate = 8000 | ||
| 17 | 85 | ||
| 18 | if __name__ == '__main__': | 86 | if __name__ == '__main__': |
| 19 | from unittest import main | 87 | from unittest import main |