Changeset 5db398e


Ignore:
Timestamp:
Sep 14, 2017, 2:00:19 PM (7 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
Children:
4d1bf0e
Parents:
8a3acad
Message:

python/demos/demo_bpm_extract.py: add argparse

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/demos/demo_bpm_extract.py

    r8a3acad r5db398e  
    1111    if params is None:
    1212        params = {}
    13     try:
    14         win_s = params['win_s']
    15         samplerate = params['samplerate']
    16         hop_s = params['hop_s']
    17     except KeyError:
    18         """
    19         # super fast
    20         samplerate, win_s, hop_s = 4000, 128, 64
    21         # fast
    22         samplerate, win_s, hop_s = 8000, 512, 128
    23         """
    24         # default:
    25         samplerate, win_s, hop_s = 44100, 1024, 512
     13    # default:
     14    samplerate, win_s, hop_s = 44100, 1024, 512
     15    if 'mode' in params:
     16        if params.mode in ['super-fast']:
     17            # super fast
     18            samplerate, win_s, hop_s = 4000, 128, 64
     19        elif params.mode in ['fast']:
     20            # fast
     21            samplerate, win_s, hop_s = 8000, 512, 128
     22        elif params.mode in ['default']:
     23            pass
     24        else:
     25            print("unknown mode {:s}".format(params.mode))
     26    # manual settings
     27    if 'samplerate' in params:
     28        samplerate = params.samplerate
     29    if 'win_s' in params:
     30        win_s = params.win_s
     31    if 'hop_s' in params:
     32        hop_s = params.hop_s
    2633
    2734    s = source(path, samplerate, hop_s)
     
    5764
    5865if __name__ == '__main__':
    59     import sys
    60     for f in sys.argv[1:]:
    61         bpm = get_file_bpm(f)
     66    import argparse
     67    parser = argparse.ArgumentParser()
     68    parser.add_argument('-m', '--mode',
     69            help="mode [default|fast|super-fast]",
     70            dest="mode")
     71    parser.add_argument('sources',
     72            nargs='*',
     73            help="input_files")
     74    args = parser.parse_args()
     75    for f in args.sources:
     76        bpm = get_file_bpm(f, params = args)
    6277        print("{:6s} {:s}".format("{:2f}".format(bpm), f))
Note: See TracChangeset for help on using the changeset viewer.