From 65fed2fa898c9acb0a7fdf0a1116d77219673275 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Sat, 9 Jun 2018 18:50:43 +0200 Subject: [PATCH] Make makeup_gain smoothening of a-expander same as in a-comp --- libs/plugins/a-exp.lv2/a-exp.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/libs/plugins/a-exp.lv2/a-exp.c b/libs/plugins/a-exp.lv2/a-exp.c index 7365386567..6e748b5877 100644 --- a/libs/plugins/a-exp.lv2/a-exp.c +++ b/libs/plugins/a-exp.lv2/a-exp.c @@ -43,6 +43,11 @@ #define isfinite_local isfinite #endif +#ifndef FLT_EPSILON +# define FLT_EPSILON 1.192093e-07 +#endif + + typedef enum { AEXP_ATTACK = 0, AEXP_RELEASE, @@ -87,7 +92,6 @@ typedef struct { float srate; float makeup_gain; - float tau; bool was_disabled; @@ -132,7 +136,6 @@ instantiate(const LV2_Descriptor* descriptor, } aexp->srate = rate; - aexp->tau = (1.0 - exp (-2.f * M_PI * 25.f / aexp->srate)); #ifdef LV2_EXTENDED aexp->need_expose = true; aexp->v_lvl_out = -70.f; @@ -306,7 +309,7 @@ run_mono(LV2_Handle instance, uint32_t n_samples) float makeup_target = from_dB(makeup); float makeup_gain = aexp->makeup_gain; - const float tau = aexp->tau; + const float tau = (1.0 - exp (-2.f * M_PI * 25.f / aexp->srate)); if (*aexp->enable <= 0) { ratio = 1.f; @@ -395,12 +398,16 @@ run_mono(LV2_Handle instance, uint32_t n_samples) lgaininp = in0 * Lgain; - makeup_gain += tau * (makeup_target - makeup_gain) + 1e-12; + makeup_gain += tau * (makeup_target - makeup_gain); output[i] = lgaininp * makeup_gain; max = (fabsf(output[i]) > max) ? fabsf(output[i]) : sanitize_denormal(max); } + if (fabsf(tau * (makeup_gain - makeup_target)) < FLT_EPSILON*makeup_gain) { + makeup_gain = makeup_target; + } + *(aexp->outlevel) = (max < 0.0056f) ? -45.f : to_dB(max); *(aexp->inlevel) = in_peak_db; aexp->makeup_gain = makeup_gain; @@ -476,7 +483,7 @@ run_stereo(LV2_Handle instance, uint32_t n_samples) float makeup_target = from_dB(makeup); float makeup_gain = aexp->makeup_gain; - const float tau = aexp->tau; + const float tau = (1.0 - exp (-2.f * M_PI * 25.f / aexp->srate)); if (*aexp->enable <= 0) { ratio = 1.f; @@ -569,7 +576,7 @@ run_stereo(LV2_Handle instance, uint32_t n_samples) lgaininp = in0 * Lgain; rgaininp = in1 * Lgain; - makeup_gain += tau * (makeup_target - makeup_gain) + 1e-12; + makeup_gain += tau * (makeup_target - makeup_gain); output0[i] = lgaininp * makeup_gain; output1[i] = rgaininp * makeup_gain; @@ -577,6 +584,10 @@ run_stereo(LV2_Handle instance, uint32_t n_samples) max = (fmaxf(fabs(output0[i]), fabs(output1[i])) > max) ? fmaxf(fabs(output0[i]), fabs(output1[i])) : sanitize_denormal(max); } + if (fabsf(tau * (makeup_gain - makeup_target)) < FLT_EPSILON*makeup_gain) { + makeup_gain = makeup_target; + } + *(aexp->outlevel) = (max < 0.0056f) ? -45.f : to_dB(max); *(aexp->inlevel) = in_peak_db; aexp->makeup_gain = makeup_gain;