source: python/tests/test_filterbank.py @ eacc55c

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5sampleryinfft+
Last change on this file since eacc55c was 0b6d23d, checked in by Paul Brossier <piem@piem.org>, 9 years ago

python/tests: fix most prospect warnings

  • Property mode set to 100755
File size: 2.5 KB
Line 
1#! /usr/bin/env python
2
3from unittest import main
4from numpy.testing import TestCase
5from numpy.testing import assert_equal, assert_almost_equal
6import numpy as np
7from aubio import cvec, filterbank, float_type
8from utils import array_from_text_file
9
10class aubio_filterbank_test_case(TestCase):
11
12    def test_members(self):
13        f = filterbank(40, 512)
14        assert_equal ([f.n_filters, f.win_s], [40, 512])
15
16    def test_set_coeffs(self):
17        f = filterbank(40, 512)
18        r = np.random.random([40, int(512 / 2) + 1]).astype(float_type)
19        f.set_coeffs(r)
20        assert_equal (r, f.get_coeffs())
21
22    def test_phase(self):
23        f = filterbank(40, 512)
24        c = cvec(512)
25        c.phas[:] = np.pi
26        assert_equal( f(c), 0);
27
28    def test_norm(self):
29        f = filterbank(40, 512)
30        c = cvec(512)
31        c.norm[:] = 1
32        assert_equal( f(c), 0);
33
34    def test_random_norm(self):
35        f = filterbank(40, 512)
36        c = cvec(512)
37        c.norm[:] = np.random.random((int(512 / 2) + 1,)).astype(float_type)
38        assert_equal( f(c), 0)
39
40    def test_random_coeffs(self):
41        win_s = 128
42        f = filterbank(40, win_s)
43        c = cvec(win_s)
44        r = np.random.random([40, int(win_s / 2) + 1]).astype(float_type)
45        r /= r.sum()
46        f.set_coeffs(r)
47        c.norm[:] = np.random.random((int(win_s / 2) + 1,)).astype(float_type)
48        assert_equal ( f(c) < 1., True )
49        assert_equal ( f(c) > 0., True )
50
51    def test_mfcc_coeffs(self):
52        f = filterbank(40, 512)
53        c = cvec(512)
54        f.set_mel_coeffs_slaney(44100)
55        c.norm[:] = np.random.random((int(512 / 2) + 1,)).astype(float_type)
56        assert_equal ( f(c) < 1., True )
57        assert_equal ( f(c) > 0., True )
58
59    def test_mfcc_coeffs_16000(self):
60        expected = array_from_text_file('filterbank_mfcc_16000_512.expected')
61        f = filterbank(40, 512)
62        f.set_mel_coeffs_slaney(16000)
63        assert_almost_equal ( expected, f.get_coeffs() )
64
65class aubio_filterbank_wrong_values(TestCase):
66
67    def test_negative_window(self):
68        self.assertRaises(ValueError, filterbank, 40, -20)
69
70    def test_negative_filters(self):
71        self.assertRaises(ValueError, filterbank, -40, 1024)
72
73    def test_filterbank_long_cvec(self):
74        f = filterbank(40, 512)
75        with self.assertRaises(ValueError):
76            f(cvec(1024))
77
78    def test_filterbank_short_cvec(self):
79        f = filterbank(40, 512)
80        with self.assertRaises(ValueError):
81            f(cvec(256))
82
83if __name__ == '__main__':
84    main()
Note: See TracBrowser for help on using the repository browser.