Showing the changes to python/tests (1 of 1 file). Show all
Unified · Split
| @@ -1,11 +1,12 @@ | ||
| 1 | 1 | #! /usr/bin/env python |
| 2 | 2 | |
| 3 | 3 | from numpy.testing import TestCase, assert_equal, assert_almost_equal |
| 4 | −from aubio import fvec, cvec, pvoc | |
| 4 | +from aubio import fvec, cvec, pvoc, float_type | |
| 5 | 5 | from numpy import array, shape |
| 6 | 6 | from numpy.random import random |
| 7 | +import numpy as np | |
| 7 | 8 | |
| 8 | −precision = 6 | |
| 9 | +precision = 4 | |
| 9 | 10 | |
| 10 | 11 | class aubio_pvoc_test_case(TestCase): |
| 11 | 12 | """ pvoc object test case """ |
| @@ -38,38 +39,32 @@ class aubio_pvoc_test_case(TestCase): · 26 unmodified lines | ||
| 38 | 39 | assert_equal ( s.phas, 0) |
| 39 | 40 | assert_equal ( r, 0) |
| 40 | 41 | |
| 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 | |
| 42 | + def test_resynth_8_steps(self): | |
| 43 | + """ check the resynthesis of is correct with 87.5% overlap """ | |
| 44 | + hop_s = 256 | |
| 45 | + ratio = 8 | |
| 46 | + sigin = np.random.rand(hop_s).astype(float_type) * 2. - 1. | |
| 47 | + buf_s = hop_s * ratio | |
| 45 | 48 | 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 | 49 | zeros = fvec(hop_s) |
| 50 | + r2 = f.rdo( f(sigin) ) | |
| 51 | + for i in range(1, ratio): | |
| 52 | + r2 = f.rdo( f(zeros) ) | |
| 53 | + r2 *= .5 | |
| 54 | + assert_almost_equal ( r2 - sigin, 0., decimal = precision ) | |
| 55 | + | |
| 56 | + def test_resynth_4_steps(self): | |
| 57 | + """ check the resynthesis of is correct with 75% overlap """ | |
| 58 | + hop_s = 256 | |
| 59 | + ratio = 4 | |
| 60 | + sigin = np.random.rand(hop_s).astype(float_type) * 2. - 1. | |
| 61 | + buf_s = hop_s * ratio | |
| 65 | 62 | 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 ) | |
| 63 | + zeros = fvec(hop_s) | |
| 64 | + r2 = f.rdo( f(sigin) ) | |
| 65 | + for i in range(1, ratio): | |
| 66 | + r2 = f.rdo( f(zeros) ) | |
| 67 | + assert_almost_equal ( r2 - sigin, 0., decimal = precision ) | |
| 73 | 68 | |
| 74 | 69 | def plot_this( self, this ): |
| 75 | 70 | from pylab import semilogy, show |