[75e715f] | 1 | #! /usr/bin/env python |
---|
[5e3ed60] | 2 | |
---|
[0536612] | 3 | from numpy.testing import TestCase, run_module_suite |
---|
| 4 | from numpy.testing import assert_equal, assert_almost_equal |
---|
[5e3ed60] | 5 | from numpy import random |
---|
[ac9eea7] | 6 | from math import pi |
---|
[71ef9c2] | 7 | from numpy import array |
---|
[c4b2183] | 8 | from aubio import cvec, filterbank, float_type |
---|
[a4cc8e5] | 9 | from utils import array_from_text_file |
---|
[71ef9c2] | 10 | |
---|
[5e3ed60] | 11 | class aubio_filterbank_test_case(TestCase): |
---|
[0536612] | 12 | |
---|
[5e3ed60] | 13 | def test_members(self): |
---|
[0536612] | 14 | f = filterbank(40, 512) |
---|
[5e3ed60] | 15 | assert_equal ([f.n_filters, f.win_s], [40, 512]) |
---|
[0536612] | 16 | |
---|
[5e3ed60] | 17 | def test_set_coeffs(self): |
---|
| 18 | f = filterbank(40, 512) |
---|
[c4b2183] | 19 | r = random.random([40, int(512 / 2) + 1]).astype(float_type) |
---|
[5e3ed60] | 20 | f.set_coeffs(r) |
---|
| 21 | assert_equal (r, f.get_coeffs()) |
---|
[0536612] | 22 | |
---|
[ac9eea7] | 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) |
---|
[c4b2183] | 38 | c.norm[:] = random.random((int(512 / 2) + 1,)).astype(float_type) |
---|
[ac9eea7] | 39 | assert_equal( f(c), 0) |
---|
| 40 | |
---|
| 41 | def test_random_coeffs(self): |
---|
| 42 | f = filterbank(40, 512) |
---|
| 43 | c = cvec(512) |
---|
[c4b2183] | 44 | r = random.random([40, int(512 / 2) + 1]).astype(float_type) |
---|
[ac9eea7] | 45 | r /= r.sum() |
---|
| 46 | f.set_coeffs(r) |
---|
[c4b2183] | 47 | c.norm[:] = random.random((int(512 / 2) + 1,)).astype(float_type) |
---|
[ac9eea7] | 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) |
---|
[c4b2183] | 55 | c.norm[:] = random.random((int(512 / 2) + 1,)).astype(float_type) |
---|
[ac9eea7] | 56 | assert_equal ( f(c) < 1., True ) |
---|
| 57 | assert_equal ( f(c) > 0., True ) |
---|
| 58 | |
---|
[71ef9c2] | 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 | |
---|
[0536612] | 65 | if __name__ == '__main__': |
---|
| 66 | from unittest import main |
---|
| 67 | main() |
---|
| 68 | |
---|