From b73474ca7325fc35f2bd9853c88b3db037330c3c Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Tue, 15 Sep 2009 23:40:36 +0200 Subject: [PATCH] ZynAddSubFX: eliminate global data in favour of per-synth data OscilGen::tmpsmps and OscilGen::outoscilFFTfreqs were static member variables initialized once in LocalZynAddSubFx class. However having this data global is not a good idea because it gets modified by each synth (possibly in parallel), causing heavy distortion under various circumstances. Now that this data is allocated and used per-synth everything works fine. --- plugins/zynaddsubfx/LocalZynAddSubFx.cpp | 5 ----- plugins/zynaddsubfx/src/Synth/OscilGen.C | 8 ++++---- plugins/zynaddsubfx/src/Synth/OscilGen.h | 6 +++--- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/plugins/zynaddsubfx/LocalZynAddSubFx.cpp b/plugins/zynaddsubfx/LocalZynAddSubFx.cpp index 013f1bea9..bce9655c6 100644 --- a/plugins/zynaddsubfx/LocalZynAddSubFx.cpp +++ b/plugins/zynaddsubfx/LocalZynAddSubFx.cpp @@ -60,9 +60,6 @@ LocalZynAddSubFx::LocalZynAddSubFx() { denormalkillbuf[i] = (RND-0.5)*1e-16; } - - OscilGen::tmpsmps = new REALTYPE[OSCIL_SIZE]; - newFFTFREQS( &OscilGen::outoscilFFTfreqs, OSCIL_SIZE/2 ); } ++s_instanceCount; @@ -80,8 +77,6 @@ LocalZynAddSubFx::~LocalZynAddSubFx() if( --s_instanceCount == 0 ) { delete[] denormalkillbuf; - delete[] OscilGen::tmpsmps; - deleteFFTFREQS( &OscilGen::outoscilFFTfreqs ); } } diff --git a/plugins/zynaddsubfx/src/Synth/OscilGen.C b/plugins/zynaddsubfx/src/Synth/OscilGen.C index ba1102735..8e18ff214 100644 --- a/plugins/zynaddsubfx/src/Synth/OscilGen.C +++ b/plugins/zynaddsubfx/src/Synth/OscilGen.C @@ -27,14 +27,12 @@ #include "OscilGen.h" #include "../Effects/Distorsion.h" -REALTYPE *OscilGen::tmpsmps;//this array stores some termporary data and it has SOUND_BUFFER_SIZE elements -FFTFREQS OscilGen::outoscilFFTfreqs; - - OscilGen::OscilGen(FFTwrapper *fft_,Resonance *res_):Presets(){ setpresettype("Poscilgen"); fft=fft_; res=res_; + tmpsmps = new REALTYPE[OSCIL_SIZE]; + newFFTFREQS(&outoscilFFTfreqs, OSCIL_SIZE/2); newFFTFREQS(&oscilFFTfreqs,OSCIL_SIZE/2); newFFTFREQS(&basefuncFFTfreqs,OSCIL_SIZE/2); @@ -45,6 +43,8 @@ OscilGen::OscilGen(FFTwrapper *fft_,Resonance *res_):Presets(){ }; OscilGen::~OscilGen(){ + delete[] tmpsmps; + deleteFFTFREQS(&outoscilFFTfreqs); deleteFFTFREQS(&basefuncFFTfreqs); deleteFFTFREQS(&oscilFFTfreqs); }; diff --git a/plugins/zynaddsubfx/src/Synth/OscilGen.h b/plugins/zynaddsubfx/src/Synth/OscilGen.h index 4a3d808da..22ccd0b7f 100644 --- a/plugins/zynaddsubfx/src/Synth/OscilGen.h +++ b/plugins/zynaddsubfx/src/Synth/OscilGen.h @@ -107,11 +107,11 @@ class OscilGen:public Presets{ bool ADvsPAD;//if it is used by ADsynth or by PADsynth - static REALTYPE *tmpsmps;//this array stores some termporary data and it has SOUND_BUFFER_SIZE elements - static FFTFREQS outoscilFFTfreqs; - private: + REALTYPE *tmpsmps;//this array stores some termporary data and it has SOUND_BUFFER_SIZE elements + FFTFREQS outoscilFFTfreqs; + REALTYPE hmag[MAX_AD_HARMONICS],hphase[MAX_AD_HARMONICS];//the magnituides and the phases of the sine/nonsine harmonics // private: FFTwrapper *fft;