Changeset 4d1bf0e


Ignore:
Timestamp:
Sep 14, 2017, 2:01:00 PM (2 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master
Children:
c4fc0f2
Parents:
5db398e
Message:

python/demos/demo_bpm_extract.py: add beats_to_bpm

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/demos/demo_bpm_extract.py

    r5db398e r4d1bf0e  
    44from numpy import median, diff
    55
    6 def get_file_bpm(path, params = None):
     6def get_file_bpm(path, params=None):
    77    """ Calculate the beats per minute (bpm) of a given file.
    88        path: path to the file
     
    5252            break
    5353
    54     # Convert to periods and to bpm
    55     if len(beats) > 1:
    56         if len(beats) < 4:
    57             print("few beats found in {:s}".format(path))
    58         bpms = 60./diff(beats)
    59         b = median(bpms)
    60     else:
    61         b = 0
    62         print("not enough beats found in {:s}".format(path))
    63     return b
     54    def beats_to_bpm(beats, path):
     55        # if enough beats are found, convert to periods then to bpm
     56        if len(beats) > 1:
     57            if len(beats) < 4:
     58                print("few beats found in {:s}".format(path))
     59            bpms = 60./diff(beats)
     60            return median(bpms)
     61        else:
     62            print("not enough beats found in {:s}".format(path))
     63            return 0
     64
     65    return beats_to_bpm(beats, path)
    6466
    6567if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.