Changeset 215b33c


Ignore:
Timestamp:
Apr 29, 2016, 8:06:36 PM (4 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
Children:
c2a39af
Parents:
83a768e
Message:

python/tests/test_phasevoc.py: clean up, add 50% overlap test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/tests/test_phasevoc.py

    r83a768e r215b33c  
    11#! /usr/bin/env python
    22
    3 from numpy.testing import TestCase, assert_equal, assert_almost_equal
     3from numpy.testing import TestCase, assert_equal, assert_array_less
    44from aubio import fvec, cvec, pvoc, float_type
    55from numpy import array, shape
     
    77import numpy as np
    88
    9 precision = 4
     9max_sq_error = 1.e-12
     10
     11def create_sine(hop_s, freq, samplerate):
     12    t = np.arange(hop_s).astype(float_type)
     13    return np.sin( 2. * np.pi * t * freq / samplerate)
     14
     15def create_noise(hop_s):
     16    return np.random.rand(hop_s).astype(float_type) * 2. - 1.
    1017
    1118class aubio_pvoc_test_case(TestCase):
     
    4552        ratio = 8
    4653        freq = 445; samplerate = 22050
    47         sigin = np.sin( 2. * np.pi * np.arange(hop_s).astype(float_type) * freq / samplerate)
    48         r2 = self.reconstruction( sigin, hop_s, ratio)
    49         error = ((r2 - sigin)**2).mean()
    50         self.assertLessEqual(error , 1.e-3)
     54        sigin = create_sine(hop_s, freq, samplerate)
     55        self.reconstruction( sigin, hop_s, ratio)
    5156
    5257    def test_resynth_8_steps(self):
     
    5459        hop_s = 1024
    5560        ratio = 8
    56         sigin = np.random.rand(hop_s).astype(float_type) * 2. - 1.
    57         r2 = self.reconstruction( sigin, hop_s, ratio)
    58         error = ((r2 - sigin)**2).mean()
    59         self.assertLessEqual(error , 1.e-2)
     61        sigin = create_noise(hop_s)
     62        self.reconstruction(sigin, hop_s, ratio)
     63
     64    def test_resynth_4_steps_sine(self):
     65        """ check the resynthesis of is correct with 87.5% overlap """
     66        hop_s = 1024
     67        ratio = 4
     68        freq = 445; samplerate = 22050
     69        sigin = create_sine(hop_s, freq, samplerate)
     70        self.reconstruction(sigin, hop_s, ratio)
    6071
    6172    def test_resynth_4_steps(self):
     
    6374        hop_s = 1024
    6475        ratio = 4
    65         sigin = np.random.rand(hop_s).astype(float_type) * 2. - 1.
    66         r2 = self.reconstruction( sigin, hop_s, ratio)
    67         error = ((r2 - sigin)**2).mean()
    68         self.assertLessEqual(error , 1.e-2)
     76        sigin = create_noise(hop_s)
     77        self.reconstruction(sigin, hop_s, ratio)
     78
     79    def test_resynth_2_steps_sine(self):
     80        """ check the resynthesis of is correct with 50% overlap """
     81        hop_s = 1024
     82        ratio = 2
     83        freq = 445; samplerate = 22050
     84        sigin = create_sine(hop_s, freq, samplerate)
     85        self.reconstruction(sigin, hop_s, ratio)
     86
     87    def test_resynth_2_steps(self):
     88        """ check the resynthesis of is correct with 50% overlap """
     89        hop_s = 1024
     90        ratio = 2
     91        sigin = create_noise(hop_s)
     92        self.reconstruction(sigin, hop_s, ratio)
    6993
    7094    def reconstruction(self, sigin, hop_s, ratio):
     
    7599        for i in range(1, ratio):
    76100            r2 = f.rdo( f(zeros) )
    77 
    78         # FIXME: if we don't return a copy here, test_phasevoc.py will crash
    79         # once in a while
    80         return np.copy(r2)
    81 
    82     def plot_this( self, this ):
    83         from pylab import semilogy, show
    84         semilogy ( this )
    85         show ()
     101        # compute square errors
     102        sq_error = (r2 - sigin)**2
     103        # make sure all square errors are less than desired precision
     104        assert_array_less(sq_error, max_sq_error)
    86105
    87106if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.