ref: bc24e9ce23a6a38da41e2c00ea90e408f9b72ba8
parent: 88432a9429e344b282b59f96a8de7d8aaf7a5548
author: Paul Brossier <piem@piem.org>
date: Sat Jan 11 17:09:25 EST 2014
python/scripts/aubiocut: use slice_source_at_stamps
--- a/python/scripts/aubiocut
+++ b/python/scripts/aubiocut
@@ -166,43 +166,9 @@
# cutting pass
if options.cut and nstamps > 0:
# generate output filenames
- import os
- source_base_name, source_ext = os.path.splitext(os.path.basename(source_file))
- if options.output_directory != None:
- if not os.path.isdir(options.output_directory):
- os.makedirs(options.output_directory)
- source_base_name = os.path.join(options.output_directory, source_base_name)
- def new_sink_name(source_base_name, timestamp):
- return source_base_name + '_%02.3f' % (timestamp) + '.wav'
- # reopen source file
- s = source(source_file, samplerate, hopsize)
- if samplerate == 0: samplerate = s.get_samplerate()
- # create first sink at 0
- g = sink(new_sink_name(source_base_name, 0.), samplerate)
- total_frames = 0
- # get next region
- next_stamp = int(timestamps.pop(0))
- while True:
- vec, read = s()
- remaining = next_stamp - total_frames
- if remaining <= read:
- # write remaining samples from current region
- g(vec[0:remaining], remaining)
- # close this file
- del g
- # create a new file for the new region
- g = sink(new_sink_name(source_base_name, next_stamp / float(samplerate)), samplerate)
- # write the remaining samples in the new file
- g(vec[remaining:read], read - remaining)
- #print "new slice", total_frames_written, "+", remaining, "=", start_of_next_region
- if len(timestamps):
- next_stamp = int(timestamps.pop(0))
- else:
- next_stamp = 1e120
- else:
- g(vec[0:read], read)
- total_frames += read
- if read < hopsize: break
+ from aubio.slicing import slice_source_at_stamps
+ slice_source_at_stamps(source_file, timestamps,
+ output_dir = options.output_directory)
# print some info
duration = float (total_frames) / float(samplerate)