From 3df530e7f6521a74d5184c6de04589cd762c5f12 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 30 Mar 2020 21:59:07 +0200 Subject: [PATCH] Clean up double/float narrowing math in plugins. --- libs/plugins/a-comp.lv2/a-comp.c | 12 ++++++------ libs/plugins/a-eq.lv2/a-eq.c | 2 +- libs/plugins/a-exp.lv2/a-exp.c | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libs/plugins/a-comp.lv2/a-comp.c b/libs/plugins/a-comp.lv2/a-comp.c index d7286a59aa..e27d17104c 100644 --- a/libs/plugins/a-comp.lv2/a-comp.c +++ b/libs/plugins/a-comp.lv2/a-comp.c @@ -266,12 +266,12 @@ sanitize_denormal(float value) { static inline float from_dB(float gdb) { - return (exp(gdb/20.f*log(10.f))); + return powf (10.0f, 0.05f * gdb); } static inline float to_dB(float g) { - return (20.f*log10(g)); + return (20.f * log10f (g)); } static void @@ -300,8 +300,8 @@ run(LV2_Handle instance, uint32_t n_samples) float srate = acomp->srate; float width = (6.f * *(acomp->knee)) + 0.01; - float attack_coeff = exp(-1000.f/(*(acomp->attack) * srate)); - float release_coeff = exp(-1000.f/(*(acomp->release) * srate)); + float attack_coeff = expf (-1000.f / (*(acomp->attack) * srate)); + float release_coeff = expf (-1000.f / (*(acomp->release) * srate)); float max_out = 0.f; float Lgain = 1.f; @@ -323,7 +323,7 @@ run(LV2_Handle instance, uint32_t n_samples) float makeup_target = from_dB(makeup); float makeup_gain = acomp->makeup_gain; - const float tau = (1.0 - exp (-2.f * M_PI * 25.f / acomp->srate)); + const float tau = (1.f - expf (-2.f * M_PI * 25.f / acomp->srate)); if (*acomp->enable <= 0) { ratio = 1.f; @@ -446,7 +446,7 @@ run(LV2_Handle instance, uint32_t n_samples) if (acomp->v_gainr > knee_lim_gr) { state_x = acomp->v_gainr / (1.f - 1.f/ratio) + thresdb; } else { - state_x = sqrt ( (2.f*width*acomp->v_gainr) / (1.f-1.f/ratio) ) + thresdb - width/2.f; + state_x = sqrtf ( (2.f*width*acomp->v_gainr) / (1.f-1.f/ratio) ) + thresdb - width/2.f; } if (fabsf (acomp->v_lvl_out - v_lvl_out) >= .1f || diff --git a/libs/plugins/a-eq.lv2/a-eq.c b/libs/plugins/a-eq.lv2/a-eq.c index 809b8a9f06..7aea800fb2 100644 --- a/libs/plugins/a-eq.lv2/a-eq.c +++ b/libs/plugins/a-eq.lv2/a-eq.c @@ -149,7 +149,7 @@ instantiate(const LV2_Descriptor* descriptor, { Aeq* aeq = (Aeq*)calloc(1, sizeof(Aeq)); aeq->srate = rate; - aeq->tau = 1.0 - expf (-2.f * M_PI * 64.f * 25.f / aeq->srate); // 25Hz time constant @ 64fpp + aeq->tau = 1.f - expf (-2.f * M_PI * 64.f * 25.f / aeq->srate); // 25Hz time constant @ 64fpp #ifdef LV2_EXTENDED for (int i=0; features[i]; ++i) { diff --git a/libs/plugins/a-exp.lv2/a-exp.c b/libs/plugins/a-exp.lv2/a-exp.c index c90611517f..7f13e1a2ff 100644 --- a/libs/plugins/a-exp.lv2/a-exp.c +++ b/libs/plugins/a-exp.lv2/a-exp.c @@ -268,12 +268,12 @@ sanitize_denormal(float value) { static inline float from_dB(float gdb) { - return (exp(gdb/20.f*log(10.f))); + return powf (10.0f, 0.05f * gdb); } static inline float to_dB(float g) { - return (20.f*log10(g)); + return (20.f * log10f (g)); } static void @@ -302,8 +302,8 @@ run(LV2_Handle instance, uint32_t n_samples) float srate = aexp->srate; float width = (6.f * *(aexp->knee)) + 0.01; - float attack_coeff = exp(-1000.f/(*(aexp->attack) * srate)); - float release_coeff = exp(-1000.f/(*(aexp->release) * srate)); + float attack_coeff = expf (-1000.f / (*(aexp->attack) * srate)); + float release_coeff = expf (-1000.f / (*(aexp->release) * srate)); float max_out = 0.f; float Lgain = 1.f; @@ -325,7 +325,7 @@ run(LV2_Handle instance, uint32_t n_samples) float makeup_target = from_dB(makeup); float makeup_gain = aexp->makeup_gain; - const float tau = (1.0 - exp (-2.f * M_PI * 25.f / aexp->srate)); + const float tau = (1.f - expf (-2.f * M_PI * 25.f / aexp->srate)); if (*aexp->enable <= 0) { ratio = 1.f;