source: python/tests/test_filterbank_mel.py @ 7a83a47

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 7a83a47 was 0b6d23d, checked in by Paul Brossier <piem@piem.org>, 9 years ago

python/tests: fix most prospect warnings

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