Changeset a0e0f56


Ignore:
Timestamp:
Sep 21, 2016, 1:32:57 AM (8 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn, feature/crepe, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch
Children:
04fc360
Parents:
b3f79ca
Message:

python/tests/test_pitchshift.py: run in a few modes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/tests/test_pitchshift.py

    rb3f79ca ra0e0f56  
    22
    33from numpy.testing import TestCase
     4from nose2.tools import params
     5import numpy as np
    46import aubio
    57
     
    810    def setUp(self):
    911        try:
    10             self.o = aubio.pitchshift()
     12            self.o = aubio.pitchshift(hop_size = 128)
    1113        except RuntimeError as e:
    1214            self.skipTest("creating aubio.pitchshift failed (recompile with rubberband?)")
     
    1719
    1820    def test_on_zeros(self):
    19         test_length = 20000
     21        test_length = self.o.hop_size * 100
    2022        read = 0
    2123        # test on zeros
    22         vec = aubio.fvec(512)
     24        vec = aubio.fvec(self.o.hop_size)
    2325        transpose_range = 24
    2426        while read < test_length:
     
    2628            out = self.o(vec)
    2729            self.assertTrue((out == 0).all())
     30            # position in the file (between 0. and 1.)
     31            percent_read = read / float(test_length)
     32            # variable transpose rate (in semitones)
     33            transpose = 2 * transpose_range * percent_read - transpose_range
     34            # set transpose rate
     35            self.o.set_transpose(transpose)
     36            read += len(vec)
     37
     38    def test_on_ones(self):
     39        test_length = self.o.hop_size * 100
     40        read = 0
     41        # test on zeros
     42        vec = aubio.fvec(self.o.hop_size) + 1
     43        transpose_range = 1.24
     44        while read < test_length:
     45            # transpose the samples
     46            out = self.o(vec)
    2847            # position in the file (between 0. and 1.)
    2948            percent_read = read / float(test_length)
     
    4261            self.o.set_transpose(-24.3)
    4362
     63
     64class aubio_pitchshift_testruns(TestCase):
     65
     66    @params(
     67            ("default",     1.2,  128,  44100),
     68            ("crispness:0", 0.43,  64,   8000),
     69            ("crispness:3", 0.53, 256,   8000),
     70            ("crispness:3", 1.53, 512,   8000),
     71            ("crispness:6", 2.3, 4096, 192000),
     72            )
     73    def test_run_with_params(self, mode, pitchscale, hop_size, samplerate):
     74        self.o = aubio.pitchshift(mode, pitchscale, hop_size, samplerate)
     75        test_length = self.o.hop_size * 50
     76        read = 0
     77        # test on random
     78        vec = np.random.rand(self.o.hop_size).astype(aubio.float_type)
     79        transpose_range = self.o.get_transpose()
     80        while read < test_length:
     81            # transpose the samples
     82            out = self.o(vec)
     83            # position in the file (between 0. and 1.)
     84            percent_read = read / float(test_length)
     85            # variable transpose rate (in semitones)
     86            transpose =  transpose_range - 2 * transpose_range * percent_read
     87            # set transpose rate
     88            self.o.set_transpose(transpose)
     89            read += len(vec)
     90
    4491if __name__ == '__main__':
    4592    from nose2 import main
Note: See TracChangeset for help on using the changeset viewer.