From b0546e5e7f7044019892543c6c82029db8d564a7 Mon Sep 17 00:00:00 2001 From: Robert Jonsson Date: Thu, 15 Sep 2011 12:14:55 +0000 Subject: moved attic to a branch of it's own --- .../synti/zynaddsubfx/DSP/AnalogFilter.C | 358 --------------------- .../synti/zynaddsubfx/DSP/AnalogFilter.h | 72 ----- .../synti/zynaddsubfx/DSP/FFTwrapper.C | 99 ------ .../synti/zynaddsubfx/DSP/FFTwrapper.h | 59 ---- .../synti/zynaddsubfx/DSP/Filter.C | 72 ----- .../synti/zynaddsubfx/DSP/Filter.h | 51 --- .../synti/zynaddsubfx/DSP/Filter_.h | 42 --- .../synti/zynaddsubfx/DSP/FormantFilter.C | 163 ---------- .../synti/zynaddsubfx/DSP/FormantFilter.h | 67 ---- .../synti/zynaddsubfx/DSP/SVFilter.C | 152 --------- .../synti/zynaddsubfx/DSP/SVFilter.h | 67 ---- 11 files changed, 1202 deletions(-) delete mode 100644 attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/AnalogFilter.C delete mode 100644 attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/AnalogFilter.h delete mode 100644 attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/FFTwrapper.C delete mode 100644 attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/FFTwrapper.h delete mode 100644 attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/Filter.C delete mode 100644 attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/Filter.h delete mode 100644 attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/Filter_.h delete mode 100644 attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/FormantFilter.C delete mode 100644 attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/FormantFilter.h delete mode 100644 attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/SVFilter.C delete mode 100644 attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/SVFilter.h (limited to 'attic/muse_qt4_evolution/synti/zynaddsubfx/DSP') diff --git a/attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/AnalogFilter.C b/attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/AnalogFilter.C deleted file mode 100644 index 5e461a0b..00000000 --- a/attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/AnalogFilter.C +++ /dev/null @@ -1,358 +0,0 @@ -/* - ZynAddSubFX - a software synthesizer - - AnalogFilter.C - Several analog filters (lowpass, highpass...) - 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 -#include -#include "AnalogFilter.h" - -AnalogFilter::AnalogFilter(unsigned char Ftype,REALTYPE Ffreq, REALTYPE Fq,unsigned char Fstages){ - stages=Fstages; - for (int i=0;i<3;i++){ - oldc[i]=0.0;oldd[i]=0.0; - c[i]=0.0;d[i]=0.0; - }; - type=Ftype; - freq=Ffreq; - q=Fq; - gain=1.0; - if (stages>=MAX_FILTER_STAGES) stages=MAX_FILTER_STAGES; - cleanup(); - firsttime=0; - abovenq=0;oldabovenq=0; - setfreq_and_q(Ffreq,Fq); - firsttime=1; - d[0]=0;//this is not used - outgain=1.0; -}; - -AnalogFilter::~AnalogFilter(){ -}; - -void AnalogFilter::cleanup(){ - for (int i=0;ifreq; - if (freq>(SAMPLE_RATE/2-500.0)) { - freq=SAMPLE_RATE/2-500.0; - zerocoefs=1; - }; - if (freq<0.1) freq=0.1; - //do not allow bogus Q - if (q<0.0) q=0.0; - REALTYPE tmpq,tmpgain; - if (stages==0) { - tmpq=q; - tmpgain=gain; - } else { - tmpq=(q>1.0 ? pow(q,1.0/(stages+1)) : q); - tmpgain=pow(gain,1.0/(stages+1)); - }; - - //most of theese are implementations of - //the "Cookbook formulae for audio EQ" by Robert Bristow-Johnson - //The original location of the Cookbook is: - //http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt - switch(type){ - case 0://LPF 1 pole - if (zerocoefs==0) tmp=exp(-2.0*PI*freq/SAMPLE_RATE); - else tmp=0.0; - c[0]=1.0-tmp;c[1]=0.0;c[2]=0.0; - d[1]=tmp;d[2]=0.0; - order=1; - break; - case 1://HPF 1 pole - if (zerocoefs==0) tmp=exp(-2.0*PI*freq/SAMPLE_RATE); - else tmp=0.0; - c[0]=(1.0+tmp)/2.0;c[1]=-(1.0+tmp)/2.0;c[2]=0.0; - d[1]=tmp;d[2]=0.0; - order=1; - break; - case 2://LPF 2 poles - if (zerocoefs==0){ - omega=2*PI*freq/SAMPLE_RATE; - sn=sin(omega); - cs=cos(omega); - alpha=sn/(2*tmpq); - tmp=1+alpha; - c[0]=(1.0-cs)/2.0/tmp; - c[1]=(1.0-cs)/tmp; - c[2]=(1.0-cs)/2.0/tmp; - d[1]=-2*cs/tmp*(-1); - d[2]=(1-alpha)/tmp*(-1); - } else { - c[0]=1.0;c[1]=0.0;c[2]=0.0; - d[1]=0.0;d[2]=0.0; - }; - order=2; - break; - case 3://HPF 2 poles - if (zerocoefs==0){ - omega=2*PI*freq/SAMPLE_RATE; - sn=sin(omega); - cs=cos(omega); - alpha=sn/(2*tmpq); - tmp=1+alpha; - c[0]=(1.0+cs)/2.0/tmp; - c[1]=-(1.0+cs)/tmp; - c[2]=(1.0+cs)/2.0/tmp; - d[1]=-2*cs/tmp*(-1); - d[2]=(1-alpha)/tmp*(-1); - } else { - c[0]=0.0;c[1]=0.0;c[2]=0.0; - d[1]=0.0;d[2]=0.0; - }; - order=2; - break; - case 4://BPF 2 poles - if (zerocoefs==0){ - omega=2*PI*freq/SAMPLE_RATE; - sn=sin(omega); - cs=cos(omega); - alpha=sn/(2*tmpq); - tmp=1+alpha; - c[0]=alpha/tmp*sqrt(tmpq+1); - c[1]=0; - c[2]=-alpha/tmp*sqrt(tmpq+1); - d[1]=-2*cs/tmp*(-1); - d[2]=(1-alpha)/tmp*(-1); - } else { - c[0]=0.0;c[1]=0.0;c[2]=0.0; - d[1]=0.0;d[2]=0.0; - }; - order=2; - break; - case 5://NOTCH 2 poles - if (zerocoefs==0){ - omega=2*PI*freq/SAMPLE_RATE; - sn=sin(omega); - cs=cos(omega); - alpha=sn/(2*sqrt(tmpq)); - tmp=1+alpha; - c[0]=1/tmp; - c[1]=-2*cs/tmp; - c[2]=1/tmp; - d[1]=-2*cs/tmp*(-1); - d[2]=(1-alpha)/tmp*(-1); - } else { - c[0]=1.0;c[1]=0.0;c[2]=0.0; - d[1]=0.0;d[2]=0.0; - }; - order=2; - break; - case 6://PEAK (2 poles) - if (zerocoefs==0){ - omega=2*PI*freq/SAMPLE_RATE; - sn=sin(omega); - cs=cos(omega); - tmpq*=3.0; - alpha=sn/(2*tmpq); - tmp=1+alpha/tmpgain; - c[0]=(1.0+alpha*tmpgain)/tmp; - c[1]=(-2.0*cs)/tmp; - c[2]=(1.0-alpha*tmpgain)/tmp; - d[1]=-2*cs/tmp*(-1); - d[2]=(1-alpha/tmpgain)/tmp*(-1); - } else { - c[0]=1.0;c[1]=0.0;c[2]=0.0; - d[1]=0.0;d[2]=0.0; - }; - order=2; - break; - case 7://Low Shelf - 2 poles - if (zerocoefs==0){ - omega=2*PI*freq/SAMPLE_RATE; - sn=sin(omega); - cs=cos(omega); - tmpq=sqrt(tmpq); - alpha=sn/(2*tmpq); - beta=sqrt(tmpgain)/tmpq; - tmp=(tmpgain+1.0)+(tmpgain-1.0)*cs+beta*sn; - - c[0]=tmpgain*((tmpgain+1.0)-(tmpgain-1.0)*cs+beta*sn)/tmp; - c[1]=2.0*tmpgain*((tmpgain-1.0)-(tmpgain+1.0)*cs)/tmp; - c[2]=tmpgain*((tmpgain+1.0)-(tmpgain-1.0)*cs-beta*sn)/tmp; - d[1]=-2.0*((tmpgain-1.0)+(tmpgain+1.0)*cs)/tmp*(-1); - d[2]=((tmpgain+1.0)+(tmpgain-1.0)*cs-beta*sn)/tmp*(-1); - } else { - c[0]=tmpgain;c[1]=0.0;c[2]=0.0; - d[1]=0.0;d[2]=0.0; - }; - order=2; - break; - case 8://High Shelf - 2 poles - if (zerocoefs==0){ - omega=2*PI*freq/SAMPLE_RATE; - sn=sin(omega); - cs=cos(omega); - tmpq=sqrt(tmpq); - alpha=sn/(2*tmpq); - beta=sqrt(tmpgain)/tmpq; - tmp=(tmpgain+1.0)-(tmpgain-1.0)*cs+beta*sn; - - c[0]=tmpgain*((tmpgain+1.0)+(tmpgain-1.0)*cs+beta*sn)/tmp; - c[1]=-2.0*tmpgain*((tmpgain-1.0)+(tmpgain+1.0)*cs)/tmp; - c[2]=tmpgain*((tmpgain+1.0)+(tmpgain-1.0)*cs-beta*sn)/tmp; - d[1]=2.0*((tmpgain-1.0)-(tmpgain+1.0)*cs)/tmp*(-1); - d[2]=((tmpgain+1.0)-(tmpgain-1.0)*cs-beta*sn)/tmp*(-1); - } else { - c[0]=1.0;c[1]=0.0;c[2]=0.0; - d[1]=0.0;d[2]=0.0; - }; - order=2; - break; - default://wrong type - type=0; - computefiltercoefs(); - break; - }; -}; - - -void AnalogFilter::setfreq(REALTYPE frequency){ - if (frequency<0.1) frequency=0.1; - REALTYPE rap=freq/frequency;if (rap<1.0) rap=1.0/rap; - - oldabovenq=abovenq;abovenq=frequency>(SAMPLE_RATE/2-500.0); - - int nyquistthresh=(abovenq^oldabovenq); - - - if ((rap>3.0)||(nyquistthresh!=0)){//if the frequency is changed fast, it needs interpolation (now, filter and coeficients backup) - for (int i=0;i<3;i++){ - oldc[i]=c[i];oldd[i]=d[i]; - }; - for (int i=0;i=MAX_FILTER_STAGES) stages_=MAX_FILTER_STAGES-1; - stages=stages_; - cleanup(); - computefiltercoefs(); -}; - -void AnalogFilter::singlefilterout(REALTYPE *smp,fstage &x,fstage &y,REALTYPE *c,REALTYPE *d){ - int i; - REALTYPE y0; - if (order==1) {//First order filter - for (i=0;i1,1->2,etc.) - REALTYPE freq;//Frequency given in Hz - REALTYPE q; //Q factor (resonance or Q factor) - REALTYPE gain;//the gain of the filter (if are shelf/peak) filters - - int order;//the order of the filter (number of poles) - - REALTYPE c[3],d[3];//coefficients - - REALTYPE oldc[3],oldd[3];//old coefficients(used only if some filter paremeters changes very fast, and it needs interpolation) - - REALTYPE xd[3],yd[3];//used if the filter is applied more times - int needsinterpolation,firsttime; - int abovenq;//this is 1 if the frequency is above the nyquist - int oldabovenq;//if the last time was above nyquist (used to see if it needs interpolation) -}; - - -#endif - diff --git a/attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/FFTwrapper.C b/attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/FFTwrapper.C deleted file mode 100644 index 7c67e631..00000000 --- a/attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/FFTwrapper.C +++ /dev/null @@ -1,99 +0,0 @@ -/* - ZynAddSubFX - a software synthesizer - - FFTwrapper.c - A wrapper for Fast Fourier Transforms - 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 -#include "FFTwrapper.h" - -FFTwrapper::FFTwrapper(int fftsize_){ - fftsize=fftsize_; - tmpfftdata1=new fftw_real[fftsize]; - tmpfftdata2=new fftw_real[fftsize]; -#ifdef FFTW_VERSION_2 - planfftw=rfftw_create_plan(fftsize,FFTW_REAL_TO_COMPLEX,FFTW_ESTIMATE|FFTW_IN_PLACE); - planfftw_inv=rfftw_create_plan(fftsize,FFTW_COMPLEX_TO_REAL,FFTW_ESTIMATE|FFTW_IN_PLACE); -#else - planfftw=fftw_plan_r2r_1d(fftsize,tmpfftdata1,tmpfftdata1,FFTW_R2HC,FFTW_ESTIMATE); - planfftw_inv=fftw_plan_r2r_1d(fftsize,tmpfftdata2,tmpfftdata2,FFTW_HC2R,FFTW_ESTIMATE); -#endif -}; - -FFTwrapper::~FFTwrapper(){ -#ifdef FFTW_VERSION_2 - rfftw_destroy_plan(planfftw); - rfftw_destroy_plan(planfftw_inv); -#else - fftw_destroy_plan(planfftw); - fftw_destroy_plan(planfftw_inv); -#endif - - delete [] tmpfftdata1; - delete [] tmpfftdata2; -}; - -/* - * do the Fast Fourier Transform - */ -void FFTwrapper::smps2freqs(REALTYPE *smps,FFTFREQS freqs){ -#ifdef FFTW_VERSION_2 - for (int i=0;i - -/* If you got error messages about rfftw.h, replace the next include line with "#include " -or with "#include (if one doesn't work try the other). It may be necessary to replace -the with or . If the neither one doesn't work, -please install latest version of fftw(recomanded from the sources) from www.fftw.org. -If you'll install fftw3 you need to change the Makefile.inc -Hope all goes right." */ -#include - -#else - -#include -#define fftw_real double -#define rfftw_plan fftw_plan -#endif - -class FFTwrapper{ - public: - FFTwrapper(int fftsize_); - ~FFTwrapper(); - void smps2freqs(REALTYPE *smps,FFTFREQS freqs); - void freqs2smps(FFTFREQS freqs,REALTYPE *smps); - private: - int fftsize; - fftw_real *tmpfftdata1,*tmpfftdata2; - rfftw_plan planfftw,planfftw_inv; -}; -#endif - diff --git a/attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/Filter.C b/attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/Filter.C deleted file mode 100644 index fccb0265..00000000 --- a/attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/Filter.C +++ /dev/null @@ -1,72 +0,0 @@ -/* - ZynAddSubFX - a software synthesizer - - Filter.C - Filters, uses analog,formant,etc. filters - 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 -#include - -#include "Filter.h" - -Filter::Filter(FilterParams *pars){ - unsigned char Ftype=pars->Ptype; - unsigned char Fstages=pars->Pstages; - - category=pars->Pcategory; - - switch (category) { - case 1:filter=new FormantFilter(pars); - break; - case 2:filter=new SVFilter(Ftype,1000.0,pars->getq(),Fstages); - filter->outgain=dB2rap(pars->getgain()); - if (filter->outgain>1.0) filter->outgain=sqrt(filter->outgain); - break; - default:filter=new AnalogFilter(Ftype,1000.0,pars->getq(),Fstages); - if ((Ftype>=6)&&(Ftype<=8)) filter->setgain(pars->getgain()); - else filter->outgain=dB2rap(pars->getgain()); - break; - }; -}; - -Filter::~Filter(){ - delete (filter); -}; - -void Filter::filterout(REALTYPE *smp){ - filter->filterout(smp); -}; - -void Filter::setfreq(REALTYPE frequency){ - filter->setfreq(frequency); -}; - -void Filter::setfreq_and_q(REALTYPE frequency,REALTYPE q_){ - filter->setfreq_and_q(frequency,q_); -}; - -void Filter::setq(REALTYPE q_){ - filter->setq(q_); -}; - -REALTYPE Filter::getrealfreq(REALTYPE freqpitch){ - if ((category==0)||(category==2)) return(pow(2.0,freqpitch+9.96578428));//log2(1000)=9.95748 - else return(freqpitch); -}; - diff --git a/attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/Filter.h b/attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/Filter.h deleted file mode 100644 index dab948c1..00000000 --- a/attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/Filter.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - ZynAddSubFX - a software synthesizer - - Filter.h - Filters, uses analog,formant,etc. filters - 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 FILTER_H -#define FILTER_H - -#include "../globals.h" - -#include "Filter_.h" -#include "AnalogFilter.h" -#include "FormantFilter.h" -#include "SVFilter.h" -#include "../Params/FilterParams.h" - -class Filter{ - public: - Filter(FilterParams *pars); - ~Filter(); - void filterout(REALTYPE *smp); - void setfreq(REALTYPE frequency); - void setfreq_and_q(REALTYPE frequency,REALTYPE q_); - void setq(REALTYPE q_); - - REALTYPE getrealfreq(REALTYPE freqpitch); - private: - Filter_ *filter; - unsigned char category; -}; - - -#endif - diff --git a/attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/Filter_.h b/attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/Filter_.h deleted file mode 100644 index 66fff867..00000000 --- a/attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/Filter_.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - ZynAddSubFX - a software synthesizer - - Filter_.h - This class is inherited by filter classes - 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 FILTER__H -#define FILTER__H - -#include "../globals.h" - -class Filter_{ - public: - virtual ~Filter_(){}; - virtual void filterout(REALTYPE */*smp*/){}; - virtual void setfreq(REALTYPE /*frequency*/){}; - virtual void setfreq_and_q(REALTYPE /*frequency*/,REALTYPE /*q_*/){}; - virtual void setq(REALTYPE /*q_*/){}; - virtual void setgain(REALTYPE /*dBgain*/){}; - REALTYPE outgain; - private: -}; - - -#endif - diff --git a/attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/FormantFilter.C b/attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/FormantFilter.C deleted file mode 100644 index 482cef91..00000000 --- a/attic/muse_qt4_evolution/synti/zynaddsubfx/DSP/FormantFilter.C +++ /dev/null @@ -1,163 +0,0 @@ -/* - ZynAddSubFX - a software synthesizer - - FormantFilter.C - formant filters - 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 -#include -#include "FormantFilter.h" - -FormantFilter::FormantFilter(FilterParams *pars){ - numformants=pars->Pnumformants; - for (int i=0;iPstages); - cleanup(); - inbuffer=new REALTYPE [SOUND_BUFFER_SIZE]; - tmpbuf=new REALTYPE [SOUND_BUFFER_SIZE]; - - for (int j=0;jgetformantfreq(pars->Pvowels[j].formants[i].freq); - formantpar[j][i].amp=pars->getformantamp(pars->Pvowels[j].formants[i].amp); - formantpar[j][i].q=pars->getformantq(pars->Pvowels[j].formants[i].q); - }; - for (int i=0;iPformantslowness/128.0),3.0); - - sequencesize=pars->Psequencesize;if (sequencesize==0) sequencesize=1; - for (int k=0;kPsequence[k].nvowel; - - vowelclearness=pow(10.0,(pars->Pvowelclearness-32.0)/48.0); - - sequencestretch=pow(0.1,(pars->Psequencestretch-32.0)/48.0); - if (pars->Psequencereversed) sequencestretch*= -1.0; - - outgain=dB2rap(pars->getgain()); - - oldinput=-1.0; - Qfactor=1.0;oldQfactor=Qfactor; - firsttime=1; -}; - -FormantFilter::~FormantFilter(){ - for (int i=0;icleanup(); -}; - -void FormantFilter::setpos(REALTYPE input){ - int p1,p2; - - if (firsttime!=0) slowinput=input; - else slowinput=slowinput*(1.0-formantslowness)+input*formantslowness; - - if ((fabs(oldinput-input)<0.001)&&(fabs(slowinput-input)<0.001)&& - (fabs(Qfactor-oldQfactor)<0.001)) { -// oldinput=input; daca setez asta, o sa faca probleme la schimbari foarte lente - firsttime=0; - return; - } else oldinput=input; - - - REALTYPE pos=fmod(input*sequencestretch,1.0);if (pos<0.0) pos+=1.0; - - F2I(pos*sequencesize,p2); - p1=p2-1;if (p1<0) p1+=sequencesize; - - pos=fmod(pos*sequencesize,1.0); - if (pos<0.0) pos=0.0; else if (pos>1.0) pos=1.0; - pos=(atan((pos*2.0-1.0)*vowelclearness)/atan(vowelclearness)+1.0)*0.5; - - p1=sequence[p1].nvowel; - p2=sequence[p2].nvowel; - - if (firsttime!=0) { - for (int i=0;isetfreq_and_q(currentformants[i].freq,currentformants[i].q*Qfactor); - oldformantamp[i]=currentformants[i].amp; - }; - firsttime=0; - } else { - for (int i=0;isetfreq_and_q(currentformants[i].freq,currentformants[i].q*Qfactor); - }; - }; - - oldQfactor=Qfactor; -}; - -void FormantFilter::setfreq(REALTYPE frequency){ - setpos(frequency); -}; - -void FormantFilter::setq(REALTYPE q_){ - Qfactor=q_; - for (int i=0;isetq(Qfactor*currentformants[i].q); -}; - -void FormantFilter::setfreq_and_q(REALTYPE frequency,REALTYPE q_){ - Qfactor=q_; - setpos(frequency); -}; - - -void FormantFilter::filterout(REALTYPE *smp){ - int i,j; - for (i=0;ifilterout(tmpbuf); - - if (ABOVE_AMPLITUDE_THRESHOLD(oldformantamp[j],currentformants[j].amp)) - for (i=0;i -#include -#include "SVFilter.h" - -SVFilter::SVFilter(unsigned char Ftype,REALTYPE Ffreq, REALTYPE Fq,unsigned char Fstages){ - stages=Fstages; - type=Ftype; - freq=Ffreq; - q=Fq; - gain=1.0; - outgain=1.0; - needsinterpolation=0; - firsttime=1; - if (stages>=MAX_FILTER_STAGES) stages=MAX_FILTER_STAGES; - cleanup(); - setfreq_and_q(Ffreq,Fq); -}; - -SVFilter::~SVFilter(){ -}; - -void SVFilter::cleanup(){ - for (int i=0;i0.99999) par.f=0.99999; - par.q=1.0-atan(sqrt(q))*2.0/PI; - par.q=pow(par.q,1.0/(stages+1)); - par.q_sqrt=sqrt(par.q); -}; - - -void SVFilter::setfreq(REALTYPE frequency){ - if (frequency<0.1) frequency=0.1; - REALTYPE rap=freq/frequency;if (rap<1.0) rap=1.0/rap; - - oldabovenq=abovenq;abovenq=frequency>(SAMPLE_RATE/2-500.0); - - int nyquistthresh=(abovenq^oldabovenq); - - - if ((rap>3.0)||(nyquistthresh!=0)){//if the frequency is changed fast, it needs interpolation (now, filter and coeficients backup) - if (firsttime==0) needsinterpolation=1; - ipar=par; - }; - freq=frequency; - computefiltercoefs(); - firsttime=0; - -}; - -void SVFilter::setfreq_and_q(REALTYPE frequency,REALTYPE q_){ - q=q_; - setfreq(frequency); -}; - -void SVFilter::setq(REALTYPE q_){ - q=q_; - computefiltercoefs(); -}; - -void SVFilter::settype(int type_){ - type=type_; - computefiltercoefs(); -}; - -void SVFilter::setgain(REALTYPE dBgain){ - gain=dB2rap(dBgain); - computefiltercoefs(); -}; - -void SVFilter::setstages(int stages_){ - if (stages_>=MAX_FILTER_STAGES) stages_=MAX_FILTER_STAGES-1; - stages=stages_; - cleanup(); - computefiltercoefs(); -}; - -void SVFilter::singlefilterout(REALTYPE *smp,fstage &x,parameters &par){ - int i; - REALTYPE *out=NULL; - switch(type){ - case 0: out=&x.low;break; - case 1: out=&x.high;break; - case 2: out=&x.band;break; - case 3: out=&x.notch;break; - }; - - for (i=0;i1,1->2,etc.) - REALTYPE freq;//Frequency given in Hz - REALTYPE q; //Q factor (resonance or Q factor) - REALTYPE gain;//the gain of the filter (if are shelf/peak) filters - - int abovenq;//this is 1 if the frequency is above the nyquist - int oldabovenq; - int needsinterpolation,firsttime; -}; - - -#endif - -- cgit v1.2.3