aboutsummaryrefslogtreecommitdiffstats
path: root/src/mdaDeEss.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2008-08-08 22:45:58 +0000
committerDavid Robillard <d@drobilla.net>2008-08-08 22:45:58 +0000
commite360047054117d63fb579ec9231e9dc77c99f12a (patch)
tree4a497365f6ecd30449e2c66c1fe77c816bd1fe4a /src/mdaDeEss.cpp
downloadmda.lv2-e360047054117d63fb579ec9231e9dc77c99f12a.tar.gz
mda.lv2-e360047054117d63fb579ec9231e9dc77c99f12a.tar.bz2
mda.lv2-e360047054117d63fb579ec9231e9dc77c99f12a.zip
Add preliminary (library side only) LV2 port of MDA (open-sourced VST plugins).
git-svn-id: http://svn.drobilla.net/lad/mda-lv2@1321 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/mdaDeEss.cpp')
-rw-r--r--src/mdaDeEss.cpp183
1 files changed, 183 insertions, 0 deletions
diff --git a/src/mdaDeEss.cpp b/src/mdaDeEss.cpp
new file mode 100644
index 0000000..4a84dd9
--- /dev/null
+++ b/src/mdaDeEss.cpp
@@ -0,0 +1,183 @@
+#include "mdaDeEss.h"
+
+#include <math.h>
+#include <float.h>
+
+AudioEffect *createEffectInstance(audioMasterCallback audioMaster)
+{
+ return new mdaDeEss(audioMaster);
+}
+
+mdaDeEss::mdaDeEss(audioMasterCallback audioMaster) : AudioEffectX(audioMaster, 1, 3) // programs, parameters
+{
+ //inits here!
+ fParam1 = (float)0.15f; //thresh
+ fParam2 = (float)0.60f; //f
+ fParam3 = (float)0.50f; //drive
+ setNumInputs(2);
+ setNumOutputs(2);
+ setUniqueID("mdas"); //identify here
+ DECLARE_LVZ_DEPRECATED(canMono) ();
+ canProcessReplacing();
+ strcpy(programName, "De-esser");
+
+ env=0.f;
+ setParameter(0, 0.5f);
+}
+
+bool mdaDeEss::getProductString(char* text) { strcpy(text, "mda De-ess"); return true; }
+bool mdaDeEss::getVendorString(char* text) { strcpy(text, "mda"); return true; }
+bool mdaDeEss::getEffectName(char* name) { strcpy(name, "De-ess"); return true; }
+
+void mdaDeEss::setParameter(LvzInt32 index, float value)
+{
+ switch(index)
+ {
+ case 0: fParam1 = value; break;
+ case 1: fParam2 = value; break;
+ case 2: fParam3 = value; break;
+ }
+ //calcs here
+ thr=(float)pow(10.0f, 3.f * fParam1 - 3.f);
+ att=0.01f;
+ rel=0.992f;
+ fil=0.05f + 0.94f * fParam2 * fParam2;
+ gai=(float)pow(10.0f, 2.f * fParam3 - 1.f);
+}
+
+mdaDeEss::~mdaDeEss()
+{
+}
+
+void mdaDeEss::setProgramName(char *name)
+{
+ strcpy(programName, name);
+}
+
+void mdaDeEss::getProgramName(char *name)
+{
+ strcpy(name, programName);
+}
+
+float mdaDeEss::getParameter(LvzInt32 index)
+{
+ float v=0;
+
+ switch(index)
+ {
+ case 0: v = fParam1; break;
+ case 1: v = fParam2; break;
+ case 2: v = fParam3; break;
+ }
+ return v;
+}
+
+void mdaDeEss::getParameterName(LvzInt32 index, char *label)
+{
+ switch(index)
+ {
+ case 0: strcpy(label, "Thresh"); break;
+ case 1: strcpy(label, "Freq"); break;
+ case 2: strcpy(label, "HF Drive"); break;
+ }
+}
+
+#include <stdio.h>
+void long2string(long value, char *string) { sprintf(string, "%ld", value); }
+
+void mdaDeEss::getParameterDisplay(LvzInt32 index, char *text)
+{
+ switch(index)
+ {
+ case 0: long2string((long)(60.f * fParam1 - 60.f), text); break;
+ case 1: long2string((long)(1000 + 11000 * fParam2), text); break;
+ case 2: long2string((long)(40.0 * fParam3 - 20.0), text); break;
+ }
+}
+
+void mdaDeEss::getParameterLabel(LvzInt32 index, char *label)
+{
+ switch(index)
+ {
+ case 0: strcpy(label, "dB"); break;
+ case 1: strcpy(label, "Hz"); break;
+ case 2: strcpy(label, "dB"); break;
+ }
+}
+
+//--------------------------------------------------------------------------------
+// process
+
+void mdaDeEss::process(float **inputs, float **outputs, LvzInt32 sampleFrames)
+{
+ float *in1 = inputs[0];
+ float *in2 = inputs[1];
+ float *out1 = outputs[0];
+ float *out2 = outputs[1];
+ float a, b, c, d;
+ float f1=fbuf1, f2=fbuf2, tmp, fi=fil, fo=(1.f-fil);
+ float at=att, re=rel, en=env, th=thr, g, gg=gai;
+
+ --in1;
+ --in2;
+ --out1;
+ --out2;
+ while(--sampleFrames >= 0)
+ {
+ a = *++in1;
+ b = *++in2;
+ c = out1[1];
+ d = out2[1];
+
+ tmp = 0.5f * (a + b); //2nd order crossover
+ f1 = fo * f1 + fi * tmp;
+ tmp -= f1;
+ f2 = fo * f2 + fi * tmp;
+ tmp = gg*(tmp - f2); //extra HF gain
+
+ en=(tmp>en)? en+at*(tmp-en) : en*re; //envelope
+ if(en>th) g=f1+f2+tmp*(th/en); else g=f1+f2+tmp; //limit
+
+ c += g;
+ d += g;
+ *++out1 = c;
+ *++out2 = d;
+ }
+ if(fabs(f1)<1.0e-10) {fbuf1=0.f; fbuf2=0.f;} else {fbuf1=f1; fbuf2=f2;}
+ if(fabs(en)<1.0e-10) env=0.f; else env=en;
+}
+
+void mdaDeEss::processReplacing(float **inputs, float **outputs, LvzInt32 sampleFrames)
+{
+ float *in1 = inputs[0];
+ float *in2 = inputs[1];
+ float *out1 = outputs[0];
+ float *out2 = outputs[1];
+ float a, b;
+ float f1=fbuf1, f2=fbuf2, tmp, fi=fil, fo=(1.f-fil);
+ float at=att, re=rel, en=env, th=thr, g, gg=gai;
+
+ --in1;
+ --in2;
+ --out1;
+ --out2;
+ while(--sampleFrames >= 0)
+ {
+ a = *++in1;
+ b = *++in2;
+
+ tmp = 0.5f * (a + b); //2nd order crossover
+ f1 = fo * f1 + fi * tmp;
+ tmp -= f1;
+ f2 = fo * f2 + fi * tmp;
+ tmp = gg*(tmp - f2); //extra HF gain
+
+ en=(tmp>en)? en+at*(tmp-en) : en*re; //envelope
+ if(en>th) g=f1+f2+tmp*(th/en); else g=f1+f2+tmp; //limit
+ //brackets for full-band!!!
+ *++out1 = g;
+ *++out2 = g;
+ }
+ if(fabs(f1)<1.0e-10) {fbuf1=0.f; fbuf2=0.f;} else {fbuf1=f1; fbuf2=f2;}
+ if(fabs(en)<1.0e-10) env=0.f; else env=en;
+}