Changeset bd72039
- Timestamp:
- Mar 23, 2017, 3:19:19 PM (8 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/lib/aubio/cmd.py
r5ab3c4e rbd72039 54 54 # tempo subcommand 55 55 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', 56 65 help='get locations of beats') 57 66 parser_add_input(subparser) … … 238 247 sys.stdout.write(fmt_out + "%.6f\n" % res[0]) 239 248 240 class process_ tempo(default_process):249 class process_beat(default_process): 241 250 valid_opts = ['method', 'hop_size', 'buf_size', 'samplerate'] 242 251 def __init__(self, args): 243 252 self.options = parse_options(args, self.valid_opts) 244 253 self.tempo = aubio.tempo(**self.options) 245 super(process_ tempo, self).__init__(args)254 super(process_beat, self).__init__(args) 246 255 def __call__(self, block): 247 256 return self.tempo(block) … … 250 259 outstr = self.time2string(self.tempo.get_last(), samplerate) 251 260 sys.stdout.write(outstr + '\n') 261 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') 252 274 253 275 class process_notes(default_process):
Note: See TracChangeset
for help on using the changeset viewer.