Howto: Set A Specific Db Value As The Volume

See the reply from vV below (scroll or click here). These functions are built in.

[s]Hi all,

I couldn’t figure out an easy way to set a specific dB value for a volume parameter, so I did some calculations and came up with the following formulas:[/s]

renoise_volume = 10^(db_value * 0.05) and thus  
db_value = log10(renoise_volume) / 0.05  

Here is some example code that incorporate the above:

function set_prefx_volume(db)  
 -- set the prefx volume for the selected track to the specified db value  
 if db < -96 then  
 renoise.song().selected_track.prefx_volume.value = 0  
 return  
 elseif db > 3 then  
 db = 3  
 end  
 renoise.song().selected_track.prefx_volume.value = math.pow(10, (db * 0.05)  
end  
  
  
function get_prefx_volume()  
 -- return the selected track prefx volume parameter as a db value  
 return (math.log10(renoise.song().selected_track.prefx_volume.value) / 0.05)  
end  

[s]Hope this helps someone.

Martin[/s]

Hi martin,
Values from 0 to 1 (or 0 to 4) have to be supplied to these controls.
The Renoise LUA API has two functions which convert these figures to DB and back to figures for you which you can also use:

math.lin2db(value)
math.db2lin(db)

Saves you a lot of code.