tests/python/src/spectral/filterbank.py: replaced by python/tests/test_filterbank.py
authorPaul Brossier <piem@piem.org>
Sun, 3 Mar 2013 20:14:32 +0000 (15:14 -0500)
committerPaul Brossier <piem@piem.org>
Sun, 3 Mar 2013 20:14:32 +0000 (15:14 -0500)
python/tests/test_filterbank.py
tests/python/src/spectral/filterbank.py [deleted file]

index c00a568585c6f1e46f32e5c183e97e4ea7593316..595d022a34bf393c013fecf1e8a2d00e42726782 100755 (executable)
@@ -3,6 +3,7 @@
 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 aubio import cvec, filterbank
 
 class aubio_filterbank_test_case(TestCase):
@@ -17,6 +18,42 @@ class aubio_filterbank_test_case(TestCase):
     f.set_coeffs(r)
     assert_equal (r, f.get_coeffs())
 
+  def test_phase(self):
+    f = filterbank(40, 512)
+    c = cvec(512)
+    c.phas[:] = pi
+    assert_equal( f(c), 0);
+
+  def test_norm(self):
+    f = filterbank(40, 512)
+    c = cvec(512)
+    c.norm[:] = 1
+    assert_equal( f(c), 0);
+
+  def test_random_norm(self):
+    f = filterbank(40, 512)
+    c = cvec(512)
+    c.norm[:] = random.random((512 / 2 + 1,)).astype('float32')
+    assert_equal( f(c), 0)
+
+  def test_random_coeffs(self):
+    f = filterbank(40, 512)
+    c = cvec(512)
+    r = random.random([40, 512 / 2 + 1]).astype('float32')
+    r /= r.sum()
+    f.set_coeffs(r)
+    c.norm[:] = random.random((512 / 2 + 1,)).astype('float32')
+    assert_equal ( f(c) < 1., True )
+    assert_equal ( f(c) > 0., True )
+
+  def test_mfcc_coeffs(self):
+    f = filterbank(40, 512)
+    c = cvec(512)
+    f.set_mel_coeffs_slaney(44100)
+    c.norm[:] = random.random((512 / 2 + 1,)).astype('float32')
+    assert_equal ( f(c) < 1., True )
+    assert_equal ( f(c) > 0., True )
+
 if __name__ == '__main__':
   from unittest import main
   main()
diff --git a/tests/python/src/spectral/filterbank.py b/tests/python/src/spectral/filterbank.py
deleted file mode 100644 (file)
index 1d9fe20..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-from template import aubio_unit_template
-from localaubio import *
-
-win_size = 2048 
-channels = 1
-n_filters = 40
-samplerate = 44100
-
-class filterbank_test_case(unittest.TestCase):
-  
-  def setUp(self):
-      self.input_spectrum = new_cvec(win_size,channels)
-      self.output_banks = new_fvec(n_filters,channels)
-      self.filterbank = new_aubio_filterbank(n_filters,win_size)
-
-  def tearDown(self):
-      del_aubio_filterbank(self.filterbank)
-      del_cvec(self.input_spectrum)
-      del_fvec(self.output_banks)
-
-  def testzeroes(self):
-      """ check the output of the filterbank is 0 when input spectrum is 0 """
-      aubio_filterbank_do(self.filterbank,self.input_spectrum,
-        self.output_banks) 
-      for channel in range(channels):
-        for index in range(n_filters): 
-          self.assertEqual(fvec_read_sample(self.output_banks,channel,index), 0)
-
-  def testphase(self):
-      """ check the output of the filterbank is 0 when input phase is pi """
-      from math import pi
-      for channel in range(channels):
-        for index in range(win_size/2+1): 
-          cvec_write_phas(self.input_spectrum,pi,channel,index)
-      aubio_filterbank_do(self.filterbank,self.input_spectrum,
-        self.output_banks) 
-      for channel in range(channels):
-        for index in range(n_filters): 
-          self.assertEqual(fvec_read_sample(self.output_banks,channel,index), 0)
-
-  def testones(self):
-      """ check the output of the filterbank is 0 when input norm is 1
-          (the filterbank is currently set to 0).
-      """
-      for channel in range(channels):
-        for index in range(win_size/2+1): 
-          cvec_write_norm(self.input_spectrum,1.,channel,index)
-      aubio_filterbank_do(self.filterbank,self.input_spectrum,
-        self.output_banks) 
-      for channel in range(channels):
-        for index in range(n_filters): 
-          self.assertEqual(fvec_read_sample(self.output_banks,channel,index), 0)
-
-  def testmfcc_zeroes(self):
-      """ check the mfcc filterbank output is 0 when input is 0 """
-      self.filterbank = new_aubio_filterbank(n_filters, win_size) 
-      aubio_filterbank_do(self.filterbank, self.input_spectrum,
-        self.output_banks) 
-      for channel in range(channels):
-        for index in range(n_filters): 
-          self.assertEqual(fvec_read_sample(self.output_banks,channel,index), 0)
-
-  def testmfcc_phasepi(self):
-      """ check the mfcc filterbank output is 0 when input phase is pi """
-      self.filterbank = new_aubio_filterbank(n_filters, win_size) 
-      aubio_filterbank_set_mel_coeffs_slaney(self.filterbank, samplerate)
-      from math import pi
-      for channel in range(channels):
-        for index in range(win_size/2+1): 
-          cvec_write_phas(self.input_spectrum,pi,channel,index)
-      aubio_filterbank_do(self.filterbank,self.input_spectrum,
-        self.output_banks) 
-      for channel in range(channels):
-        for index in range(n_filters): 
-          self.assertEqual(fvec_read_sample(self.output_banks,channel,index), 0)
-
-  def testmfcc_ones(self):
-      """ check setting the input spectrum to 1 gives something between 0. and 1. """ 
-      self.filterbank = new_aubio_filterbank(n_filters, win_size) 
-      aubio_filterbank_set_mel_coeffs_slaney(self.filterbank, samplerate)
-      for channel in range(channels):
-        for index in range(win_size/2+1): 
-          cvec_write_norm(self.input_spectrum,1.,channel,index)
-      aubio_filterbank_do(self.filterbank,self.input_spectrum,
-        self.output_banks) 
-      for channel in range(channels):
-        for index in range(n_filters): 
-          val = fvec_read_sample(self.output_banks,channel,index)
-          self.failIf(val < 0. , val )
-          self.failIf(val > 1. , val )
-
-  def testmfcc_channels(self):
-      """ check the values of each filters in the mfcc filterbank """
-      import os.path
-      win_size = 512
-      self.filterbank = new_aubio_filterbank(n_filters, win_size) 
-      aubio_filterbank_set_mel_coeffs_slaney(self.filterbank, 16000)
-      filterbank_mfcc = array_from_text_file ( 
-          os.path.join('src','spectral','filterbank_mfcc_16000_512.txt') )
-      vec = aubio_filterbank_get_coeffs(self.filterbank)
-      for channel in range(n_filters):
-        for index in range(win_size/2+1): 
-          self.assertAlmostEqual(fvec_read_sample(vec,channel,index),
-            filterbank_mfcc[channel][index])
-      aubio_filterbank_do(self.filterbank, self.input_spectrum,
-        self.output_banks) 
-      for channel in range(channels):
-        for index in range(n_filters): 
-          self.assertEqual(fvec_read_sample(self.output_banks,channel,index), 0)
-
-if __name__ == '__main__':
-    unittest.main()