source: python/tests/test_phasevoc.py @ 52efae1

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

python/tests/test_phasevoc.py: split tests

  • Property mode set to 100755
File size: 1.7 KB
Line 
1#! /usr/bin/env python
2
3from numpy.testing import TestCase, run_module_suite
4from numpy.testing import assert_equal, assert_almost_equal
5from aubio import fvec, cvec, pvoc
6from numpy import array, shape
7
8class aubio_pvoc_test_case(TestCase):
9
10  def test_members_automatic_sizes_default(self):
11    f = pvoc()
12    assert_equal ([f.win_s, f.hop_s], [1024, 512])
13
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])
17
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)
29
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 )
45   
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 )
58   
59  def plot_this( self, this ):
60    from pylab import semilogy, show
61    semilogy ( this )
62    show ()
63
64if __name__ == '__main__':
65  from unittest import main
66  main()
67
Note: See TracBrowser for help on using the repository browser.