source: python/tests/test_phasevoc.py @ c02a1cc

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since c02a1cc was 467122d, checked in by Paul Brossier <piem@piem.org>, 11 years ago

python/tests/test_phasevoc.py: improve

  • Property mode set to 100755
File size: 2.5 KB
RevLine 
[75e715f]1#! /usr/bin/env python
[1ebf8770]2
[467122d]3from numpy.testing import TestCase, assert_equal, assert_almost_equal
[4c01c0f]4from aubio import fvec, cvec, pvoc
[0536612]5from numpy import array, shape
[467122d]6from numpy.random import random
7
8precision = 6
[0536612]9
10class aubio_pvoc_test_case(TestCase):
[467122d]11    """ pvoc object test case """
12
13    def test_members_automatic_sizes_default(self):
14        """ check object creation with default parameters """
15        f = pvoc()
16        assert_equal ([f.win_s, f.hop_s], [1024, 512])
[0536612]17
[467122d]18    def test_members_unnamed_params(self):
19        """ check object creation with unnamed parameters """
20        f = pvoc(2048, 128)
21        assert_equal ([f.win_s, f.hop_s], [2048, 128])
[86ad546]22
[467122d]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])
[0536612]27
[467122d]28    def test_zeros(self):
29        """ check the resynthesis of zeros gives zeros """
30        win_s, hop_s = 1024, 256
31        f = pvoc (win_s, hop_s)
32        t = fvec (hop_s)
33        for time in range( 4 * win_s / hop_s ):
34            s = f(t)
35            r = f.rdo(s)
36            assert_equal ( array(t), 0)
37            assert_equal ( s.norm, 0)
38            assert_equal ( s.phas, 0)
39            assert_equal ( r, 0)
[0536612]40
[467122d]41    def test_resynth_two_steps(self):
42        """ check the resynthesis of steps is correct with 50% overlap """
43        hop_s = 512
44        buf_s = hop_s * 2
45        f = pvoc(buf_s, hop_s)
46        sigin = fvec(hop_s)
47        zeros = fvec(hop_s)
48        # negative step
49        sigin[20:50] = -.1
50        # positive step
51        sigin[100:200] = .1
52        s1 = f(sigin)
53        r1 = f.rdo(s1)
54        s2 = f(zeros)
55        r2 = f.rdo(s2)
56        #self.plot_this ( s2.norm.T )
57        assert_almost_equal ( r2, sigin, decimal = precision )
[0536612]58   
[467122d]59    def test_resynth_three_steps(self):
60        """ check the resynthesis of steps is correct with 25% overlap """
61        hop_s = 16
62        buf_s = hop_s * 4
63        sigin = fvec(hop_s)
64        zeros = fvec(hop_s)
65        f = pvoc(buf_s, hop_s)
66        for i in xrange(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 )
[0536612]73   
[467122d]74    def plot_this( self, this ):
75        from pylab import semilogy, show
76        semilogy ( this )
77        show ()
[0536612]78
79if __name__ == '__main__':
80  from unittest import main
81  main()
82
Note: See TracBrowser for help on using the repository browser.