shithub: aubio

Download patch

ref: fb434c4655ff157c0bdee0539889d527ec4577e6
parent: 7498e482ffe8a31a9135a30527a7603ce4444f25
author: Paul Brossier <piem@piem.org>
date: Sat Apr 30 03:19:39 EDT 2016

python/tests/test_phasevoc.py: cleanup, start using nose2

--- a/python/tests/test_phasevoc.py
+++ b/python/tests/test_phasevoc.py
@@ -4,13 +4,17 @@
 from aubio import fvec, cvec, pvoc, float_type
 from numpy import array, shape
 from numpy.random import random
+from nose2.tools import params
 import numpy as np
 
-max_sq_error = 1.e-12
+if float_type == 'float32':
+    max_sq_error = 1.e-12
+else:
+    max_sq_error = 1.e-29
 
 def create_sine(hop_s, freq, samplerate):
     t = np.arange(hop_s).astype(float_type)
-    return np.sin( 2. * np.pi * t * freq / samplerate)
+    return np.sin( 2. * np.pi * freq * t / float(samplerate))
 
 def create_noise(hop_s):
     return np.random.rand(hop_s).astype(float_type) * 2. - 1.
@@ -41,10 +45,10 @@
         for time in range( int ( 4 * win_s / hop_s ) ):
             s = f(t)
             r = f.rdo(s)
-            assert_equal ( array(t), 0)
-            assert_equal ( s.norm, 0)
-            assert_equal ( s.phas, 0)
-            assert_equal ( r, 0)
+            assert_equal ( t, 0.)
+            assert_equal ( s.norm, 0.)
+            assert_equal ( s.phas, 0.)
+            assert_equal ( r, 0.)
 
     def test_resynth_8_steps_sine(self):
         """ check the resynthesis of is correct with 87.5% overlap """
@@ -91,6 +95,52 @@
         sigin = create_noise(hop_s)
         self.reconstruction(sigin, hop_s, ratio)
 
+    @params(
+            ( 256, 8),
+            ( 256, 4),
+            ( 256, 2),
+            ( 512, 8),
+            ( 512, 4),
+            ( 512, 2),
+            (1024, 8),
+            (1024, 4),
+            (1024, 2),
+            (2048, 8),
+            (2048, 4),
+            (2048, 2),
+            (4096, 8),
+            (4096, 4),
+            (4096, 2),
+            (8192, 8),
+            (8192, 4),
+            (8192, 2),
+            )
+    def test_resynth_steps_noise(self, hop_s, ratio):
+        """ check the resynthesis of a random signal is correct """
+        sigin = create_noise(hop_s)
+        self.reconstruction(sigin, hop_s, ratio)
+
+    @params(
+            (44100,  256, 8,   441),
+            (44100,  256, 4,  1203),
+            (44100,  256, 2,  3045),
+            (44100,  512, 8,   445),
+            (44100,  512, 4,   445),
+            (44100,  512, 2,   445),
+            (44100, 1024, 8,   445),
+            (44100, 1024, 4,   445),
+            (44100, 1024, 2,   445),
+            ( 8000, 1024, 2,   445),
+            (22050, 1024, 2,   445),
+            (22050,  256, 8,   445),
+            (96000, 1024, 8, 47000),
+            (96000, 1024, 8,    20),
+            )
+    def test_resynth_steps_sine(self, samplerate, hop_s, ratio, freq):
+        """ check the resynthesis of a sine is correct """
+        sigin = create_sine(hop_s, freq, samplerate)
+        self.reconstruction(sigin, hop_s, ratio)
+
     def reconstruction(self, sigin, hop_s, ratio):
         buf_s = hop_s * ratio
         f = pvoc(buf_s, hop_s)
@@ -104,6 +154,6 @@
         assert_array_less(sq_error, max_sq_error)
 
 if __name__ == '__main__':
-  from unittest import main
-  main()
+    from nose2 import main
+    main()