From 9df5eeb47ac4d6765ea0c3be7545ca6adff92d74 Mon Sep 17 00:00:00 2001 From: KubaPro010 Date: Thu, 10 Jul 2025 18:59:39 +0200 Subject: [PATCH] change bs412 implementation --- filter/bs412.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/filter/bs412.c b/filter/bs412.c index 799ef27..c220d0b 100644 --- a/filter/bs412.c +++ b/filter/bs412.c @@ -48,12 +48,18 @@ float bs412_compress(BS412Compressor* mpx, float sample) { mpx->average_counter = 1; } - float gain_target = powf(10.0f, (mpx->target - modulation_power) / 20.0f); - if (gain_target > mpx->gain) { - mpx->gain = mpx->gain * mpx->attack + (1.0f - mpx->attack) * gain_target; - } else { - mpx->gain = mpx->gain * mpx->release + (1.0f - mpx->release) * gain_target; - } + if (modulation_power > mpx->target) { + float excess_power = modulation_power - mpx->target; + + if (excess_power > 0.0f && excess_power < 10.0f) { + float target_gain = dbr_to_deviation(-excess_power) / config.mpx_deviation; + + target_gain = fmaxf(target_gain, 0.1f); + target_gain = fminf(target_gain, 1.0f); + + mpx->gain = mpx->attack * mpx->gain + (1 - mpx->attack) * target_gain; + } + } else mpx->gain = fminf(1.0f, mpx->release * mpx->gain + (1 - mpx->release) * 1.0f); mpx->gain = fminf(mpx->max, mpx->gain); mpx->gain = fmaxf(0.0f, mpx->gain);