source: python/tests/test_filterbank_mel.py @ 319edae

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

[tests] avoid some imports, move main to end

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