diff options
author | Johannes Mueller <github@johannes-mueller.org> | 2017-08-03 22:20:07 +0200 |
---|---|---|
committer | Damien Zammit <damien@zamaudio.com> | 2017-10-11 18:23:56 +1100 |
commit | d437f9570e3eac0d0602a424d433d10d84b87a9d (patch) | |
tree | 28a0d31ec8e1a9588425e2df1c35a7421d3cd7bd | |
parent | 577fb21ac32b8fa4efe3d22b48fcb5283fd4be11 (diff) |
compressors: Make the attack no longer influence the release.
Before this change, setting a low release time and a high attack time
made any compressor also release slowly (according to the attack parameter).
This commit changes this behavior so that the attack parameter
only affects the attack without affecting the release.
Signed-off-by: Damien Zammit <damien@zamaudio.com>
-rw-r--r-- | plugins/ZaMultiComp/ZaMultiCompPlugin.cpp | 16 | ||||
-rw-r--r-- | plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.cpp | 29 | ||||
-rw-r--r-- | plugins/ZamComp/ZamCompPlugin.cpp | 17 | ||||
-rw-r--r-- | plugins/ZamCompX2/ZamCompX2Plugin.cpp | 30 |
4 files changed, 53 insertions, 39 deletions
diff --git a/plugins/ZaMultiComp/ZaMultiCompPlugin.cpp b/plugins/ZaMultiComp/ZaMultiCompPlugin.cpp index 0e183c0..ffb7976 100644 --- a/plugins/ZaMultiComp/ZaMultiCompPlugin.cpp +++ b/plugins/ZaMultiComp/ZaMultiCompPlugin.cpp @@ -791,7 +791,7 @@ void ZaMultiCompPlugin::run_comp(int k, float in, float *out) float cdb=0.f; float Lgain = 1.f; float Lxg, Lyg; - float Lxl, Lyl, Ly1; + float Lxl, Lyl; Lyg = 0.f; in = sanitize_denormal(in); @@ -811,12 +811,15 @@ void ZaMultiCompPlugin::run_comp(int k, float in, float *out) Lxl = Lxg - Lyg; - old_y1[k] = sanitize_denormal(old_y1[k]); - old_yl[k] = sanitize_denormal(old_yl[k]); + old_yl[k] = sanitize_denormal(old_yl[k]); - Ly1 = fmaxf(Lxl, release_coeff * old_y1[k]+(1.f-release_coeff)*Lxl); - Lyl = attack_coeff * old_yl[k]+(1.f-attack_coeff)*Ly1; - Ly1 = sanitize_denormal(Ly1); + if (Lxl < old_yl[k]) { + Lyl = release_coeff * old_yl[k] + (1.f-release_coeff)*Lxl; + } else if (Lxl > old_yl[k]) { + Lyl = attack_coeff * old_yl[k]+(1.f-attack_coeff)*Lxl; + } else { + Lyl = Lxl; + } Lyl = sanitize_denormal(Lyl); cdb = -Lyl; @@ -827,7 +830,6 @@ void ZaMultiCompPlugin::run_comp(int k, float in, float *out) *out = in * Lgain; old_yl[k] = Lyl; - old_y1[k] = Ly1; old_yg[k] = Lyg; } diff --git a/plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.cpp b/plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.cpp index d74093f..877377b 100644 --- a/plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.cpp +++ b/plugins/ZaMultiCompX2/ZaMultiCompX2Plugin.cpp @@ -811,8 +811,8 @@ void ZaMultiCompX2Plugin::run_comp(int k, float inL, float inR, float *outL, flo float Rgain = 1.f; float Lxg, Lyg; float Rxg, Ryg; - float Lxl, Lyl, Ly1; - float Rxl, Ryl, Ry1; + float Lxl, Lyl; + float Rxl, Ryl; Lyg = Ryg = 0.f; inL = sanitize_denormal(inL); @@ -850,22 +850,29 @@ void ZaMultiCompX2Plugin::run_comp(int k, float inL, float inR, float *outL, flo Lxl = Rxl = (Lxg - Lyg + Rxg - Ryg) / 2.f; } - old_y1[0][k] = sanitize_denormal(old_y1[0][k]); - old_y1[1][k] = sanitize_denormal(old_y1[1][k]); old_yl[0][k] = sanitize_denormal(old_yl[0][k]); old_yl[1][k] = sanitize_denormal(old_yl[1][k]); - Ly1 = fmaxf(Lxl, release_coeff * old_y1[0][k]+(1.f-release_coeff)*Lxl); - Lyl = attack_coeff * old_yl[0][k]+(1.f-attack_coeff)*Ly1; - Ly1 = sanitize_denormal(Ly1); + + if (Lxl < old_yl[0][k]) { + Lyl = release_coeff * old_yl[0][k] + (1.f-release_coeff)*Lxl; + } else if (Lxl > old_yl[0][k]) { + Lyl = attack_coeff * old_yl[0][k]+(1.f-attack_coeff)*Lxl; + } else { + Lyl = Lxl; + } Lyl = sanitize_denormal(Lyl); cdb = -Lyl; Lgain = from_dB(cdb); - Ry1 = fmaxf(Rxl, release_coeff * old_y1[1][k]+(1.f-release_coeff)*Rxl); - Ryl = attack_coeff * old_yl[1][k]+(1.f-attack_coeff)*Ry1; - Ry1 = sanitize_denormal(Ry1); + if (Rxl < old_yl[1][k]) { + Ryl = release_coeff * old_yl[1][k] + (1.f-release_coeff)*Rxl; + } else if (Rxl > old_yl[1][k]) { + Ryl = attack_coeff * old_yl[1][k]+(1.f-attack_coeff)*Rxl; + } else { + Ryl = Rxl; + } Ryl = sanitize_denormal(Ryl); cdb = -Ryl; @@ -881,8 +888,6 @@ void ZaMultiCompX2Plugin::run_comp(int k, float inL, float inR, float *outL, flo old_yl[0][k] = Lyl; old_yl[1][k] = Ryl; - old_y1[0][k] = Ly1; - old_y1[1][k] = Ry1; old_yg[0][k] = Lyg; old_yg[1][k] = Ryg; } diff --git a/plugins/ZamComp/ZamCompPlugin.cpp b/plugins/ZamComp/ZamCompPlugin.cpp index 876dda3..af2a279 100644 --- a/plugins/ZamComp/ZamCompPlugin.cpp +++ b/plugins/ZamComp/ZamCompPlugin.cpp @@ -300,7 +300,7 @@ void ZamCompPlugin::run(const float** inputs, float** outputs, uint32_t frames) float max = 0.f; float lgaininp = 0.f; float Lgain = 1.f; - float Lxg, Lxl, Lyg, Lyl, Ly1; + float Lxg, Lxl, Lyg, Lyl; float checkwidth = 0.f; bool usesidechain = (sidechain < 0.5) ? false : true; uint32_t i; @@ -340,11 +340,15 @@ void ZamCompPlugin::run(const float** inputs, float** outputs, uint32_t frames) Lxl = Lxg - Lyg; - oldL_y1 = sanitize_denormal(oldL_y1); oldL_yl = sanitize_denormal(oldL_yl); - Ly1 = fmaxf(Lxl, release_coeff * oldL_y1+(1.f-release_coeff)*Lxl); - Lyl = attack_coeff * oldL_yl+(1.f-attack_coeff)*Ly1; - Ly1 = sanitize_denormal(Ly1); + + if (Lxl < oldL_yl) { + Lyl = release_coeff * oldL_yl + (1.f-release_coeff)*Lxl; + } else if (Lxl > oldL_yl) { + Lyl = attack_coeff * oldL_yl+(1.f-attack_coeff)*Lxl; + } else { + Lyl = Lxl; + } Lyl = sanitize_denormal(Lyl); cdb = -Lyl; @@ -358,11 +362,10 @@ void ZamCompPlugin::run(const float** inputs, float** outputs, uint32_t frames) max = (fabsf(outputs[0][i]) > max) ? fabsf(outputs[0][i]) : sanitize_denormal(max); oldL_yl = Lyl; - oldL_y1 = Ly1; oldL_yg = Lyg; } outlevel = (max == 0.f) ? -45.f : to_dB(max); // relative to - thresdb; - } +} // ----------------------------------------------------------------------- diff --git a/plugins/ZamCompX2/ZamCompX2Plugin.cpp b/plugins/ZamCompX2/ZamCompX2Plugin.cpp index 78fc43d..330b1b5 100644 --- a/plugins/ZamCompX2/ZamCompX2Plugin.cpp +++ b/plugins/ZamCompX2/ZamCompX2Plugin.cpp @@ -322,8 +322,8 @@ void ZamCompX2Plugin::run(const float** inputs, float** outputs, uint32_t frames float rgaininp = 0.f; float Lgain = 1.f; float Rgain = 1.f; - float Lxg, Lxl, Lyg, Lyl, Ly1; - float Rxg, Rxl, Ryg, Ryl, Ry1; + float Lxg, Lxl, Lyg, Lyl; + float Rxg, Rxl, Ryg, Ryl; float checkwidth = 0.f; uint32_t i; float in0; @@ -393,13 +393,14 @@ void ZamCompX2Plugin::run(const float** inputs, float** outputs, uint32_t frames Lxl = Rxl = (Lxg - Lyg + Rxg - Ryg) / 2.f; } - oldL_y1 = sanitize_denormal(oldL_y1); - oldR_y1 = sanitize_denormal(oldR_y1); oldL_yl = sanitize_denormal(oldL_yl); - oldR_yl = sanitize_denormal(oldR_yl); - Ly1 = fmaxf(Lxl, release_coeff * oldL_y1+(1.f-release_coeff)*Lxl); - Lyl = attack_coeff * oldL_yl+(1.f-attack_coeff)*Ly1; - Ly1 = sanitize_denormal(Ly1); + if (Lxl < oldL_yl) { + Lyl = release_coeff * oldL_yl + (1.f-release_coeff)*Lxl; + } else if (Lxl > oldL_yl) { + Lyl = attack_coeff * oldL_yl+(1.f-attack_coeff)*Lxl; + } else { + Lyl = Lxl; + } Lyl = sanitize_denormal(Lyl); cdb = -Lyl; @@ -407,9 +408,14 @@ void ZamCompX2Plugin::run(const float** inputs, float** outputs, uint32_t frames gainred = Lyl; - Ry1 = fmaxf(Rxl, release_coeff * oldR_y1+(1.f-release_coeff)*Rxl); - Ryl = attack_coeff * oldR_yl+(1.f-attack_coeff)*Ry1; - Ry1 = sanitize_denormal(Ry1); + oldR_y1 = sanitize_denormal(oldR_y1); + if (Rxl < oldR_yl) { + Ryl = release_coeff * oldR_yl + (1.f-release_coeff)*Rxl; + } else if (Rxl > oldR_yl) { + Ryl = attack_coeff * oldR_yl+(1.f-attack_coeff)*Rxl; + } else { + Ryl = Rxl; + } Ryl = sanitize_denormal(Ryl); cdb = -Ryl; @@ -424,8 +430,6 @@ void ZamCompX2Plugin::run(const float** inputs, float** outputs, uint32_t frames oldL_yl = Lyl; oldR_yl = Ryl; - oldL_y1 = Ly1; - oldR_y1 = Ry1; oldL_yg = Lyg; oldR_yg = Ryg; } |