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

    HiseSnippet 1080.3oc6X0kaaaDDdojYZkRUPRQO.D4I4.aARG2zBDTTaIYEHzXGCKWG69RvJxURa0xcIHWZE0fbD54nmhB3iROB809T6L7GKpTZCqBzfX.uOXv428amclYG4CCUtrnHUHw39GOOfQL9ByAyk5IclP4RR+tDiGXtOMRyBsRY0dd.MJh4QLLp9BjgQs0HIq+76aSEToKaAKB4DE2k8RtOWufavN+.WH5Q8XGy8Kn816z2UI6nDpX.OUMsIAT2ozwrCnnZULImyYyhHF1lOcqVgScF9K61BWsakudY2eZ71B5zY8ZMDo+4N3eItwggLo9DvbhgoweCKCy873ZU3.MUy.eVssxa9fIpYxzs9DdDenfgDNjA.lRYS5LgK7NLOrEQHFqc3hfX0zf3WYtO2ieI+EAyGlHvZgEECmFUVFRqsDjbtJH0SI7PGbEvyn.7VKEdOxbfaHOPuPBhs6a1WB2yinvMXQXkpKoxuUwriBzPpa4Smx5EBDWZQymYaug0V11q+7F0aTGtGizVmSCs5dzYudui2u+o6cj02Yk6fwLcGkefRBDMebAcdLZ+BqA1GClkjRhFs2nQLWvBj+GnJ3jyJSUjehpnR5QdYeIYrEDApnyohXVB14RAWxrFEKc0bkzRIKfO7.DpDMcyQ+FVIVtdi5uqQcKXk6K.K49DYCaFvww1dy8o..CTyZ5.QL6VNOI2h0yTMEZIZ+jDkEpwMAN4xaTuFd9aEwz6p0g7gwZVyDNXA4FValoaM7nurVIbR0JcWP8dexwtvgDsI6f1gJDCgpvlkEEV+4EBRGnzrWIatd82UuV82W+CkLZTYhxbjfEVlTr8P30XVSYr+PVX9UPldPZ9x0Q26lUG4llaVPQkrujqeU.KidQklSIUZjrjarlKCffp5jJtGjUwMPv8XgDN3jFlEBnjjSPwFmjereWpll6LvuvdEvB0b7HYzkcNzXMsbtlYWVzTsJHQ2r7Rf8MbqeK1R7WgcbN9Qa3iYbO8Dj32AhIL93IZjBZuP7K1w+rK7ousHn8UdY3wkOjIHj+cuGnCnxKVP0K2VDyIyD.WwK0+A6wHi354EepYE5UZWZuxRuAugv8QlGx0tSJGuUJAuvs3+23M6kmFlo88V.10L6c5GgmYpT.Ke1kiRv8CDrWjCk6YhcotpQHrHWb5EcYB5RAtWmlKdYJ2NkLjgQ0q6sbm+iuke8Y.Hvst0jw9klIA1aS.N4h+1Cfen4gzOERHNREq4xwvbCgbry9Aw9Cf4ocY.TkRlHB6jWAesJk1FoQ.MfI8rymNNSnCRajIzIWH4FUpiiZbUk5+wE+UuctqT+tR86J0+DuT+iwd3ScCUuwMcjYrz7yS3.maYxO7ul49HskS9TxXrwG9czuw0EmuYSH5TtEasxV7zU1hsWYK95U1hmsxV7MqrEe60XA9OsX2XsxOMemP9G.w4sNm
    

    alt text


  • administrators

    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:

    HiseSnippet 1082.3oc6X0saZbDEdVfIIPJQIQU45UHUIrjCBxesRUUAavDgbsCJD6zzahFlcVXDyNypYm0NjnH0Gs9nzGg9FzdlcWXgFL0ToFEKYtaN+9sey4bli8.shxhhTZjyse8rPFx4avCmIMS5Lgvkn9cQN2AeDIxvztoh1eVHIJh4gbbJ9Bq.mxkPI+9ymuOQPjTVtHD5TEmx9Yd.2jKMr8gbgnGwi8ZdvRV+j18oJYGkPEC3oHtIJjPmRFyNlXMq.FcFmcdDxoI9wOpgdZqQeXuF+ieGt29cZ36upbDMVqYRyof6HGryeA+bvG3wMJ8PCwvfXVbek2rgSTmKSS8o7H9HAydnEZHfoTwnNS3BuAyosHDxozfbRrXJI9s3i3d7ExyIy6lnvM2ikoSmBqBoRq.oVWDj5oDd1.bAvyYI3UJEd2COjp4glbMVrcabeIbO6SfavkgUpsnB+ZAbGEXgzzHfLk0SCGV3Q8m0r4ttOsYyc9wpUpVAtGiLtmQztc0yb+I2jZpFiYlC78YTS8Zf3ZVSyM7MLy5LDDWKMlUqvkBtj45GKoFtR5pjGJUiZYQkVIpSUAgJIfucg.JhY6TsxGqVorPQIB2yO0JBxvAxwPPronKixGwDQ8TZakbOBEH+5otBYrLj5FQLydFilOJ1vpaEXsb2rnkX0hL3cYyPqFMcenadd.t3hxi2h77oDNX9E.D6Ny+ZqWKgEpsiMHYbQGhPLBZdpuJEYCzRr2wJC6kx56T4iUJW4SelFe+0oJKTBldcZscz5M3VcYbvHld9MTlcPk4pk923xU5SSoikLTI6K4lWFxxNm2bzZMMGnL9z1ljAPvTSRSxcxZRFJ3dLMhCA4l3DxDkf8kmxgNoeWhgLOLPDgrDxzFt8iwoK6LXJXZuWYbWVzTiJLw1rqPn46eMoueQBaeR6Y4Y+UsOm6YlXmq8avwIL93IF6IXZ.JxLyxZ2HIFn.tmmfMPEwsWJ4g3OddTruO+8VZ56P9bQPDTJF1O.l8hbtO9jHlqGymDKLtQSgQYAJOPwCvGqzADA+CLuALME9PrNf97ANvXOkWrfXVcVnsFOSgEOKOzwNXQB3b1xuurECHat1AjqsF3RB26gGvMzIqGuEVCdgpg+uwa1yMUwoSKyAaIbue4KvaKEVBK2bw9C7fPA6EygBFCy21vZCHTWlfrBu8lzB54Bda60rXgSwM89cq+iueu4B.KvcuxTvdebBwdUBvIW7Wc.7cwCHeMTP7JUrgKGeDAlZCCwwGGGLD1glx.nJkv9G1mCJXetK8bS6YKfFxjdMmuQblxV1yNYJaMWI5R0oCKtrgN8296W2oecm90c5ek2o+kHGADpV8NZ5J21VyakHA9tkI+s9kwGYO6tXWaK2.quxeGkZ2t4g.6rdOdzV6wi2ZOdxV6wS2ZOd1V6w2u0d7CavC6+mh8hMpfz5cD5uQz7tGH
    


  • 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 🙂


  • administrators

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


Log in to reply
 

0
Online

277
Users

739
Topics

4.8k
Posts

Looks like your connection to Forum was lost, please wait while we try to reconnect.