Changeset bd72039 for python/lib/aubio


Ignore:
Timestamp:
Mar 23, 2017, 3:19:19 PM (8 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, sampler
Children:
4077fa1
Parents:
5ab3c4e
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/lib/aubio/cmd.py

    r5ab3c4e rbd72039  
    5454    # tempo subcommand
    5555    subparser = subparsers.add_parser('beat',
     56            help='get locations of beats')
     57    parser_add_input(subparser)
     58    parser_add_buf_hop_size(subparser, buf_size=1024, hop_size=512)
     59    parser_add_time_format(subparser)
     60    parser_add_verbose_help(subparser)
     61    subparser.set_defaults(process=process_beat)
     62
     63    # tempo subcommand
     64    subparser = subparsers.add_parser('tempo',
    5665            help='get locations of beats')
    5766    parser_add_input(subparser)
     
    238247        sys.stdout.write(fmt_out + "%.6f\n" % res[0])
    239248
    240 class process_tempo(default_process):
     249class 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)
     
    250259            outstr = self.time2string(self.tempo.get_last(), samplerate)
    251260            sys.stdout.write(outstr + '\n')
     261
     262class 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')
    252274
    253275class process_notes(default_process):
Note: See TracChangeset for help on using the changeset viewer.