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

@ -409,10 +409,6 @@
;; Stereo: push g g on stack, where g is calculated using l^2 + r^2
;;-------------------------------------------------------------------------------
(func $su_op_compressor (param $stereo i32) (local $x2 f32) (local $level f32) (local $t2 f32)
(call $push (f32.div ;; the inverse gain is applied on this signal, even if the gain is side-chained somewhere else
(call $pop)
(call $input (i32.const {{.InputNumber "compressor" "invgain"}}))
))
{{- if .Stereo "compressor"}}
(local.set $x2 (f32.mul
(call $peek)
@ -420,10 +416,6 @@
))
(if (local.get $stereo)(then
(call $pop)
(call $push (f32.div
(call $pop)
(call $input (i32.const {{.InputNumber "compressor" "invgain"}}))
))
(local.set $x2 (f32.add
(local.get $x2)
(f32.mul
@ -472,6 +464,10 @@
)(else
(call $push (f32.const 1)) ;; unity gain if we are below threshold
))
(call $push (f32.div ;; apply post-gain ("make up gain")
(call $pop)
(call $input (i32.const {{.InputNumber "compressor" "invgain"}}))
))
{{- if .Stereo "compressor"}}
(if (local.get $stereo)(then
(call $push (call $peek))