Changeset 4320679 for python/lib/aubio
- Timestamp:
- Jan 12, 2014, 7:58:06 AM (11 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, pitchshift, sampler, timestretch, yinfft+
- Children:
- 6fbee46
- Parents:
- f36ecea
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/lib/aubio/slicing.py
rf36ecea r4320679 15 15 timestamps = [0] + timestamps 16 16 17 if timestamps_end != None and len(timestamps_end) != len(timestamps): 18 raise ValueError ("len(timestamps_end) != len(timestamps)") 17 if timestamps_end != None: 18 if len(timestamps_end) != len(timestamps): 19 raise ValueError ("len(timestamps_end) != len(timestamps)") 19 20 else: 20 21 timestamps_end = [t - 1 for t in timestamps[1:] ] + [ max_timestamp ] 22 23 regions = zip(timestamps, timestamps_end) 24 #print regions 21 25 22 26 source_base_name, source_ext = os.path.splitext(os.path.basename(source_file)) … … 33 37 # reopen source file 34 38 s = source(source_file, samplerate, hopsize) 35 if samplerate == 0: samplerate = s.get_samplerate() 39 samplerate = s.get_samplerate() 40 36 41 total_frames = 0 37 # get next region 38 start_stamp = int(timestamps.pop(0)) 39 end_stamp = int(timestamps_end.pop(0)) 40 41 # create first sink 42 new_sink_path = new_sink_name(source_base_name, start_stamp, samplerate) 43 #print "new slice", total_frames, "+", remaining, "=", end_stamp 44 g = sink(new_sink_path, samplerate) 42 slices = [] 45 43 46 44 while True: 47 45 # get hopsize new samples from source 48 46 vec, read = s() 49 # number of samples until end of region 50 remaining = end_stamp - total_frames 51 # not enough frames remaining, time to split 52 if remaining < read: 53 if remaining != 0: 54 # write remaining samples from current region 55 g(vec[0:remaining], remaining) 56 # close this file 57 del g 58 # get the next region 59 start_stamp = int(timestamps.pop(0)) 60 end_stamp = int(timestamps_end.pop(0)) 61 # create a new file for the new region 47 # if the total number of frames read will exceed the next region start 48 if len(regions) and total_frames + read >= regions[0][0]: 49 #print "getting", regions[0], "at", total_frames 50 # get next region 51 start_stamp, end_stamp = regions.pop(0) 52 # create a name for the sink 62 53 new_sink_path = new_sink_name(source_base_name, start_stamp, samplerate) 63 # print "new slice", total_frames, "+", remaining, "=", end_stamp54 # create its sink 64 55 g = sink(new_sink_path, samplerate) 65 # write the remaining samples in the new file 66 g(vec[remaining:read], read - remaining) 67 elif read > 0: 68 # write all the samples 69 g(vec[0:read], read) 56 # create a dictionary containing all this 57 new_slice = {'start_stamp': start_stamp, 'end_stamp': end_stamp, 'sink': g} 58 # append the dictionary to the current list of slices 59 slices.append(new_slice) 60 61 for current_slice in slices: 62 start_stamp = current_slice['start_stamp'] 63 end_stamp = current_slice['end_stamp'] 64 g = current_slice['sink'] 65 # sample index to start writing from new source vector 66 start = max(start_stamp - total_frames, 0) 67 # number of samples yet to written be until end of region 68 remaining = end_stamp - total_frames + 1 69 #print current_slice, remaining, start 70 # not enough frames remaining, time to split 71 if remaining < read: 72 if remaining > start: 73 # write remaining samples from current region 74 g(vec[start:remaining], remaining - start) 75 #print "closing region", "remaining", remaining 76 # close this file 77 del g 78 elif read > start: 79 # write all the samples 80 g(vec[start:read], read - start) 70 81 total_frames += read 71 82 if read < hopsize: break
Note: See TracChangeset
for help on using the changeset viewer.