// // Plug-in: "MDA Template" v1.0 // // Copyright(c)1999-2000 Paul Kellett (maxim digital audio) // #include "mdaDetune.h" #include #include #include #include AudioEffect *createEffectInstance(audioMasterCallback audioMaster) { return new mdaDetune(audioMaster); } bool mdaDetune::getProductString(char* text) { strcpy(text, "mda Detune"); return true; } bool mdaDetune::getVendorString(char* text) { strcpy(text, "mda"); return true; } bool mdaDetune::getEffectName(char* name) { strcpy(name, "Detune"); return true; } mdaDetune::mdaDetune(audioMasterCallback audioMaster): AudioEffectX(audioMaster, NPROGS, NPARAMS) { setNumInputs(2); setNumOutputs(2); setUniqueID("mdaDetune"); ///identify mdaDetune-in here DECLARE_LVZ_DEPRECATED(canMono) (); canProcessReplacing(); ///initialise... buflen=0; programs[0].param[0] = 0.20f; //fine programs[0].param[1] = 0.90f; //mix programs[0].param[2] = 0.50f; //output programs[0].param[3] = 0.50f; //chunksize strcpy(programs[0].name, "Stereo Detune"); programs[1].param[0] = 0.20f; programs[1].param[1] = 0.90f; programs[1].param[2] = 0.50f; programs[1].param[3] = 0.50f; strcpy(programs[1].name,"Symphonic"); programs[2].param[0] = 0.8f; programs[2].param[1] = 0.7f; programs[2].param[2] = 0.50f; programs[2].param[3] = 0.50f; strcpy(programs[2].name,"Out Of Tune"); setProgram(0); suspend(); } void mdaDetune::resume() ///update internal parameters... { float * param = programs[curProgram].param; semi = 3.0f * param[0] * param[0] * param[0]; dpos2 = (float)pow(1.0594631f, semi); dpos1 = 1.0f / dpos2; wet = (float)pow(10.0f, 2.0f * param[2] - 1.0f); dry = wet - wet * param[1] * param[1]; wet = (wet + wet - wet * param[1]) * param[1]; LvzInt32 tmp = 1 << (8 + (LvzInt32)(4.9f * param[3])); if(tmp!=buflen) //recalculate crossfade window { buflen = tmp; if (buflen > BUFMAX) buflen = BUFMAX; bufres = 1000.0f * (float)buflen / getSampleRate(); LvzInt32 i; //hanning half-overlap-and-add double p=0.0, dp=6.28318530718/buflen; for(i=0;i>1; float lf = (float)buflen; --in1; --in2; --out1; --out2; while(--sampleFrames >= 0) { a = *++in1; b = *++in2; c = out1[1]; d = out2[1]; c += y * a; d += y * b; --p0 &= l; *(buf + p0) = w * (a + b); //input p1 -= d1; if(p1<0.0f) p1 += lf; //output p1i = (LvzInt32)p1; p1f = p1 - (float)p1i; a = *(buf + p1i); ++p1i &= l; a += p1f * (*(buf + p1i) - a); //linear interpolation p2i = (p1i + lh) & l; //180-degree ouptut b = *(buf + p2i); ++p2i &= l; b += p1f * (*(buf + p2i) - b); //linear interpolation p2i = (p1i - p0) & l; //crossfade window x = *(win + p2i); //++p2i &= l; //x += p1f * (*(win + p2i) - x); //linear interpolation (doesn't do much) c += b + x * (a - b); p2 -= d2; //repeat for downwards shift - can't see a more efficient way? if(p2<0.0f) p2 += lf; //output p1i = (LvzInt32)p2; p1f = p2 - (float)p1i; a = *(buf + p1i); ++p1i &= l; a += p1f * (*(buf + p1i) - a); //linear interpolation p2i = (p1i + lh) & l; //180-degree ouptut b = *(buf + p2i); ++p2i &= l; b += p1f * (*(buf + p2i) - b); //linear interpolation p2i = (p1i - p0) & l; //crossfade window x = *(win + p2i); //++p2i &= l; //x += p1f * (*(win + p2i) - x); //linear interpolation (doesn't do much) d += b + x * (a - b); *++out1 = c; *++out2 = d; } pos0=p0; pos1=p1; pos2=p2; } void mdaDetune::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 x, w=wet, y=dry, p1=pos1, p1f, d1=dpos1; float p2=pos2, d2=dpos2; LvzInt32 p0=pos0, p1i, p2i; LvzInt32 l=buflen-1, lh=buflen>>1; float lf = (float)buflen; --in1; --in2; --out1; --out2; while(--sampleFrames >= 0) //had to disable optimization /Og in MSVC++5! { a = *++in1; b = *++in2; c = y * a; d = y * b; --p0 &= l; *(buf + p0) = w * (a + b); //input p1 -= d1; if(p1<0.0f) p1 += lf; //output p1i = (LvzInt32)p1; p1f = p1 - (float)p1i; a = *(buf + p1i); ++p1i &= l; a += p1f * (*(buf + p1i) - a); //linear interpolation p2i = (p1i + lh) & l; //180-degree ouptut b = *(buf + p2i); ++p2i &= l; b += p1f * (*(buf + p2i) - b); //linear interpolation p2i = (p1i - p0) & l; //crossfade x = *(win + p2i); //++p2i &= l; //x += p1f * (*(win + p2i) - x); //linear interpolation (doesn't do much) c += b + x * (a - b); p2 -= d2; //repeat for downwards shift - can't see a more efficient way? if(p2<0.0f) p2 += lf; //output p1i = (LvzInt32)p2; p1f = p2 - (float)p1i; a = *(buf + p1i); ++p1i &= l; a += p1f * (*(buf + p1i) - a); //linear interpolation p2i = (p1i + lh) & l; //180-degree ouptut b = *(buf + p2i); ++p2i &= l; b += p1f * (*(buf + p2i) - b); //linear interpolation p2i = (p1i - p0) & l; //crossfade x = *(win + p2i); //++p2i &= l; //x += p1f * (*(win + p2i) - x); //linear interpolation (doesn't do much) d += b + x * (a - b); *++out1 = c; *++out2 = d; } pos0=p0; pos1=p1; pos2=p2; }