source: python/tests/test_filterbank_mel.py @ 5af36fa

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/timestretchfix/ffmpeg5
Last change on this file since 5af36fa was 0d52f92, checked in by Paul Brossier <piem@piem.org>, 5 years ago

[tests] remove warning filter

  • Property mode set to 100755
File size: 1.8 KB
Line 
1#! /usr/bin/env python
2
3import numpy as np
4from numpy.testing import TestCase, assert_equal, assert_almost_equal
5
6from aubio import cvec, filterbank, float_type
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(np.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        self.assertIsInstance(f.get_coeffs(), np.ndarray)
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(32000)
24            #print "sum is", sum(sum(a))
25            self.assertIsInstance(f.get_coeffs(), np.ndarray)
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 = np.array(freq_list, dtype = float_type)
31        f.set_triangle_bands(freqs, 48000)
32        assert_equal ( f(cvec(1024)), 0)
33        self.assertIsInstance(f.get_coeffs(), np.ndarray)
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 = np.array(freq_list, dtype = float_type)
39        f.set_triangle_bands(freqs, 48000)
40        self.assertIsInstance(f.get_coeffs(), np.ndarray)
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()
Note: See TracBrowser for help on using the repository browser.