# Decibel to Linear value to make Dry/Wet Slider...

• As you know, dB values are not linear. So we want to decrease one instrument and increase other one; dB values are not relatively linear. I've found this equation to convert dB to linear percentage

dB = 10 log(1 + X )
So if X = 1%
dB = 10 log(1 + 0.01)

I've tried this equation on 2 different simple gain unit for making DRY/WET effect relatively for two different instruments. But something is wrong.
Both of two Simple gain units' gain amounts are not changing (one will be decreased and other will ve increased and they are not supposed to be linear because of the decibel values to keep the level amount same.) - Like Dry/Wet Knob.

Content.makeFrontInterface(600, 200);

const var DRYWETMIXER = Content.getComponent("DRYWETMIXER");
const var WETT = Synth.getEffect("WETT");
const var DRYY = Synth.getEffect("DRYY");
var tfd;
var neetfd;
var posvalue;

inline function onDRYWETMIXERControl(component, value)
{
posvalue = value;
tfd = 100-Math.pow(10, 0.1*posvalue);
neetfd = 10*Math.log(tfd);

WETT.setAttribute(WETT.Gain, -tfd);
DRYY.setAttribute(DRYY.Gain, neetfd);
};

DRYWETMIXER.setControlCallback(onDRYWETMIXERControl);

This is the HISEsnippet

1. Use Engine.getDecibelsForGainFactor() and its brother Engine.getGainFactorForDecibels() for the conversion between db values and 0...1. No need to reinvent the wheel here and get dirty with log and pow
2. Use the Slider mode LinearPercentage, which shows a percentage value, but uses a value from 0...1 internally.
3. This is not crucial for the functionality, but use local variables whenever you can. tfd neetfd and posValue have no usability outside of the control callback so their lifetime / visibility should be limited to this scope. For more information, google Encapsulation, which is the paradigm behind that advice.

This is the recommended way to make a Dry Wet knob:

inline function onKnob1Control(component, value)
{
local wValue = Engine.getDecibelsForGainFactor(value);
Wet.setAttribute(Wet.Gain, wValue);

local dValue = Engine.getDecibelsForGainFactor(1.0 - value);
Dry.setAttribute(Wet.Gain, dValue);
};

As complete example:

• Hmm I didn't know Engine.getGainFactorForDecibels() is exist.
Yes you are right it's useless to give weird names to variables. I will take this advice....
Great solution bro, thank you so much

• Ah I was wondering why the variable names are so weird. Congratulations, you've just invented Encapsulation by Mystification