Changeset 155cc10 for python/demos/demo_bpm_extract.py
- Timestamp:
- Mar 10, 2017, 2:26:32 PM (7 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/demos/demo_bpm_extract.py
r00d0275 r155cc10 4 4 from numpy import median, diff 5 5 6 def get_file_bpm(path, params = {}):6 def get_file_bpm(path, params = None): 7 7 """ Calculate the beats per minute (bpm) of a given file. 8 8 path: path to the file 9 9 param: dictionary of parameters 10 10 """ 11 if params is None: 12 params = {} 11 13 try: 12 14 win_s = params['win_s'] 13 15 samplerate = params['samplerate'] 14 16 hop_s = params['hop_s'] 15 except :17 except KeyError: 16 18 """ 17 19 # super fast … … 44 46 45 47 # 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)) 48 56 return b 49 57 … … 52 60 for f in sys.argv[1:]: 53 61 bpm = get_file_bpm(f) 54 print "%6s" % ("%.2f" % bpm), f62 print("{:6s} {:s}".format("{:2f}".format(bpm), f))
Note: See TracChangeset
for help on using the changeset viewer.