History

python/scripts/aubiocut: add -b option

Paul Brossier committed 13 years ago

Commit 7fc5ba21 parent 70798871 file · +13 −11Browse files

Showing the changes to python/scripts (1 of 1 file). Show all

Unified · Split

python/scripts/aubiocut+13−11
@@ -8,7 +8,7 @@ import sys · 7 unmodified lines
88 #from aubio.task import *
99
1010 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]
1212
1313 def parse_args():
1414 from optparse import OptionParser
@@ -21,10 +21,10 @@ def parse_args(): · 6 unmodified lines
2121 help="onset detection method [default=default] \
2222 complexdomain|hfc|phase|specdiff|energy|kl|mkl")
2323 # cutting methods
24− """
2524 parser.add_option("-b","--beat",
2625 action="store_true", dest="beat", default=False,
2726 help="use beat locations")
27+ """
2828 parser.add_option("-S","--silencecut",
2929 action="store_true", dest="silencecut", default=False,
3030 help="use silence locations")
@@ -40,10 +40,10 @@ def parse_args(): · 9 unmodified lines
4040 help="samplerate at which the file should be represented")
4141 parser.add_option("-B","--bufsize",
4242 action="store", dest="bufsize", default=512,
43− metavar = "<size>",
43+ metavar = "<size>", type='int',
4444 help="buffer size [default=512]")
4545 parser.add_option("-H","--hopsize",
46− metavar = "<size>",
46+ metavar = "<size>", type='int',
4747 action="store", dest="hopsize", default=256,
4848 help="overlap size [default=256]")
4949 parser.add_option("-t","--threshold",
@@ -126,12 +126,15 @@ if __name__ == '__main__': · 76 unmodified lines
126126 samplerate = options.samplerate
127127 source_file = options.source_file
128128
129− from aubio import onset, source, sink
129+ from aubio import onset, tempo, source, sink
130130
131131 s = source(source_file, samplerate, hopsize)
132132 if samplerate == 0: samplerate = s.get_samplerate()
133133
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)
135138 o.set_threshold(options.threshold)
136139
137140 timestamps = []
@@ -140,12 +143,11 @@ if __name__ == '__main__': · 2 unmodified lines
140143 while True:
141144 samples, read = s()
142145 if o(samples):
143− this_onset = o.get_last_onset()
144− if options.verbose: print "%.4f" % o.get_last_onset_s()
145− timestamps.append (this_onset)
146+ timestamps.append (o.get_last())
147+ if options.verbose: print "%.4f" % o.get_last_s()
146148 total_frames += read
147149 if read < hopsize: break
148−
150+ del s
149151 # print some info
150152 nstamps = len(timestamps)
151153 duration = float (total_frames) / float(samplerate)
@@ -161,8 +163,8 @@ if __name__ == '__main__': · 9 unmodified lines
161163 def new_sink_name(source_base_name, timestamp):
162164 return source_base_name + '_%02.3f' % (timestamp) + '.wav'
163165 # reopen source file
164− del s
165166 s = source(source_file, samplerate, hopsize)
167+ if samplerate == 0: samplerate = s.get_samplerate()
166168 # create first sink at 0
167169 g = sink(new_sink_name(source_base_name, 0.), samplerate)
168170 total_frames = 0

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t