Changeset 2c8ada6 for python/lib
- Timestamp:
- Nov 4, 2018, 8:01:08 PM (6 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master
- Children:
- 9374e57
- Parents:
- 78ebc27
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/lib/aubio/slicing.py
r78ebc27 r2c8ada6 5 5 6 6 _max_timestamp = 1e120 7 7 8 8 9 def slice_source_at_stamps(source_file, timestamps, timestamps_end=None, … … 73 74 """ 74 75 75 if timestamps is None or len(timestamps) == 0:76 if not timestamps: 76 77 raise ValueError("no timestamps given") 77 78 … … 90 91 91 92 regions = list(zip(timestamps, timestamps_end)) 92 #print regions93 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 a sink based on a timestamp in samples, converted in seconds """100 def _new_sink_name(source_base_name, timestamp, samplerate): 101 # create name 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 len(regions) and total_frames + read >= regions[0][0]: 117 #print "getting", regions[0], "at", total_frames 116 while regions and total_frames + read >= regions[0][0]: 118 117 # get next region 119 118 start_stamp, end_stamp = regions.pop(0) 120 119 # create a name for the sink 121 new_sink_path = new_sink_name(source_base_name, start_stamp, samplerate) 120 new_sink_path = _new_sink_name(source_base_name, start_stamp, 121 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, 'sink': _sink} 125 new_slice = {'start_stamp': start_stamp, 'end_stamp': end_stamp, 126 'sink': _sink} 126 127 # append the dictionary to the current list of slices 127 128 slices.append(new_slice) … … 135 136 # number of samples yet to written be until end of region 136 137 remaining = end_stamp - total_frames + 1 137 #print current_slice, remaining, start138 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)144 143 # close this file 145 144 _sink.close() … … 150 149 # remove old slices 151 150 slices = list(filter(lambda s: s['end_stamp'] > total_frames, 152 slices))151 slices)) 153 152 if read < hopsize: 154 153 break
Note: See TracChangeset
for help on using the changeset viewer.