Ignore:
Timestamp:
Dec 5, 2018, 10:34:39 PM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn, feature/crepe, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
Children:
283a619a
Parents:
5b46bc3 (diff), f19db54 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into feature/pitchshift

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/tests/test_source.py

    r5b46bc3 r633400d  
    33from nose2 import main
    44from nose2.tools import params
    5 from numpy.testing import TestCase
     5from numpy.testing import TestCase, assert_equal
    66from aubio import source
    7 from utils import list_all_sounds
     7from .utils import list_all_sounds
    88
    99import warnings
     
    5252        total_frames = 0
    5353        while True:
    54             _ , read = f()
     54            samples , read = f()
    5555            total_frames += read
    56             if read < f.hop_size: break
     56            if read < f.hop_size:
     57                assert_equal(samples[read:], 0)
     58                break
    5759        #result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}"
    5860        #result_params = total_frames / float(f.samplerate), total_frames, total_frames//f.hop_size, f.samplerate, f.uri
     
    6769            self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e)))
    6870        assert f.samplerate != 0
    69         self.read_from_source(f)
     71        read_frames = self.read_from_source(f)
     72        if 'f_' in soundfile and samplerate == 0:
     73            import re
     74            f = re.compile('.*_\([0:9]*f\)_.*')
     75            match_f = re.findall('([0-9]*)f_', soundfile)
     76            if len(match_f) == 1:
     77                expected_frames = int(match_f[0])
     78                self.assertEqual(expected_frames, read_frames)
    7079
    7180    @params(*list_of_sounds)
     
    150159        total_frames = 0
    151160        while True:
    152             _, read = f.do_multi()
     161            samples, read = f.do_multi()
    153162            total_frames += read
    154             if read < f.hop_size: break
     163            if read < f.hop_size:
     164                assert_equal(samples[:,read:], 0)
     165                break
    155166        #result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}"
    156167        #result_params = total_frames / float(f.samplerate), total_frames, f.channels, int(total_frames/f.hop_size), f.samplerate, f.uri
     
    158169        return total_frames
    159170
     171class aubio_source_with(aubio_source_test_case_base):
     172
     173    #@params(*list_of_sounds)
     174    @params(*list_of_sounds)
     175    def test_read_from_mono(self, filename):
     176        total_frames = 0
     177        hop_size = 2048
     178        with source(filename, 0, hop_size) as input_source:
     179            assert_equal(input_source.hop_size, hop_size)
     180            #assert_equal(input_source.samplerate, samplerate)
     181            total_frames = 0
     182            for frames in input_source:
     183                total_frames += frames.shape[-1]
     184            # check we read as many samples as we expected
     185            assert_equal(total_frames, input_source.duration)
     186
    160187if __name__ == '__main__':
    161188    main()
Note: See TracChangeset for help on using the changeset viewer.