fmalcher/soundcraft-ui

Get and Set Gain for input channels

NaturalDevCR opened this issue ยท 7 comments

It would be great to have a simpler way to get channel gain, and also to set it, just as we have with the fader levels.

Thanks in advance!

While the data source is relatively easy to use, the difficulty for this is the conversion between linear fader value and dB equivalent. The gain faders do not cover the same range as the channel faders. So we cannot reuse the logic.

So, if you find out how we can transform between dB and the linear value (both directions), I can definitely implement this.

For the fader values I used a lookup table that I made with values based on the original conversion function from the web app. For the gain faders it MIGHT be easier as they look somewhat linear.

What about converting both ranges:

0 -- 1

-40 -- 50

To their relative percentage values... That way you could work in percentage values and convert back to each range accordingly.

That could work, however I don't really care how the exact implementation will look like (as long as it's okay in terms of performance). We need two functions to convert between the raw value (0...1) to the dB value displayed in the UI.
My first attempt would be to take a look at the source code of the web app. This way I explored the algorithm for fader value conversion.

I asked chat gpt-3 and this was it's answer xD

"To convert a value from the gain range (which is in decibels) to the fader range (which is a linear value), you can use the following formula:

faderValue = 10^(gainValue/20)

To convert a value from the fader range (which is a linear value) to the gain range (which is in decibels), you can use the following formula:

gainValue = 20 * log10(faderValue)

You can then use these formulas to convert values between the two ranges as needed. To make the conversion more intuitive, you can also define helper functions to handle the conversion for you.

For example, you could define the following functions to convert between the two ranges:

function fromGainToFader(gainValue) {
  return Math.pow(10, (gainValue / 20))
}

function fromFaderToGain(faderValue) {
  return 20 * Math.log10(faderValue)
}

You can then use these functions to easily convert between the two ranges, like this:

const faderRange = {
  min: 0,
  max: 1
}

const gainRange = {
  min: -40,
  max: 50
}

const gainValue = -20
const faderValue = fromGainToFader(gainValue)
console.log(faderValue)  // Outputs: 0.31622776601683794

const faderValue = 0.5
const gainValue = fromFaderToGain(faderValue)
console.log(gainValue)  // Outputs: -6.020599913279623

How about that?

The idea is good, but the values are wrong. ๐Ÿ˜„
A few examples for values:

Gain (dB) Linear
0 0.09523809523809523
57 1
-6 0
24 0.47619047619047616

The fader doesn't seem to be linear (which is not unexpected for dB values), so a linear conversion won't work.
Probably a lookup table is good for this case, too. But we need the values!

Dang... I'll scarve the Ui mixer code to see if there's a function or something...

By the way...

Here is my project made in VueJS with your library:

https://github.com/NaturalDevCR/MyUiPro

Found it! ๐ŸŽ‰