source: interfaces/python/test_filterbank.py @ 20ae690

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 20ae690 was 4c01c0f, checked in by Paul Brossier <piem@piem.org>, 15 years ago

test_*.py: use aubio module

  • Property mode set to 100644
File size: 1.5 KB
Line 
1from numpy.testing import TestCase, run_module_suite
2from numpy.testing import assert_equal, assert_almost_equal
3from numpy import array, shape
4from aubio import cvec, filterbank
5
6class 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    assert_equal(shape (a), (40, 512/2 + 1) )
14
15  def test_other_slaney(self):
16    f = filterbank(40, 512*2)
17    f.set_mel_coeffs_slaney(44100)
18    a = f.get_coeffs()
19    #print "sum is", sum(sum(a))
20    for win_s in [256, 512, 1024, 2048, 4096]:
21      f = filterbank(40, win_s)
22      f.set_mel_coeffs_slaney(320000)
23      a = f.get_coeffs()
24      #print "sum is", sum(sum(a))
25
26  def test_triangle_freqs_zeros(self):
27    f = filterbank(9, 1024)
28    freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
29    freqs = array(freq_list, dtype = 'float32')
30    f.set_triangle_bands(freqs, 48000)
31    f.get_coeffs().T
32    assert_equal ( f(cvec(1024)), 0)
33
34  def test_triangle_freqs_ones(self):
35    f = filterbank(9, 1024)
36    freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
37    freqs = array(freq_list, dtype = 'float32')
38    f.set_triangle_bands(freqs, 48000)
39    f.get_coeffs().T
40    spec = cvec(1024)
41    spec.norm[:] = 1
42    assert_almost_equal ( f(spec),
43            [ 0.02070313,  0.02138672,  0.02127604,  0.02135417, 
44        0.02133301, 0.02133301,  0.02133311,  0.02133334,  0.02133345])
45
46if __name__ == '__main__':
47  from unittest import main
48  main()
49
Note: See TracBrowser for help on using the repository browser.