interfaces/python: added more tests
[aubio.git] / interfaces / python / test_filterbank.py
1 from numpy.testing import TestCase, run_module_suite
2 from numpy.testing import assert_equal, assert_almost_equal
3 from numpy import array, shape
4 from _aubio import *
5
6 class aubio_filter_test_case(TestCase):
7
8   def test_slaney(self):
9     f = filterbank(40, 512)
10     f.set_mel_coeffs_slaney(16000)
11     a = f.get_coeffs()
12     a.T
13
14   def test_other_slaney(self):
15     f = filterbank(40, 512*2)
16     f.set_mel_coeffs_slaney(44100)
17     a = f.get_coeffs()
18     #print "sum is", sum(sum(a))
19     for win_s in [256, 512, 1024, 2048, 4096]:
20       f = filterbank(40, win_s)
21       f.set_mel_coeffs_slaney(320000)
22       a = f.get_coeffs()
23       #print "sum is", sum(sum(a))
24
25   def test_triangle_freqs(self):
26     f = filterbank(9, 1024)
27     freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
28     freqs = array(freq_list, dtype = 'float32')
29     f.set_triangle_bands(freqs, 48000)
30     f.get_coeffs().T
31     assert_equal ( f(cvec(1024)), [0] * 9)
32     spec = cvec(1024)
33     spec[0][40:100] = 100
34     #print f(spec)
35
36 if __name__ == '__main__':
37   from unittest import main
38   main()
39