ref: c853c1d12ff8aca51206f869d6711890cf010f55
parent: be8b18bc704b8a9b5e4be79ca66055a78b218571
author: Paul Brossier <piem@piem.org>
date: Sat Nov 17 09:26:54 EST 2018
[py] add tests for new filterbank methods
--- a/python/tests/test_filterbank_mel.py
+++ b/python/tests/test_filterbank_mel.py
@@ -110,6 +110,63 @@
# TODO add assert_warns
f.set_triangle_bands(fvec(freq_list), samplerate)
+ def test_triangle_freqs_without_norm(self):
+ """make sure set_triangle_bands works without """
+ samplerate = 22050
+ freq_list = fvec([0, 100, 1000, 10000])
+ f = filterbank(len(freq_list) - 2, 1024)
+ f.set_norm(0)
+ f.set_triangle_bands(freq_list, samplerate)
+ expected = f.get_coeffs()
+ f.set_norm(1)
+ f.set_triangle_bands(fvec(freq_list), samplerate)
+ assert_almost_equal(f.get_coeffs().T,
+ expected.T * 2. / (freq_list[2:] - freq_list[:-2]))
+
+ def test_triangle_freqs_wrong_norm(self):
+ f = filterbank(10, 1024)
+ with self.assertRaises(ValueError):
+ f.set_norm(-1)
+
+ def test_triangle_freqs_with_power(self):
+ f = filterbank(9, 1024)
+ freqs = fvec([40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000,
+ 24000])
+ f.set_power(2)
+ f.set_triangle_bands(freqs, 48000)
+ spec = cvec(1024)
+ spec.norm[:] = .1
+ expected = fvec([0.02070313, 0.02138672, 0.02127604, 0.02135417,
+ 0.02133301, 0.02133301, 0.02133311, 0.02133334, 0.02133345])
+ expected /= 100.
+ assert_almost_equal(f(spec), expected)
+
+ def test_mel_coeffs(self):
+ f = filterbank(40, 1024)
+ f.set_mel_coeffs(44100, 0, 44100 / 2)
+
+ def test_zero_fmax(self):
+ f = filterbank(40, 1024)
+ f.set_mel_coeffs(44100, 0, 0)
+
+ def test_wrong_mel_coeffs(self):
+ f = filterbank(40, 1024)
+ with self.assertRaises(ValueError):
+ f.set_mel_coeffs_slaney(0)
+ with self.assertRaises(ValueError):
+ f.set_mel_coeffs(44100, 0, -44100 / 2)
+ with self.assertRaises(ValueError):
+ f.set_mel_coeffs(44100, -0.1, 44100 / 2)
+ with self.assertRaises(ValueError):
+ f.set_mel_coeffs(-44100, 0.1, 44100 / 2)
+ with self.assertRaises(ValueError):
+ f.set_mel_coeffs_htk(-1, 0, 0)
+
+ def test_mel_coeffs_htk(self):
+ f = filterbank(40, 1024)
+ f.set_mel_coeffs_htk(44100, 0, 44100 / 2)
+
+
if __name__ == '__main__':
import nose2
nose2.main()