diff options
Diffstat (limited to 'src/mdaBeatBox.cpp')
-rw-r--r-- | src/mdaBeatBox.cpp | 138 |
1 files changed, 69 insertions, 69 deletions
diff --git a/src/mdaBeatBox.cpp b/src/mdaBeatBox.cpp index a4ca550..69ac090 100644 --- a/src/mdaBeatBox.cpp +++ b/src/mdaBeatBox.cpp @@ -13,14 +13,14 @@ mdaBeatBox::mdaBeatBox(audioMasterCallback audioMaster) : AudioEffectX(audioMast fParam1 = 0.30f; //hat thresh fParam2 = 0.45f; //hat rate fParam3 = 0.50f; //hat mix - fParam4 = 0.46f; //kick thresh + fParam4 = 0.46f; //kick thresh fParam5 = 0.15f; //kick key fParam6 = 0.50f; //kick mix fParam7 = 0.50f; //snare thresh fParam8 = 0.70f; //snare key fParam9 = 0.50f; //snare mix fParam10 = 0.00f; //dynamics - fParam11 = 0.00f; //record + fParam11 = 0.00f; //record fParam12 = 0.00f; //thru mix hbuflen = 20000; @@ -35,7 +35,7 @@ mdaBeatBox::mdaBeatBox(audioMasterCallback audioMaster) : AudioEffectX(audioMast setNumInputs(2); // stereo in setNumOutputs(2); // stereo out setUniqueID("mdaBBox"); // identify - DECLARE_LVZ_DEPRECATED(canMono) (); + DECLARE_LVZ_DEPRECATED(canMono) (); canProcessReplacing(); // supports both accumulating and replacing output strcpy(programName, "BeatBox - Drum Replacer"); // default program name synth(); @@ -51,7 +51,7 @@ mdaBeatBox::mdaBeatBox(audioMasterCallback audioMaster) : AudioEffectX(audioMast hlev = (float)(0.0001f + fParam3 * fParam3 * 4.f); klev = (float)(0.0001f + fParam6 * fParam6 * 4.f); slev = (float)(0.0001f + fParam9 * fParam9 * 4.f); - + kww = (float)pow(10.0,-3.0 + 2.2 * fParam5); ksf1 = (float)cos(3.1415927 * kww); //p ksf2 = (float)sin(3.1415927 * kww); //q @@ -109,7 +109,7 @@ void mdaBeatBox::setParameter(LvzInt32 index, float value) hlev = (float)(0.0001f + fParam3 * fParam3 * 4.f); klev = (float)(0.0001f + fParam6 * fParam6 * 4.f); slev = (float)(0.0001f + fParam9 * fParam9 * 4.f); - + wwx=ww; ww = (float)pow(10.0,-3.0 + 2.2 * fParam8); sf1 = (float)cos(3.1415927 * ww); //p @@ -121,17 +121,17 @@ void mdaBeatBox::setParameter(LvzInt32 index, float value) ksf1 = (float)cos(3.1415927 * kww); //p ksf2 = (float)sin(3.1415927 * kww); //q - if(wwx != ww) sfx = (long)(2 * getSampleRate()); + if(wwx != ww) sfx = (long)(2 * getSampleRate()); if(kwwx != kww) ksfx = (long)(2 * getSampleRate()); - - rec = (long)(4.9 * fParam11); + + rec = (long)(4.9 * fParam11); if ((rec!=recx) && (recpos>0)) //finish sample { switch(rec) { case 2: while(recpos<hbuflen) *(hbuf + recpos++) = 0.f; break; case 3: while(recpos<kbuflen) *(kbuf + recpos++) = 0.f; break; - case 4: while(recpos<sbuflen) { *(sbuf + recpos) = 0.f; + case 4: while(recpos<sbuflen) { *(sbuf + recpos) = 0.f; *(sbuf2 + recpos) = 0.f; recpos++; } break; } } @@ -154,34 +154,34 @@ void mdaBeatBox::suspend() void mdaBeatBox::synth() { - long t; - float e=0.00012f, de, o, o1=0.f, o2=0.f, p=0.2f, dp; + long t; + float e=0.00012f, de, o, o1=0.f, o2=0.f, p=0.2f, dp; memset(hbuf, 0, hbuflen * sizeof(float)); //generate hi-hat de = (float)pow(10.0,-36.0/getSampleRate()); - for(t=0;t<5000;t++) - { - o = (float)((rand() % 2000) - 1000); - *(hbuf + t) = e * ( 2.f * o1 - o2 - o); + for(t=0;t<5000;t++) + { + o = (float)((rand() % 2000) - 1000); + *(hbuf + t) = e * ( 2.f * o1 - o2 - o); e *= de; o2=o1; o1=o; } memset(kbuf, 0, kbuflen * sizeof(float)); //generate kick de = (float)pow(10.0,-3.8/getSampleRate()); e=0.5f; dp = 1588.f / getSampleRate(); - for(t=0;t<14000;t++) - { - *(kbuf + t) = e * (float)sin(p); + for(t=0;t<14000;t++) + { + *(kbuf + t) = e * (float)sin(p); e *= de; p = (float)fmod(p + dp * e ,6.2831853f); } memset(sbuf, 0, sbuflen * sizeof(float)); //generate snare de = (float)pow(10.0,-15.0/getSampleRate()); e=0.38f; dp = 1103.f / getSampleRate(); - for(t=0;t<7000;t++) - { - o = (0.3f * o) + (float)((rand() % 2000) - 1000); - *(sbuf + t) = (float)(e * (sin(p) + 0.0004 * o)); + for(t=0;t<7000;t++) + { + o = (0.3f * o) + (float)((rand() % 2000) - 1000); + *(sbuf + t) = (float)(e * (sin(p) + 0.0004 * o)); *(sbuf2 + t) = *(sbuf + t); e *= de; p = (float)fmod(p + 0.025,6.2831853); } @@ -245,10 +245,10 @@ void mdaBeatBox::getParameterDisplay(LvzInt32 index, char *text) case 6: float2strng((float)(40.0*fParam7 - 40.0),text); break; case 7: long2string((long)(0.5 * ww * getSampleRate()), text); break; case 8: long2string((long)(20.f * log10(slev)),text); break; - case 9: long2string((long)(100.f * fParam10),text); break; + case 9: long2string((long)(100.f * fParam10),text); break; case 11: long2string((long)(20.f * log10(fParam12)),text); break; - case 10: switch(rec) + case 10: switch(rec) { case 0: strcpy(text, "-"); break; case 1: strcpy(text, "MONITOR"); break; case 2: strcpy(text, "-> HAT"); break; @@ -263,16 +263,16 @@ void mdaBeatBox::getParameterLabel(LvzInt32 index, char *label) { case 0: strcpy(label, "dB"); break; case 1: strcpy(label, "ms"); break; - case 2: strcpy(label, "dB"); break; - case 3: strcpy(label, "dB"); break; - case 4: strcpy(label, "Hz"); break; - case 5: strcpy(label, "dB"); break; - case 6: strcpy(label, "dB"); break; + case 2: strcpy(label, "dB"); break; + case 3: strcpy(label, "dB"); break; + case 4: strcpy(label, "Hz"); break; + case 5: strcpy(label, "dB"); break; + case 6: strcpy(label, "dB"); break; case 7: strcpy(label, "Hz"); break; case 8: strcpy(label, "dB"); break; - case 9: strcpy(label, "%"); break; - case 10:strcpy(label, ""); break; - case 11:strcpy(label, "dB"); break; + case 9: strcpy(label, "%"); break; + case 10:strcpy(label, ""); break; + case 11:strcpy(label, "dB"); break; } } @@ -288,19 +288,19 @@ void mdaBeatBox::process(float **inputs, float **outputs, LvzInt32 sampleFrames) float a, b, c, d, e, o, hf=hfil, ht=hthr, mx3=0.f, mx1=mix; long hp=hbufpos, hl=hbuflen-2, hd=hdel; float kt=kthr; - long kp=kbufpos, kl=kbuflen-2, kd=kdel; + long kp=kbufpos, kl=kbuflen-2, kd=kdel; float st=sthr, s, f1=sb1, f2=sb2, b1=sf1, b2=sf2, b3=sf3; float k, kf1=ksb1, kf2=ksb2, kb1=ksf1, kb2=ksf2; - float hlv=hlev, klv=klev, slv=slev; - long sp=sbufpos, sl=sbuflen-2, sd=sdel; + float hlv=hlev, klv=klev, slv=slev; + long sp=sbufpos, sl=sbuflen-2, sd=sdel; float ya=dyna, yr=dynr, ye=dyne, ym=dynm, mx4; - + if(sfx>0) { mx3=0.08f; slv=0.f; klv=0.f; hlv=0.f; mx1=0.f; sfx-=sampleFrames;} //key listen (snare) if(ksfx>0) { mx3=0.03f; slv=0.f; klv=0.f; hlv=0.f; mx1=0.f; ksfx-=sampleFrames; b1=ksf1; b2=ksf2; } //key listen (kick) - --in1; - --in2; + --in1; + --in2; --out1; --out2; @@ -311,7 +311,7 @@ void mdaBeatBox::process(float **inputs, float **outputs, LvzInt32 sampleFrames) a = *++in1; //input b = *++in2; e = a + b; - + ye = (e<ye)? ye * yr : e - ya * (e - ye); //dynamics envelope hf = e - hf; //high @@ -319,13 +319,13 @@ void mdaBeatBox::process(float **inputs, float **outputs, LvzInt32 sampleFrames) o = hlv * *(hbuf + hp); k = e + (kf1 * kb1) - (kf2 * kb2); - kf2 = b3 * ((kf1 * kb2) + (kf2 * kb1)); + kf2 = b3 * ((kf1 * kb2) + (kf2 * kb1)); kf1 = b3 * k; if((kp>kd) && (k>kt)) kp=0; else { kp++; if(kp>kl)kp=kl; } o += klv * *(kbuf + kp); - + s = hf + (0.3f * e) + (f1 * b1) - (f2 * b2); - f2 = b3 * ((f1 * b2) + (f2 * b1)); + f2 = b3 * ((f1 * b2) + (f2 * b1)); f1 = b3 * s; if((sp>sd) && (s>st)) sp=0; else { sp++; if(sp>sl)sp=sl; } @@ -334,8 +334,8 @@ void mdaBeatBox::process(float **inputs, float **outputs, LvzInt32 sampleFrames) c = out1[1] + mx1*a + mx3*s + mx4*(o + slv * *(sbuf + sp)); d = out2[1] + mx1*b + mx3*s + mx4*(o + slv * *(sbuf2 + sp)); - *++out1 = c; - *++out2 = d; + *++out1 = c; + *++out2 = d; hf=e; } @@ -344,28 +344,28 @@ void mdaBeatBox::process(float **inputs, float **outputs, LvzInt32 sampleFrames) { while(--sampleFrames >= 0) { - + a = *++in1; b = *++in2; e = 0.5f * (a + b); if((recpos==0) && (fabs(e) < 0.004)) e=0.f; - else - { + else + { switch(rec) { case 1: break; //echo case 2: if(recpos<hl) *(hbuf + recpos++) = e; else e=0.f; break; case 3: if(recpos<kl) *(kbuf + recpos++) = e; else e=0.f; break; - case 4: if(recpos<sl) + case 4: if(recpos<sl) { *(sbuf+recpos)=a; *(sbuf2+recpos)=b; recpos++; } else e=0.f; break; } } c = out1[1] + e; d = out2[1] + e; - *++out1 = c; - *++out2 = d; + *++out1 = c; + *++out2 = d; } } hfil=hf; hbufpos=hp; @@ -383,19 +383,19 @@ void mdaBeatBox::processReplacing(float **inputs, float **outputs, LvzInt32 samp float a, b, e, o, hf=hfil, ht=hthr, mx3=0.f, mx1=mix; long hp=hbufpos, hl=hbuflen-2, hd=hdel; float kt=kthr; - long kp=kbufpos, kl=kbuflen-2, kd=kdel; + long kp=kbufpos, kl=kbuflen-2, kd=kdel; float st=sthr, s, f1=sb1, f2=sb2, b1=sf1, b2=sf2, b3=sf3; float k, kf1=ksb1, kf2=ksb2, kb1=ksf1, kb2=ksf2; - float hlv=hlev, klv=klev, slv=slev; - long sp=sbufpos, sl=sbuflen-2, sd=sdel; + float hlv=hlev, klv=klev, slv=slev; + long sp=sbufpos, sl=sbuflen-2, sd=sdel; float ya=dyna, yr=dynr, ye=dyne, ym=dynm, mx4; if(sfx>0) { mx3=0.08f; slv=0.f; klv=0.f; hlv=0.f; mx1=0.f; sfx-=sampleFrames;} //key listen (snare) if(ksfx>0) { mx3=0.03f; slv=0.f; klv=0.f; hlv=0.f; mx1=0.f; ksfx-=sampleFrames; b1=ksf1; b2=ksf2; } //key listen (kick) - --in1; - --in2; + --in1; + --in2; --out1; --out2; @@ -406,29 +406,29 @@ void mdaBeatBox::processReplacing(float **inputs, float **outputs, LvzInt32 samp a = *++in1; b = *++in2; e = a + b; - + ye = (e<ye)? ye * yr : e - ya * (e - ye); //dynamics envelope hf = e - hf; //high filter if((hp>hd) && (hf>ht)) hp=0; else { hp++; if(hp>hl)hp=hl; } o = hlv * *(hbuf + hp); //hat - + k = e + (kf1 * kb1) - (kf2 * kb2); //low filter - kf2 = b3 * ((kf1 * kb2) + (kf2 * kb1)); + kf2 = b3 * ((kf1 * kb2) + (kf2 * kb1)); kf1 = b3 * k; if((kp>kd) && (k>kt)) kp=0; else { kp++; if(kp>kl)kp=kl; } o += klv * *(kbuf + kp); //kick - + s = hf + (0.3f * e) + (f1 * b1) - (f2 * b2); //mid filter - f2 = b3 * ((f1 * b2) + (f2 * b1)); + f2 = b3 * ((f1 * b2) + (f2 * b1)); f1 = b3 * s; if((sp>sd) && (s>st)) sp=0; else { sp++; if(sp>sl)sp=sl; } - + mx4 = 1.f + ym * (ye + ye - 1.f); //dynamics - *++out1 = mx1*a + mx3*s + mx4*(o + slv * *(sbuf + sp)); - *++out2 = mx1*a + mx3*s + mx4*(o + slv * *(sbuf2 + sp)); + *++out1 = mx1*a + mx3*s + mx4*(o + slv * *(sbuf + sp)); + *++out2 = mx1*a + mx3*s + mx4*(o + slv * *(sbuf2 + sp)); hf=e; } @@ -442,23 +442,23 @@ void mdaBeatBox::processReplacing(float **inputs, float **outputs, LvzInt32 samp e = 0.5f * (a + b); if((recpos==0) && (fabs(e) < 0.004)) e=0.f; - else - { + else + { switch(rec) { case 1: break; //echo case 2: if(recpos<hl) *(hbuf + recpos++) = e; else e=0.f; break; case 3: if(recpos<kl) *(kbuf + recpos++) = e; else e=0.f; break; - case 4: if(recpos<sl) + case 4: if(recpos<sl) { *(sbuf+recpos)=a; *(sbuf2+recpos)=b; recpos++; } else e=0.f; break; } } - *++out1 = e; - *++out2 = e; + *++out1 = e; + *++out2 = e; } } - hfil=hf; hbufpos=hp; + hfil=hf; hbufpos=hp; sbufpos=sp; sb1 = f1; sb2 = f2; kbufpos=kp; ksb1 = kf1; ksb2 = kf2; dyne=ye; |