Changeset 633400d for python/tests/test_source.py
- Timestamp:
- Dec 5, 2018, 10:34:39 PM (6 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/tests/test_source.py
r5b46bc3 r633400d 3 3 from nose2 import main 4 4 from nose2.tools import params 5 from numpy.testing import TestCase 5 from numpy.testing import TestCase, assert_equal 6 6 from aubio import source 7 from utils import list_all_sounds7 from .utils import list_all_sounds 8 8 9 9 import warnings … … 52 52 total_frames = 0 53 53 while True: 54 _, read = f()54 samples , read = f() 55 55 total_frames += read 56 if read < f.hop_size: break 56 if read < f.hop_size: 57 assert_equal(samples[read:], 0) 58 break 57 59 #result_str = "read {:.2f}s ({:d} frames in {:d} blocks at {:d}Hz) from {:s}" 58 60 #result_params = total_frames / float(f.samplerate), total_frames, total_frames//f.hop_size, f.samplerate, f.uri … … 67 69 self.skipTest('failed opening with hop_s = {:d}, samplerate = {:d} ({:s})'.format(hop_size, samplerate, str(e))) 68 70 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) 70 79 71 80 @params(*list_of_sounds) … … 150 159 total_frames = 0 151 160 while True: 152 _, read = f.do_multi()161 samples, read = f.do_multi() 153 162 total_frames += read 154 if read < f.hop_size: break 163 if read < f.hop_size: 164 assert_equal(samples[:,read:], 0) 165 break 155 166 #result_str = "read {:.2f}s ({:d} frames in {:d} channels and {:d} blocks at {:d}Hz) from {:s}" 156 167 #result_params = total_frames / float(f.samplerate), total_frames, f.channels, int(total_frames/f.hop_size), f.samplerate, f.uri … … 158 169 return total_frames 159 170 171 class 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 160 187 if __name__ == '__main__': 161 188 main()
Note: See TracChangeset
for help on using the changeset viewer.