Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

29
LINES

< > BotCompany Repo | #1025113 // BPMExtractor1

JavaX fragment (include)

sclass BPMExtractor1 {
  double minBPM = 60, maxBPM = 200;
  
  // 0 if not found
  double getBPM(L<IntRange> ranges) {
    int[] gaps = intRangeStartGaps(ranges);
    if (empty(gaps)) ret 0;
    sort(gaps);
    MultiSet<Int> ms = intArrayAsTreeMultiSet(gaps);
    new Best<Int> best;
    for (int gap : keys(ms))
      if (isBetween_double(
        audio_frequencyImage_pixelsToBPM(gap),
        minBPM, maxBPM))
        best.put(gap, ms.get(gap-1)+ms.get(gap)+ms.get(gap+1));
    Int gap = best!;
    if (gap == null) { print("no fitting gaps"); ret 0; }
    print(ms);
    
    double exactGap = weightedAverage_lit(
      gap-1, ms.get(gap-1),
      gap, ms.get(gap),
      gap+1, ms.get(gap+1));
    double bpm = audio_frequencyImage_pixelsToBPM(exactGap);
    
    printVars_str(+gap, +exactGap, +bpm);
    ret bpm;
  }
}

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: 195 / 528
Version history: 6 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)