feat: change the compressor unit to apply post-gain instead of pregain.

Pregaining ran into trouble: could not bring the signal level back to near 0dB. For example, with infinite ratio in the pre-gain system, the signal level was capped at threshold, which in turn ran into trouble with stereo signals.
This commit is contained in:
vsariola
2021-03-20 17:01:04 +02:00
parent 76cf47a070
commit 42c9e045b7
7 changed files with 15 additions and 20 deletions

View File

@ -505,10 +505,8 @@ func (s *Interpreter) Render(buffer []float32, syncBuf []float32, maxtime int) (
}
unit.ports[4] = 0
case opCompressor:
stack[l-1] /= params[2] // apply inverse gain
signalLevel := stack[l-1] * stack[l-1] // square the signal to get power
if stereo {
stack[l-2] /= params[2] // apply inverse gain
signalLevel += stack[l-2] * stack[l-2]
}
currentLevel := unit.state[0]
@ -523,6 +521,7 @@ func (s *Interpreter) Render(buffer []float32, syncBuf []float32, maxtime int) (
if threshold2 := params[3] * params[3]; currentLevel > threshold2 {
gain = float32(math.Pow(float64(threshold2/currentLevel), float64(params[4]/2)))
}
gain /= params[2] // apply inverse gain
stack = append(stack, gain)
if stereo {
stack = append(stack, gain)