Class: AudioStream::Decibel

Inherits:
Object
  • Object
show all
Defined in:
lib/audio_stream/decibel.rb

Class Method Summary collapse

Instance Method Summary collapse

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

.create(val) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/audio_stream/decibel.rb', line 24

def self.create(val)
  if self===val
    val
  else
    new(db: val.to_f)
  end
end

.db(db) ⇒ Object



16
17
18
# File 'lib/audio_stream/decibel.rb', line 16

def self.db(db)
  new(db: db)
end

.mag(mag) ⇒ Object



20
21
22
# File 'lib/audio_stream/decibel.rb', line 20

def self.mag(mag)
  new(mag: mag)
end

Instance Method Details

#dbObject



8
9
10
# File 'lib/audio_stream/decibel.rb', line 8

def db
  @db || 20 * Math.log10(@mag)
end

#magObject



12
13
14
# File 'lib/audio_stream/decibel.rb', line 12

def mag
  @mag || 10 ** (@db / 20.0)
end