Class: AudioStream::Decibel
- Inherits:
-
Object
- Object
- AudioStream::Decibel
- Defined in:
- lib/audio_stream/decibel.rb
Class Method Summary collapse
Instance Method Summary collapse
- #db ⇒ Object
-
#initialize(db: nil, mag: nil) ⇒ Decibel
constructor
A new instance of Decibel.
- #mag ⇒ Object
Constructor Details
#initialize(db: nil, mag: nil) ⇒ Decibel
Returns a new instance of Decibel.
3 4 5 6 |
# File 'lib/audio_stream/decibel.rb', line 3 def initialize(db: nil, mag: nil) @db = db @mag = mag end |
Class Method Details
.db(db) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/audio_stream/decibel.rb', line 16 def self.db(db) if self===db db else new(db: db.to_f) end end |
.mag(mag) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/audio_stream/decibel.rb', line 24 def self.mag(mag) if self===mag mag else new(mag: mag.to_f) end end |
Instance Method Details
#db ⇒ Object
8 9 10 |
# File 'lib/audio_stream/decibel.rb', line 8 def db @db || 20 * Math.log10(@mag) end |
#mag ⇒ Object
12 13 14 |
# File 'lib/audio_stream/decibel.rb', line 12 def mag @mag || 10 ** (@db / 20.0) end |