shithub: aubio

Download patch

ref: 69378423f4a682b69967cced95339cb0613e3c36
parent: 92a880038648589865c7bd3fac15647a7b792788
author: Paul Brossier <piem@piem.org>
date: Thu Apr 28 15:32:48 EDT 2016

python/tests/test_phasevoc.py: add more tests

--- a/python/tests/test_phasevoc.py
+++ b/python/tests/test_phasevoc.py
@@ -39,25 +39,35 @@
             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 """
+        hop_s = 1024
+        ratio = 8
+        freq = 445; samplerate = 22050
+        sigin = np.sin( 2. * np.pi * np.arange(hop_s).astype(float_type) * freq / samplerate)
+        r2 = self.reconstruction( sigin, hop_s, ratio)
+        error = ((r2 - sigin)**2).mean()
+        self.assertLessEqual(error , 1.e-3)
+
     def test_resynth_8_steps(self):
         """ check the resynthesis of is correct with 87.5% overlap """
-        hop_s = 256
+        hop_s = 1024
         ratio = 8
         sigin = np.random.rand(hop_s).astype(float_type) * 2. - 1.
-        buf_s = hop_s * ratio
-        f = pvoc(buf_s, hop_s)
-        zeros = fvec(hop_s)
-        r2 = f.rdo( f(sigin) )
-        for i in range(1, ratio):
-            r2 = f.rdo( f(zeros) )
-        r2 *= .5
-        assert_almost_equal ( r2 - sigin, 0., decimal = precision )
+        r2 = self.reconstruction( sigin, hop_s, ratio)
+        error = ((r2 - sigin)**2).mean()
+        self.assertLessEqual(error , 1.e-2)
 
     def test_resynth_4_steps(self):
         """ check the resynthesis of is correct with 75% overlap """
-        hop_s = 256
+        hop_s = 1024
         ratio = 4
         sigin = np.random.rand(hop_s).astype(float_type) * 2. - 1.
+        r2 = self.reconstruction( sigin, hop_s, ratio)
+        error = ((r2 - sigin)**2).mean()
+        self.assertLessEqual(error , 1.e-2)
+
+    def reconstruction(self, sigin, hop_s, ratio):
         buf_s = hop_s * ratio
         f = pvoc(buf_s, hop_s)
         zeros = fvec(hop_s)
@@ -64,8 +74,8 @@
         r2 = f.rdo( f(sigin) )
         for i in range(1, ratio):
             r2 = f.rdo( f(zeros) )
-        assert_almost_equal ( r2 - sigin, 0., decimal = precision )
-    
+        return r2
+
     def plot_this( self, this ):
         from pylab import semilogy, show
         semilogy ( this )