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/demos (1 of 1 file). Show all

Unified · Split

python/demos/demo_bpm_extract.py+13−11
@@ -3,7 +3,7 @@ · 2 unmodified lines
3from aubio import source, tempo3from aubio import source, tempo
4from numpy import median, diff4from numpy import median, diff
5 5
6def get_file_bpm(path, params = None):6def get_file_bpm(path, params=None):
7 """ Calculate the beats per minute (bpm) of a given file.7 """ Calculate the beats per minute (bpm) of a given file.
8 path: path to the file8 path: path to the file
9 param: dictionary of parameters9 param: dictionary of parameters
@@ -51,16 +51,18 @@ def get_file_bpm(path, params = None): · 41 unmodified lines
51 if read < hop_s:51 if read < hop_s:
52 break52 break
53 53
54 # Convert to periods and to bpm 54 def beats_to_bpm(beats, path):
55 if len(beats) > 1:55 # if enough beats are found, convert to periods then to bpm
56 if len(beats) < 4:56 if len(beats) > 1:
57 print("few beats found in {:s}".format(path))57 if len(beats) < 4:
58 bpms = 60./diff(beats)58 print("few beats found in {:s}".format(path))
59 b = median(bpms)59 bpms = 60./diff(beats)
60 else:60 return median(bpms)
61 b = 061 else:
62 print("not enough beats found in {:s}".format(path))62 print("not enough beats found in {:s}".format(path))
63 return b63 return 0
64
65 return beats_to_bpm(beats, path)
64 66
65if __name__ == '__main__':67if __name__ == '__main__':
66 import argparse68 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