History

python/demos/demo_bpm_extract.py: add beats_to_bpm

Paul Brossier committed 9 years ago

Commit 4d1bf0e1 parent 5db398e1 file · +13 −11Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/demos/demo_bpm_extract.py+13−11
@@ -3,7 +3,7 @@ · 2 unmodified lines
33 from aubio import source, tempo
44 from numpy import median, diff
55
6−def get_file_bpm(path, params = None):
6+def 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
@@ -51,16 +51,18 @@ def get_file_bpm(path, params = None): · 41 unmodified lines
5151 if read < hop_s:
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
6567 if __name__ == '__main__':
6668 import argparse

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t