logarithmic gain equation for slider

DSP, Plug-in and Host development discussion.
KVRer
4 posts since 6 Mar, 2012

Post Fri May 04, 2012 3:47 pm

I'd really like a nice equation to emulate mixer faders. Something that maps a slider 0-1 to a 0-1 gain that has a appropriate logarithmic curve. Efficiency is irrelevant.

KVRAF
6182 posts since 12 Feb, 2006 from Helsinki, Finland

Post Fri May 04, 2012 4:20 pm

Well, in theory you can simply start with dBgain equation like the following:

gain = 10^(dBgain/20) = exp(log(10) * dbGain/20)

So if the slider position is in decibels (say -80 to +20 or whatever) you'd just plug the decibel gain into to above to calculate gain to apply.

The main problem with using the above directly is that you can't take the gain all the way down to zero. If you want that, you could offset the whole thing down a bit like so:

gain = 10^(dBgain/20) - 10^(dBgainMin/20)

where dBgainMin would be the logarithmic decibel gain at the minimum position (eg -80 in the above). Since 10^(-80/20) = 10^-4 = 0.0001 your "0dB gain" is now 0.9999 or roughly -0.000043dB which is very close to unity, but if you really wanted exact unity at unity-setting then we could fix that too to get the following

gain = (10^(dBgain/20) - 10^(dBgainMin/20)) / (1 - 10^(dbGainMin/20))

This is still really only a single exponential (since the second one is constant) so it's not too inefficient either. You could shape it further if you wanted particular positions to give some particular values, but the above should be rather workable. Basically with "dBgainMin" set to -80, you get very close to logarithmic response from about -60dB up, which then tapers smoothly to linear control at the very bottom of the range.

So the whole thing in pseudo-code (with slider in [0,1]) looks something like:

Code: Select all

   dBmin = -80
   dBmax = +20
   range = dBmax - dBmin

   zeroShape = 10^(dBmin/20)
   unityFix = 1 / (1 + zeroShape)

   gain = (10^((range*slider-dBmin)/20)-zeroShape)*unityFix
If you want unity at max value, just set dBmax = 0.
If you want it go towards linear control earlier, set dBmin to a larger value (like -60 or something).
Preferred pronouns would be "it/it" because according to this country, I'm a piece of human trash.

KVRer
25 posts since 8 Feb, 2011

Post Sat May 05, 2012 10:18 am

friendofphi wrote:I'd really like a nice equation to emulate mixer faders. Something that maps a slider 0-1 to a 0-1 gain that has a appropriate logarithmic curve. Efficiency is irrelevant.
if the fader value is 0.0 to 1.0, like the vst stuff I'm using, I just do value * value. Then you can go louder as needed, like * 10.0. But correct me if I'm wrong. I just thought that was the same as an analog volume control.

User avatar
KVRAF
12422 posts since 7 Dec, 2004

Post Sat May 05, 2012 10:30 am

no, an "analog control" is usually of the form 1/(1/r1 + 1/r2) but there are major variations.

a lot of db fader tapers go to about -40db and then trail off in a linear taper from there. the log taper can be a mixture of two linearly tapered strips and the equation above applies but there are other methods.

some just say "f*** decibels!" and have two linear sections, a super poor piece-wise linear approximation of the model taper.

with consoles or devices that have displays showing db, generally the faders will match the response of the vu meters or vice-versa.

generally you can assume if the device has a fader label to -50db, the led display shows a 50db range the faders are probably accurate at least to there.

you "can" use 4(n^2) but it feels way different and the labels wouldn't be evenly spaced.
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.

KVRer
25 posts since 8 Feb, 2011

Post Sat May 05, 2012 12:05 pm

Well I don't care about models of volume controls I just meant that in general. In other words a formula that goes from 0 to 1 that sounds like the average volume control, though that average may be subjective. Actually your ear's own response would be the goal wouldn't it but back to the subject of the OP, a formula for linear 0.0 - 1.0 converted to logarithmic 0.0 - 1.0.

Image

(10^(x)-1)/9 is all I could come up with based on what was said here, is that correct at least in the sense of the best approximation, or is there another formula I should try.

KVRAF
6182 posts since 12 Feb, 2006 from Helsinki, Finland

Post Sat May 05, 2012 3:12 pm

