source: interfaces/python/test_phasevoc.py @ 474f297

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

test_*.py: switch to mono, add tests for cvec

  • 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
4from _aubio import *
5from numpy import array, shape
6
7class aubio_pvoc_test_case(TestCase):
8
9  def test_members(self):
10    f = pvoc()
11    assert_equal ([f.win_s, f.hop_s], [1024, 512])
12    f = pvoc(2048, 128)
13    assert_equal ([f.win_s, f.hop_s], [2048, 128])
14
15  def test_zeros(self):
16    win_s, hop_s = 1024, 256
17    f = pvoc (win_s, hop_s)
18    t = fvec (hop_s)
19    for time in range( 4 * win_s / hop_s ):
20      s = f(t)
21      r = f.rdo(s)
22      assert_equal ( array(t), 0)
23      assert_equal ( s.norm, 0)
24      assert_equal ( s.phas, 0)
25      assert_equal ( r, 0)
26
27  def test_steps_two_channels(self):
28    """ check the resynthesis of steps is correct """
29    f = pvoc(1024, 512)
30    t1 = fvec(512)
31    t2 = fvec(512)
32    # positive step in first channel
33    t1[100:200] = .1
34    # positive step in second channel
35    t1[20:50] = -.1
36    s1 = f(t1)
37    r1 = f.rdo(s1)
38    s2 = f(t2)
39    r2 = f.rdo(s2)
40    #self.plot_this ( s1.norm.T )
41    assert_almost_equal ( t1, r2, decimal = 6 )
42   
43  def test_steps_three_random_channels(self):
44    from random import random
45    f = pvoc(64, 16)
46    t0 = fvec(16)
47    t1 = fvec(16)
48    for i in xrange(16):
49        t1[i] = 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.