source: python/tests/test_pitchshift.py @ fe6a4cdd

feature/cnnfeature/crepefeature/pitchshiftfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretch
Last change on this file since fe6a4cdd was fe6a4cdd, checked in by Paul Brossier <piem@piem.org>, 8 years ago

python/tests/test_pitchshift.py: add minimal tests

  • Property mode set to 100755
File size: 1.2 KB
Line 
1#! /usr/bin/env python
2
3from nose2 import TestCase
4import aubio
5
6class aubio_pitchshift(TestCase):
7
8    def setUp(self):
9        self.o = aubio.pitchshift()
10
11    def test_default_creation(self):
12        self.assertEqual(self.o.get_pitchscale(), 1)
13        self.assertEqual(self.o.get_transpose(), 0)
14
15    def test_on_zeros(self):
16        test_length = 20000
17        read = 0
18        # test on zeros
19        vec = aubio.fvec(512)
20        transpose_range = 24
21        while read < test_length:
22            # transpose the samples
23            out = self.o(vec)
24            self.assertTrue((out == 0).all())
25            # position in the file (between 0. and 1.)
26            percent_read = read / float(test_length)
27            # variable transpose rate (in semitones)
28            transpose = 2 * transpose_range * percent_read - transpose_range
29            # set transpose rate
30            self.o.set_transpose(transpose)
31            read += len(vec)
32
33    def test_transpose_too_high(self):
34        with self.assertRaises(ValueError):
35            self.o.set_transpose(24.3)
36
37    def test_transpose_too_low(self):
38        with self.assertRaises(ValueError):
39            self.o.set_transpose(-24.3)
40
41if __name__ == '__main__':
42    from nose2 import main
43    main()
Note: See TracBrowser for help on using the repository browser.