sclass BPMExtractor1 { double minBPM = 60, maxBPM = 200; // 0 if not found double getBPM(L ranges) { int[] gaps = intRangeStartGaps(ranges); if (empty(gaps)) ret 0; sort(gaps); MultiSet ms = intArrayAsTreeMultiSet(gaps); new Best 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; } }