Class: PulseAnalysis::Analysis
- Inherits:
-
Object
- Object
- PulseAnalysis::Analysis
- Defined in:
- lib/pulse-analysis/analysis.rb
Constant Summary collapse
- MINIMUM_PULSES =
10- MAX_BPM =
280
Instance Attribute Summary collapse
-
#abberations ⇒ Array<Integer>
readonly
Non-zero pulse timing abberations derived from the periods.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#periods ⇒ Object
readonly
Returns the value of attribute periods.
-
#sound ⇒ Object
readonly
Returns the value of attribute sound.
Instance Method Summary collapse
-
#amplitude_threshold ⇒ Float
The threshold (0..1) at which pulses will register as high.
-
#average_abberation ⇒ Float
Average sequential abberation between pulses.
-
#average_period ⇒ Float
Average number of samples between pulses.
-
#initialize(sound, options = {}) ⇒ Analysis
constructor
A new instance of Analysis.
-
#largest_abberation ⇒ Integer
Largest sequential abberation between pulses.
-
#longest_period ⇒ Integer
Longest number of samples between pulse.
-
#num_pulses ⇒ Integer
Number of usable pulses in the audio file.
-
#run ⇒ Boolean
Run the analysis.
-
#shortest_period ⇒ Integer
Shortest number of samples between pulse.
-
#tempo_bpm ⇒ Float
Tempo of the audio file in beats per minute (BPM) Assumes that the pulse is 16th notes as per the Innerclock Litmus Test.
-
#valid? ⇒ Boolean
Validate that the analysis has produced meaningful results.
-
#validate ⇒ Boolean
Validate that analysis on the given data can produce meaningful results.
Constructor Details
#initialize(sound, options = {}) ⇒ Analysis
Returns a new instance of Analysis.
14 15 16 17 18 19 |
# File 'lib/pulse-analysis/analysis.rb', line 14 def initialize(sound, = {}) @amplitude_threshold = [:amplitude_threshold] @length_threshold = [:length_threshold] populate_sound(sound) @data = AudioData.new(@sound) end |
Instance Attribute Details
#abberations ⇒ Array<Integer> (readonly)
Non-zero pulse timing abberations derived from the periods
76 77 78 |
# File 'lib/pulse-analysis/analysis.rb', line 76 def abberations @abberations end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/pulse-analysis/analysis.rb', line 8 def data @data end |
#periods ⇒ Object (readonly)
Returns the value of attribute periods.
8 9 10 |
# File 'lib/pulse-analysis/analysis.rb', line 8 def periods @periods end |
#sound ⇒ Object (readonly)
Returns the value of attribute sound.
8 9 10 |
# File 'lib/pulse-analysis/analysis.rb', line 8 def sound @sound end |
Instance Method Details
#amplitude_threshold ⇒ Float
The threshold (0..1) at which pulses will register as high
82 83 84 |
# File 'lib/pulse-analysis/analysis.rb', line 82 def amplitude_threshold @amplitude_threshold ||= calculate_amplitude_threshold end |
#average_abberation ⇒ Float
Average sequential abberation between pulses
70 71 72 |
# File 'lib/pulse-analysis/analysis.rb', line 70 def average_abberation @average_abberation ||= calculate_average_abberation end |
#average_period ⇒ Float
Average number of samples between pulses
32 33 34 |
# File 'lib/pulse-analysis/analysis.rb', line 32 def average_period @average_period ||= @periods.inject(&:+).to_f / num_pulses end |
#largest_abberation ⇒ Integer
Largest sequential abberation between pulses
64 65 66 |
# File 'lib/pulse-analysis/analysis.rb', line 64 def largest_abberation @largest_abberation ||= abberations.max || 0 end |
#longest_period ⇒ Integer
Longest number of samples between pulse
44 45 46 |
# File 'lib/pulse-analysis/analysis.rb', line 44 def longest_period @longest_period ||= @periods.max end |
#num_pulses ⇒ Integer
Number of usable pulses in the audio file
38 39 40 |
# File 'lib/pulse-analysis/analysis.rb', line 38 def num_pulses @num_pulses ||= @periods.count end |
#run ⇒ Boolean
Run the analysis
23 24 25 26 27 28 |
# File 'lib/pulse-analysis/analysis.rb', line 23 def run prepare populate_periods validate true end |
#shortest_period ⇒ Integer
Shortest number of samples between pulse
50 51 52 |
# File 'lib/pulse-analysis/analysis.rb', line 50 def shortest_period @shortest_period ||= @periods.min end |
#tempo_bpm ⇒ Float
Tempo of the audio file in beats per minute (BPM) Assumes that the pulse is 16th notes as per the Innerclock Litmus Test
58 59 60 |
# File 'lib/pulse-analysis/analysis.rb', line 58 def tempo_bpm @tempo_bpm ||= calculate_tempo_bpm end |
#valid? ⇒ Boolean
Validate that the analysis has produced meaningful results
100 101 102 |
# File 'lib/pulse-analysis/analysis.rb', line 100 def valid? @periods.count > MINIMUM_PULSES end |
#validate ⇒ Boolean
Validate that analysis on the given data can produce meaningful results
89 90 91 92 93 94 95 96 |
# File 'lib/pulse-analysis/analysis.rb', line 89 def validate if valid? true else = "Could not produce a valid analysis." raise() end end |