Hi.

So what I’m trying to do is make a volume slider for audio using the audio mixer. I want the max (100%) to be -10db and the minimum (0%) to be -80db. My thought process if -10db is 100% and -80 is 0%, what would, for instance, 75% be? This is what I’m trying to do.

The reason I’m doing this is because I want the slider to display the percentage instead of the decibel level.

There might be an easier way to go about this, but any help would be much appreciated! Thank you!

See Mathf.Lerp() and Mathf.InverseLerp(). The math of it is pretty simple.

`Mathf.Lerp(-80f, -10f, 0.75)`

gives the 75% value between -80 and -10, or -27.5.

But beware, that may or may not be what you want on a logarithmic scale like decibels.

5 Likes

Decibels are definitely NOT linear, but the biggest issue with them is that they are relativistic. Moreover there are two kinds of decibel uses. One of them is attenuating, where the zero is the supposed maximum, and then it attenuates to -inf, and the other is the absolute scale which goes from some convenient positive minimum and then scales up, theoretically to +inf. Obviously, because it’s relativistic, this is all just a convention. I believe mixers use the first kind, because you kind of want to normalize the amplitude information across a range of devices (so they usually track from -inf to +3 dB to avoid hard clipping).

Anyway, it’s doable if you can accept that you can only ever approach the 0%, not **get** there. And you need to know and understand exp and log functions and use them accordingly. From my recent experience with log-polar grids I can tell that this tends to be much more easier in code than by looking at math. Math notation is intimidating as hell.

3 Likes

The percentage might be visually intuitive, but it might not “look right” when comparing with the loudness, given the log scaling that the audio mixer uses.

If you convert to 0-1 range, it can be easier to do some of the exponential/log operations, then you can scale back to 0-100% for visual representation. I’m sure you can do it without scaling, but don’t have the formula off the top of my head, been too long since math class hehe.

The log base for decibels is ~1.2589, so that to the 10th power gives you 10, to the 20th power gives you 100, etc. Might be useful for scaling the percent display if you’re using decibels in the calculation somewhere.

1 Like