1 | sclass BPMExtractor1 { |
2 | double minBPM = 60, maxBPM = 200; |
3 | |
4 | // 0 if not found |
5 | double getBPM(L<IntRange> ranges) { |
6 | int[] gaps = intRangeStartGaps(ranges); |
7 | if (empty(gaps)) ret 0; |
8 | sort(gaps); |
9 | MultiSet<Int> ms = intArrayAsTreeMultiSet(gaps); |
10 | new Best<Int> best; |
11 | for (int gap : keys(ms)) |
12 | if (isBetween_double( |
13 | audio_frequencyImage_pixelsToBPM(gap), |
14 | minBPM, maxBPM)) |
15 | best.put(gap, ms.get(gap-1)+ms.get(gap)+ms.get(gap+1)); |
16 | Int gap = best!; |
17 | if (gap == null) { print("no fitting gaps"); ret 0; } |
18 | print(ms); |
19 | |
20 | double exactGap = weightedAverage_lit( |
21 | gap-1, ms.get(gap-1), |
22 | gap, ms.get(gap), |
23 | gap+1, ms.get(gap+1)); |
24 | double bpm = audio_frequencyImage_pixelsToBPM(exactGap); |
25 | |
26 | printVars_str(+gap, +exactGap, +bpm); |
27 | ret bpm; |
28 | } |
29 | } |
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1025113 |
Snippet name: | BPMExtractor1 |
Eternal ID of this version: | #1025113/7 |
Text MD5: | fd5ba7ea87081cbe09ab37c724a6fd76 |
Author: | stefan |
Category: | javax / audio analysis |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-09-05 19:24:05 |
Source code size: | 855 bytes / 29 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 194 / 527 |
Version history: | 6 change(s) |
Referenced in: | [show references] |