Changes in / [92a6af0:7165fc56]
- Location:
- python
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
python/lib/aubio/cmd.py
r92a6af0 r7165fc56 248 248 action = "store", dest = "cut_until_nslices", default = None, 249 249 help="how many extra slices should be added at the end of each slice") 250 self.add_argument("--create-first",251 action = "store_true", dest = "create_first", default = False,252 help="always include first slice")253 250 254 251 # some utilities -
python/lib/aubio/cut.py
r92a6af0 r7165fc56 102 102 s = source(source_uri, samplerate, hopsize) 103 103 if samplerate == 0: 104 samplerate = s. samplerate104 samplerate = s.get_samplerate() 105 105 options.samplerate = samplerate 106 106 … … 151 151 timestamps, timestamps_end = timestamps_end, 152 152 output_dir = options.output_directory, 153 samplerate = options.samplerate, 154 create_first = options.create_first) 153 samplerate = options.samplerate) 155 154 156 155 def main(): -
python/lib/aubio/slicing.py
r92a6af0 r7165fc56 7 7 8 8 def slice_source_at_stamps(source_file, timestamps, timestamps_end=None, 9 output_dir=None, samplerate=0, hopsize=256, 10 create_first=False): 9 output_dir=None, samplerate=0, hopsize=256): 11 10 """ slice a sound file at given timestamps """ 12 11 … … 14 13 raise ValueError("no timestamps given") 15 14 16 if timestamps[0] != 0 and create_first:15 if timestamps[0] != 0: 17 16 timestamps = [0] + timestamps 18 17 if timestamps_end is not None: … … 20 19 21 20 if timestamps_end is not None: 22 if len(timestamps_end) == len(timestamps) - 1: 23 timestamps_end = timestamps_end + [_max_timestamp] 24 elif len(timestamps_end) != len(timestamps): 21 if len(timestamps_end) != len(timestamps): 25 22 raise ValueError("len(timestamps_end) != len(timestamps)") 26 23 else: … … 52 49 vec, read = _source.do_multi() 53 50 # if the total number of frames read will exceed the next region start 54 whilelen(regions) and total_frames + read >= regions[0][0]:51 if len(regions) and total_frames + read >= regions[0][0]: 55 52 #print "getting", regions[0], "at", total_frames 56 53 # get next region … … 79 76 # write remaining samples from current region 80 77 _sink.do_multi(vec[:, start:remaining], remaining - start) 81 #print ("closing region", "remaining", remaining)78 #print "closing region", "remaining", remaining 82 79 # close this file 83 80 _sink.close() … … 86 83 _sink.do_multi(vec[:, start:read], read - start) 87 84 total_frames += read 88 # remove old slices89 slices = list(filter(lambda s: s['end_stamp'] > total_frames,90 slices))91 85 if read < hopsize: 92 86 break -
python/tests/test_slicing.py
r92a6af0 r7165fc56 24 24 def test_slice_start_only_no_zero(self): 25 25 regions_start = [i*1000 for i in range(1, n_slices)] 26 slice_source_at_stamps(self.source_file, regions_start, 27 output_dir = self.output_dir, create_first=True) 26 slice_source_at_stamps(self.source_file, regions_start, output_dir = self.output_dir) 28 27 29 28 def test_slice_start_beyond_end(self): 30 29 regions_start = [i*1000 for i in range(1, n_slices)] 31 30 regions_start += [count_samples_in_file(self.source_file) + 1000] 32 slice_source_at_stamps(self.source_file, regions_start, 33 output_dir = self.output_dir, create_first=True) 31 slice_source_at_stamps(self.source_file, regions_start, output_dir = self.output_dir) 34 32 35 33 def test_slice_start_every_blocksize(self): … … 38 36 slice_source_at_stamps(self.source_file, regions_start, output_dir = self.output_dir, 39 37 hopsize = 200) 40 41 def test_slice_start_every_half_blocksize(self):42 hopsize = 20043 regions_start = [i*hopsize//2 for i in range(1, n_slices)]44 slice_source_at_stamps(self.source_file, regions_start,45 output_dir = self.output_dir, hopsize = 200)46 38 47 39 def tearDown(self): … … 100 92 "number of samples written different from number of original samples") 101 93 102 def test_slice_start_and_ends_with_missing_end(self):103 regions_start = [i*1000 for i in range(n_slices)]104 regions_ends = [r-1 for r in regions_start[1:]]105 slice_source_at_stamps(self.source_file, regions_start, regions_ends,106 output_dir = self.output_dir)107 written_samples = count_samples_in_directory(self.output_dir)108 original_samples = count_samples_in_file(self.source_file)109 total_files = count_files_in_directory(self.output_dir)110 assert_equal(n_slices, total_files,111 "number of slices created different from expected")112 assert_equal(written_samples, original_samples,113 "number of samples written different from number of original samples")114 115 94 def tearDown(self): 116 95 shutil.rmtree(self.output_dir) … … 155 134 regions_end = None 156 135 slice_source_at_stamps (self.source_file, regions_start, regions_end, 157 output_dir = self.output_dir , create_first=True)136 output_dir = self.output_dir) 158 137 total_files = count_files_in_directory(self.output_dir) 159 138 assert_equal(n_slices, total_files,
Note: See TracChangeset
for help on using the changeset viewer.