source: python/tests/test_filterbank_mel.py @ ce1d788

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

moved tests to subdirectory

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