From 7fc5ba23e5afdc3bbafb180aa6736958304c5b77 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Thu, 17 Oct 2013 14:54:51 +0200 Subject: [PATCH] python/scripts/aubiocut: add -b option --- python/scripts/aubiocut | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/python/scripts/aubiocut b/python/scripts/aubiocut index 93fd0113..91215947 100755 --- a/python/scripts/aubiocut +++ b/python/scripts/aubiocut @@ -8,7 +8,7 @@ import sys #from aubio.task import * usage = "usage: %s [options] -i soundfile" % sys.argv[0] -usage += "\nhelp: %s -h" % sys.argv[0] +usage += "\n help: %s -h" % sys.argv[0] def parse_args(): from optparse import OptionParser @@ -21,10 +21,10 @@ def parse_args(): help="onset detection method [default=default] \ complexdomain|hfc|phase|specdiff|energy|kl|mkl") # cutting methods - """ parser.add_option("-b","--beat", action="store_true", dest="beat", default=False, help="use beat locations") + """ parser.add_option("-S","--silencecut", action="store_true", dest="silencecut", default=False, help="use silence locations") @@ -40,10 +40,10 @@ def parse_args(): help="samplerate at which the file should be represented") parser.add_option("-B","--bufsize", action="store", dest="bufsize", default=512, - metavar = "", + metavar = "", type='int', help="buffer size [default=512]") parser.add_option("-H","--hopsize", - metavar = "", + metavar = "", type='int', action="store", dest="hopsize", default=256, help="overlap size [default=256]") parser.add_option("-t","--threshold", @@ -126,12 +126,15 @@ if __name__ == '__main__': samplerate = options.samplerate source_file = options.source_file - from aubio import onset, source, sink + from aubio import onset, tempo, source, sink s = source(source_file, samplerate, hopsize) if samplerate == 0: samplerate = s.get_samplerate() - o = onset(options.onset_method, bufsize, hopsize) + if options.beat: + o = tempo(options.onset_method, bufsize, hopsize) + else: + o = onset(options.onset_method, bufsize, hopsize) o.set_threshold(options.threshold) timestamps = [] @@ -140,12 +143,11 @@ if __name__ == '__main__': while True: samples, read = s() if o(samples): - this_onset = o.get_last_onset() - if options.verbose: print "%.4f" % o.get_last_onset_s() - timestamps.append (this_onset) + timestamps.append (o.get_last()) + if options.verbose: print "%.4f" % o.get_last_s() total_frames += read if read < hopsize: break - + del s # print some info nstamps = len(timestamps) duration = float (total_frames) / float(samplerate) @@ -161,8 +163,8 @@ if __name__ == '__main__': def new_sink_name(source_base_name, timestamp): return source_base_name + '_%02.3f' % (timestamp) + '.wav' # reopen source file - del s 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 -- 2.11.0