source: python/tests/test_phasevoc.py @ 98e9d69

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

python/tests/test_phasevoc.py: add a note about ocasional crash

  • Property mode set to 100755
File size: 2.9 KB
Line 
1#! /usr/bin/env python
2
3from numpy.testing import TestCase, assert_equal, assert_almost_equal
4from aubio import fvec, cvec, pvoc, float_type
5from numpy import array, shape
6from numpy.random import random
7import numpy as np
8
9precision = 4
10
11class aubio_pvoc_test_case(TestCase):
12    """ pvoc object test case """
13
14    def test_members_automatic_sizes_default(self):
15        """ check object creation with default parameters """
16        f = pvoc()
17        assert_equal ([f.win_s, f.hop_s], [1024, 512])
18
19    def test_members_unnamed_params(self):
20        """ check object creation with unnamed parameters """
21        f = pvoc(2048, 128)
22        assert_equal ([f.win_s, f.hop_s], [2048, 128])
23
24    def test_members_named_params(self):
25        """ check object creation with named parameters """
26        f = pvoc(hop_s = 128, win_s = 2048)
27        assert_equal ([f.win_s, f.hop_s], [2048, 128])
28
29    def test_zeros(self):
30        """ check the resynthesis of zeros gives zeros """
31        win_s, hop_s = 1024, 256
32        f = pvoc (win_s, hop_s)
33        t = fvec (hop_s)
34        for time in range( int ( 4 * win_s / hop_s ) ):
35            s = f(t)
36            r = f.rdo(s)
37            assert_equal ( array(t), 0)
38            assert_equal ( s.norm, 0)
39            assert_equal ( s.phas, 0)
40            assert_equal ( r, 0)
41
42    def test_resynth_8_steps_sine(self):
43        """ check the resynthesis of is correct with 87.5% overlap """
44        hop_s = 1024
45        ratio = 8
46        freq = 445; samplerate = 22050
47        sigin = np.sin( 2. * np.pi * np.arange(hop_s).astype(float_type) * freq / samplerate)
48        r2 = self.reconstruction( sigin, hop_s, ratio)
49        error = ((r2 - sigin)**2).mean()
50        self.assertLessEqual(error , 1.e-3)
51
52    def test_resynth_8_steps(self):
53        """ check the resynthesis of is correct with 87.5% overlap """
54        hop_s = 1024
55        ratio = 8
56        sigin = np.random.rand(hop_s).astype(float_type) * 2. - 1.
57        r2 = self.reconstruction( sigin, hop_s, ratio)
58        error = ((r2 - sigin)**2).mean()
59        self.assertLessEqual(error , 1.e-2)
60
61    def test_resynth_4_steps(self):
62        """ check the resynthesis of is correct with 75% overlap """
63        hop_s = 1024
64        ratio = 4
65        sigin = np.random.rand(hop_s).astype(float_type) * 2. - 1.
66        r2 = self.reconstruction( sigin, hop_s, ratio)
67        error = ((r2 - sigin)**2).mean()
68        self.assertLessEqual(error , 1.e-2)
69
70    def reconstruction(self, sigin, hop_s, ratio):
71        buf_s = hop_s * ratio
72        f = pvoc(buf_s, hop_s)
73        zeros = fvec(hop_s)
74        r2 = f.rdo( f(sigin) )
75        for i in range(1, ratio):
76            r2 = f.rdo( f(zeros) )
77
78        # FIXME: if we don't return a copy here, test_phasevoc.py will crash
79        # once in a while
80        return np.copy(r2)
81
82    def plot_this( self, this ):
83        from pylab import semilogy, show
84        semilogy ( this )
85        show ()
86
87if __name__ == '__main__':
88  from unittest import main
89  main()
90
Note: See TracBrowser for help on using the repository browser.