What's mean gain linear space (SOLVED)

In documentation you have the phrase “Note that gain is in linear scale.” and in the editor you have warning that gain must be in [-100:0] range. so i don’t know how properly setup this value in editor. then change in code and return it back so it will equal to editor value.

Thanks.

Hmm, good question. I don’t know much about audio. @sicher, do you know?

In the editor gain is specified in dB -100 (infinity) to 0. The linear scale used in code is between 0 and 1.

To get the dB value from the linear value, the formula 20 * log(n) is used:

gain (linear)      gain (dB) 
0                  -100
0.5                -6.02
1                  0

Note that 20*log(0) is not possible so a gain below 0.00001 is considered negative infinite (silent).

The benefit of using the linear values in code is that to get the final gain after having the signal passing through several mixers, you just multiply the gain values.

3 Likes

Inversely, if you want to find a linear value from dB: 10^(db/20)

So if you want to set the gain to -6 dB, the value should be 10^(-6/20) which is about 0.5.

Sidenote: The RMS (root mean square) value is calculated from the linear values. If you create a sinus wave signal with a peak at -1.94 dB (0.8 linear) the RMS is 0.8 * 1/sqrt(2) which is about 0.566.

3 Likes

Brilliant stuff. Thank you for explaining! Is this in the docs?

1 Like

It will be soon. :slight_smile:

1 Like

thanks a lot for this clear explanation it really what i was looking for.

1 Like