Class: PulseAnalysis::Analysis
- Inherits:
-
Object
- Object
- PulseAnalysis::Analysis
- Defined in:
- lib/pulse-analysis/analysis.rb
Constant Summary collapse
- MINIMUM_PULSES =
10
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.
13 14 15 16 17 18 |
# File 'lib/pulse-analysis/analysis.rb', line 13 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
75 76 77 |
# File 'lib/pulse-analysis/analysis.rb', line 75 def abberations @abberations end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/pulse-analysis/analysis.rb', line 7 def data @data end |
#periods ⇒ Object (readonly)
Returns the value of attribute periods.
7 8 9 |
# File 'lib/pulse-analysis/analysis.rb', line 7 def periods @periods end |
#sound ⇒ Object (readonly)
Returns the value of attribute sound.
7 8 9 |
# File 'lib/pulse-analysis/analysis.rb', line 7 def sound @sound end |
Instance Method Details
#amplitude_threshold ⇒ Float
The threshold (0..1) at which pulses will register as high
81 82 83 |
# File 'lib/pulse-analysis/analysis.rb', line 81 def amplitude_threshold @amplitude_threshold ||= calculate_amplitude_threshold end |
#average_abberation ⇒ Float
Average sequential abberation between pulses
69 70 71 |
# File 'lib/pulse-analysis/analysis.rb', line 69 def average_abberation @average_abberation ||= calculate_average_abberation end |
#average_period ⇒ Float
Average number of samples between pulses
31 32 33 |
# File 'lib/pulse-analysis/analysis.rb', line 31 def average_period @average_period ||= @periods.inject(&:+).to_f / num_pulses end |
#largest_abberation ⇒ Integer
Largest sequential abberation between pulses
63 64 65 |
# File 'lib/pulse-analysis/analysis.rb', line 63 def largest_abberation @largest_abberation ||= abberations.max || 0 end |
#longest_period ⇒ Integer
Longest number of samples between pulse
43 44 45 |
# File 'lib/pulse-analysis/analysis.rb', line 43 def longest_period @longest_period ||= @periods.max end |
#num_pulses ⇒ Integer
Number of usable pulses in the audio file
37 38 39 |
# File 'lib/pulse-analysis/analysis.rb', line 37 def num_pulses @num_pulses ||= @periods.count end |
#run ⇒ Boolean
Run the analysis
22 23 24 25 26 27 |
# File 'lib/pulse-analysis/analysis.rb', line 22 def run prepare populate_periods validate true end |
#shortest_period ⇒ Integer
Shortest number of samples between pulse
49 50 51 |
# File 'lib/pulse-analysis/analysis.rb', line 49 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
57 58 59 |
# File 'lib/pulse-analysis/analysis.rb', line 57 def tempo_bpm @tempo_bpm ||= calculate_tempo_bpm end |
#valid? ⇒ Boolean
Validate that the analysis has produced meaningful results
99 100 101 |
# File 'lib/pulse-analysis/analysis.rb', line 99 def valid? @periods.count > MINIMUM_PULSES end |
#validate ⇒ Boolean
Validate that analysis on the given data can produce meaningful results
88 89 90 91 92 93 94 95 |
# File 'lib/pulse-analysis/analysis.rb', line 88 def validate if valid? true else = "Could not produce a valid analysis." raise() end end |