Class: Sox::Stats
- Inherits:
-
Object
- Object
- Sox::Stats
- Defined in:
- lib/sox/stats.rb
Defined Under Namespace
Classes: Cache
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#use_cache ⇒ Object
Returns the value of attribute use_cache.
Instance Method Summary collapse
- #attributes ⇒ Object
- #attributes_with_cache ⇒ Object
- #attributes_without_cache ⇒ Object
-
#initialize(file = nil, options = {}) ⇒ Stats
constructor
A new instance of Stats.
- #peak_level ⇒ Object
- #raw_output ⇒ Object
- #raw_values ⇒ Object
- #rms_level ⇒ Object
- #rms_peak ⇒ Object
- #silent?(minimum_rms_peak = -45)) ⇒ Boolean
Constructor Details
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
4 5 6 |
# File 'lib/sox/stats.rb', line 4 def command @command end |
#use_cache ⇒ Object
Returns the value of attribute use_cache.
5 6 7 |
# File 'lib/sox/stats.rb', line 5 def use_cache @use_cache end |
Instance Method Details
#attributes ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/sox/stats.rb', line 83 def attributes if use_cache and command.inputs.size == 1 attributes_with_cache else attributes_without_cache end end |
#attributes_with_cache ⇒ Object
77 78 79 80 81 |
# File 'lib/sox/stats.rb', line 77 def attributes_with_cache Cache.new(command.inputs.first.filename).fetch do attributes_without_cache end end |
#attributes_without_cache ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/sox/stats.rb', line 58 def attributes_without_cache @attributes ||= begin paires = raw_values.collect do |key, _, value| value = case value when /^-?[0-9.]+$/ value.to_f when "-inf" -Float::INFINITY else value end [key, value] end Hash[paires] end end |
#peak_level ⇒ Object
99 100 101 |
# File 'lib/sox/stats.rb', line 99 def peak_level attributes['Pk lev dB'] end |
#raw_output ⇒ Object
17 18 19 |
# File 'lib/sox/stats.rb', line 17 def raw_output command.run!.run_output end |
#raw_values ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/sox/stats.rb', line 21 def raw_values if raw_output.chomp == "sox WARN stats: no audio" raise "No audio found by sox" else raw_output.scan(/^(\w+( \w+)*) +([\w.-]+)/i) end end |
#rms_level ⇒ Object
91 92 93 |
# File 'lib/sox/stats.rb', line 91 def rms_level attributes['RMS lev dB'] end |
#rms_peak ⇒ Object
95 96 97 |
# File 'lib/sox/stats.rb', line 95 def rms_peak attributes['RMS Pk dB'] end |
#silent?(minimum_rms_peak = -45)) ⇒ Boolean
103 104 105 |
# File 'lib/sox/stats.rb', line 103 def silent?(minimum_rms_peak = -45) rms_peak < minimum_rms_peak end |