Changes in python/lib/aubio/slicing.py [2c8ada6:f9400d0]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/lib/aubio/slicing.py
r2c8ada6 rf9400d0 5 5 6 6 _max_timestamp = 1e120 7 8 7 9 8 def slice_source_at_stamps(source_file, timestamps, timestamps_end=None, … … 74 73 """ 75 74 76 if not timestamps:75 if timestamps is None or len(timestamps) == 0: 77 76 raise ValueError("no timestamps given") 78 77 … … 91 90 92 91 regions = list(zip(timestamps, timestamps_end)) 92 #print regions 93 93 94 94 source_base_name, _ = os.path.splitext(os.path.basename(source_file)) … … 98 98 source_base_name = os.path.join(output_dir, source_base_name) 99 99 100 def _new_sink_name(source_base_name, timestamp, samplerate):101 # create name based on a timestamp in samples, converted in seconds100 def new_sink_name(source_base_name, timestamp, samplerate): 101 """ create a sink based on a timestamp in samples, converted in seconds """ 102 102 timestamp_seconds = timestamp / float(samplerate) 103 103 return source_base_name + "_%011.6f" % timestamp_seconds + '.wav' … … 114 114 vec, read = _source.do_multi() 115 115 # if the total number of frames read will exceed the next region start 116 while regions and total_frames + read >= regions[0][0]: 116 while len(regions) and total_frames + read >= regions[0][0]: 117 #print "getting", regions[0], "at", total_frames 117 118 # get next region 118 119 start_stamp, end_stamp = regions.pop(0) 119 120 # create a name for the sink 120 new_sink_path = _new_sink_name(source_base_name, start_stamp, 121 samplerate) 121 new_sink_path = new_sink_name(source_base_name, start_stamp, samplerate) 122 122 # create its sink 123 123 _sink = sink(new_sink_path, samplerate, _source.channels) 124 124 # create a dictionary containing all this 125 new_slice = {'start_stamp': start_stamp, 'end_stamp': end_stamp, 126 'sink': _sink} 125 new_slice = {'start_stamp': start_stamp, 'end_stamp': end_stamp, 'sink': _sink} 127 126 # append the dictionary to the current list of slices 128 127 slices.append(new_slice) … … 136 135 # number of samples yet to written be until end of region 137 136 remaining = end_stamp - total_frames + 1 137 #print current_slice, remaining, start 138 138 # not enough frames remaining, time to split 139 139 if remaining < read: … … 141 141 # write remaining samples from current region 142 142 _sink.do_multi(vec[:, start:remaining], remaining - start) 143 #print("closing region", "remaining", remaining) 143 144 # close this file 144 145 _sink.close() … … 149 150 # remove old slices 150 151 slices = list(filter(lambda s: s['end_stamp'] > total_frames, 151 152 slices)) 152 153 if read < hopsize: 153 154 break
Note: See TracChangeset
for help on using the changeset viewer.