aboutsummaryrefslogtreecommitdiffstats
path: root/src/mdaOverdrive.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/mdaOverdrive.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/mdaOverdrive.cpp')
-rw-r--r--src/mdaOverdrive.cpp180
1 files changed, 180 insertions, 0 deletions
diff --git a/src/mdaOverdrive.cpp b/src/mdaOverdrive.cpp
new file mode 100644
index 0000000..ee72611
--- /dev/null
+++ b/src/mdaOverdrive.cpp
@@ -0,0 +1,180 @@
+#include "mdaOverdrive.h"
+
+#include <math.h>
+
+
+AudioEffect *createEffectInstance(audioMasterCallback audioMaster)
+{
+ return new mdaOverdrive(audioMaster);
+}
+
+mdaOverdrive::mdaOverdrive(audioMasterCallback audioMaster) : AudioEffectX(audioMaster, 1, 3) // 1 program, 3 parameters
+{
+ fParam1 = 0.0f;
+ fParam2 = 0.0f;
+ fParam3 = 0.5f;
+
+ setNumInputs(2);
+ setNumOutputs(2);
+ setUniqueID("mdaO"); // identify
+ DECLARE_LVZ_DEPRECATED(canMono) ();
+ canProcessReplacing();
+ strcpy(programName, "Soft Overdrive");
+
+ filt1 = filt2 = 0.0f;
+ setParameter(0, 0.0f);
+}
+
+mdaOverdrive::~mdaOverdrive()
+{
+
+}
+
+bool mdaOverdrive::getProductString(char* text) { strcpy(text, "mda Overdrive"); return true; }
+bool mdaOverdrive::getVendorString(char* text) { strcpy(text, "mda"); return true; }
+bool mdaOverdrive::getEffectName(char* name) { strcpy(name, "Overdrive"); return true; }
+
+void mdaOverdrive::setProgramName(char *name)
+{
+ strcpy(programName, name);
+}
+
+void mdaOverdrive::getProgramName(char *name)
+{
+ strcpy(name, programName);
+}
+
+void mdaOverdrive::setParameter(LvzInt32 index, float value)
+{
+ switch(index)
+ {
+ case 0: fParam1 = value; break;
+ case 1: fParam2 = value; break;
+ case 2: fParam3 = value; break;
+ }
+ filt = (float)pow(10.0,-1.6 * fParam2);
+ gain = (float)pow(10.0f, 2.0f * fParam3 - 1.0f);
+}
+
+float mdaOverdrive::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 mdaOverdrive::getParameterName(LvzInt32 index, char *label)
+{
+ switch(index)
+ {
+ case 0: strcpy(label, "Drive "); break;
+ case 1: strcpy(label, "Muffle "); break;
+ case 2: strcpy(label, "Output "); break;
+ }
+}
+
+#include <stdio.h>
+void long2string(long value, char *string) { sprintf(string, "%ld", value); }
+
+void mdaOverdrive::getParameterDisplay(LvzInt32 index, char *text)
+{
+ switch(index)
+ {
+ case 0: long2string((long)(100 * fParam1 ), text); break;
+ case 1: long2string((long)(100 * fParam2 ), text); break;
+ case 2: long2string((long)( 40 * fParam3 - 20), text); break;
+ }
+
+}
+
+void mdaOverdrive::getParameterLabel(LvzInt32 index, char *label)
+{
+ switch(index)
+ {
+ case 0: strcpy(label, "%"); break;
+ case 1: strcpy(label, "%"); break;
+ case 2: strcpy(label, "dB"); break;
+ }
+}
+
+//--------------------------------------------------------------------------------
+// process
+
+void mdaOverdrive::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 i=fParam1, g=gain, aa, bb;
+ float f=filt, fa=filt1, fb=filt2;
+
+ --in1;
+ --in2;
+ --out1;
+ --out2;
+ while(--sampleFrames >= 0)
+ {
+ a = *++in1;
+ b = *++in2;
+
+ c = out1[1];
+ d = out2[1];
+
+ aa = (a>0.0f)? (float)sqrt(a) : (float)-sqrt(-a); //overdrive
+ bb = (b>0.0f)? (float)sqrt(b) : (float)-sqrt(-b);
+
+ fa = fa + f * (i*(aa-a) + a - fa); //filter
+ fb = fb + f * (i*(bb-b) + b - fb);
+
+ c += fa * g;
+ d += fb * g;
+
+ *++out1 = c;
+ *++out2 = d;
+ }
+ if(fabs(fa)>1.0e-10) filt1 = fa; else filt1 = 0.0f; //catch denormals
+ if(fabs(fb)>1.0e-10) filt2 = fb; else filt2 = 0.0f;
+}
+
+void mdaOverdrive::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, c, d;
+ float i=fParam1, g=gain, aa, bb;
+ float f=filt, fa=filt1, fb=filt2;
+
+ --in1;
+ --in2;
+ --out1;
+ --out2;
+ while(--sampleFrames >= 0)
+ {
+ a = *++in1;
+ b = *++in2;
+
+ aa = (a>0.0f)? (float)sqrt(a) : (float)-sqrt(-a); //overdrive
+ bb = (b>0.0f)? (float)sqrt(b) : (float)-sqrt(-b);
+
+ fa = fa + f * (i*(aa-a) + a - fa); //filter
+ fb = fb + f * (i*(bb-b) + b - fb);
+
+ c = fa * g;
+ d = fb * g;
+
+ *++out1 = c;
+ *++out2 = d;
+ }
+ if(fabs(fa)>1.0e-10) filt1 = fa; else filt1 = 0.0f; //catch denormals
+ if(fabs(fb)>1.0e-10) filt2 = fb; else filt2 = 0.0f;
+}