diff options
author | Robert Jonsson <spamatica@gmail.com> | 2009-12-27 11:30:35 +0000 |
---|---|---|
committer | Robert Jonsson <spamatica@gmail.com> | 2009-12-27 11:30:35 +0000 |
commit | b703eab295330e6f81564fbb39a10a1a2fdd2f54 (patch) | |
tree | e46b5c9a6bc22fd661c15d1d2123f5bf631cef80 /muse_qt4_evolution/synti/zynaddsubfx/Effects | |
parent | 5d5fa0fdf913907edbc3d2d29a7548f0cb658c94 (diff) |
moved old qt4 branch
Diffstat (limited to 'muse_qt4_evolution/synti/zynaddsubfx/Effects')
22 files changed, 3604 insertions, 0 deletions
diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/Alienwah.C b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Alienwah.C new file mode 100644 index 00000000..8d2475d2 --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Alienwah.C @@ -0,0 +1,244 @@ +/* + ZynAddSubFX - a software synthesizer + + Alienwah.C - "AlienWah" effect + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#include <math.h> +#include "Alienwah.h" +#include <stdio.h> + +Alienwah::Alienwah(int insertion_,REALTYPE *efxoutl_,REALTYPE *efxoutr_){ + efxoutl=efxoutl_; + efxoutr=efxoutr_; + + oldl=NULL; + oldr=NULL; + filterpars=NULL; + insertion=insertion_; + + Ppreset=0; + setpreset(Ppreset); + cleanup(); + oldclfol.a=fb;oldclfol.b=0.0; + oldclfor.a=fb;oldclfor.b=0.0; +}; + +Alienwah::~Alienwah(){ + if (oldl!=NULL) delete [] oldl; + if (oldr!=NULL) delete [] oldr ; +}; + + +/* + * Apply the effect + */ +void Alienwah::out(REALTYPE *smpsl,REALTYPE *smpsr){ + int i; + REALTYPE lfol,lfor; + COMPLEXTYPE clfol,clfor,out,tmp; + + lfo.effectlfoout(&lfol,&lfor); + lfol*=depth*PI*2.0;lfor*=depth*PI*2.0; + clfol.a=cos(lfol+phase)*fb;clfol.b=sin(lfol+phase)*fb; + clfor.a=cos(lfor+phase)*fb;clfor.b=sin(lfor+phase)*fb; + + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + REALTYPE x=((REALTYPE) i)/SOUND_BUFFER_SIZE; + REALTYPE x1=1.0-x; + //left + tmp.a=clfol.a*x+oldclfol.a*x1; + tmp.b=clfol.b*x+oldclfol.b*x1; + + out.a=tmp.a*oldl[oldk].a-tmp.b*oldl[oldk].b + +(1-fabs(fb))*smpsl[i]*panning; + out.b=tmp.a*oldl[oldk].b+tmp.b*oldl[oldk].a; + oldl[oldk].a=out.a; + oldl[oldk].b=out.b; + REALTYPE l=out.a*10.0*(fb+0.1); + + //right + tmp.a=clfor.a*x+oldclfor.a*x1; + tmp.b=clfor.b*x+oldclfor.b*x1; + + out.a=tmp.a*oldr[oldk].a-tmp.b*oldr[oldk].b + +(1-fabs(fb))*smpsr[i]*(1.0-panning); + out.b=tmp.a*oldr[oldk].b+tmp.b*oldr[oldk].a; + oldr[oldk].a=out.a; + oldr[oldk].b=out.b; + REALTYPE r=out.a*10.0*(fb+0.1); + + + if (++oldk>=Pdelay) oldk=0; + //LRcross + efxoutl[i]=l*(1.0-lrcross)+r*lrcross; + efxoutr[i]=r*(1.0-lrcross)+l*lrcross; + }; + + oldclfol.a=clfol.a;oldclfol.b=clfol.b; + oldclfor.a=clfor.a;oldclfor.b=clfor.b; + +}; + +/* + * Cleanup the effect + */ +void Alienwah::cleanup(){ + for (int i=0;i<Pdelay;i++) { + oldl[i].a=0.0; + oldl[i].b=0.0; + oldr[i].a=0.0; + oldr[i].b=0.0; + }; + oldk=0; +}; + + +/* + * Parameter control + */ + +void Alienwah::setdepth(unsigned char Pdepth){ + this->Pdepth=Pdepth; + depth=(Pdepth/127.0); +}; + +void Alienwah::setfb(unsigned char Pfb){ + this->Pfb=Pfb; + fb=fabs((Pfb-64.0)/64.1); + fb=sqrt(fb); + if (fb<0.4) fb=0.4; + if (Pfb<64) fb=-fb; +}; + +void Alienwah::setvolume(unsigned char Pvolume){ + this->Pvolume=Pvolume; + outvolume=Pvolume/127.0; + if (insertion==0) volume=1.0; + else volume=outvolume; +}; + +void Alienwah::setpanning(unsigned char Ppanning){ + this->Ppanning=Ppanning; + panning=Ppanning/127.0; +}; + +void Alienwah::setlrcross(unsigned char Plrcross){ + this->Plrcross=Plrcross; + lrcross=Plrcross/127.0; +}; + +void Alienwah::setphase(unsigned char Pphase){ + this->Pphase=Pphase; + phase=(Pphase-64.0)/64.0*PI; +}; + +void Alienwah::setdelay(unsigned char Pdelay){ + if (oldl!=NULL) delete [] oldl; + if (oldr!=NULL) delete [] oldr; + if (Pdelay>=MAX_ALIENWAH_DELAY) Pdelay=MAX_ALIENWAH_DELAY; + this->Pdelay=Pdelay; + oldl=new COMPLEXTYPE[Pdelay]; + oldr=new COMPLEXTYPE[Pdelay]; + cleanup(); +}; + +void Alienwah::setpreset(unsigned char npreset){ + const int PRESET_SIZE=11; + const int NUM_PRESETS=4; + unsigned char presets[NUM_PRESETS][PRESET_SIZE]={ + //AlienWah1 + {127,64,70,0,0,62,60,105,25,0,64}, + //AlienWah2 + {127,64,73,106,0,101,60,105,17,0,64}, + //AlienWah3 + {127,64,63,0,1,100,112,105,31,0,42}, + //AlienWah4 + {93,64,25,0,1,66,101,11,47,0,86}}; + + if (npreset>=NUM_PRESETS) npreset=NUM_PRESETS-1; + for (int n=0;n<PRESET_SIZE;n++) changepar(n,presets[npreset][n]); + if (insertion==0) changepar(0,presets[npreset][0]/2);//lower the volume if this is system effect + Ppreset=npreset; +}; + + +void Alienwah::changepar(int npar,unsigned char value){ + switch(npar){ + case 0: setvolume(value); + break; + case 1: setpanning(value); + break; + case 2: lfo.Pfreq=value; + lfo.updateparams(); + break; + case 3: lfo.Prandomness=value; + lfo.updateparams(); + break; + case 4: lfo.PLFOtype=value; + lfo.updateparams(); + break; + case 5: lfo.Pstereo=value; + lfo.updateparams(); + break; + case 6: setdepth(value); + break; + case 7: setfb(value); + break; + case 8: setdelay(value); + break; + case 9: setlrcross(value); + break; + case 10:setphase(value); + break; + }; +}; + +unsigned char Alienwah::getpar(int npar){ + switch (npar){ + case 0: return(Pvolume); + break; + case 1: return(Ppanning); + break; + case 2: return(lfo.Pfreq); + break; + case 3: return(lfo.Prandomness); + break; + case 4: return(lfo.PLFOtype); + break; + case 5: return(lfo.Pstereo); + break; + case 6: return(Pdepth); + break; + case 7: return(Pfb); + break; + case 8: return(Pdelay); + break; + case 9: return(Plrcross); + break; + case 10:return(Pphase); + break; + default:return (0); + }; + +}; + + + + diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/Alienwah.h b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Alienwah.h new file mode 100644 index 00000000..b1bfaedc --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Alienwah.h @@ -0,0 +1,77 @@ +/* + ZynAddSubFX - a software synthesizer + + Alienwah.h - "AlienWah" effect + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#ifndef ALIENWAH_H +#define ALIENWAH_H +#include "../globals.h" +#include "Effect.h" +#include "EffectLFO.h" + + +#define MAX_ALIENWAH_DELAY 100 + +struct COMPLEXTYPE { + REALTYPE a,b; +}; + +class Alienwah:public Effect { + public: + Alienwah(int insetion_,REALTYPE *efxoutl_,REALTYPE *efxoutr_); + ~Alienwah(); + void out(REALTYPE *smpsl,REALTYPE *smpsr); + + void setpreset(unsigned char npreset); + void changepar(int npar,unsigned char value); + unsigned char getpar(int npar); + void cleanup(); + + private: + //Parametrii Alienwah + EffectLFO lfo;//lfo-ul Alienwah + unsigned char Pvolume; + unsigned char Ppanning; + unsigned char Pdepth;//the depth of the Alienwah + unsigned char Pfb;//feedback + unsigned char Plrcross;//feedback + unsigned char Pdelay; + unsigned char Pphase; + + + //Control Parametrii + void setvolume(unsigned char Pvolume); + void setpanning(unsigned char Ppanning); + void setdepth(unsigned char Pdepth); + void setfb(unsigned char Pfb); + void setlrcross(unsigned char Plrcross); + void setdelay(unsigned char Pdelay); + void setphase(unsigned char Pphase); + + //Valorile interne + int insertion; + REALTYPE panning,fb,depth,lrcross,phase; + COMPLEXTYPE *oldl,*oldr; + COMPLEXTYPE oldclfol,oldclfor; + int oldk; +}; + +#endif + diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/Chorus.C b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Chorus.C new file mode 100644 index 00000000..fb40c93b --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Chorus.C @@ -0,0 +1,277 @@ +/* + ZynAddSubFX - a software synthesizer + + Chorus.C - Chorus and Flange effects + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#include <math.h> +#include "Chorus.h" +#include <stdio.h> + +Chorus::Chorus(int insertion_,REALTYPE *efxoutl_,REALTYPE *efxoutr_){ + efxoutl=efxoutl_; + efxoutr=efxoutr_; + dlk=0;drk=0; + maxdelay=(int)(MAX_CHORUS_DELAY/1000.0*SAMPLE_RATE); + delayl=new REALTYPE[maxdelay]; + delayr=new REALTYPE[maxdelay]; + insertion=insertion_; + + filterpars=NULL; + Ppreset=0; + setpreset(Ppreset); + + lfo.effectlfoout(&lfol,&lfor); + dl2=getdelay(lfol); + dr2=getdelay(lfor); + cleanup(); +}; + +Chorus::~Chorus(){ + delete [] delayl; + delete [] delayr; +}; + +/* + * get the delay value in samples; xlfo is the current lfo value + */ +REALTYPE Chorus::getdelay(REALTYPE xlfo){ + REALTYPE result; + if (Pflangemode==0){ + result=(delay+xlfo*depth)*SAMPLE_RATE; + } else result=0; + + //check if it is too big delay(caused bu errornous setdelay() and setdepth() + if ((result+0.5)>=maxdelay) { + fprintf(stderr,"%s","WARNING: Chorus.C::getdelay(..) too big delay (see setdelay and setdepth funcs.)\n"); + result=maxdelay-1.0; + }; + return(result); +}; + +/* + * Apply the effect + */ +void Chorus::out(REALTYPE *smpsl,REALTYPE *smpsr){ + int i; + dl1=dl2;dr1=dr2; + lfo.effectlfoout(&lfol,&lfor); + + dl2=getdelay(lfol); + dr2=getdelay(lfor); + + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + REALTYPE inl=smpsl[i]; + REALTYPE inr=smpsr[i]; + //LRcross + REALTYPE l=inl; + REALTYPE r=inr; + inl=l*(1.0-lrcross)+r*lrcross; + inr=r*(1.0-lrcross)+l*lrcross; + + //Left channel + + //compute the delay in samples using linear interpolation between the lfo delays + mdel=(dl1*(SOUND_BUFFER_SIZE-i)+dl2*i)/SOUND_BUFFER_SIZE; + if (++dlk>=maxdelay) dlk=0; + REALTYPE tmp=dlk-mdel+maxdelay*2.0;//where should I get the sample from + + F2I(tmp,dlhi); + dlhi%=maxdelay; + + dlhi2=(dlhi-1+maxdelay)%maxdelay; + dllo=1.0-fmod(tmp,1.0); + efxoutl[i]=delayl[dlhi2]*dllo+delayl[dlhi]*(1.0-dllo); + delayl[dlk]=inl+efxoutl[i]*fb; + + //Right channel + + //compute the delay in samples using linear interpolation between the lfo delays + mdel=(dr1*(SOUND_BUFFER_SIZE-i)+dr2*i)/SOUND_BUFFER_SIZE; + if (++drk>=maxdelay) drk=0; + tmp=drk-mdel+maxdelay*2.0;//where should I get the sample from + + F2I(tmp,dlhi); + dlhi%=maxdelay; + + dlhi2=(dlhi-1+maxdelay)%maxdelay; + dllo=1.0-fmod(tmp,1.0); + efxoutr[i]=delayr[dlhi2]*dllo+delayr[dlhi]*(1.0-dllo); + delayr[dlk]=inr+efxoutr[i]*fb; + + }; + + if (Poutsub!=0) + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + efxoutl[i] *= -1.0; + efxoutr[i] *= -1.0; + }; + + + for (int i=0;i<SOUND_BUFFER_SIZE;i++){ + efxoutl[i]*=panning; + efxoutr[i]*=(1.0-panning); + }; +}; + +/* + * Cleanup the effect + */ +void Chorus::cleanup(){ + for (int i=0;i<maxdelay;i++){ + delayl[i]=0.0; + delayr[i]=0.0; + }; + +}; + +/* + * Parameter control + */ +void Chorus::setdepth(unsigned char Pdepth){ + this->Pdepth=Pdepth; + depth=(pow(8.0,(Pdepth/127.0)*2.0)-1.0)/1000.0;//seconds +}; + +void Chorus::setdelay(unsigned char Pdelay){ + this->Pdelay=Pdelay; + delay=(pow(10.0,(Pdelay/127.0)*2.0)-1.0)/1000.0;//seconds +}; + +void Chorus::setfb(unsigned char Pfb){ + this->Pfb=Pfb; + fb=(Pfb-64.0)/64.1; +}; +void Chorus::setvolume(unsigned char Pvolume){ + this->Pvolume=Pvolume; + outvolume=Pvolume/127.0; + if (insertion==0) volume=1.0; + else volume=outvolume; +}; + +void Chorus::setpanning(unsigned char Ppanning){ + this->Ppanning=Ppanning; + panning=Ppanning/127.0; +}; + +void Chorus::setlrcross(unsigned char Plrcross){ + this->Plrcross=Plrcross; + lrcross=Plrcross/127.0; +}; + +void Chorus::setpreset(unsigned char npreset){ + const int PRESET_SIZE=12; + const int NUM_PRESETS=10; + unsigned char presets[NUM_PRESETS][PRESET_SIZE]={ + //Chorus1 + {64,64,50,0,0,90,40,85,64,119,0,0}, + //Chorus2 + {64,64,45,0,0,98,56,90,64,19,0,0}, + //Chorus3 + {64,64,29,0,1,42,97,95,90,127,0,0}, + //Celeste1 + {64,64,26,0,0,42,115,18,90,127,0,0}, + //Celeste2 + {64,64,29,117,0,50,115,9,31,127,0,1}, + //Flange1 + {64,64,57,0,0,60,23,3,62,0,0,0}, + //Flange2 + {64,64,33,34,1,40,35,3,109,0,0,0}, + //Flange3 + {64,64,53,34,1,94,35,3,54,0,0,1}, + //Flange4 + {64,64,40,0,1,62,12,19,97,0,0,0}, + //Flange5 + {64,64,55,105,0,24,39,19,17,0,0,1}}; + + if (npreset>=NUM_PRESETS) npreset=NUM_PRESETS-1; + for (int n=0;n<PRESET_SIZE;n++) changepar(n,presets[npreset][n]); + Ppreset=npreset; +}; + + +void Chorus::changepar(int npar,unsigned char value){ + switch(npar){ + case 0: setvolume(value); + break; + case 1: setpanning(value); + break; + case 2: lfo.Pfreq=value; + lfo.updateparams(); + break; + case 3: lfo.Prandomness=value; + lfo.updateparams(); + break; + case 4: lfo.PLFOtype=value; + lfo.updateparams(); + break; + case 5: lfo.Pstereo=value; + lfo.updateparams(); + break; + case 6: setdepth(value); + break; + case 7: setdelay(value); + break; + case 8: setfb(value); + break; + case 9: setlrcross(value); + break; + case 10:if (value>1) value=1; + Pflangemode=value; + break; + case 11:if (value>1) value=1; + Poutsub=value; + break; + }; +}; + +unsigned char Chorus::getpar(int npar){ + switch (npar){ + case 0: return(Pvolume); + break; + case 1: return(Ppanning); + break; + case 2: return(lfo.Pfreq); + break; + case 3: return(lfo.Prandomness); + break; + case 4: return(lfo.PLFOtype); + break; + case 5: return(lfo.Pstereo); + break; + case 6: return(Pdepth); + break; + case 7: return(Pdelay); + break; + case 8: return(Pfb); + break; + case 9: return(Plrcross); + break; + case 10:return(Pflangemode); + break; + case 11:return(Poutsub); + break; + default:return (0); + }; + +}; + + + + diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/Chorus.h b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Chorus.h new file mode 100644 index 00000000..25e2ec34 --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Chorus.h @@ -0,0 +1,73 @@ +/* + ZynAddSubFX - a software synthesizer + + Chorus.h - Chorus and Flange effects + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#ifndef CHORUS_H +#define CHORUS_H +#include "../globals.h" +#include "Effect.h" +#include "EffectLFO.h" + +#define MAX_CHORUS_DELAY 250.0 //ms + +class Chorus:public Effect { + public: + Chorus(int insetion_,REALTYPE *efxoutl_,REALTYPE *efxoutr_); + ~Chorus(); + void out(REALTYPE *smpsl,REALTYPE *smpsr); + void setpreset(unsigned char npreset); + void changepar(int npar,unsigned char value); + unsigned char getpar(int npar); + void cleanup(); + + private: + //Parametrii Chorus + EffectLFO lfo;//lfo-ul chorus + unsigned char Pvolume; + unsigned char Ppanning; + unsigned char Pdepth;//the depth of the Chorus(ms) + unsigned char Pdelay;//the delay (ms) + unsigned char Pfb;//feedback + unsigned char Plrcross;//feedback + unsigned char Pflangemode;//how the LFO is scaled, to result chorus or flange + unsigned char Poutsub;//if I wish to substract the output instead of the adding it + + + //Control Parametrii + void setvolume(unsigned char Pvolume); + void setpanning(unsigned char Ppanning); + void setdepth(unsigned char Pdepth); + void setdelay(unsigned char Pdelay); + void setfb(unsigned char Pfb); + void setlrcross(unsigned char Plrcross); + + //Valorile interne + REALTYPE depth,delay,fb,lrcross,panning; + REALTYPE dl1,dl2,dr1,dr2,lfol,lfor; + int insertion,maxdelay; + REALTYPE *delayl,*delayr; + int dlk,drk,dlhi,dlhi2; + REALTYPE getdelay(REALTYPE xlfo); + REALTYPE dllo,mdel; +}; + +#endif + diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/Distorsion.C b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Distorsion.C new file mode 100644 index 00000000..fa1b1163 --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Distorsion.C @@ -0,0 +1,384 @@ +/* + ZynAddSubFX - a software synthesizer + + Distorsion.C - Distorsion effect + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include "Distorsion.h" + + +/* + * Waveshape (this is called by OscilGen::waveshape and Distorsion::process) + */ + +void waveshapesmps(int n,REALTYPE *smps,unsigned char type,unsigned char drive){ + int i; + REALTYPE ws=drive/127.0; + REALTYPE tmpv; + + switch(type){ + case 1: ws=pow(10,ws*ws*3.0)-1.0+0.001;//Arctangent + for (i=0;i<n;i++) + smps[i]=atan(smps[i]*ws)/atan(ws); + break; + case 2: ws=ws*ws*32.0+0.0001;//Asymmetric + if (ws<1.0) tmpv=sin(ws)+0.1; + else tmpv=1.1; + for (i=0;i<n;i++) { + smps[i]=sin(smps[i]*(0.1+ws-ws*smps[i]))/tmpv; + }; + break; + case 3: ws=ws*ws*ws*20.0+0.0001;//Pow + for (i=0;i<n;i++) { + smps[i]*=ws; + if (fabs(smps[i])<1.0) { + smps[i]=(smps[i]-pow(smps[i],3.0))*3.0; + if (ws<1.0) smps[i]/=ws; + } else smps[i]=0.0; + }; + break; + case 4: ws=ws*ws*ws*32.0+0.0001;//Sine + if (ws<1.57) tmpv=sin(ws); + else tmpv=1.0; + for (i=0;i<n;i++) smps[i]=sin(smps[i]*ws)/tmpv; + break; + case 5: ws=ws*ws+0.000001;//Quantisize + for (i=0;i<n;i++) + smps[i]=floor(smps[i]/ws+0.5)*ws; + break; + case 6: ws=ws*ws*ws*32+0.0001;//Zigzag + if (ws<1.0) tmpv=sin(ws); + else tmpv=1.0; + for (i=0;i<n;i++) + smps[i]=asin(sin(smps[i]*ws))/tmpv; + break; + case 7: ws=pow(2.0,-ws*ws*8.0); //Limiter + for (i=0;i<n;i++) { + REALTYPE tmp=smps[i]; + if (fabs(tmp)>ws) { + if (tmp>=0.0) smps[i]=1.0; + else smps[i]=-1.0; + } else smps[i]/=ws; + }; + break; + case 8: ws=pow(2.0,-ws*ws*8.0); //Upper Limiter + for (i=0;i<n;i++) { + REALTYPE tmp=smps[i]; + if (tmp>ws) smps[i]=ws; + smps[i]*=2.0; + }; + break; + case 9: ws=pow(2.0,-ws*ws*8.0); //Lower Limiter + for (i=0;i<n;i++) { + REALTYPE tmp=smps[i]; + if (tmp<-ws) smps[i]=-ws; + smps[i]*=2.0; + }; + break; + case 10:ws=(pow(2.0,ws*6.0)-1.0)/pow(2.0,6.0); //Inverse Limiter + for (i=0;i<n;i++) { + REALTYPE tmp=smps[i]; + if (fabs(tmp)>ws) { + if (tmp>=0.0) smps[i]=tmp-ws; + else smps[i]=tmp+ws; + } else smps[i]=0; + }; + break; + case 11:ws=pow(5,ws*ws*1.0)-1.0;//Clip + for (i=0;i<n;i++) + smps[i]=smps[i]*(ws+0.5)*0.9999-floor(0.5+smps[i]*(ws+0.5)*0.9999); + break; + case 12:ws=ws*ws*ws*30+0.001;//Asym2 + if (ws<0.3) tmpv=ws; + else tmpv=1.0; + for (i=0;i<n;i++) { + REALTYPE tmp=smps[i]*ws; + if ((tmp>-2.0) && (tmp<1.0)) smps[i]=tmp*(1.0-tmp)*(tmp+2.0)/tmpv; + else smps[i]=0.0; + }; + break; + case 13:ws=ws*ws*ws*32.0+0.0001;//Pow2 + if (ws<1.0) tmpv=ws*(1+ws)/2.0; + else tmpv=1.0; + for (i=0;i<n;i++) { + REALTYPE tmp=smps[i]*ws; + if ((tmp>-1.0)&&(tmp<1.618034)) smps[i]=tmp*(1.0-tmp)/tmpv; + else if (tmp>0.0) smps[i]=-1.0; + else smps[i]=-2.0; + }; + break; + case 14:ws=pow(ws,5.0)*80.0+0.0001;//sigmoid + if (ws>10.0) tmpv=0.5; + else tmpv=0.5-1.0/(exp(ws)+1.0); + for (i=0;i<n;i++) { + REALTYPE tmp=smps[i]*ws; + if (tmp<-10.0) tmp=-10.0; + else if (tmp>10.0) tmp=10.0; + tmp=0.5-1.0/(exp(tmp)+1.0); + smps[i]=tmp/tmpv; + }; + break; + //update to Distorsion::changepar (Ptype max) if there is added more waveshapings functions + }; + +}; + + +Distorsion::Distorsion(int insertion_,REALTYPE *efxoutl_,REALTYPE *efxoutr_){ + efxoutl=efxoutl_; + efxoutr=efxoutr_; + + lpfl=new AnalogFilter(2,22000,1,0); + lpfr=new AnalogFilter(2,22000,1,0); + hpfl=new AnalogFilter(3,20,1,0); + hpfr=new AnalogFilter(3,20,1,0); + + filterpars=NULL; + + insertion=insertion_; + //default values + Ppreset=0; + Pvolume=50; + Plrcross=40; + Pdrive=90; + Plevel=64; + Ptype=0; + Pnegate=0; + Plpf=127; + Phpf=0; + Pstereo=0; + Pprefiltering=0; + + setpreset(Ppreset); + cleanup(); +}; + +Distorsion::~Distorsion(){ + delete (lpfl); + delete (lpfr); + delete (hpfl); + delete (hpfr); + +}; + +/* + * Cleanup the effect + */ +void Distorsion::cleanup(){ + lpfl->cleanup(); + hpfl->cleanup(); + lpfr->cleanup(); + hpfr->cleanup(); +}; + + +/* + * Apply the filters + */ + +void Distorsion::applyfilters(REALTYPE *efxoutl,REALTYPE *efxoutr){ + lpfl->filterout(efxoutl); + hpfl->filterout(efxoutl); + if (Pstereo!=0){//stereo + lpfr->filterout(efxoutr); + hpfr->filterout(efxoutr); + }; + +}; + + +/* + * Effect output + */ +void Distorsion::out(REALTYPE *smpsl,REALTYPE *smpsr){ + int i; + REALTYPE l,r,lout,rout; + + REALTYPE inputvol=pow(5.0,(Pdrive-32.0)/127.0); + if (Pnegate!=0) inputvol*=-1.0; + + if (Pstereo!=0){//Stereo + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + efxoutl[i]=smpsl[i]*inputvol*panning; + efxoutr[i]=smpsr[i]*inputvol*(1.0-panning); + }; + } else { + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + efxoutl[i]=( smpsl[i]*panning + smpsr[i]*(1.0-panning) ) * inputvol; + }; + }; + + if (Pprefiltering!=0) applyfilters(efxoutl,efxoutr); + + //no optimised, yet (no look table) + waveshapesmps(SOUND_BUFFER_SIZE,efxoutl,Ptype+1,Pdrive); + if (Pstereo!=0) waveshapesmps(SOUND_BUFFER_SIZE,efxoutr,Ptype+1,Pdrive); + + if (Pprefiltering==0) applyfilters(efxoutl,efxoutr); + + if (Pstereo==0) for (i=0;i<SOUND_BUFFER_SIZE;i++) efxoutr[i]=efxoutl[i]; + + REALTYPE level=dB2rap(60.0*Plevel/127.0-40.0); + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + lout=efxoutl[i]; + rout=efxoutr[i]; + l=lout*(1.0-lrcross)+rout*lrcross; + r=rout*(1.0-lrcross)+lout*lrcross; + lout=l;rout=r; + + efxoutl[i]=lout*2.0*level; + efxoutr[i]=rout*2.0*level; + + }; + +}; + + +/* + * Parameter control + */ +void Distorsion::setvolume(unsigned char Pvolume){ + this->Pvolume=Pvolume; + + if (insertion==0) { + outvolume=pow(0.01,(1.0-Pvolume/127.0))*4.0; + volume=1.0; + } else { + volume=outvolume=Pvolume/127.0; + }; + if (Pvolume==0) cleanup(); + +}; + +void Distorsion::setpanning(unsigned char Ppanning){ + this->Ppanning=Ppanning; + panning=(Ppanning+0.5)/127.0; +}; + + +void Distorsion::setlrcross(unsigned char Plrcross){ + this->Plrcross=Plrcross; + lrcross=Plrcross/127.0*1.0; +}; + +void Distorsion::setlpf(unsigned char Plpf){ + this->Plpf=Plpf; + REALTYPE fr=exp(pow(Plpf/127.0,0.5)*log(25000.0))+40; + lpfl->setfreq(fr); + lpfr->setfreq(fr); +}; + +void Distorsion::sethpf(unsigned char Phpf){ + this->Phpf=Phpf; + REALTYPE fr=exp(pow(Phpf/127.0,0.5)*log(25000.0))+20.0; + hpfl->setfreq(fr); + hpfr->setfreq(fr); +}; + + +void Distorsion::setpreset(unsigned char npreset){ + const int PRESET_SIZE=11; + const int NUM_PRESETS=6; + unsigned char presets[NUM_PRESETS][PRESET_SIZE]={ + //Overdrive 1 + {127,64,35,56,70,0,0,96,0,0,0}, + //Overdrive 2 + {127,64,35,29,75,1,0,127,0,0,0}, + //A. Exciter 1 + {64,64,35,75,80,5,0,127,105,1,0}, + //A. Exciter 2 + {64,64,35,85,62,1,0,127,118,1,0}, + //Guitar Amp + {127,64,35,63,75,2,0,55,0,0,0}, + //Quantisize + {127,64,35,88,75,4,0,127,0,1,0}}; + + + if (npreset>=NUM_PRESETS) npreset=NUM_PRESETS-1; + for (int n=0;n<PRESET_SIZE;n++) changepar(n,presets[npreset][n]); + if (insertion==0) changepar(0,(int) (presets[npreset][0]/1.5));//lower the volume if this is system effect + Ppreset=npreset; + cleanup(); +}; + + +void Distorsion::changepar(int npar,unsigned char value){ + switch (npar){ + case 0: setvolume(value); + break; + case 1: setpanning(value); + break; + case 2: setlrcross(value); + break; + case 3: Pdrive=value; + break; + case 4: Plevel=value; + break; + case 5: if (value>13) value=13;//this must be increased if more distorsion types are added + Ptype=value; + break; + case 6: if (value>1) value=1; + Pnegate=value; + break; + case 7: setlpf(value); + break; + case 8: sethpf(value); + break; + case 9: if (value>1) value=1; + Pstereo=value; + break; + case 10:Pprefiltering=value; + break; + }; +}; + +unsigned char Distorsion::getpar(int npar){ + switch (npar){ + case 0: return(Pvolume); + break; + case 1: return(Ppanning); + break; + case 2: return(Plrcross); + break; + case 3: return(Pdrive); + break; + case 4: return(Plevel); + break; + case 5: return(Ptype); + break; + case 6: return(Pnegate); + break; + case 7: return(Plpf); + break; + case 8: return(Phpf); + break; + case 9: return(Pstereo); + break; + case 10:return(Pprefiltering); + break; + }; + return(0);//in case of bogus parameter number +}; + + + + diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/Distorsion.h b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Distorsion.h new file mode 100644 index 00000000..5e0aba93 --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Distorsion.h @@ -0,0 +1,73 @@ +/* + ZynAddSubFX - a software synthesizer + + Distorsion.h - Distorsion Effect + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#ifndef DISTORSION_H +#define DISTORSION_H + +#include "../globals.h" +#include "../DSP/AnalogFilter.h" +#include "Effect.h" + +//Waveshaping(called by Distorsion effect and waveshape from OscilGen) +void waveshapesmps(int n,REALTYPE *smps,unsigned char type,unsigned char drive); + +class Distorsion:public Effect{ + public: + Distorsion(int insertion,REALTYPE *efxoutl_,REALTYPE *efxoutr_); + ~Distorsion(); + void out(REALTYPE *smpsl,REALTYPE *smpr); + void setpreset(unsigned char npreset); + void changepar(int npar,unsigned char value); + unsigned char getpar(int npar); + void cleanup(); + void applyfilters(REALTYPE *efxoutl,REALTYPE *efxoutr); + + private: + //Parametrii + unsigned char Pvolume; //Volumul or E/R + unsigned char Ppanning;//Panning + unsigned char Plrcross;// L/R Mixing + unsigned char Pdrive; //the input amplification + unsigned char Plevel; //the ouput amplification + unsigned char Ptype; //Distorsion type + unsigned char Pnegate; //if the input is negated + unsigned char Plpf; //lowpass filter + unsigned char Phpf; //highpass filter + unsigned char Pstereo; //0=mono,1=stereo + unsigned char Pprefiltering;//if you want to do the filtering before the distorsion + + void setvolume(unsigned char Pvolume); + void setpanning(unsigned char Ppanning); + void setlrcross(unsigned char Plrcross); + void setlpf(unsigned char Plpf); + void sethpf(unsigned char Phpf); + + //Parametrii reali + REALTYPE panning,lrcross; + AnalogFilter *lpfl,*lpfr,*hpfl,*hpfr; + +}; + + +#endif + + diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/DynamicFilter.C b/muse_qt4_evolution/synti/zynaddsubfx/Effects/DynamicFilter.C new file mode 100644 index 00000000..a86794f0 --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/DynamicFilter.C @@ -0,0 +1,318 @@ +/* + ZynAddSubFX - a software synthesizer + + DynamicFilter.C - "WahWah" effect and others + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#include <math.h> +#include "DynamicFilter.h" +#include <stdio.h> + +DynamicFilter::DynamicFilter(int insertion_,REALTYPE *efxoutl_,REALTYPE *efxoutr_){ + efxoutl=efxoutl_; + efxoutr=efxoutr_; + + insertion=insertion_; + + Ppreset=0; + filterl=NULL; + filterr=NULL; + filterpars=new FilterParams(0,64,64); + setpreset(Ppreset); + cleanup(); +}; + +DynamicFilter::~DynamicFilter(){ + delete(filterpars); + delete(filterl); + delete(filterr); +}; + + +/* + * Apply the effect + */ +void DynamicFilter::out(REALTYPE *smpsl,REALTYPE *smpsr){ + int i; + if (filterpars->changed){ + filterpars->changed=false; + cleanup(); + }; + + REALTYPE lfol,lfor; + lfo.effectlfoout(&lfol,&lfor); + lfol*=depth*5.0;lfor*=depth*5.0; + REALTYPE freq=filterpars->getfreq(); + REALTYPE q=filterpars->getq(); + + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + efxoutl[i]=smpsl[i]; + efxoutr[i]=smpsr[i]; + + REALTYPE x=(fabs(smpsl[i])+fabs(smpsr[i]))*0.5; + ms1=ms1*(1.0-ampsmooth)+x*ampsmooth+1e-10; + }; + + + REALTYPE ampsmooth2=pow(ampsmooth,0.2)*0.3; + ms2=ms2*(1.0-ampsmooth2)+ms1*ampsmooth2; + ms3=ms3*(1.0-ampsmooth2)+ms2*ampsmooth2; + ms4=ms4*(1.0-ampsmooth2)+ms3*ampsmooth2; + REALTYPE rms=(sqrt(ms4))*ampsns; + + REALTYPE frl=filterl->getrealfreq(freq+lfol+rms); + REALTYPE frr=filterr->getrealfreq(freq+lfor+rms); + + filterl->setfreq_and_q(frl,q); + filterr->setfreq_and_q(frr,q); + + + filterl->filterout(efxoutl); + filterr->filterout(efxoutr); + + //panning + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + efxoutl[i]*=panning; + efxoutr[i]*=(1.0-panning); + }; + +}; + +/* + * Cleanup the effect + */ +void DynamicFilter::cleanup(){ + reinitfilter(); + ms1=0.0; + ms2=0.0; + ms3=0.0; + ms4=0.0; +}; + + +/* + * Parameter control + */ + +void DynamicFilter::setdepth(unsigned char Pdepth){ + this->Pdepth=Pdepth; + depth=pow((Pdepth/127.0),2.0); +}; + + +void DynamicFilter::setvolume(unsigned char Pvolume){ + this->Pvolume=Pvolume; + outvolume=Pvolume/127.0; + if (insertion==0) volume=1.0; + else volume=outvolume; +}; + +void DynamicFilter::setpanning(unsigned char Ppanning){ + this->Ppanning=Ppanning; + panning=Ppanning/127.0; +}; + + +void DynamicFilter::setampsns(unsigned char Pampsns){ + ampsns=pow(Pampsns/127.0,2.5)*10.0; + if (Pampsnsinv!=0) ampsns=-ampsns; + ampsmooth=exp(-Pampsmooth/127.0*10.0)*0.99; + this->Pampsns=Pampsns; +}; + +void DynamicFilter::reinitfilter(){ + if (filterl!=NULL) delete(filterl); + if (filterr!=NULL) delete(filterr); + filterl=new Filter(filterpars); + filterr=new Filter(filterpars); +}; + +void DynamicFilter::setpreset(unsigned char npreset){ + const int PRESET_SIZE=10; + const int NUM_PRESETS=5; + unsigned char presets[NUM_PRESETS][PRESET_SIZE]={ + //WahWah + {110,64,80,0,0,64,0,90,0,60}, + //AutoWah + {110,64,70,0,0,80,70,0,0,60}, + //Sweep + {100,64,30,0,0,50,80,0,0,60}, + //VocalMorph1 + {110,64,80,0,0,64,0,64,0,60}, + //VocalMorph1 + {127,64,50,0,0,96,64,0,0,60}}; + + if (npreset>=NUM_PRESETS) npreset=NUM_PRESETS-1; + for (int n=0;n<PRESET_SIZE;n++) changepar(n,presets[npreset][n]); + + filterpars->defaults(); + switch(npreset){ + case 0: + filterpars->Pcategory=0; + filterpars->Ptype=2; + filterpars->Pfreq=45; + filterpars->Pq=64; + filterpars->Pstages=1; + filterpars->Pgain=64; + break; + case 1: + filterpars->Pcategory=2; + filterpars->Ptype=0; + filterpars->Pfreq=72; + filterpars->Pq=64; + filterpars->Pstages=0; + filterpars->Pgain=64; + break; + case 2: + filterpars->Pcategory=0; + filterpars->Ptype=4; + filterpars->Pfreq=64; + filterpars->Pq=64; + filterpars->Pstages=2; + filterpars->Pgain=64; + break; + case 3: + filterpars->Pcategory=1; + filterpars->Ptype=0; + filterpars->Pfreq=50; + filterpars->Pq=70; + filterpars->Pstages=1; + filterpars->Pgain=64; + + filterpars->Psequencesize=2; + // "I" + filterpars->Pvowels[0].formants[0].freq=34; + filterpars->Pvowels[0].formants[0].amp=127; + filterpars->Pvowels[0].formants[0].q=64; + filterpars->Pvowels[0].formants[1].freq=99; + filterpars->Pvowels[0].formants[1].amp=122; + filterpars->Pvowels[0].formants[1].q=64; + filterpars->Pvowels[0].formants[2].freq=108; + filterpars->Pvowels[0].formants[2].amp=112; + filterpars->Pvowels[0].formants[2].q=64; + // "A" + filterpars->Pvowels[1].formants[0].freq=61; + filterpars->Pvowels[1].formants[0].amp=127; + filterpars->Pvowels[1].formants[0].q=64; + filterpars->Pvowels[1].formants[1].freq=71; + filterpars->Pvowels[1].formants[1].amp=121; + filterpars->Pvowels[1].formants[1].q=64; + filterpars->Pvowels[1].formants[2].freq=99; + filterpars->Pvowels[1].formants[2].amp=117; + filterpars->Pvowels[1].formants[2].q=64; + break; + case 4: + filterpars->Pcategory=1; + filterpars->Ptype=0; + filterpars->Pfreq=64; + filterpars->Pq=70; + filterpars->Pstages=1; + filterpars->Pgain=64; + + filterpars->Psequencesize=2; + filterpars->Pnumformants=2; + filterpars->Pvowelclearness=0; + + filterpars->Pvowels[0].formants[0].freq=70; + filterpars->Pvowels[0].formants[0].amp=127; + filterpars->Pvowels[0].formants[0].q=64; + filterpars->Pvowels[0].formants[1].freq=80; + filterpars->Pvowels[0].formants[1].amp=122; + filterpars->Pvowels[0].formants[1].q=64; + + filterpars->Pvowels[1].formants[0].freq=20; + filterpars->Pvowels[1].formants[0].amp=127; + filterpars->Pvowels[1].formants[0].q=64; + filterpars->Pvowels[1].formants[1].freq=100; + filterpars->Pvowels[1].formants[1].amp=121; + filterpars->Pvowels[1].formants[1].q=64; + break; + }; + +// for (int i=0;i<5;i++){ +// printf("freq=%d amp=%d q=%d\n",filterpars->Pvowels[0].formants[i].freq,filterpars->Pvowels[0].formants[i].amp,filterpars->Pvowels[0].formants[i].q); +// }; + if (insertion==0) changepar(0,presets[npreset][0]/2);//lower the volume if this is system effect + Ppreset=npreset; + + reinitfilter(); +}; + + +void DynamicFilter::changepar(int npar,unsigned char value){ + switch(npar){ + case 0: setvolume(value); + break; + case 1: setpanning(value); + break; + case 2: lfo.Pfreq=value; + lfo.updateparams(); + break; + case 3: lfo.Prandomness=value; + lfo.updateparams(); + break; + case 4: lfo.PLFOtype=value; + lfo.updateparams(); + break; + case 5: lfo.Pstereo=value; + lfo.updateparams(); + break; + case 6: setdepth(value); + break; + case 7: setampsns(value); + break; + case 8: Pampsnsinv=value; + setampsns(Pampsns); + break; + case 9: Pampsmooth=value; + setampsns(Pampsns); + break; + }; +}; + +unsigned char DynamicFilter::getpar(int npar){ + switch (npar){ + case 0: return(Pvolume); + break; + case 1: return(Ppanning); + break; + case 2: return(lfo.Pfreq); + break; + case 3: return(lfo.Prandomness); + break; + case 4: return(lfo.PLFOtype); + break; + case 5: return(lfo.Pstereo); + break; + case 6: return(Pdepth); + break; + case 7: return(Pampsns); + break; + case 8: return(Pampsnsinv); + break; + case 9: return(Pampsmooth); + break; + default:return (0); + }; + +}; + + + + diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/DynamicFilter.h b/muse_qt4_evolution/synti/zynaddsubfx/Effects/DynamicFilter.h new file mode 100644 index 00000000..42ab5981 --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/DynamicFilter.h @@ -0,0 +1,72 @@ +/* + ZynAddSubFX - a software synthesizer + + DynamicFilter.h - "WahWah" effect and others + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#ifndef DYNAMICFILTER_H +#define DYNAMICFILTER_H +#include "../globals.h" +#include "Effect.h" +#include "EffectLFO.h" + +#include "../DSP/Filter.h" + +class DynamicFilter:public Effect { + public: + DynamicFilter(int insetion_,REALTYPE *efxoutl_,REALTYPE *efxoutr_); + ~DynamicFilter(); + void out(REALTYPE *smpsl,REALTYPE *smpsr); + + void setpreset(unsigned char npreset); + void changepar(int npar,unsigned char value); + unsigned char getpar(int npar); + void cleanup(); + +// void setdryonly(); + + private: + //Parametrii DynamicFilter + EffectLFO lfo;//lfo-ul DynamicFilter + unsigned char Pvolume; + unsigned char Ppanning; + unsigned char Pdepth;//the depth of the lfo of the DynamicFilter + unsigned char Pampsns;//how the filter varies according to the input amplitude + unsigned char Pampsnsinv;//if the filter freq is lowered if the input amplitude rises + unsigned char Pampsmooth;//how smooth the input amplitude changes the filter + + //Control Parametrii + void setvolume(unsigned char Pvolume); + void setpanning(unsigned char Ppanning); + void setdepth(unsigned char Pdepth); + void setampsns(unsigned char Pampsns); + + void reinitfilter(); + + //Valorile interne + int insertion; + REALTYPE panning,depth,ampsns,ampsmooth; + + Filter *filterl,*filterr; + + REALTYPE ms1,ms2,ms3,ms4;//mean squares +}; + +#endif + diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/EQ.C b/muse_qt4_evolution/synti/zynaddsubfx/Effects/EQ.C new file mode 100644 index 00000000..8180a655 --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/EQ.C @@ -0,0 +1,198 @@ +/* + ZynAddSubFX - a software synthesizer + + EQ.C - EQ effect + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include "EQ.h" + +EQ::EQ(int insertion_,REALTYPE *efxoutl_,REALTYPE *efxoutr_){ + efxoutl=efxoutl_; + efxoutr=efxoutr_; + insertion=insertion_; + filterpars=NULL; + + for (int i=0;i<MAX_EQ_BANDS;i++){ + filter[i].Ptype=0; + filter[i].Pfreq=64; + filter[i].Pgain=64; + filter[i].Pq=64; + filter[i].Pstages=0; + filter[i].l=new AnalogFilter(6,1000.0,1.0,0); + filter[i].r=new AnalogFilter(6,1000.0,1.0,0); + }; + //default values + Ppreset=0; + Pvolume=50; + + setpreset(Ppreset); + cleanup(); +}; + +EQ::~EQ(){ +}; + +/* + * Cleanup the effect + */ +void EQ::cleanup(){ + for (int i=0;i<MAX_EQ_BANDS;i++){ + filter[i].l->cleanup(); + filter[i].r->cleanup(); + }; +}; + + + +/* + * Effect output + */ +void EQ::out(REALTYPE *smpsl,REALTYPE *smpsr){ + int i; + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + efxoutl[i]=smpsl[i]*volume; + efxoutr[i]=smpsr[i]*volume; + }; + + for (i=0;i<MAX_EQ_BANDS;i++){ + if (filter[i].Ptype==0) continue; + filter[i].l->filterout(efxoutl); + filter[i].r->filterout(efxoutr); + }; +}; + + +/* + * Parameter control + */ +void EQ::setvolume(unsigned char Pvolume){ + this->Pvolume=Pvolume; + + outvolume=pow(0.005,(1.0-Pvolume/127.0))*10.0; + if (insertion==0) { + volume=1.0; + } else { + volume=outvolume; + }; + +}; + + +void EQ::setpreset(unsigned char npreset){ + const int PRESET_SIZE=1; + const int NUM_PRESETS=2; + unsigned char presets[NUM_PRESETS][PRESET_SIZE]={ + //EQ 1 + {67}, + //EQ 2 + {67}}; + + if (npreset>=NUM_PRESETS) npreset=NUM_PRESETS-1; + for (int n=0;n<PRESET_SIZE;n++) changepar(n,presets[npreset][n]); + Ppreset=npreset; +}; + + +void EQ::changepar(int npar,unsigned char value){ + switch (npar){ + case 0: setvolume(value); + break; + }; + if (npar<10) return; + + int nb=(npar-10)/5;//number of the band (filter) + if (nb>=MAX_EQ_BANDS) return; + int bp=npar%5;//band paramenter + + REALTYPE tmp; + switch(bp){ + case 0: if (value>9) value=0;//has to be changed if more filters will be added + filter[nb].Ptype=value; + if (value!=0){ + filter[nb].l->settype(value-1); + filter[nb].r->settype(value-1); + }; + break; + case 1: filter[nb].Pfreq=value; + tmp=600.0*pow(30.0,(value-64.0)/64.0); + filter[nb].l->setfreq(tmp); + filter[nb].r->setfreq(tmp); + break; + case 2: filter[nb].Pgain=value; + tmp=30.0*(value-64.0)/64.0; + filter[nb].l->setgain(tmp); + filter[nb].r->setgain(tmp); + break; + case 3: filter[nb].Pq=value; + tmp=pow(30.0,(value-64.0)/64.0); + filter[nb].l->setq(tmp); + filter[nb].r->setq(tmp); + break; + case 4: if (value>=MAX_FILTER_STAGES) value=MAX_FILTER_STAGES-1; + filter[nb].Pstages=value; + filter[nb].l->setstages(value); + filter[nb].r->setstages(value); + break; + }; +}; + +unsigned char EQ::getpar(int npar){ + switch (npar){ + case 0: return(Pvolume); + break; + }; + + if (npar<10) return(0); + + int nb=(npar-10)/5;//number of the band (filter) + if (nb>=MAX_EQ_BANDS) return(0); + int bp=npar%5;//band paramenter + switch(bp){ + case 0: return(filter[nb].Ptype); + break; + case 1: return(filter[nb].Pfreq); + break; + case 2: return(filter[nb].Pgain); + break; + case 3: return(filter[nb].Pq); + break; + case 4: return(filter[nb].Pstages); + break; + }; + + return(0);//in case of bogus parameter number +}; + + + + +REALTYPE EQ::getfreqresponse(REALTYPE freq){ + REALTYPE resp=1.0; + + for (int i=0;i<MAX_EQ_BANDS;i++){ + if (filter[i].Ptype==0) continue; + resp*=filter[i].l->H(freq); + }; + return(rap2dB(resp*outvolume)); +}; + + diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/EQ.h b/muse_qt4_evolution/synti/zynaddsubfx/Effects/EQ.h new file mode 100644 index 00000000..843b957b --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/EQ.h @@ -0,0 +1,58 @@ +/* + ZynAddSubFX - a software synthesizer + + EQ.h - EQ Effect + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#ifndef EQ_H +#define EQ_H + +#include "../globals.h" +#include "../DSP/AnalogFilter.h" +#include "Effect.h" + +class EQ:public Effect{ + public: + EQ(int insertion,REALTYPE *efxoutl_,REALTYPE *efxoutr_); + ~EQ(); + void out(REALTYPE *smpsl,REALTYPE *smpr); + void setpreset(unsigned char npreset); + void changepar(int npar,unsigned char value); + unsigned char getpar(int npar); + void cleanup(); + REALTYPE getfreqresponse(REALTYPE freq); + private: + //Parametrii + unsigned char Pvolume;//Volumul + + void setvolume(unsigned char Pvolume); + + struct { + //parameters + unsigned char Ptype,Pfreq,Pgain,Pq,Pstages; + //internal values + AnalogFilter *l,*r; + }filter[MAX_EQ_BANDS]; + +}; + + +#endif + + diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/Echo.C b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Echo.C new file mode 100644 index 00000000..a35ee1ba --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Echo.C @@ -0,0 +1,240 @@ +/* + ZynAddSubFX - a software synthesizer + + Echo.C - Echo effect + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include "Echo.h" + +Echo::Echo(int insertion_,REALTYPE *efxoutl_,REALTYPE *efxoutr_){ + efxoutl=efxoutl_; + efxoutr=efxoutr_; + filterpars=NULL; + + insertion=insertion_; + //default values + Ppreset=0; + Pvolume=50; + Ppanning=64; + Pdelay=60; + Plrdelay=100; + Plrcross=100; + Pfb=40; + Phidamp=60; + + ldelay=NULL; + rdelay=NULL; + lrdelay=0; + + setpreset(Ppreset); + cleanup(); +}; + +Echo::~Echo(){ + delete[] ldelay; + delete[] rdelay; +}; + +/* + * Cleanup the effect + */ +void Echo::cleanup(){ + int i; + for (i=0;i<dl;i++) ldelay[i]=0.0; + for (i=0;i<dr;i++) rdelay[i]=0.0; + oldl=0.0; + oldr=0.0; +}; + + +/* + * Initialize the delays + */ +void Echo::initdelays(){ + kl=0;kr=0; + dl=delay-lrdelay;if (dl<1) dl=1; + dr=delay+lrdelay;if (dr<1) dr=1; + + if (ldelay!=NULL) delete [] ldelay; + if (rdelay!=NULL) delete [] rdelay; + ldelay=new REALTYPE[dl]; + rdelay=new REALTYPE[dr]; + + cleanup(); +}; + +/* + * Effect output + */ +void Echo::out(REALTYPE *smpsl,REALTYPE *smpsr){ + int i; + REALTYPE l,r,ldl,rdl; + + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + ldl=ldelay[kl]; + rdl=rdelay[kr]; + l=ldl*(1.0-lrcross)+rdl*lrcross; + r=rdl*(1.0-lrcross)+ldl*lrcross; + ldl=l;rdl=r; + + efxoutl[i]=ldl*2.0; + efxoutr[i]=rdl*2.0; + ldl=smpsl[i]*panning-ldl*fb; + rdl=smpsr[i]*(1.0-panning)-rdl*fb; + + //LowPass Filter + ldelay[kl]=ldl=ldl*hidamp+oldl*(1.0-hidamp); + rdelay[kr]=rdl=rdl*hidamp+oldr*(1.0-hidamp); + oldl=ldl; + oldr=rdl; + + if (++kl>=dl) kl=0; + if (++kr>=dr) kr=0; + }; + +}; + + +/* + * Parameter control + */ +void Echo::setvolume(unsigned char Pvolume){ + this->Pvolume=Pvolume; + + if (insertion==0) { + outvolume=pow(0.01,(1.0-Pvolume/127.0))*4.0; + volume=1.0; + } else { + volume=outvolume=Pvolume/127.0; + }; + if (Pvolume==0) cleanup(); + +}; + +void Echo::setpanning(unsigned char Ppanning){ + this->Ppanning=Ppanning; + panning=(Ppanning+0.5)/127.0; +}; + +void Echo::setdelay(unsigned char Pdelay){ + this->Pdelay=Pdelay; + delay=1+(int)(Pdelay/127.0*SAMPLE_RATE*1.5);//0 .. 1.5 sec + initdelays(); +}; + +void Echo::setlrdelay(unsigned char Plrdelay){ + REALTYPE tmp; + this->Plrdelay=Plrdelay; + tmp=(pow(2,fabs(Plrdelay-64.0)/64.0*9)-1.0)/1000.0*SAMPLE_RATE; + if (Plrdelay<64.0) tmp=-tmp; + lrdelay=(int) tmp; + initdelays(); +}; + +void Echo::setlrcross(unsigned char Plrcross){ + this->Plrcross=Plrcross; + lrcross=Plrcross/127.0*1.0; +}; + +void Echo::setfb(unsigned char Pfb){ + this->Pfb=Pfb; + fb=Pfb/128.0; +}; + +void Echo::sethidamp(unsigned char Phidamp){ + this->Phidamp=Phidamp; + hidamp=1.0-Phidamp/127.0; +}; + +void Echo::setpreset(unsigned char npreset){ + const int PRESET_SIZE=7; + const int NUM_PRESETS=9; + unsigned char presets[NUM_PRESETS][PRESET_SIZE]={ + //Echo 1 + {67,64,35,64,30,59,0}, + //Echo 2 + {67,64,21,64,30,59,0}, + //Echo 3 + {67,75,60,64,30,59,10}, + //Simple Echo + {67,60,44,64,30,0,0}, + //Canyon + {67,60,102,50,30,82,48}, + //Panning Echo 1 + {67,64,44,17,0,82,24}, + //Panning Echo 2 + {81,60,46,118,100,68,18}, + //Panning Echo 3 + {81,60,26,100,127,67,36}, + //Feedback Echo + {62,64,28,64,100,90,55}}; + + + if (npreset>=NUM_PRESETS) npreset=NUM_PRESETS-1; + for (int n=0;n<PRESET_SIZE;n++) changepar(n,presets[npreset][n]); + if (insertion!=0) changepar(0,presets[npreset][0]/2);//lower the volume if this is insertion effect + Ppreset=npreset; +}; + + +void Echo::changepar(int npar,unsigned char value){ + switch (npar){ + case 0: setvolume(value); + break; + case 1: setpanning(value); + break; + case 2: setdelay(value); + break; + case 3: setlrdelay(value); + break; + case 4: setlrcross(value); + break; + case 5: setfb(value); + break; + case 6: sethidamp(value); + break; + }; +}; + +unsigned char Echo::getpar(int npar){ + switch (npar){ + case 0: return(Pvolume); + break; + case 1: return(Ppanning); + break; + case 2: return(Pdelay); + break; + case 3: return(Plrdelay); + break; + case 4: return(Plrcross); + break; + case 5: return(Pfb); + break; + case 6: return(Phidamp); + break; + }; + return(0);//in case of bogus parameter number +}; + + + + diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/Echo.h b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Echo.h new file mode 100644 index 00000000..8d6e6288 --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Echo.h @@ -0,0 +1,71 @@ +/* + ZynAddSubFX - a software synthesizer + + Echo.h - Echo Effect + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#ifndef ECHO_H +#define ECHO_H + +#include "../globals.h" +#include "Effect.h" + +class Echo:public Effect{ + public: + Echo(int insertion,REALTYPE *efxoutl_,REALTYPE *efxoutr_); + ~Echo(); + void out(REALTYPE *smpsl,REALTYPE *smpr); + void setpreset(unsigned char npreset); + void changepar(int npar,unsigned char value); + unsigned char getpar(int npar); + void cleanup(); + + void setdryonly(); + private: + //Parametrii + unsigned char Pvolume;//Volumul or E/R + unsigned char Ppanning;//Panning + unsigned char Pdelay; + unsigned char Plrdelay;// L/R delay difference + unsigned char Plrcross;// L/R Mixing + unsigned char Pfb;//Feed-back-ul + unsigned char Phidamp; + + void setvolume(unsigned char Pvolume); + void setpanning(unsigned char Ppanning); + void setdelay(unsigned char Pdelay); + void setlrdelay(unsigned char Plrdelay); + void setlrcross(unsigned char Plrcross); + void setfb(unsigned char Pfb); + void sethidamp(unsigned char Phidamp); + + //Parametrii reali + REALTYPE panning,lrcross,fb,hidamp; + int dl,dr,delay,lrdelay; + + void initdelays(); + REALTYPE *ldelay,*rdelay; + REALTYPE oldl,oldr;//pt. lpf + int kl,kr; +}; + + +#endif + + diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/Effect.C b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Effect.C new file mode 100644 index 00000000..d9ec124c --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Effect.C @@ -0,0 +1,24 @@ +/* + ZynAddSubFX - a software synthesizer + + Effect.C - this class is inherited by the all effects(Reverb, Echo, ..) + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#include "Effect.h" + diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/Effect.h b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Effect.h new file mode 100644 index 00000000..14df43ba --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Effect.h @@ -0,0 +1,61 @@ +/* + ZynAddSubFX - a software synthesizer + + Effect.h - this class is inherited by the all effects(Reverb, Echo, ..) + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#ifndef EFFECT_H +#define EFFECT_H + +#include <pthread.h> +#include "../Misc/Util.h" +#include "../globals.h" +#include "../Params/FilterParams.h" + + +class Effect{ + public: + + virtual ~Effect(){}; + virtual void setpreset(unsigned char /*npreset*/){}; + virtual void changepar(int /*npar*/,unsigned char /*value*/){}; + virtual unsigned char getpar(int /*npar*/){return(0);}; + virtual void out(REALTYPE */*smpsl*/,REALTYPE */*smpsr*/){}; + virtual void cleanup(){}; + virtual REALTYPE getfreqresponse(REALTYPE /*freq*/){return (0);};//this is only used for EQ (for user interface) + + unsigned char Ppreset; + REALTYPE *efxoutl; + REALTYPE *efxoutr; + + REALTYPE outvolume;//this is the volume of effect and is public because need it in system effect. The out volume of such effects are always 1.0, so this setting tells me how is the volume to the Master Output only. + + REALTYPE volume; + + FilterParams *filterpars; + protected: + + int insertion;//1 for insertion effect +}; + +#endif + + + + diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/EffectLFO.C b/muse_qt4_evolution/synti/zynaddsubfx/Effects/EffectLFO.C new file mode 100644 index 00000000..1e800710 --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/EffectLFO.C @@ -0,0 +1,110 @@ +/* + ZynAddSubFX - a software synthesizer + + EffectLFO.C - Stereo LFO used by some effects + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#include <stdlib.h> +#include <stdio.h> +#include <math.h> + +#include "EffectLFO.h" + + +EffectLFO::EffectLFO(){ + xl=0.0;xr=0.0; + Pfreq=40; + Prandomness=0; + PLFOtype=0; + Pstereo=96; + + updateparams(); + + ampl1=(1-lfornd)+lfornd*RND; + ampl2=(1-lfornd)+lfornd*RND; + ampr1=(1-lfornd)+lfornd*RND; + ampr2=(1-lfornd)+lfornd*RND; +}; + +EffectLFO::~EffectLFO(){ +}; + + +/* + * Update the changed parameters + */ +void EffectLFO::updateparams(){ + REALTYPE lfofreq=(pow(2,Pfreq/127.0*10.0)-1.0)*0.03; + incx=fabs(lfofreq)*(REALTYPE)SOUND_BUFFER_SIZE/(REALTYPE)SAMPLE_RATE; + if (incx>0.49999999) incx=0.499999999; //Limit the Frequency + + lfornd=Prandomness/127.0; + if (lfornd<0.0) lfornd=0.0; else if (lfornd>1.0) lfornd=1.0; + + if (PLFOtype>1) PLFOtype=1;//this has to be updated if more lfo's are added + lfotype=PLFOtype; + + xr=fmod(xl+(Pstereo-64.0)/127.0+1.0,1.0); +}; + + +/* + * Compute the shape of the LFO + */ +REALTYPE EffectLFO::getlfoshape(REALTYPE x){ + REALTYPE out; + switch (lfotype){ + case 1: //EffectLFO_TRIANGLE + if ((x>0.0)&&(x<0.25)) out=4.0*x; + else if ((x>0.25)&&(x<0.75)) out=2-4*x; + else out=4.0*x-4.0; + break; + //more to be added here; also ::updateparams() need to be updated (to allow more lfotypes) + default:out=cos(x*2*PI);//EffectLFO_SINE + }; + return(out); +}; + +/* + * LFO output + */ +void EffectLFO::effectlfoout(REALTYPE *outl,REALTYPE *outr){ + REALTYPE out; + + out=getlfoshape(xl); + if ((lfotype==0)||(lfotype==1)) out*=(ampl1+xl*(ampl2-ampl1)); + xl+=incx; + if (xl>1.0) { + xl-=1.0; + ampl1=ampl2; + ampl2=(1.0-lfornd)+lfornd*RND; + }; + *outl=(out+1.0)*0.5; + + out=getlfoshape(xr); + if ((lfotype==0)||(lfotype==1)) out*=(ampr1+xr*(ampr2-ampr1)); + xr+=incx; + if (xr>1.0) { + xr-=1.0; + ampr1=ampr2; + ampr2=(1.0-lfornd)+lfornd*RND; + }; + *outr=(out+1.0)*0.5; +}; + diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/EffectLFO.h b/muse_qt4_evolution/synti/zynaddsubfx/Effects/EffectLFO.h new file mode 100644 index 00000000..c1bb8cce --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/EffectLFO.h @@ -0,0 +1,50 @@ +/* + ZynAddSubFX - a software synthesizer + + EffectLFO.h - Stereo LFO used by some effects + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#ifndef EFFECT_LFO_H +#define EFFECT_LFO_H + +#include "../globals.h" + +class EffectLFO{ + public: + EffectLFO(); + ~EffectLFO(); + void effectlfoout(REALTYPE *outl,REALTYPE *outr); + void updateparams(); + unsigned char Pfreq; + unsigned char Prandomness; + unsigned char PLFOtype; + unsigned char Pstereo;//"64"=0 + private: + REALTYPE getlfoshape(REALTYPE x); + + REALTYPE xl,xr; + REALTYPE incx; + REALTYPE ampl1,ampl2,ampr1,ampr2;//necesar pentru "randomness" + REALTYPE lfointensity; + REALTYPE lfornd; + char lfotype; +}; + + +#endif diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/EffectMgr.C b/muse_qt4_evolution/synti/zynaddsubfx/Effects/EffectMgr.C new file mode 100644 index 00000000..efdb672a --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/EffectMgr.C @@ -0,0 +1,292 @@ +/* + ZynAddSubFX - a software synthesizer + + EffectMgr.C - Effect manager, an interface betwen the program and effects + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#include <stdlib.h> +#include <stdio.h> +#include "EffectMgr.h" +#include "../Misc/Master.h" + +EffectMgr::EffectMgr(int insertion_,Master* master_){ + setpresettype("Peffect"); + efx=NULL; + nefx=0; + insertion=insertion_; + master=master_; + efxoutl=new REALTYPE[SOUND_BUFFER_SIZE]; + efxoutr=new REALTYPE[SOUND_BUFFER_SIZE];; + for (int i=0;i<SOUND_BUFFER_SIZE;i++){ + efxoutl[i]=0.0; + efxoutr[i]=0.0; + }; + filterpars=NULL; + dryonly=false; + defaults(); +}; + + +EffectMgr::~EffectMgr(){ + if (efx!=NULL) delete (efx); + delete (efxoutl); + delete (efxoutr); +}; + +void EffectMgr::defaults(){ + changeeffect(0); + setdryonly(false); +}; + +/* + * Change the effect + */ +void EffectMgr::changeeffect(int nefx_){ + cleanup(); + if (nefx==nefx_) return; + nefx=nefx_; + for (int i=0;i<SOUND_BUFFER_SIZE;i++){ + efxoutl[i]=0.0; + efxoutr[i]=0.0; + }; + + if (efx!=NULL) delete (efx); + switch (nefx){ + case 1:efx=new Reverb(insertion,efxoutl,efxoutr);break; + case 2:efx=new Echo(insertion,efxoutl,efxoutr);break; + case 3:efx=new Chorus(insertion,efxoutl,efxoutr);break; + case 4:efx=new Phaser(insertion,efxoutl,efxoutr);break; + case 5:efx=new Alienwah(insertion,efxoutl,efxoutr);break; + case 6:efx=new Distorsion(insertion,efxoutl,efxoutr);break; + case 7:efx=new EQ(insertion,efxoutl,efxoutr);break; + case 8:efx=new DynamicFilter(insertion,efxoutl,efxoutr);break; + //put more effect here + default:efx=NULL;break;//no effect (thru) + }; + + if (efx!=NULL) filterpars=efx->filterpars; +}; + +/* + * Obtain the effect number + */ +int EffectMgr::geteffect(){ + return (nefx); +}; + +/* + * Cleanup the current effect + */ +void EffectMgr::cleanup(){ + if (efx!=NULL) efx->cleanup(); +}; + + +/* + * Get the preset of the current effect + */ + +unsigned char EffectMgr::getpreset(){ + if (efx!=NULL) return(efx->Ppreset); + else return(0); +}; + +/* + * Change the preset of the current effect + */ +void EffectMgr::changepreset_nolock(unsigned char npreset){ + if (efx!=NULL) efx->setpreset(npreset); +}; + +/* + * Change the preset of the current effect(with thread locking) + */ +void EffectMgr::changepreset(unsigned char npreset){ + master->lock(); + changepreset_nolock(npreset); + master->unlock(); +}; + + +/* + * Change a parameter of the current effect + */ +void EffectMgr::seteffectpar_nolock(int npar,unsigned char value){ + if (efx==NULL) return; + efx->changepar(npar,value); +}; + +/* + * Change a parameter of the current effect (with thread locking) + */ +void EffectMgr::seteffectpar(int npar,unsigned char value){ + master->lock(); + seteffectpar_nolock(npar,value); + master->unlock(); +}; + +/* + * Get a parameter of the current effect + */ +unsigned char EffectMgr::geteffectpar(int npar){ + if (efx==NULL) return(0); + return(efx->getpar(npar)); +}; + + +/* + * Apply the effect + */ +void EffectMgr::out(REALTYPE *smpsl,REALTYPE *smpsr){ + int i; + if (efx==NULL){ + if (insertion==0) + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + smpsl[i]=0.0;smpsr[i]=0.0; + efxoutl[i]=0.0;efxoutr[i]=0.0; + }; + return; + }; + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + smpsl[i]+=denormalkillbuf[i]; + smpsr[i]+=denormalkillbuf[i]; + efxoutl[i]=0.0; + efxoutr[i]=0.0; + }; + efx->out(smpsl,smpsr); + + REALTYPE volume=efx->volume; + + if (nefx==7){//this is need only for the EQ effect + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + smpsl[i]=efxoutl[i]; + smpsr[i]=efxoutr[i]; + }; + return; + }; + + //Insertion effect + if (insertion!=0) { + REALTYPE v1,v2; + if (volume<0.5) { + v1=1.0; + v2=volume*2.0; + } else { + v1=(1.0-volume)*2.0; + v2=1.0; + }; + if ((nefx==1)||(nefx==2)) v2*=v2;//for Reverb and Echo, the wet function is not liniar + + if (dryonly){//this is used for instrument effect only + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + smpsl[i]*=v1; + smpsr[i]*=v1; + efxoutl[i]*=v2; + efxoutr[i]*=v2; + }; + }else{//normal instrument/insertion effect + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + smpsl[i]=smpsl[i]*v1+efxoutl[i]*v2; + smpsr[i]=smpsr[i]*v1+efxoutr[i]*v2; + }; + }; + } else {//System effect + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + efxoutl[i]*=2.0*volume; + efxoutr[i]*=2.0*volume; + smpsl[i]=efxoutl[i]; + smpsr[i]=efxoutr[i]; + }; + }; + +}; + +/* + * Get the effect volume for the system effect + */ +REALTYPE EffectMgr::sysefxgetvolume(){ + if (efx==NULL) return (1.0); + else return(efx->outvolume); +}; + + +/* + * Get the EQ response + */ +REALTYPE EffectMgr::getEQfreqresponse(REALTYPE freq){ + if (nefx==7) return(efx->getfreqresponse(freq)); + else return(0.0); +}; + + +void EffectMgr::setdryonly(bool value){ + dryonly=value; +}; + +void EffectMgr::add2XML(XMLwrapper *xml){ + xml->addpar("type",geteffect()); + + if ((efx==NULL)||(geteffect()==0)) return; + xml->addpar("preset",efx->Ppreset); + + xml->beginbranch("EFFECT_PARAMETERS"); + for (int n=0;n<128;n++){ + int par=geteffectpar(n); + if (par==0) continue; + xml->beginbranch("par_no",n); + xml->addpar("par",par); + xml->endbranch(); + }; + if (filterpars!=NULL){ + xml->beginbranch("FILTER"); + filterpars->add2XML(xml); + xml->endbranch(); + }; + xml->endbranch(); +}; + +void EffectMgr::getfromXML(XMLwrapper *xml){ + changeeffect(xml->getpar127("type",geteffect())); + + if ((efx==NULL)||(geteffect()==0)) return; + + efx->Ppreset=xml->getpar127("preset",efx->Ppreset); + + if (xml->enterbranch("EFFECT_PARAMETERS")){ + for (int n=0;n<128;n++){ + seteffectpar_nolock(n,0);//erase effect parameter + if (xml->enterbranch("par_no",n)==0) continue; + + int par=geteffectpar(n); + seteffectpar_nolock(n,xml->getpar127("par",par)); + xml->exitbranch(); + }; + if (filterpars!=NULL){ + if (xml->enterbranch("FILTER")){ + filterpars->getfromXML(xml); + xml->exitbranch(); + }; + }; + xml->exitbranch(); + }; + cleanup(); +}; + + + diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/EffectMgr.h b/muse_qt4_evolution/synti/zynaddsubfx/Effects/EffectMgr.h new file mode 100644 index 00000000..6216fa33 --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/EffectMgr.h @@ -0,0 +1,87 @@ +/* + ZynAddSubFX - a software synthesizer + + EffectMgr.h - Effect manager, an interface betwen the program and effects + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#ifndef EFFECTMGR_H +#define EFFECTMGR_H + +#include <pthread.h> + +#include "Effect.h" +#include "Reverb.h" +#include "Echo.h" +#include "Chorus.h" +#include "Phaser.h" +#include "Alienwah.h" +#include "Distorsion.h" +#include "EQ.h" +#include "DynamicFilter.h" +#include "../Misc/XMLwrapper.h" +#include "../Params/FilterParams.h" +#include "../Params/Presets.h" + +class Master; + +class EffectMgr:public Presets{ + public: + EffectMgr(int insertion_,Master*); + ~EffectMgr(); + + void add2XML(XMLwrapper *xml); + void defaults(); + void getfromXML(XMLwrapper *xml); + + void out(REALTYPE *smpsl,REALTYPE *smpsr); + + void setdryonly(bool value); + + //get the output(to speakers) volume of the systemeffect + REALTYPE sysefxgetvolume(); + + void cleanup();//cleanup the effect + + void changeeffect(int nefx_); + int geteffect(); + void changepreset(unsigned char npreset); + void changepreset_nolock(unsigned char npreset); + unsigned char getpreset(); + void seteffectpar(int npar,unsigned char value); + void seteffectpar_nolock(int npar,unsigned char value);//sets the effect par without thread lock + unsigned char geteffectpar(int npar); + int insertion;//1 if the effect is connected as insertion effect + REALTYPE *efxoutl,*efxoutr; + + //used by UI + REALTYPE getEQfreqresponse(REALTYPE freq); + + FilterParams *filterpars; + + private: + int nefx; + Effect *efx; + Master* master; + bool dryonly; +}; + +#endif + + + diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/Phaser.C b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Phaser.C new file mode 100644 index 00000000..6f21f39e --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Phaser.C @@ -0,0 +1,260 @@ +/* + ZynAddSubFX - a software synthesizer + + Phaser.C - Phaser effect + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#include <math.h> +#include "Phaser.h" +#include <stdio.h> +#define PHASER_LFO_SHAPE 2 + +Phaser::Phaser(int insertion_,REALTYPE *efxoutl_,REALTYPE *efxoutr_){ + efxoutl=efxoutl_; + efxoutr=efxoutr_; + filterpars=NULL; + + oldl=NULL; + oldr=NULL; + insertion=insertion_; + + Ppreset=0; + setpreset(Ppreset); + cleanup(); +}; + +Phaser::~Phaser(){ + if (oldl!=NULL) delete [] oldl; + if (oldr!=NULL) delete [] oldr; +}; + + +/* + * Effect output + */ +void Phaser::out(REALTYPE *smpsl,REALTYPE *smpsr){ + int i,j; + REALTYPE lfol,lfor,lgain,rgain,tmp; + + lfo.effectlfoout(&lfol,&lfor); + lgain=lfol; + rgain=lfor; + lgain=(exp(lgain*PHASER_LFO_SHAPE)-1)/(exp(PHASER_LFO_SHAPE)-1.0); + rgain=(exp(rgain*PHASER_LFO_SHAPE)-1)/(exp(PHASER_LFO_SHAPE)-1.0); + + + lgain=1.0-phase*(1.0-depth)-(1.0-phase)*lgain*depth; + rgain=1.0-phase*(1.0-depth)-(1.0-phase)*rgain*depth; + + if (lgain>1.0) lgain=1.0;else if (lgain<0.0) lgain=0.0; + if (rgain>1.0) rgain=1.0;else if (rgain<0.0) rgain=0.0; + + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + REALTYPE x=(REALTYPE) i /SOUND_BUFFER_SIZE; + REALTYPE x1=1.0-x; + REALTYPE gl=lgain*x+oldlgain*x1; + REALTYPE gr=rgain*x+oldrgain*x1; + REALTYPE inl=smpsl[i]*panning+fbl; + REALTYPE inr=smpsr[i]*(1.0-panning)+fbr; + + //Left channel + for (j=0;j<Pstages*2;j++){//Phasing routine + tmp=oldl[j]; + oldl[j]=gl*tmp+inl; + inl=tmp-gl*oldl[j]; + }; + //Right channel + for (j=0;j<Pstages*2;j++){//Phasing routine + tmp=oldr[j]; + oldr[j]=gr*tmp+inr; + inr=tmp-gr*oldr[j]; + }; + //Left/Right crossing + REALTYPE l=inl; + REALTYPE r=inr; + inl=l*(1.0-lrcross)+r*lrcross; + inr=r*(1.0-lrcross)+l*lrcross; + + fbl=inl*fb; + fbr=inr*fb; + efxoutl[i]=inl; + efxoutr[i]=inr; + + }; + + oldlgain=lgain; oldrgain=rgain; + + if (Poutsub!=0) + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + efxoutl[i]*= -1.0; + efxoutr[i]*= -1.0; + }; + +}; + +/* + * Cleanup the effect + */ +void Phaser::cleanup(){ + fbl=0.0;fbr=0.0; + oldlgain=0.0; + oldrgain=0.0; + for (int i=0;i<Pstages*2;i++) { + oldl[i]=0.0; + oldr[i]=0.0; + }; +}; + +/* + * Parameter control + */ +void Phaser::setdepth(unsigned char Pdepth){ + this->Pdepth=Pdepth; + depth=(Pdepth/127.0); +}; + + +void Phaser::setfb(unsigned char Pfb){ + this->Pfb=Pfb; + fb=(Pfb-64.0)/64.1; +}; + +void Phaser::setvolume(unsigned char Pvolume){ + this->Pvolume=Pvolume; + outvolume=Pvolume/127.0; + if (insertion==0) volume=1.0; + else volume=outvolume; +}; + +void Phaser::setpanning(unsigned char Ppanning){ + this->Ppanning=Ppanning; + panning=Ppanning/127.0; +}; + +void Phaser::setlrcross(unsigned char Plrcross){ + this->Plrcross=Plrcross; + lrcross=Plrcross/127.0; +}; + +void Phaser::setstages(unsigned char Pstages){ + if (oldl!=NULL) delete [] oldl; + if (oldr!=NULL) delete [] oldr; + if (Pstages>=MAX_PHASER_STAGES) Pstages=MAX_PHASER_STAGES-1; + this->Pstages=Pstages; + oldl=new REALTYPE[Pstages*2]; + oldr=new REALTYPE[Pstages*2]; + cleanup(); +}; + +void Phaser::setphase(unsigned char Pphase){ + this->Pphase=Pphase; + phase=(Pphase/127.0); +}; + + +void Phaser::setpreset(unsigned char npreset){ + const int PRESET_SIZE=12; + const int NUM_PRESETS=6; + unsigned char presets[NUM_PRESETS][PRESET_SIZE]={ + //Phaser1 + {64,64,36,0,0,64,110,64,1,0,0,20}, + //Phaser2 + {64,64,35,0,0,88,40,64,3,0,0,20}, + //Phaser3 + {64,64,31,0,0,66,68,107,2,0,0,20}, + //Phaser4 + {39,64,22,0,0,66,67,10,5,0,1,20}, + //Phaser5 + {64,64,20,0,1,110,67,78,10,0,0,20}, + //Phaser6 + {64,64,53,100,0,58,37,78,3,0,0,20}}; + if (npreset>=NUM_PRESETS) npreset=NUM_PRESETS-1; + for (int n=0;n<PRESET_SIZE;n++) changepar(n,presets[npreset][n]); + Ppreset=npreset; +}; + + +void Phaser::changepar(int npar,unsigned char value){ + switch(npar){ + case 0: setvolume(value); + break; + case 1: setpanning(value); + break; + case 2: lfo.Pfreq=value; + lfo.updateparams(); + break; + case 3: lfo.Prandomness=value; + lfo.updateparams(); + break; + case 4: lfo.PLFOtype=value; + lfo.updateparams(); + break; + case 5: lfo.Pstereo=value; + lfo.updateparams(); + break; + case 6: setdepth(value); + break; + case 7: setfb(value); + break; + case 8: setstages(value); + break; + case 9: setlrcross(value); + break; + case 10:if (value>1) value=1; + Poutsub=value; + break; + case 11:setphase(value); + break; + }; +}; + +unsigned char Phaser::getpar(int npar){ + switch (npar){ + case 0: return(Pvolume); + break; + case 1: return(Ppanning); + break; + case 2: return(lfo.Pfreq); + break; + case 3: return(lfo.Prandomness); + break; + case 4: return(lfo.PLFOtype); + break; + case 5: return(lfo.Pstereo); + break; + case 6: return(Pdepth); + break; + case 7: return(Pfb); + break; + case 8: return(Pstages); + break; + case 9: return(Plrcross); + break; + case 10:return(Poutsub); + break; + case 11:return(Pphase); + break; + default:return (0); + }; + +}; + + + + diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/Phaser.h b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Phaser.h new file mode 100644 index 00000000..b4382668 --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Phaser.h @@ -0,0 +1,70 @@ +/* + ZynAddSubFX - a software synthesizer + + Phaser.h - Phaser effect + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#ifndef PHASER_H +#define PHASER_H +#include "../globals.h" +#include "Effect.h" +#include "EffectLFO.h" + +#define MAX_PHASER_STAGES 12 +class Phaser:public Effect { + public: + Phaser(int insetion_,REALTYPE *efxoutl_,REALTYPE *efxoutr_); + ~Phaser(); + void out(REALTYPE *smpsl,REALTYPE *smpsr); + void setpreset(unsigned char npreset); + void changepar(int npar,unsigned char value); + unsigned char getpar(int npar); + void cleanup(); + void setdryonly(); + + private: + //Parametrii Phaser + EffectLFO lfo;//lfo-ul Phaser + unsigned char Pvolume; + unsigned char Ppanning; + unsigned char Pdepth;//the depth of the Phaser + unsigned char Pfb;//feedback + unsigned char Plrcross;//feedback + unsigned char Pstages; + unsigned char Poutsub;//if I wish to substract the output instead of the adding it + unsigned char Pphase; + + //Control Parametrii + void setvolume(unsigned char Pvolume); + void setpanning(unsigned char Ppanning); + void setdepth(unsigned char Pdepth); + void setfb(unsigned char Pfb); + void setlrcross(unsigned char Plrcross); + void setstages(unsigned char Pstages); + void setphase(unsigned char Pphase); + + //Valorile interne + int insertion; + REALTYPE panning,fb,depth,lrcross,fbl,fbr,phase; + REALTYPE *oldl,*oldr; + REALTYPE oldlgain,oldrgain; +}; + +#endif + diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/Reverb.C b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Reverb.C new file mode 100644 index 00000000..b39e41c9 --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Reverb.C @@ -0,0 +1,438 @@ +/* + ZynAddSubFX - a software synthesizer + + Reverb.C - Reverberation effect + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#include <stdio.h> + +#include <math.h> +#include <stdlib.h> +#include "Reverb.h" + +/*TODO: EarlyReflections,Prdelay,Perbalance */ + +Reverb::Reverb(int insertion_,REALTYPE *efxoutl_,REALTYPE *efxoutr_){ + efxoutl=efxoutl_; + efxoutr=efxoutr_; + inputbuf=new REALTYPE[SOUND_BUFFER_SIZE]; + filterpars=NULL; + + insertion=insertion_; + //defaults + Ppreset=0; + Pvolume=48; + Ppan=64; + Ptime=64; + Pidelay=40; + Pidelayfb=0; + Prdelay=0; + Plpf=127; + Phpf=0; + Perbalance=64; + Plohidamp=80; + Ptype=1; + Proomsize=64;roomsize=1.0;rs=1.0; + + for (int i=0;i<REV_COMBS*2;i++) { + comblen[i]=800+(int)(RND*1400); + combk[i]=0; + lpcomb[i]=0; + combfb[i]=-0.97; + comb[i]=NULL; + }; + + for (int i=0;i<REV_APS*2;i++) { + aplen[i]=500+(int)(RND*500); + apk[i]=0; + ap[i]=NULL; + }; + + lpf=NULL;hpf=NULL;//no filter + idelay=NULL; + + setpreset(Ppreset); + cleanup();//do not call this before the comb initialisation +}; + + +Reverb::~Reverb(){ + int i; + if (idelay!=NULL) delete idelay; + if (hpf!=NULL) delete hpf; + if (lpf!=NULL) delete lpf; + + for (i=0;i<REV_APS*2;i++) delete ap[i]; + for (i=0;i<REV_COMBS*2;i++) delete comb[i]; + + delete [] inputbuf; +}; + +/* + * Cleanup the effect + */ +void Reverb::cleanup(){ + int i,j; + for (i=0;i<REV_COMBS*2;i++){ + lpcomb[i]=0.0; + for (j=0;j<comblen[i];j++) comb[i][j]=0.0; + }; + + for (i=0;i<REV_APS*2;i++) + for (j=0;j<aplen[i];j++) ap[i][j]=0.0; + + if (idelay!=NULL) for (i=0;i<idelaylen;i++) idelay[i]=0.0; + + if (hpf!=NULL) hpf->cleanup(); + if (lpf!=NULL) lpf->cleanup(); + +}; + +/* + * Process one channel; 0=left,1=right + */ +void Reverb::processmono(int ch,REALTYPE *output){ + int i,j; + REALTYPE fbout,tmp; + //TODO: implement the high part from lohidamp + + for (j=REV_COMBS*ch;j<REV_COMBS*(ch+1);j++){ + + int ck=combk[j]; + int comblength=comblen[j]; + REALTYPE lpcombj=lpcomb[j]; + + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + fbout=comb[j][ck]*combfb[j]; + fbout=fbout*(1.0-lohifb)+lpcombj*lohifb; + lpcombj=fbout; + + comb[j][ck]=inputbuf[i]+fbout; + output[i]+=fbout; + + if ((++ck)>=comblength) ck=0; + }; + + combk[j]=ck; + lpcomb[j]=lpcombj; + }; + + for (j=REV_APS*ch;j<REV_APS*(1+ch);j++){ + int ak=apk[j]; + int aplength=aplen[j]; + for (i=0;i<SOUND_BUFFER_SIZE;i++){ + tmp=ap[j][ak]; + ap[j][ak]=0.7*tmp+output[i]; + output[i]=tmp-0.7*ap[j][ak]; + if ((++ak)>=aplength) ak=0; + }; + apk[j]=ak; + }; +}; + +/* + * Effect output + */ +void Reverb::out(REALTYPE *smps_l, REALTYPE *smps_r){ + int i; + if ((Pvolume==0)&&(insertion!=0)) return; + + for (i=0;i<SOUND_BUFFER_SIZE;i++) { + inputbuf[i]=(smps_l[i]+smps_r[i])/2.0; + //Initial delay r + if (idelay!=NULL){ + REALTYPE tmp=inputbuf[i]+idelay[idelayk]*idelayfb; + inputbuf[i]=idelay[idelayk]; + idelay[idelayk]=tmp; + idelayk++;if (idelayk>=idelaylen) idelayk=0; + }; + }; + + if (lpf!=NULL) lpf->filterout(inputbuf); + if (hpf!=NULL) hpf->filterout(inputbuf); + + processmono(0,efxoutl);//left + processmono(1,efxoutr);//right + + REALTYPE lvol=rs/REV_COMBS*pan; + REALTYPE rvol=rs/REV_COMBS*(1.0-pan); + if (insertion!=0){ + lvol*=2;rvol*=2; + }; + for (int i=0;i<SOUND_BUFFER_SIZE;i++){ + efxoutl[i]*=lvol; + efxoutr[i]*=rvol; + }; +}; + + +/* + * Parameter control + */ +void Reverb::setvolume(unsigned char Pvolume){ + this->Pvolume=Pvolume; + if (insertion==0) { + outvolume=pow(0.01,(1.0-Pvolume/127.0))*4.0; + volume=1.0; + } else { + volume=outvolume=Pvolume/127.0; + if (Pvolume==0) cleanup(); + }; +}; + +void Reverb::setpan(unsigned char Ppan){ + this->Ppan=Ppan; + pan=(REALTYPE)Ppan/127.0; +}; + +void Reverb::settime(unsigned char Ptime){ + int i; + REALTYPE t; + this->Ptime=Ptime; + t=pow(60.0,(REALTYPE)Ptime/127.0)-0.97; + + for (i=0;i<REV_COMBS*2;i++){ + combfb[i]=-exp((REALTYPE)comblen[i]/(REALTYPE)SAMPLE_RATE*log(0.001)/t); + //the feedback is negative because it removes the DC + }; +}; + +void Reverb::setlohidamp(unsigned char Plohidamp){ + REALTYPE x; + + if (Plohidamp<64) Plohidamp=64;//remove this when the high part from lohidamp will be added + + this->Plohidamp=Plohidamp; + if (Plohidamp==64) { + lohidamptype=0; + lohifb=0.0; + } else { + if (Plohidamp<64) lohidamptype=1; + if (Plohidamp>64) lohidamptype=2; + x=fabs((REALTYPE)(Plohidamp-64)/64.1); + lohifb=x*x; + }; +}; + +void Reverb::setidelay(unsigned char Pidelay){ + REALTYPE delay; + this->Pidelay=Pidelay; + delay=pow(50*Pidelay/127.0,2)-1.0; + + if (idelay!=NULL) delete (idelay); + idelay=NULL; + + idelaylen=(int) (SAMPLE_RATE*delay/1000); + if (idelaylen>1) { + idelayk=0; + idelay=new REALTYPE[idelaylen]; + for (int i=0;i<idelaylen;i++) idelay[i]=0.0; + }; +}; + +void Reverb::setidelayfb(unsigned char Pidelayfb){ + this->Pidelayfb=Pidelayfb; + idelayfb=Pidelayfb/128.0; +}; + +void Reverb::sethpf(unsigned char Phpf){ + this->Phpf=Phpf; + if (Phpf==0) {//No HighPass + if (hpf!=NULL) delete(hpf); + hpf=NULL; + } + else{ + REALTYPE fr=exp(pow(Phpf/127.0,0.5)*log(10000.0))+20.0; + if (hpf==NULL) hpf=new AnalogFilter(3,fr,1,0); + else hpf->setfreq(fr); + }; +}; + +void Reverb::setlpf(unsigned char Plpf){ + this->Plpf=Plpf; + if (Plpf==127) {//No LowPass + if (lpf!=NULL) delete(lpf); + lpf=NULL; + } + else{ + REALTYPE fr=exp(pow(Plpf/127.0,0.5)*log(25000.0))+40; + if (lpf==NULL) lpf=new AnalogFilter(2,fr,1,0); + else lpf->setfreq(fr); + }; +}; + +void Reverb::settype(unsigned char Ptype){ + const int NUM_TYPES=2; + int combtunings[NUM_TYPES][REV_COMBS]={ + //this is unused (for random) + {0,0,0,0,0,0,0,0}, + //Freeverb by Jezar at Dreampoint + {1116,1188,1277,1356,1422,1491,1557,1617} + }; + int aptunings[NUM_TYPES][REV_APS]={ + //this is unused (for random) + {0,0,0,0}, + //Freeverb by Jezar at Dreampoint + {225,341,441,556} + }; + + if (Ptype>=NUM_TYPES) Ptype=NUM_TYPES-1; + this->Ptype=Ptype; + + REALTYPE tmp; + for (int i=0;i<REV_COMBS*2;i++) { + if (Ptype==0) tmp=800.0+(int)(RND*1400.0); + else tmp=combtunings[Ptype][i%REV_COMBS]; + tmp*=roomsize; + if (i>REV_COMBS) tmp+=23.0; + tmp*=SAMPLE_RATE/44100.0;//adjust the combs according to the samplerate + if (tmp<10) tmp=10; + + comblen[i]=(int) tmp; + combk[i]=0; + lpcomb[i]=0; + if (comb[i]!=NULL) delete comb[i]; + comb[i]=new REALTYPE[comblen[i]]; + }; + + for (int i=0;i<REV_APS*2;i++) { + if (Ptype==0) tmp=500+(int)(RND*500); + else tmp=aptunings[Ptype][i%REV_APS]; + tmp*=roomsize; + if (i>REV_APS) tmp+=23.0; + tmp*=SAMPLE_RATE/44100.0;//adjust the combs according to the samplerate + if (tmp<10) tmp=10; + aplen[i]=(int) tmp; + apk[i]=0; + if (ap[i]!=NULL) delete ap[i]; + ap[i]=new REALTYPE[aplen[i]]; + }; + settime(Ptime); + cleanup(); +}; + +void Reverb::setroomsize(unsigned char Proomsize){ + if (Proomsize==0) Proomsize=64;//this is because the older versions consider roomsize=0 + this->Proomsize=Proomsize; + roomsize=(Proomsize-64.0)/64.0; + if (roomsize>0.0) roomsize*=2.0; + roomsize=pow(10.0,roomsize); + rs=sqrt(roomsize); + settype(Ptype); +}; + +void Reverb::setpreset(unsigned char npreset){ + const int PRESET_SIZE=12; + const int NUM_PRESETS=13; + unsigned char presets[NUM_PRESETS][PRESET_SIZE]={ + //Cathedral1 + {80,64,63,24,0,0,0,85,5,83,1,64}, + //Cathedral2 + {80,64,69,35,0,0,0,127,0,71,0,64}, + //Cathedral3 + {80,64,69,24,0,0,0,127,75,78,1,85}, + //Hall1 + {90,64,51,10,0,0,0,127,21,78,1,64}, + //Hall2 + {90,64,53,20,0,0,0,127,75,71,1,64}, + //Room1 + {100,64,33,0,0,0,0,127,0,106,0,30}, + //Room2 + {100,64,21,26,0,0,0,62,0,77,1,45}, + //Basement + {110,64,14,0,0,0,0,127,5,71,0,25}, + //Tunnel + {85,80,84,20,42,0,0,51,0,78,1,105}, + //Echoed1 + {95,64,26,60,71,0,0,114,0,64,1,64}, + //Echoed2 + {90,64,40,88,71,0,0,114,0,88,1,64}, + //VeryLong1 + {90,64,93,15,0,0,0,114,0,77,0,95}, + //VeryLong2 + {90,64,111,30,0,0,0,114,90,74,1,80}}; + + if (npreset>=NUM_PRESETS) npreset=NUM_PRESETS-1; + for (int n=0;n<PRESET_SIZE;n++) changepar(n,presets[npreset][n]); + if (insertion!=0) changepar(0,presets[npreset][0]/2);//lower the volume if reverb is insertion effect + Ppreset=npreset; +}; + + +void Reverb::changepar(int npar,unsigned char value){ + switch (npar){ + case 0: setvolume(value); + break; + case 1: setpan(value); + break; + case 2: settime(value); + break; + case 3: setidelay(value); + break; + case 4: setidelayfb(value); + break; +// case 5: setrdelay(value); +// break; +// case 6: seterbalance(value); +// break; + case 7: setlpf(value); + break; + case 8: sethpf(value); + break; + case 9: setlohidamp(value); + break; + case 10:settype(value); + break; + case 11:setroomsize(value); + break; + }; +}; + +unsigned char Reverb::getpar(int npar){ + switch (npar){ + case 0: return(Pvolume); + break; + case 1: return(Ppan); + break; + case 2: return(Ptime); + break; + case 3: return(Pidelay); + break; + case 4: return(Pidelayfb); + break; +// case 5: return(Prdelay); +// break; +// case 6: return(Perbalance); +// break; + case 7: return(Plpf); + break; + case 8: return(Phpf); + break; + case 9: return(Plohidamp); + break; + case 10:return(Ptype); + break; + case 11:return(Proomsize); + break; + }; + return(0);//in case of bogus "parameter" +}; + + + diff --git a/muse_qt4_evolution/synti/zynaddsubfx/Effects/Reverb.h b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Reverb.h new file mode 100644 index 00000000..99c9890c --- /dev/null +++ b/muse_qt4_evolution/synti/zynaddsubfx/Effects/Reverb.h @@ -0,0 +1,127 @@ +/* + ZynAddSubFX - a software synthesizer + + Reverb.h - Reverberation effect + Copyright (C) 2002-2005 Nasca Octavian Paul + Author: Nasca Octavian Paul + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License (version 2) for more details. + + You should have received a copy of the GNU General Public License (version 2) + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#ifndef REVERB_H +#define REVERB_H + + +#include "../globals.h" +#include "../DSP/AnalogFilter.h" +#include "Effect.h" + +#define REV_COMBS 8 +#define REV_APS 4 + +class Reverb:public Effect { + public: + Reverb(int insertion,REALTYPE *efxoutl_,REALTYPE *efxoutr_); + ~Reverb(); + void out(REALTYPE *smps_l,REALTYPE *smps_r); + void cleanup(); + + void setpreset(unsigned char npreset); + void changepar(int npar,unsigned char value); + unsigned char getpar(int npar); + + private: + //Parametrii + //Amount of the reverb, + unsigned char Pvolume; + + //LefT/Right Panning + unsigned char Ppan; + + //duration of reverb + unsigned char Ptime; + + //Initial delay + unsigned char Pidelay; + + //Initial delay feedback + unsigned char Pidelayfb; + + //delay between ER/Reverbs + unsigned char Prdelay; + + //EarlyReflections/Reverb Balance + unsigned char Perbalance; + + //HighPassFilter + unsigned char Plpf; + + //LowPassFilter + unsigned char Phpf; + + //Low/HighFrequency Damping + unsigned char Plohidamp;// 0..63 lpf,64=off,65..127=hpf(TODO) + + //Reverb type + unsigned char Ptype; + + //Room Size + unsigned char Proomsize; + + //parameter control + void setvolume(unsigned char Pvolume); + void setpan(unsigned char Ppan); + void settime(unsigned char Ptime); + void setlohidamp(unsigned char Plohidamp); + void setidelay(unsigned char Pidelay); + void setidelayfb(unsigned char Pidelayfb); + void sethpf(unsigned char Phpf); + void setlpf(unsigned char Plpf); + void settype(unsigned char Ptype); + void setroomsize(unsigned char Proomsize); + + REALTYPE pan,erbalance; + //Parametrii 2 + int lohidamptype;//0=disable,1=highdamp(lowpass),2=lowdamp(highpass) + int idelaylen,rdelaylen; + int idelayk; + REALTYPE lohifb,idelayfb,roomsize,rs;//rs is used to "normalise" the volume according to the roomsize + int comblen[REV_COMBS*2]; + int aplen[REV_APS*2]; + + //Valorile interne + + REALTYPE *comb[REV_COMBS*2]; + + int combk[REV_COMBS*2]; + REALTYPE combfb[REV_COMBS*2];//feedback-ul fiecarui filtru "comb" + REALTYPE lpcomb[REV_COMBS*2];//pentru Filtrul LowPass + + REALTYPE *ap[REV_APS*2]; + + int apk[REV_APS*2]; + + REALTYPE *idelay; + AnalogFilter *lpf,*hpf;//filters + REALTYPE *inputbuf; + + void processmono(int ch,REALTYPE *output); +}; + + + + +#endif + |