History

python/lib/aubio/cmd.py: add tempo subcommand to extract overall bpm

Paul Brossier committed 9 years ago

Commit bd720391 parent 5ab3c4e1 file · +24 −2Browse files

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

Unified · Split

python/lib/aubio/cmd.py+24−2
@@ -58,6 +58,15 @@ def aubio_parser(): · 57 unmodified lines
5858 parser_add_buf_hop_size(subparser, buf_size=1024, hop_size=512)
5959 parser_add_time_format(subparser)
6060 parser_add_verbose_help(subparser)
61+ subparser.set_defaults(process=process_beat)
62+
63+ # tempo subcommand
64+ subparser = subparsers.add_parser('tempo',
65+ help='get locations of beats')
66+ parser_add_input(subparser)
67+ parser_add_buf_hop_size(subparser, buf_size=1024, hop_size=512)
68+ parser_add_time_format(subparser)
69+ parser_add_verbose_help(subparser)
6170 subparser.set_defaults(process=process_tempo)
6271
6372 # notes subcommand
@@ -237,12 +246,12 @@ class process_pitch(default_process): · 173 unmodified lines
237246 fmt_out = self.time2string(frames_read, samplerate)
238247 sys.stdout.write(fmt_out + "%.6f\n" % res[0])
239248
240−class process_tempo(default_process):
249+class process_beat(default_process):
241250 valid_opts = ['method', 'hop_size', 'buf_size', 'samplerate']
242251 def __init__(self, args):
243252 self.options = parse_options(args, self.valid_opts)
244253 self.tempo = aubio.tempo(**self.options)
245− super(process_tempo, self).__init__(args)
254+ super(process_beat, self).__init__(args)
246255 def __call__(self, block):
247256 return self.tempo(block)
248257 def repr_res(self, res, frames_read, samplerate):
@@ -250,6 +259,19 @@ class process_tempo(default_process): · 1 unmodified line
250259 outstr = self.time2string(self.tempo.get_last(), samplerate)
251260 sys.stdout.write(outstr + '\n')
252261
262+class process_tempo(process_beat):
263+ def __init__(self, args):
264+ super(process_tempo, self).__init__(args)
265+ self.beat_locations = []
266+ def repr_res(self, res, frames_read, samplerate):
267+ if res[0] != 0:
268+ self.beat_locations.append(self.tempo.get_last_s())
269+ def flush(self, frames_read, samplerate):
270+ import numpy as np
271+ bpms = 60./ np.diff(self.beat_locations)
272+ median_bpm = np.mean(bpms)
273+ sys.stdout.write('%.2f bpm' % median_bpm + '\n')
274+
253275 class process_notes(default_process):
254276 valid_opts = ['method', 'hop_size', 'buf_size', 'samplerate']
255277 def __init__(self, args):

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