View Single Post
Old 02-20-2020, 06:08 PM   #9
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,096
Default

These are the 2 functions I use in Lua (thanks to SPK77):

Code:
------------------------------------------------------------
-- Mod from SPK77
-- http://forum.cockos.com/showpost.php?p=1608719&postcount=6
--Trak_Vol_dB = 20*math.log(val, 10) end
--Trak Vol val = 10^(dB_val/20) end
------------------------------------------------------------


-------------------------------------------------------------
-- item Vol conversion    https://forum.cockos.com/showthread.php?p=2200278#post2200278



-----------------------------------------------------------
local LN10_OVER_TWENTY = 0.11512925464970228420089957273422
function DB2VAL(x) return math.exp(x*LN10_OVER_TWENTY) end

function VAL2DB(x)
  if x < 0.0000000298023223876953125 then
    return -150
  else
    return math.max(-150, math.log(x)* 8.6858896380650365530225783783321); 
  end
end
__________________
Cheers,
Andrew K
v6.03+dev0114 - January 14 2020 Mac 10.12.+ i7 Quad 2.9GHz 24GB
Thonex is offline   Reply With Quote