source: python/tests/test_filterbank.py @ 5fe5591

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 5fe5591 was a4cc8e5, checked in by Paul Brossier <piem@piem.org>, 12 years ago

tests/: array_from_file to look for file in tests/

  • Property mode set to 100755
File size: 1.8 KB
Line 
1#! /usr/bin/env python
2
3from numpy.testing import TestCase, run_module_suite
4from numpy.testing import assert_equal, assert_almost_equal
5from numpy import random
6from math import pi
7from numpy import array
8from aubio import cvec, filterbank
9from utils import array_from_text_file
10
11class 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, 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((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, 512 / 2 + 1]).astype('float32')
45    r /= r.sum()
46    f.set_coeffs(r)
47    c.norm[:] = random.random((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((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
65if __name__ == '__main__':
66  from unittest import main
67  main()
68
Note: See TracBrowser for help on using the repository browser.