source: interfaces/python/test_phasevoc.py @ abbd910

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

test_*.py: use aubio module

  • 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 fvec, cvec, pvoc
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)
29    t1 = fvec(512)
30    t2 = fvec(512)
31    # positive step in first channel
32    t1[100:200] = .1
33    # positive step in second channel
34    t1[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)
45    t0 = fvec(16)
46    t1 = fvec(16)
47    for i in xrange(16):
48        t1[i] = random() * 2. - 1.
49    t2 = f.rdo(f(t1))
50    t2 = f.rdo(f(t0))
51    t2 = f.rdo(f(t0))
52    t2 = f.rdo(f(t0))
53    assert_almost_equal( t1, t2, decimal = 6 )
54   
55  def plot_this( self, this ):
56    from pylab import semilogy, show
57    semilogy ( this )
58    show ()
59
60if __name__ == '__main__':
61  from unittest import main
62  main()
63
Note: See TracBrowser for help on using the repository browser.