Ignore:
Timestamp:
Mar 10, 2017, 2:26:32 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, sampler
Children:
ee8a57c
Parents:
00d0275 (diff), 67b6618 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into awhitening

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/demos/demo_bpm_extract.py

    r00d0275 r155cc10  
    44from numpy import median, diff
    55
    6 def get_file_bpm(path, params = {}):
     6def get_file_bpm(path, params = None):
    77    """ Calculate the beats per minute (bpm) of a given file.
    88        path: path to the file
    99        param: dictionary of parameters
    1010    """
     11    if params is None:
     12        params = {}
    1113    try:
    1214        win_s = params['win_s']
    1315        samplerate = params['samplerate']
    1416        hop_s = params['hop_s']
    15     except:
     17    except KeyError:
    1618        """
    1719        # super fast
     
    4446
    4547    # Convert to periods and to bpm
    46     bpms = 60./diff(beats)
    47     b = median(bpms)
     48    if len(beats) > 1:
     49        if len(beats) < 4:
     50            print("few beats found in {:s}".format(path))
     51        bpms = 60./diff(beats)
     52        b = median(bpms)
     53    else:
     54        b = 0
     55        print("not enough beats found in {:s}".format(path))
    4856    return b
    4957
     
    5260    for f in sys.argv[1:]:
    5361        bpm = get_file_bpm(f)
    54         print "%6s" % ("%.2f" % bpm), f
     62        print("{:6s} {:s}".format("{:2f}".format(bpm), f))
Note: See TracChangeset for help on using the changeset viewer.