DB to gain~ to DB


    Mar 26 2011 | 2:10 am
    I am using the Gain Object to set level I want to be able to set the value in DB Then when I get the value from the outlet in the range 0 to 157 i'd like to have the exact number I punch in
    to make it simple I am searching to build these 2 subpatchs
    I look àt several docs but I can't find the exact formulas I sure I am not the first one to try this I am even surprised it is not part of the object

    • Mar 26 2011 | 7:33 am
      [expr (pow(10.,$f1*0.05))*($f1!=-90.)] [* 127]
    • Mar 26 2011 | 2:41 pm
      Sorry this is unclear could you complete the patch ? thanks Maa
    • Mar 26 2011 | 2:46 pm
      [flonum] -90. - 0. (db/A) | [expr (pow(10.,$f1*0.05))*($f1!=-90.)] (transform dB/A to 0.-1.) | [* 127] | gainslider
    • Mar 26 2011 | 4:44 pm
      The object gain~ / DB have this correspondence 158 = 17.4 dB 128 = 0 dB 1 = -75.6 dB and I don't see the relation with your expression
    • Mar 26 2011 | 4:48 pm
      maybe you could try [live.gain~]
    • Mar 26 2011 | 5:26 pm
      You have to work it out yourself, but in the patch below there might be some useful hints. All that is required is simple math and db to amplitude conversion. Hope it helps.
    • Mar 26 2011 | 5:55 pm
      oh well, when it is 1-128 it is
      [expr (pow(10.,$f1*0.05))*($f1!=-90.)] | [* 127] | [+ 1]
      i thought it is 0-127 :)
    • Mar 26 2011 | 6:16 pm
      very usefull, I can compare to exact values The live.gain do the job even simplier and better( I put it also in the patch to compare ) any differences oddities advantages with the live object en general ? or they are just msp objects ?
    • Mar 26 2011 | 6:27 pm
      Well, live.gain~ is stereo which is nice most of the time for me at least. And it has built in meters with clipping and stuff. Maybe too much for some things.
      You could try looking into combinations of slider, scale and *~ also maybe.
    • Oct 28 2012 | 4:03 am
      Hello,
      Yes I know this thread is a year old, but I was trying to do the same thing and did not find anything else in the forum that seemed clear to me.
      The formula I came up with for dB for gain~ from the slider value is:
      dB gain of the slider = 20*log(2^(( x-128)/10)) "dB"
      Where x is the gain~ slider value and the settings are the default.
      Default settings: 158 steps or 0 to 157 on the slider 128 is 0dB (no gain or loss) 10 slider value steps = 6 dB (probably 6.02) 157 is roughly +18dB 1 is roughly -76 dB 0 is off. It should say -infinity, but the meter reads -120 dB. (effectively the same thing)
      I would love to know more about these values. base value (7.94231) increment (1.071519
      Zero is a separate case - I imagine there is a more elegant way to handle it than what I did in the patch. I am relatively new to Max, but an old hand at audio.
      Generating the slider value should be the reverse of this process. Feel free to do that or I'll pursue that another time.
      If you decide to look at the patch, the left side is individual steps and the right is my attempt to pack it into one expr. The results at the very end of the scale are different. Miniscule, but may highlight differences in algorithms.
      There is a cycle~ connected to the meter so that you can compare the meter out with the calculation. How that value correlates with real VU ballistics or an RMS value is anyone's guess. It does seem to show the calc to be pretty close for a sine wave.
      Please feel free to comment and let me know if I just calculated something that's already an object. LOL
      -RB
    • Oct 28 2012 | 12:36 pm
      see the very first hit. ^^
    • Oct 28 2012 | 6:18 pm
      so, i refused to give that answer to the other guy one year ago, but i will do it now for you:
      it is misleading and makes it only extra complicated to look at the gainslider MSP object in order to find out how it is calculated. for a valid formula for "dB/A to linear" i am posting my solution for the 4th time now:
      -90. – 0. | [expr (pow(10.,$f1*0.05))*($f1!=-90.)] | 0. – 1.
      where the input and the output range will also work with this formula when you exceed +0. db/A:
      +6. | [expr (pow(10.,$f1*0.05))*($f1!=-90.)] | 2.
      the "158" of the gainslider GUI object is set by will, it is only releated to the slider resolution and has nothing to do with gaining up a digital audio signal. you shouldn´t deal at all with "step value" and these things. ignore this object and build your own.
      dB/A (float) – [expr (pow(10.,$f1*0.05))*($f1!=-90.)] – [*~ 0.] is all you need.
      for displaying the result with a GUI object you might need to scale the "linear" value. the "live" objects might be an alternative for the GUI, multislider is another one.
      i find my vesion of "dealing with the 0" the most elegant possible, just to answer that question, too. :) or did you mean the "0" of the dB/A result? that should be 100% at "0.0" if you use a correct expression.
      -110
    • Dec 16 2015 | 3:07 pm
      I wrote this little patch today, to connect dB to a gain~ object. Maybe it can be useful for someone. Bye :)