python/tests/test_filterbank.py: added test against existing coeffs
authorPaul Brossier <piem@piem.org>
Sun, 3 Mar 2013 20:33:29 +0000 (15:33 -0500)
committerPaul Brossier <piem@piem.org>
Sun, 3 Mar 2013 20:33:29 +0000 (15:33 -0500)
python/tests/filterbank_mfcc_16000_512.expected [moved from tests/python/src/spectral/filterbank_mfcc_16000_512.txt with 100% similarity]
python/tests/test_filterbank.py

index 595d022a34bf393c013fecf1e8a2d00e42726782..3fd64fd9a877c0fc7ed686ba83514e3a5181b34e 100755 (executable)
@@ -4,8 +4,13 @@ from numpy.testing import TestCase, run_module_suite
 from numpy.testing import assert_equal, assert_almost_equal
 from numpy import random
 from math import pi
+from numpy import array
 from aubio import cvec, filterbank
 
+def array_from_text_file(filename, dtype = 'float'):
+  return array([line.split() for line in open(filename).readlines()], 
+      dtype = dtype)
+
 class aubio_filterbank_test_case(TestCase):
 
   def test_members(self):
@@ -54,6 +59,12 @@ class aubio_filterbank_test_case(TestCase):
     assert_equal ( f(c) < 1., True )
     assert_equal ( f(c) > 0., True )
 
+  def test_mfcc_coeffs_16000(self):
+    expected = array_from_text_file('filterbank_mfcc_16000_512.expected')
+    f = filterbank(40, 512)
+    f.set_mel_coeffs_slaney(16000)
+    assert_almost_equal ( expected, f.get_coeffs() )
+
 if __name__ == '__main__':
   from unittest import main
   main()