rootbear wrote: (10^(x)-1)/9 is all I could come up with based on what was said here, is that correct at least in the sense of the best approximation, or is there another formula I should try.
That's not very logarithmic at all. You're using the formula I suggested, yes, but that formula has design parameters (namely "range" is the most important one) and you are essentially designing a slider that has nominal 20dB log-range, but tapers to linear at the bottom of that range (compare: I was suggesting around 60 or more nominal range; this makes it look a whole lot different).

That said, I'm not necessary against x*x (I use it for some level controls myself) but it's not really ideal because you have only a little range on top before it start becoming linear (so there's no much accuracy around -40dB for example).
Preferred pronouns would be "it/it" because according to this country, I'm a piece of human trash.

User avatar
KVRAF
2532 posts since 4 Sep, 2006 from 127.0.0.1

Post Sat May 05, 2012 3:26 pm

here are 3 pot measurements i did from my x0xb0x
the pots are "log" .. but you decide

Image
It doesn't matter how it sounds..
..as long as it has BASS and it's LOUD!

irc.freenode.net >>> #kvr

KVRAF
6182 posts since 12 Feb, 2006 from Helsinki, Finland

Post Sat May 05, 2012 4:16 pm

antto wrote:here are 3 pot measurements i did from my x0xb0x
the pots are "log" .. but you decide
That's those crappy "two-linear segments" tapers that aciddose mentioned. So whoever sourced the components for your x0x apparently didn't want to pay extra for proper log-pots (apparently there are rumors that such things actually exist). ;)

Anyway, the "linear pot plus shaping resistor" idea is explained here for example. If you're designing new analog circuits, I think that's the easier way to go since you can use a cheap linear pot and still get a smooth response.
Preferred pronouns would be "it/it" because according to this country, I'm a piece of human trash.

User avatar
KVRAF
2532 posts since 4 Sep, 2006 from 127.0.0.1

Post Sun May 06, 2012 1:01 am

mystran wrote:..So whoever sourced the components for your x0x apparently didn't want to pay extra for proper log-pots (apparently there are rumors that such things actually exist). ;)
i think the TB-303 uses pots with the same "cheap log" response
It doesn't matter how it sounds..
..as long as it has BASS and it's LOUD!

irc.freenode.net >>> #kvr

KVRAF
6182 posts since 12 Feb, 2006 from Helsinki, Finland

Post Sun May 06, 2012 9:05 pm

antto wrote:
mystran wrote:..So whoever sourced the components for your x0x apparently didn't want to pay extra for proper log-pots (apparently there are rumors that such things actually exist). ;)
i think the TB-303 uses pots with the same "cheap log" response
No idea to be honest. Unsurprisingly it appears that the originals aren't even made anymore. I found some information regarding 303 pots but that doesn't really talk anything about the log-tapers on the originals. Not that it's such a huge deal, proper log-response mostly just feels nicer.
Preferred pronouns would be "it/it" because according to this country, I'm a piece of human trash.

KVRAF
7068 posts since 17 Feb, 2005

Post Mon May 07, 2012 1:27 am

I wouldn't mind any piecewise linear or hocus pocus function-based fader at all. As long as it was documented with the device I am okay with whatever. The piecewise linear curve would work just fine for a mix fader, and might be preferred in some circumstances.

I love digital! All this stuff is a cinch to create and really adds custom vibe to everything!

KVRer

Topic Starter

4 posts since 6 Mar, 2012

Post Thu May 10, 2012 2:12 am

I'm going to start with the first post here, I don't really see how converting from db helps, -80db to 20db doesn't match to 0-1.

I'm using the square function, which seems to work nicely. It sounds like it's getting louder in even increments. And I can easily root to do meters. I appreciated that graph, it would be cool to overlay the x^2 on it.

User avatar
KVRian
1033 posts since 20 Dec, 2010

Post Thu May 10, 2012 2:37 am

I often use square as well for volume, unless I have a reason not to (it's also the response most DAWs use, last time I checked).

Richard
Synapse Audio Software - www.synapse-audio.com

User avatar
WOK
KVRAF
2113 posts since 24 Feb, 2004 from Germany

Post Thu May 10, 2012 2:47 am

friendofphi wrote:I'd really like a nice equation to emulate mixer faders. Something that maps a slider 0-1 to a 0-1 gain that has a appropriate logarithmic curve. Efficiency is irrelevant.
Like the red line here:
http://tinyurl.com/cu7szta   ?
ImageImage

Return to “DSP and Plug-in Development”