Module: Ramekin::Volume

Extended by:
Volume
Included in:
Volume
Defined in:
lib/ramekin/volume.rb

Constant Summary collapse

BASE =
Math.log(2) / 6
INF =
1.0/0

Instance Method Summary collapse

Instance Method Details

#db_to_volume(db) ⇒ Object



12
13
14
# File 'lib/ramekin/volume.rb', line 12

def db_to_volume(db)
  (256.0 * Math.exp(BASE * db) - 1).clamp(0..)
end

#volume_to_db(vol) ⇒ Object



7
8
9
10
# File 'lib/ramekin/volume.rb', line 7

def volume_to_db(vol)
  return -INF if vol == 0
  Math.log((vol+1) / 256.0) / BASE
end