Changeset 467122d for python/tests


Ignore:
Timestamp:
Feb 22, 2014, 7:37:16 PM (11 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
4c0a1db
Parents:
8eff66d
Message:

python/tests/test_phasevoc.py: improve

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/tests/test_phasevoc.py

    r8eff66d r467122d  
    11#! /usr/bin/env python
    22
    3 from numpy.testing import TestCase, run_module_suite
    4 from numpy.testing import assert_equal, assert_almost_equal
     3from numpy.testing import TestCase, assert_equal, assert_almost_equal
    54from aubio import fvec, cvec, pvoc
    65from numpy import array, shape
     6from numpy.random import random
     7
     8precision = 6
    79
    810class aubio_pvoc_test_case(TestCase):
     11    """ pvoc object test case """
    912
    10   def test_members_automatic_sizes_default(self):
    11     f = pvoc()
    12     assert_equal ([f.win_s, f.hop_s], [1024, 512])
     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])
    1317
    14   def test_members_automatic_sizes_not_null(self):
    15     f = pvoc(2048, 128)
    16     assert_equal ([f.win_s, f.hop_s], [2048, 128])
     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])
    1722
    18   def test_zeros(self):
    19     win_s, hop_s = 1024, 256
    20     f = pvoc (win_s, hop_s)
    21     t = fvec (hop_s)
    22     for time in range( 4 * win_s / hop_s ):
    23       s = f(t)
    24       r = f.rdo(s)
    25       assert_equal ( array(t), 0)
    26       assert_equal ( s.norm, 0)
    27       assert_equal ( s.phas, 0)
    28       assert_equal ( r, 0)
     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])
    2927
    30   def test_steps_two_channels(self):
    31     """ check the resynthesis of steps is correct """
    32     f = pvoc(1024, 512)
    33     t1 = fvec(512)
    34     t2 = fvec(512)
    35     # positive step in first channel
    36     t1[100:200] = .1
    37     # positive step in second channel
    38     t1[20:50] = -.1
    39     s1 = f(t1)
    40     r1 = f.rdo(s1)
    41     s2 = f(t2)
    42     r2 = f.rdo(s2)
    43     #self.plot_this ( s1.norm.T )
    44     assert_almost_equal ( t1, r2, decimal = 6 )
     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)
     40
     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 )
    4558   
    46   def test_steps_three_random_channels(self):
    47     from random import random
    48     f = pvoc(64, 16)
    49     t0 = fvec(16)
    50     t1 = fvec(16)
    51     for i in xrange(16):
    52         t1[i] = random() * 2. - 1.
    53     t2 = f.rdo(f(t1))
    54     t2 = f.rdo(f(t0))
    55     t2 = f.rdo(f(t0))
    56     t2 = f.rdo(f(t0))
    57     assert_almost_equal( t1, t2, decimal = 6 )
     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 )
    5873   
    59   def plot_this( self, this ):
    60     from pylab import semilogy, show
    61     semilogy ( this )
    62     show ()
     74    def plot_this( self, this ):
     75        from pylab import semilogy, show
     76        semilogy ( this )
     77        show ()
    6378
    6479if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.