source: interfaces/python/test_phasevoc.py @ 0536612

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

interfaces/python: added more tests

  • Property mode set to 100644
File size: 1.6 KB
Line 
1from numpy.testing import TestCase, run_module_suite
2from numpy.testing import assert_equal, assert_almost_equal
3from _aubio import *
4from numpy import array, shape
5
6class aubio_pvoc_test_case(TestCase):
7
8  def test_members(self):
9    f = pvoc()
10    assert_equal ([f.win_s, f.hop_s], [1024, 512])
11    f = pvoc(2048, 128)
12    assert_equal ([f.win_s, f.hop_s], [2048, 128])
13
14  def test_zeros(self):
15    win_s, hop_s = 1024, 256
16    f = pvoc (win_s, hop_s)
17    t = fvec (hop_s)
18    for time in range( 4 * win_s / hop_s ):
19      s = f(t)
20      r = f.rdo(s)
21      assert_equal ( array(t), 0)
22      assert_equal ( s.norm, 0)
23      assert_equal ( s.phas, 0)
24      assert_equal ( r, 0)
25
26  def test_steps_two_channels(self):
27    """ check the resynthesis of steps is correct """
28    f = pvoc(1024, 512, 2)
29    t1 = fvec(512, 2)
30    t2 = fvec(512, 2)
31    # positive step in first channel
32    t1[0][100:200] = .1
33    # positive step in second channel
34    t1[1][20:50] = -.1
35    s1 = f(t1)
36    r1 = f.rdo(s1)
37    s2 = f(t2)
38    r2 = f.rdo(s2)
39    #self.plot_this ( s1.norm.T )
40    assert_almost_equal ( t1, r2, decimal = 6 )
41   
42  def test_steps_three_random_channels(self):
43    from random import random
44    f = pvoc(64, 16, 3)
45    t0 = fvec(16, 3)
46    t1 = fvec(16, 3)
47    for i in xrange(3):
48      for j in xrange(16):
49        t1[i][j] = random() * 2. - 1.
50    t2 = f.rdo(f(t1))
51    t2 = f.rdo(f(t0))
52    t2 = f.rdo(f(t0))
53    t2 = f.rdo(f(t0))
54    assert_almost_equal( t1, t2, decimal = 6 )
55   
56  def plot_this( self, this ):
57    from pylab import semilogy, show
58    semilogy ( this )
59    show ()
60
61if __name__ == '__main__':
62  from unittest import main
63  main()
64
Note: See TracBrowser for help on using the repository browser.