[1ebf8770] | 1 | #! /usr/bin/python |
---|
| 2 | |
---|
[0536612] | 3 | from numpy.testing import TestCase, run_module_suite |
---|
| 4 | from numpy.testing import assert_equal, assert_almost_equal |
---|
[4c01c0f] | 5 | from aubio import fvec, cvec, pvoc |
---|
[0536612] | 6 | from numpy import array, shape |
---|
| 7 | |
---|
| 8 | class 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 """ |
---|
[1a6ef2c] | 30 | f = pvoc(1024, 512) |
---|
| 31 | t1 = fvec(512) |
---|
| 32 | t2 = fvec(512) |
---|
[0536612] | 33 | # positive step in first channel |
---|
[1a6ef2c] | 34 | t1[100:200] = .1 |
---|
[0536612] | 35 | # positive step in second channel |
---|
[1a6ef2c] | 36 | t1[20:50] = -.1 |
---|
[0536612] | 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 |
---|
[1a6ef2c] | 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. |
---|
[0536612] | 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 | |
---|
| 62 | if __name__ == '__main__': |
---|
| 63 | from unittest import main |
---|
| 64 | main() |
---|
| 65 | |
---|