ref: 215b33c94cfa35a27be7a11f692bee1b473e2efd
parent: 83a768ef640e5de2bc78877f0d65426b5234429f
author: Paul Brossier <piem@piem.org>
date: Fri Apr 29 16:06:36 EDT 2016
python/tests/test_phasevoc.py: clean up, add 50% overlap test
--- a/python/tests/test_phasevoc.py
+++ b/python/tests/test_phasevoc.py
@@ -1,13 +1,20 @@
#! /usr/bin/env python
-from numpy.testing import TestCase, assert_equal, assert_almost_equal
+from numpy.testing import TestCase, assert_equal, assert_array_less
from aubio import fvec, cvec, pvoc, float_type
from numpy import array, shape
from numpy.random import random
import numpy as np
-precision = 4
+max_sq_error = 1.e-12
+def create_sine(hop_s, freq, samplerate):
+ t = np.arange(hop_s).astype(float_type)
+ return np.sin( 2. * np.pi * t * freq / samplerate)
+
+def create_noise(hop_s):
+ return np.random.rand(hop_s).astype(float_type) * 2. - 1.
+
class aubio_pvoc_test_case(TestCase):
""" pvoc object test case """
@@ -44,29 +51,46 @@
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)
+ sigin = create_sine(hop_s, freq, samplerate)
+ self.reconstruction( sigin, hop_s, ratio)
def test_resynth_8_steps(self):
""" check the resynthesis of is correct with 87.5% overlap """
hop_s = 1024
ratio = 8
- 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)
+ sigin = create_noise(hop_s)
+ self.reconstruction(sigin, hop_s, ratio)
+ def test_resynth_4_steps_sine(self):
+ """ check the resynthesis of is correct with 87.5% overlap """
+ hop_s = 1024
+ ratio = 4
+ freq = 445; samplerate = 22050
+ sigin = create_sine(hop_s, freq, samplerate)
+ self.reconstruction(sigin, hop_s, ratio)
+
def test_resynth_4_steps(self):
""" check the resynthesis of is correct with 75% overlap """
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)
+ sigin = create_noise(hop_s)
+ self.reconstruction(sigin, hop_s, ratio)
+ def test_resynth_2_steps_sine(self):
+ """ check the resynthesis of is correct with 50% overlap """
+ hop_s = 1024
+ ratio = 2
+ freq = 445; samplerate = 22050
+ sigin = create_sine(hop_s, freq, samplerate)
+ self.reconstruction(sigin, hop_s, ratio)
+
+ def test_resynth_2_steps(self):
+ """ check the resynthesis of is correct with 50% overlap """
+ hop_s = 1024
+ ratio = 2
+ sigin = create_noise(hop_s)
+ self.reconstruction(sigin, hop_s, ratio)
+
def reconstruction(self, sigin, hop_s, ratio):
buf_s = hop_s * ratio
f = pvoc(buf_s, hop_s)
@@ -74,15 +98,10 @@
r2 = f.rdo( f(sigin) )
for i in range(1, ratio):
r2 = f.rdo( f(zeros) )
-
- # FIXME: if we don't return a copy here, test_phasevoc.py will crash
- # once in a while
- return np.copy(r2)
-
- def plot_this( self, this ):
- from pylab import semilogy, show
- semilogy ( this )
- show ()
+ # compute square errors
+ sq_error = (r2 - sigin)**2
+ # make sure all square errors are less than desired precision
+ assert_array_less(sq_error, max_sq_error)
if __name__ == '__main__':
from unittest import main