3 from numpy.testing import TestCase, assert_equal, assert_almost_equal
4 from aubio import fvec, cvec, pvoc
5 from numpy import array, shape
6 from numpy.random import random
10 class aubio_pvoc_test_case(TestCase):
11 """ pvoc object test case """
13 def test_members_automatic_sizes_default(self):
14 """ check object creation with default parameters """
16 assert_equal ([f.win_s, f.hop_s], [1024, 512])
18 def test_members_unnamed_params(self):
19 """ check object creation with unnamed parameters """
21 assert_equal ([f.win_s, f.hop_s], [2048, 128])
23 def test_members_named_params(self):
24 """ check object creation with named parameters """
25 f = pvoc(hop_s = 128, win_s = 2048)
26 assert_equal ([f.win_s, f.hop_s], [2048, 128])
29 """ check the resynthesis of zeros gives zeros """
30 win_s, hop_s = 1024, 256
31 f = pvoc (win_s, hop_s)
33 for time in range( 4 * win_s / hop_s ):
36 assert_equal ( array(t), 0)
37 assert_equal ( s.norm, 0)
38 assert_equal ( s.phas, 0)
41 def test_resynth_two_steps(self):
42 """ check the resynthesis of steps is correct with 50% overlap """
45 f = pvoc(buf_s, hop_s)
56 #self.plot_this ( s2.norm.T )
57 assert_almost_equal ( r2, sigin, decimal = precision )
59 def test_resynth_three_steps(self):
60 """ check the resynthesis of steps is correct with 25% overlap """
65 f = pvoc(buf_s, hop_s)
66 for i in range(hop_s):
67 sigin[i] = random() * 2. - 1.
68 t2 = f.rdo( f(sigin) )
69 t2 = f.rdo( f(zeros) )
70 t2 = f.rdo( f(zeros) )
71 t2 = f.rdo( f(zeros) )
72 assert_almost_equal( sigin, t2, decimal = precision )
74 def plot_this( self, this ):
75 from pylab import semilogy, show
79 if __name__ == '__main__':
80 from unittest import main