Changeset bc24e9c for python/scripts/aubiocut
- Timestamp:
- Jan 12, 2014, 3:09:25 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:
- 8203ae5
- Parents:
- 88432a9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/scripts/aubiocut
r88432a9 rbc24e9c 167 167 if options.cut and nstamps > 0: 168 168 # generate output filenames 169 import os 170 source_base_name, source_ext = os.path.splitext(os.path.basename(source_file)) 171 if options.output_directory != None: 172 if not os.path.isdir(options.output_directory): 173 os.makedirs(options.output_directory) 174 source_base_name = os.path.join(options.output_directory, source_base_name) 175 def new_sink_name(source_base_name, timestamp): 176 return source_base_name + '_%02.3f' % (timestamp) + '.wav' 177 # reopen source file 178 s = source(source_file, samplerate, hopsize) 179 if samplerate == 0: samplerate = s.get_samplerate() 180 # create first sink at 0 181 g = sink(new_sink_name(source_base_name, 0.), samplerate) 182 total_frames = 0 183 # get next region 184 next_stamp = int(timestamps.pop(0)) 185 while True: 186 vec, read = s() 187 remaining = next_stamp - total_frames 188 if remaining <= read: 189 # write remaining samples from current region 190 g(vec[0:remaining], remaining) 191 # close this file 192 del g 193 # create a new file for the new region 194 g = sink(new_sink_name(source_base_name, next_stamp / float(samplerate)), samplerate) 195 # write the remaining samples in the new file 196 g(vec[remaining:read], read - remaining) 197 #print "new slice", total_frames_written, "+", remaining, "=", start_of_next_region 198 if len(timestamps): 199 next_stamp = int(timestamps.pop(0)) 200 else: 201 next_stamp = 1e120 202 else: 203 g(vec[0:read], read) 204 total_frames += read 205 if read < hopsize: break 169 from aubio.slicing import slice_source_at_stamps 170 slice_source_at_stamps(source_file, timestamps, 171 output_dir = options.output_directory) 206 172 207 173 # print some info
Note: See TracChangeset
for help on using the changeset viewer.