source: python/tests/test_phasevoc.py @ 482586c

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

moved tests to subdirectory

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