Showing the changes to python/scripts/aubiocut (1 of 1 file). Show all
Unified · Split
| @@ -8,7 +8,7 @@ import sys · 7 unmodified lines | |||
| 8 | #from aubio.task import * | 8 | #from aubio.task import * |
| 9 | 9 | ||
| 10 | usage = "usage: %s [options] -i soundfile" % sys.argv[0] | 10 | usage = "usage: %s [options] -i soundfile" % sys.argv[0] |
| 11 | usage += "\nhelp: %s -h" % sys.argv[0] | 11 | usage += "\n help: %s -h" % sys.argv[0] |
| 12 | 12 | ||
| 13 | def parse_args(): | 13 | def parse_args(): |
| 14 | from optparse import OptionParser | 14 | from optparse import OptionParser |
| @@ -21,10 +21,10 @@ def parse_args(): · 6 unmodified lines | |||
| 21 | help="onset detection method [default=default] \ | 21 | help="onset detection method [default=default] \ |
| 22 | complexdomain|hfc|phase|specdiff|energy|kl|mkl") | 22 | complexdomain|hfc|phase|specdiff|energy|kl|mkl") |
| 23 | # cutting methods | 23 | # cutting methods |
| 24 | """ | ||
| 25 | parser.add_option("-b","--beat", | 24 | parser.add_option("-b","--beat", |
| 26 | action="store_true", dest="beat", default=False, | 25 | action="store_true", dest="beat", default=False, |
| 27 | help="use beat locations") | 26 | help="use beat locations") |
| 27 | """ | ||
| 28 | parser.add_option("-S","--silencecut", | 28 | parser.add_option("-S","--silencecut", |
| 29 | action="store_true", dest="silencecut", default=False, | 29 | action="store_true", dest="silencecut", default=False, |
| 30 | help="use silence locations") | 30 | help="use silence locations") |
| @@ -40,10 +40,10 @@ def parse_args(): · 9 unmodified lines | |||
| 40 | help="samplerate at which the file should be represented") | 40 | help="samplerate at which the file should be represented") |
| 41 | parser.add_option("-B","--bufsize", | 41 | parser.add_option("-B","--bufsize", |
| 42 | action="store", dest="bufsize", default=512, | 42 | action="store", dest="bufsize", default=512, |
| 43 | metavar = "<size>", | 43 | metavar = "<size>", type='int', |
| 44 | help="buffer size [default=512]") | 44 | help="buffer size [default=512]") |
| 45 | parser.add_option("-H","--hopsize", | 45 | parser.add_option("-H","--hopsize", |
| 46 | metavar = "<size>", | 46 | metavar = "<size>", type='int', |
| 47 | action="store", dest="hopsize", default=256, | 47 | action="store", dest="hopsize", default=256, |
| 48 | help="overlap size [default=256]") | 48 | help="overlap size [default=256]") |
| 49 | parser.add_option("-t","--threshold", | 49 | parser.add_option("-t","--threshold", |
| @@ -126,12 +126,15 @@ if __name__ == '__main__': · 76 unmodified lines | |||
| 126 | samplerate = options.samplerate | 126 | samplerate = options.samplerate |
| 127 | source_file = options.source_file | 127 | source_file = options.source_file |
| 128 | 128 | ||
| 129 | from aubio import onset, source, sink | 129 | from aubio import onset, tempo, source, sink |
| 130 | 130 | ||
| 131 | s = source(source_file, samplerate, hopsize) | 131 | s = source(source_file, samplerate, hopsize) |
| 132 | if samplerate == 0: samplerate = s.get_samplerate() | 132 | if samplerate == 0: samplerate = s.get_samplerate() |
| 133 | 133 | ||
| 134 | o = onset(options.onset_method, bufsize, hopsize) | 134 | if options.beat: |
| 135 | o = tempo(options.onset_method, bufsize, hopsize) | ||
| 136 | else: | ||
| 137 | o = onset(options.onset_method, bufsize, hopsize) | ||
| 135 | o.set_threshold(options.threshold) | 138 | o.set_threshold(options.threshold) |
| 136 | 139 | ||
| 137 | timestamps = [] | 140 | timestamps = [] |
| @@ -140,12 +143,11 @@ if __name__ == '__main__': · 2 unmodified lines | |||
| 140 | while True: | 143 | while True: |
| 141 | samples, read = s() | 144 | samples, read = s() |
| 142 | if o(samples): | 145 | if o(samples): |
| 143 | this_onset = o.get_last_onset() | 146 | timestamps.append (o.get_last()) |
| 144 | if options.verbose: print "%.4f" % o.get_last_onset_s() | 147 | if options.verbose: print "%.4f" % o.get_last_s() |
| 145 | timestamps.append (this_onset) | ||
| 146 | total_frames += read | 148 | total_frames += read |
| 147 | if read < hopsize: break | 149 | if read < hopsize: break |
| 148 | 150 | del s | |
| 149 | # print some info | 151 | # print some info |
| 150 | nstamps = len(timestamps) | 152 | nstamps = len(timestamps) |
| 151 | duration = float (total_frames) / float(samplerate) | 153 | duration = float (total_frames) / float(samplerate) |
| @@ -161,8 +163,8 @@ if __name__ == '__main__': · 9 unmodified lines | |||
| 161 | def new_sink_name(source_base_name, timestamp): | 163 | def new_sink_name(source_base_name, timestamp): |
| 162 | return source_base_name + '_%02.3f' % (timestamp) + '.wav' | 164 | return source_base_name + '_%02.3f' % (timestamp) + '.wav' |
| 163 | # reopen source file | 165 | # reopen source file |
| 164 | del s | ||
| 165 | s = source(source_file, samplerate, hopsize) | 166 | s = source(source_file, samplerate, hopsize) |
| 167 | if samplerate == 0: samplerate = s.get_samplerate() | ||
| 166 | # create first sink at 0 | 168 | # create first sink at 0 |
| 167 | g = sink(new_sink_name(source_base_name, 0.), samplerate) | 169 | g = sink(new_sink_name(source_base_name, 0.), samplerate) |
| 168 | total_frames = 0 | 170 | total_frames = 0 |