1 | #! /usr/bin/env python |
---|
2 | |
---|
3 | from numpy.testing import TestCase, assert_equal, assert_almost_equal |
---|
4 | from aubio import fvec, cvec, pvoc |
---|
5 | from numpy import array, shape |
---|
6 | from numpy.random import random |
---|
7 | |
---|
8 | precision = 6 |
---|
9 | |
---|
10 | class aubio_pvoc_test_case(TestCase): |
---|
11 | """ pvoc object test case """ |
---|
12 | |
---|
13 | def test_members_automatic_sizes_default(self): |
---|
14 | """ check object creation with default parameters """ |
---|
15 | f = pvoc() |
---|
16 | assert_equal ([f.win_s, f.hop_s], [1024, 512]) |
---|
17 | |
---|
18 | def test_members_unnamed_params(self): |
---|
19 | """ check object creation with unnamed parameters """ |
---|
20 | f = pvoc(2048, 128) |
---|
21 | assert_equal ([f.win_s, f.hop_s], [2048, 128]) |
---|
22 | |
---|
23 | def test_members_named_params(self): |
---|
24 | """ check object creation with named parameters """ |
---|
25 | f = pvoc(hop_s = 128, win_s = 2048) |
---|
26 | assert_equal ([f.win_s, f.hop_s], [2048, 128]) |
---|
27 | |
---|
28 | def test_zeros(self): |
---|
29 | """ check the resynthesis of zeros gives zeros """ |
---|
30 | win_s, hop_s = 1024, 256 |
---|
31 | f = pvoc (win_s, hop_s) |
---|
32 | t = fvec (hop_s) |
---|
33 | for time in range( int ( 4 * win_s / hop_s ) ): |
---|
34 | s = f(t) |
---|
35 | r = f.rdo(s) |
---|
36 | assert_equal ( array(t), 0) |
---|
37 | assert_equal ( s.norm, 0) |
---|
38 | assert_equal ( s.phas, 0) |
---|
39 | assert_equal ( r, 0) |
---|
40 | |
---|
41 | def test_resynth_two_steps(self): |
---|
42 | """ check the resynthesis of steps is correct with 50% overlap """ |
---|
43 | hop_s = 512 |
---|
44 | buf_s = hop_s * 2 |
---|
45 | f = pvoc(buf_s, hop_s) |
---|
46 | sigin = fvec(hop_s) |
---|
47 | zeros = fvec(hop_s) |
---|
48 | # negative step |
---|
49 | sigin[20:50] = -.1 |
---|
50 | # positive step |
---|
51 | sigin[100:200] = .1 |
---|
52 | s1 = f(sigin) |
---|
53 | r1 = f.rdo(s1) |
---|
54 | s2 = f(zeros) |
---|
55 | r2 = f.rdo(s2) |
---|
56 | #self.plot_this ( s2.norm.T ) |
---|
57 | assert_almost_equal ( r2, sigin, decimal = precision ) |
---|
58 | |
---|
59 | def test_resynth_three_steps(self): |
---|
60 | """ check the resynthesis of steps is correct with 25% overlap """ |
---|
61 | hop_s = 16 |
---|
62 | buf_s = hop_s * 4 |
---|
63 | sigin = fvec(hop_s) |
---|
64 | zeros = fvec(hop_s) |
---|
65 | f = pvoc(buf_s, hop_s) |
---|
66 | for i in range(hop_s): |
---|
67 | sigin[i] = random() * 2. - 1. |
---|
68 | t2 = f.rdo( f(sigin) ) |
---|
69 | t2 = f.rdo( f(zeros) ) |
---|
70 | t2 = f.rdo( f(zeros) ) |
---|
71 | t2 = f.rdo( f(zeros) ) |
---|
72 | assert_almost_equal( sigin, t2, decimal = precision ) |
---|
73 | |
---|
74 | def plot_this( self, this ): |
---|
75 | from pylab import semilogy, show |
---|
76 | semilogy ( this ) |
---|
77 | show () |
---|
78 | |
---|
79 | if __name__ == '__main__': |
---|
80 | from unittest import main |
---|
81 | main() |
---|
82 | |
---|