Class: Wavesync::BpmDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/wavesync/bpm_detector.rb

Constant Summary collapse

CONFIDENCE_THRESHOLD =
2.0

Class Method Summary collapse

Class Method Details

.available?Boolean

: () -> bool?

Returns:

  • (Boolean)


12
13
14
# File 'lib/wavesync/bpm_detector.rb', line 12

def self.available?
  EssentiaBpmDetector.available? || PercivalBpmDetector.available?
end

.detect(file_path) ⇒ Object

: (String file_path) -> Integer?



17
18
19
20
21
22
23
24
# File 'lib/wavesync/bpm_detector.rb', line 17

def self.detect(file_path)
  if EssentiaBpmDetector.available?
    essentia_result = EssentiaBpmDetector.detect(file_path)
    return essentia_result[:bpm] if essentia_result && essentia_result[:confidence] > CONFIDENCE_THRESHOLD
  end

  PercivalBpmDetector.detect(file_path) if PercivalBpmDetector.available?
end