source: python/tests/test_onset.py @ d0f19a7

feature/cnnfeature/crepefeature/pitchshiftfeature/timestretchfix/ffmpeg5
Last change on this file since d0f19a7 was d06c9a4, checked in by Paul Brossier <piem@piem.org>, 6 years ago

Merge branch 'master' into feature/pytest

  • Property mode set to 100755
File size: 3.2 KB
Line 
1#! /usr/bin/env python
2
3from numpy.testing import TestCase, assert_equal, assert_almost_equal
4from aubio import onset, fvec
5
6class aubio_onset_default(TestCase):
7
8    def test_members(self):
9        o = onset()
10        assert_equal ([o.buf_size, o.hop_size, o.method, o.samplerate],
11            [1024,512,'default',44100])
12
13class aubio_onset_params(TestCase):
14
15    samplerate = 44100
16
17    def setUp(self):
18        self.o = onset(samplerate = self.samplerate)
19
20    def test_get_delay(self):
21        self.assertGreater(self.o.get_delay(), 0)
22
23    def test_get_delay_s(self):
24        self.assertGreater(self.o.get_delay_s(), 0.)
25
26    def test_get_delay_ms(self):
27        self.assertGreater(self.o.get_delay_ms(), 0.)
28
29    def test_get_minioi(self):
30        self.assertGreater(self.o.get_minioi(), 0)
31
32    def test_get_minioi_s(self):
33        self.assertGreater(self.o.get_minioi_s(), 0.)
34
35    def test_get_minioi_ms(self):
36        self.assertGreater(self.o.get_minioi_ms(), 0.)
37
38    def test_get_threshold(self):
39        self.assertGreater(self.o.get_threshold(), 0.)
40
41    def test_set_delay(self):
42        val = 256
43        self.o.set_delay(val)
44        assert_equal (self.o.get_delay(), val)
45
46    def test_set_delay_s(self):
47        val = .05
48        self.o.set_delay_s(val)
49        assert_almost_equal (self.o.get_delay_s(), val)
50
51    def test_set_delay_ms(self):
52        val = 50.
53        self.o.set_delay_ms(val)
54        assert_almost_equal (self.o.get_delay_ms(), val)
55
56    def test_set_minioi(self):
57        val = 200
58        self.o.set_minioi(val)
59        assert_equal (self.o.get_minioi(), val)
60
61    def test_set_minioi_s(self):
62        val = 0.04
63        self.o.set_minioi_s(val)
64        assert_almost_equal (self.o.get_minioi_s(), val)
65
66    def test_set_minioi_ms(self):
67        val = 40.
68        self.o.set_minioi_ms(val)
69        assert_almost_equal (self.o.get_minioi_ms(), val)
70
71    def test_set_threshold(self):
72        val = 0.2
73        self.o.set_threshold(val)
74        assert_almost_equal (self.o.get_threshold(), val)
75
76class aubio_onset_96000(aubio_onset_params):
77    samplerate = 96000
78
79class aubio_onset_32000(aubio_onset_params):
80    samplerate = 32000
81
82class aubio_onset_8000(aubio_onset_params):
83    samplerate = 8000
84
85class aubio_onset_coverate(TestCase):
86    # extra tests to execute the C routines and improve coverage
87
88    def test_all_methods(self):
89        for method in ['default', 'energy', 'hfc', 'complexdomain', 'complex',
90                'phase', 'wphase', 'mkl', 'kl', 'specflux', 'specdiff',
91                'old_default']:
92            o = onset(method=method, buf_size=512, hop_size=256)
93            o(fvec(256))
94
95    def test_get_methods(self):
96        o = onset(method='default', buf_size=512, hop_size=256)
97
98        assert o.get_silence() == -70
99        o.set_silence(-20)
100        assert_almost_equal(o.get_silence(), -20)
101
102        assert o.get_compression() == 1
103        o.set_compression(.99)
104        assert_almost_equal(o.get_compression(), .99)
105
106        assert o.get_awhitening() == 0
107        o.set_awhitening(1)
108        assert o.get_awhitening() == 1
109
110        o.get_last()
111        o.get_last_ms()
112        o.get_last_s()
113        o.get_descriptor()
114        o.get_thresholded_descriptor()
115
116
117if __name__ == '__main__':
118    from unittest import main
119    main()
Note: See TracBrowser for help on using the repository browser.