1 | #! /usr/bin/env python |
---|
2 | |
---|
3 | from numpy.testing import TestCase, run_module_suite |
---|
4 | from numpy.testing import assert_equal, assert_almost_equal |
---|
5 | from numpy import random |
---|
6 | from math import pi |
---|
7 | from numpy import array |
---|
8 | from aubio import cvec, filterbank |
---|
9 | from utils import array_from_text_file |
---|
10 | |
---|
11 | class aubio_filterbank_test_case(TestCase): |
---|
12 | |
---|
13 | def test_members(self): |
---|
14 | f = filterbank(40, 512) |
---|
15 | assert_equal ([f.n_filters, f.win_s], [40, 512]) |
---|
16 | |
---|
17 | def test_set_coeffs(self): |
---|
18 | f = filterbank(40, 512) |
---|
19 | r = random.random([40, int(512 / 2) + 1]).astype('float32') |
---|
20 | f.set_coeffs(r) |
---|
21 | assert_equal (r, f.get_coeffs()) |
---|
22 | |
---|
23 | def test_phase(self): |
---|
24 | f = filterbank(40, 512) |
---|
25 | c = cvec(512) |
---|
26 | c.phas[:] = pi |
---|
27 | assert_equal( f(c), 0); |
---|
28 | |
---|
29 | def test_norm(self): |
---|
30 | f = filterbank(40, 512) |
---|
31 | c = cvec(512) |
---|
32 | c.norm[:] = 1 |
---|
33 | assert_equal( f(c), 0); |
---|
34 | |
---|
35 | def test_random_norm(self): |
---|
36 | f = filterbank(40, 512) |
---|
37 | c = cvec(512) |
---|
38 | c.norm[:] = random.random((int(512 / 2) + 1,)).astype('float32') |
---|
39 | assert_equal( f(c), 0) |
---|
40 | |
---|
41 | def test_random_coeffs(self): |
---|
42 | f = filterbank(40, 512) |
---|
43 | c = cvec(512) |
---|
44 | r = random.random([40, int(512 / 2) + 1]).astype('float32') |
---|
45 | r /= r.sum() |
---|
46 | f.set_coeffs(r) |
---|
47 | c.norm[:] = random.random((int(512 / 2) + 1,)).astype('float32') |
---|
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[:] = random.random((int(512 / 2) + 1,)).astype('float32') |
---|
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 | |
---|
65 | if __name__ == '__main__': |
---|
66 | from unittest import main |
---|
67 | main() |
---|
68 | |
---|