summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Zammit <damien@zamaudio.com>2015-11-01 03:26:08 +1100
committerDamien Zammit <damien@zamaudio.com>2015-11-01 03:26:08 +1100
commit96862508d3f24139c26ff182b3d440e37422eeab (patch)
treead0e44acd4aada04c131af84207e134a364b1600
parent13b5c73a47a68852cffd24a1c2af99cfe3199058 (diff)
Revert last commit
Signed-off-by: Damien Zammit <damien@zamaudio.com>
-rw-r--r--plugins/ZaMaximX2/ZaMaximX2Plugin.cpp102
-rw-r--r--plugins/ZaMaximX2/ZaMaximX2Plugin.hpp8
-rw-r--r--plugins/ZaMaximX2/ZaMaximX2UI.cpp10
3 files changed, 70 insertions, 50 deletions
diff --git a/plugins/ZaMaximX2/ZaMaximX2Plugin.cpp b/plugins/ZaMaximX2/ZaMaximX2Plugin.cpp
index c206879..d6a8396 100644
--- a/plugins/ZaMaximX2/ZaMaximX2Plugin.cpp
+++ b/plugins/ZaMaximX2/ZaMaximX2Plugin.cpp
@@ -42,7 +42,7 @@ void ZaMaximX2Plugin::initParameter(uint32_t index, Parameter& parameter)
parameter.unit = "ms";
parameter.ranges.def = 25.0f;
parameter.ranges.min = 1.0f;
- parameter.ranges.max = 500.0f;
+ parameter.ranges.max = 100.0f;
break;
case paramCeiling:
parameter.hints = kParameterIsAutomable;
@@ -97,8 +97,8 @@ void ZaMaximX2Plugin::loadProgram(uint32_t index)
{
switch(index) {
case 0:
- release = 150.0;
- ceiling = -0.5;
+ release = 25.0;
+ ceiling = -3.0;
thresdb = 0.0;
gainred = 0.0;
outlevel = -45.0;
@@ -166,12 +166,14 @@ void ZaMaximX2Plugin::activate()
gainred = 0.0f;
outlevel = -45.0f;
for (i = 0; i < MAX_SAMPLES; i++) {
- z[0][i] = 0.f;
- z[1][i] = 0.f;
+ cn[0][i] = z[0][i] = emaxn[0][i] = 0.f;
+ cn[1][i] = z[1][i] = emaxn[1][i] = 0.f;
}
posz[0] = posz[1] = 0;
- smoothold[0] = smoothold[1] = 0.f;
- envold[0] = envold[1] = 0.f;
+ pose[0] = pose[1] = 0;
+ posc[0] = posc[1] = 0;
+ emax_old[0] = emax_old[1] = 0.f;
+ eavg_old[0] = eavg_old[1] = 0.f;
}
void ZaMaximX2Plugin::deactivate()
@@ -240,64 +242,80 @@ double ZaMaximX2Plugin::maxsample(double in[])
void ZaMaximX2Plugin::run(const float** inputs, float** outputs, uint32_t frames)
{
uint32_t i;
+ double N = (float)MAX_SAMPLES;
+ double M = (float)MAX_SAMPLES;
double absx[2];
double c[2];
+ double xmax[2];
+ double emax[2];
+ double eavg[2];
+ double g[2];
double srate = getSampleRate();
- double tau = exp(-1000. / (release*srate));
- double env[2];
- double smooth[2];
- double targetgain = from_dB(ceiling);
+ double alpha = 1.0001;
+ double aa = 1. - pow( (alpha - 1.f) / alpha, 1. / ( N + 1. ) );
+ double a;
+ double beta = 0.f;
+ for (i = 0; i < M; i++) {
+ beta += pow(1. - aa, N + 1. - i);
+ }
+ beta /= M;
double inL, inR;
for (i = 0; i < frames; i++) {
inL = inputs[0][i];
inR = inputs[1][i];
-
- // input
absx[0] = MAX(fabs(inL), fabs(inR));
-
- // Envelope extractor
- if (envold[0] > absx[0]) {
- env[0] = tau * envold[0] + (1. - tau) * absx[0];
+ c[0] = MAX(absx[0], (absx[0]-beta*eavg_old[0]) / (1. - beta));
+ pushsample(&cn[0][0], sanitize_denormal(c[0]), &posc[0]);
+ xmax[0] = maxsample(&cn[0][0]);
+
+ if (xmax[0] < emaxn[0][pose[0]]) {
+ a = 1000 / (release * srate);
} else {
- env[0] = absx[0];
+ a = aa;
}
- if (envold[1] > absx[0]) {
- env[1] = tau * envold[1] + (1. - tau) * absx[0];
+ emax[0] = a*xmax[0] + (1. - a)*emaxn[0][pose[0]];
+ pushsample(&emaxn[0][0], sanitize_denormal(emax[0]), &pose[0]);
+ eavg[0] = avgall(&emaxn[0][0]);
+ if (eavg[0] == 0.f) {
+ g[0] = 1.;
} else {
- env[1] = absx[0];
+ g[0] = MIN(1., from_dB(thresdb) / eavg[0]);
}
-
- // control gain calculator
- c[0] = 1. / (1. / targetgain + (1. - 1. / targetgain)*env[0]);
- c[0] *= MIN(1., env[0] / from_dB(thresdb));
- c[1] = 1. / (1. / targetgain + (1. - 1. / targetgain)*env[1]);
- c[1] *= MIN(1., env[1] / from_dB(thresdb));
-
- // smoother
- if (c[0] > smoothold[0]) {
- smooth[0] = smoothold[0]*tau + c[0]*(1.-tau);
+
+ absx[1] = absx[0];
+ c[1] = MAX(absx[1], (absx[1]-beta*eavg_old[1]) / (1. - beta));
+ pushsample(&cn[1][0], sanitize_denormal(c[1]), &posc[1]);
+ xmax[1] = maxsample(&cn[1][0]);
+
+ if (xmax[1] < emaxn[1][pose[1]]) {
+ a = 1000 / (release * srate);
} else {
- smooth[0] = c[0];
+ a = aa;
}
- if (c[1] > smoothold[1]) {
- smooth[1] = smoothold[1]*tau + c[1]*(1.-tau);
+ emax[1] = a*xmax[1] + (1. - a)*emaxn[1][pose[1]];
+ pushsample(&emaxn[1][0], sanitize_denormal(emax[1]), &pose[1]);
+ eavg[1] = avgall(&emaxn[1][0]);
+ if (eavg[1] == 0.f) {
+ g[1] = 1.;
} else {
- smooth[1] = c[1];
+ g[1] = MIN(1., from_dB(thresdb) / eavg[1]);
}
- outputs[0][i] = (float)clip(normalise(z[0][posz[0]] * smooth[0], 0.));
- outputs[1][i] = (float)clip(normalise(z[1][posz[1]] * smooth[1], 0.));
+ gainred = MAX(-to_dB(g[0]), -to_dB(g[1]));
+
+ outputs[0][i] = (float)clip(normalise(z[0][posz[0]] * g[0], 0.));
+ outputs[1][i] = (float)clip(normalise(z[1][posz[1]] * g[1], 0.));
- outlevel = to_dB(MAX(fabs(outputs[0][i]), fabs(outputs[1][i]))) + (ceiling - thresdb);
+ outlevel = to_dB(MAX(fabs(eavg[0]), fabs(eavg[1]))) + (ceiling - thresdb);
pushsample(&z[0][0], sanitize_denormal(inL), &posz[0]);
pushsample(&z[1][0], sanitize_denormal(inR), &posz[1]);
- smoothold[0] = sanitize_denormal(smooth[0]);
- smoothold[1] = sanitize_denormal(smooth[1]);
- envold[0] = sanitize_denormal(env[0]);
- envold[1] = sanitize_denormal(env[1]);
+ emax_old[0] = sanitize_denormal(emax[0]);
+ eavg_old[0] = sanitize_denormal(eavg[0]);
+ emax_old[1] = sanitize_denormal(emax[1]);
+ eavg_old[1] = sanitize_denormal(eavg[1]);
}
}
diff --git a/plugins/ZaMaximX2/ZaMaximX2Plugin.hpp b/plugins/ZaMaximX2/ZaMaximX2Plugin.hpp
index c5b1782..feff4f5 100644
--- a/plugins/ZaMaximX2/ZaMaximX2Plugin.hpp
+++ b/plugins/ZaMaximX2/ZaMaximX2Plugin.hpp
@@ -121,10 +121,12 @@ protected:
private:
float release,ceiling,thresdb,gainred,outlevel;//parameters
- int posz[2];
+ int pose[2], posz[2], posc[2];
+ double cn[2][MAX_SAMPLES];
+ double emaxn[2][MAX_SAMPLES];
double z[2][MAX_SAMPLES];
- double smoothold[2];
- double envold[2];
+ double emax_old[2];
+ double eavg_old[2];
};
// -----------------------------------------------------------------------
diff --git a/plugins/ZaMaximX2/ZaMaximX2UI.cpp b/plugins/ZaMaximX2/ZaMaximX2UI.cpp
index 03e6150..d62378f 100644
--- a/plugins/ZaMaximX2/ZaMaximX2UI.cpp
+++ b/plugins/ZaMaximX2/ZaMaximX2UI.cpp
@@ -47,9 +47,9 @@ ZaMaximX2UI::ZaMaximX2UI()
fKnobRelease = new ImageKnob(this, knobImage);
fKnobRelease->setAbsolutePos(27, 46);
fKnobRelease->setId(ZaMaximX2Plugin::paramRelease);
- fKnobRelease->setRange(1.0f, 500.0f);
+ fKnobRelease->setRange(1.0f, 100.0f);
fKnobRelease->setStep(1.0f);
- fKnobRelease->setDefault(150.0f);
+ fKnobRelease->setDefault(25.0f);
fKnobRelease->setRotationAngle(240);
fKnobRelease->setCallback(this);
@@ -67,7 +67,7 @@ ZaMaximX2UI::ZaMaximX2UI()
fKnobCeiling->setId(ZaMaximX2Plugin::paramCeiling);
fKnobCeiling->setRange(-30.0f, 0.0f);
fKnobCeiling->setStep(0.1f);
- fKnobCeiling->setDefault(-0.5f);
+ fKnobCeiling->setDefault(-3.0f);
fKnobCeiling->setRotationAngle(240);
fKnobCeiling->setCallback(this);
@@ -112,9 +112,9 @@ void ZaMaximX2UI::programLoaded(uint32_t index)
{
switch(index) {
case 0:
- fKnobRelease->setValue(150.0f);
+ fKnobRelease->setValue(1.0f);
fKnobThresh->setValue(0.0f);
- fKnobCeiling->setValue(-0.5f);
+ fKnobCeiling->setValue(-6.0f);
break;
}
}