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