From 966f2d253cd2ee6ce140ad68095a20a9d2b63052 Mon Sep 17 00:00:00 2001 From: Chris Johnson Date: Sun, 27 Jan 2019 21:13:54 -0500 Subject: Floating Point Dither For All --- plugins/WinVST/Average/.vs/VSTProject/v14/.suo | Bin 22528 -> 22528 bytes plugins/WinVST/Average/Average.cpp | 7 +-- plugins/WinVST/Average/Average.h | 7 +-- plugins/WinVST/Average/AverageProc.cpp | 66 +++++++------------------ 4 files changed, 23 insertions(+), 57 deletions(-) (limited to 'plugins/WinVST/Average') diff --git a/plugins/WinVST/Average/.vs/VSTProject/v14/.suo b/plugins/WinVST/Average/.vs/VSTProject/v14/.suo index 24b500e..832bbaa 100755 Binary files a/plugins/WinVST/Average/.vs/VSTProject/v14/.suo and b/plugins/WinVST/Average/.vs/VSTProject/v14/.suo differ diff --git a/plugins/WinVST/Average/Average.cpp b/plugins/WinVST/Average/Average.cpp index 945c76c..2f39ca1 100755 --- a/plugins/WinVST/Average/Average.cpp +++ b/plugins/WinVST/Average/Average.cpp @@ -17,11 +17,8 @@ Average::Average(audioMasterCallback audioMaster) : for(int count = 0; count < 11; count++) {bL[count] = 0.0; bR[count] = 0.0; f[count] = 0.0;} - fpNShapeLA = 0.0; - fpNShapeLB = 0.0; - fpNShapeRA = 0.0; - fpNShapeRB = 0.0; - fpFlip = true; + fpNShapeL = 0.0; + fpNShapeR = 0.0; //this is reset: values being initialized only once. Startup values, whatever they are. _canDo.insert("plugAsChannelInsert"); // plug-in can be used as a channel insert effect. diff --git a/plugins/WinVST/Average/Average.h b/plugins/WinVST/Average/Average.h index 7e4b25e..9932e99 100755 --- a/plugins/WinVST/Average/Average.h +++ b/plugins/WinVST/Average/Average.h @@ -57,11 +57,8 @@ private: double f[11]; double bR[11]; - long double fpNShapeLA; - long double fpNShapeLB; - long double fpNShapeRA; - long double fpNShapeRB; - bool fpFlip; + long double fpNShapeL; + long double fpNShapeR; //default stuff float A; diff --git a/plugins/WinVST/Average/AverageProc.cpp b/plugins/WinVST/Average/AverageProc.cpp index 2b1c355..17f4783 100755 --- a/plugins/WinVST/Average/AverageProc.cpp +++ b/plugins/WinVST/Average/AverageProc.cpp @@ -14,9 +14,6 @@ void Average::processReplacing(float **inputs, float **outputs, VstInt32 sampleF float* out1 = outputs[0]; float* out2 = outputs[1]; - float fpTemp; - long double fpOld = 0.618033988749894848204586; //golden ratio! - long double fpNew = 1.0 - fpOld; double correctionSample; double accumulatorSampleL; @@ -154,25 +151,14 @@ void Average::processReplacing(float **inputs, float **outputs, VstInt32 sampleF //in the floating point system. - //noise shaping to 32-bit floating point - if (fpFlip) { - fpTemp = inputSampleL; - fpNShapeLA = (fpNShapeLA*fpOld)+((inputSampleL-fpTemp)*fpNew); - inputSampleL += fpNShapeLA; - fpTemp = inputSampleR; - fpNShapeRA = (fpNShapeRA*fpOld)+((inputSampleR-fpTemp)*fpNew); - inputSampleR += fpNShapeRA; - } - else { - fpTemp = inputSampleL; - fpNShapeLB = (fpNShapeLB*fpOld)+((inputSampleL-fpTemp)*fpNew); - inputSampleL += fpNShapeLB; - fpTemp = inputSampleR; - fpNShapeRB = (fpNShapeRB*fpOld)+((inputSampleR-fpTemp)*fpNew); - inputSampleR += fpNShapeRB; - } - fpFlip = !fpFlip; - //end noise shaping on 32 bit output + //stereo 32 bit dither, made small and tidy. + int expon; frexpf((float)inputSampleL, &expon); + long double dither = (rand()/(RAND_MAX*7.737125245533627e+25))*pow(2,expon+62); + inputSampleL += (dither-fpNShapeL); fpNShapeL = dither; + frexpf((float)inputSampleR, &expon); + dither = (rand()/(RAND_MAX*7.737125245533627e+25))*pow(2,expon+62); + inputSampleR += (dither-fpNShapeR); fpNShapeR = dither; + //end 32 bit dither *out1 = inputSampleL; *out2 = inputSampleR; @@ -189,12 +175,7 @@ void Average::processDoubleReplacing(double **inputs, double **outputs, VstInt32 double* in1 = inputs[0]; double* in2 = inputs[1]; double* out1 = outputs[0]; - double* out2 = outputs[1]; - - double fpTemp; - long double fpOld = 0.618033988749894848204586; //golden ratio! - long double fpNew = 1.0 - fpOld; - + double* out2 = outputs[1]; double correctionSample; double accumulatorSampleL; double accumulatorSampleR; @@ -330,25 +311,16 @@ void Average::processDoubleReplacing(double **inputs, double **outputs, VstInt32 //if it 'won't change anything' but our sample might be at a very different scaling //in the floating point system. - //noise shaping to 64-bit floating point - if (fpFlip) { - fpTemp = inputSampleL; - fpNShapeLA = (fpNShapeLA*fpOld)+((inputSampleL-fpTemp)*fpNew); - inputSampleL += fpNShapeLA; - fpTemp = inputSampleR; - fpNShapeRA = (fpNShapeRA*fpOld)+((inputSampleR-fpTemp)*fpNew); - inputSampleR += fpNShapeRA; - } - else { - fpTemp = inputSampleL; - fpNShapeLB = (fpNShapeLB*fpOld)+((inputSampleL-fpTemp)*fpNew); - inputSampleL += fpNShapeLB; - fpTemp = inputSampleR; - fpNShapeRB = (fpNShapeRB*fpOld)+((inputSampleR-fpTemp)*fpNew); - inputSampleR += fpNShapeRB; - } - fpFlip = !fpFlip; - //end noise shaping on 64 bit output + //stereo 64 bit dither, made small and tidy. + int expon; frexp((double)inputSampleL, &expon); + long double dither = (rand()/(RAND_MAX*7.737125245533627e+25))*pow(2,expon+62); + dither /= 536870912.0; //needs this to scale to 64 bit zone + inputSampleL += (dither-fpNShapeL); fpNShapeL = dither; + frexp((double)inputSampleR, &expon); + dither = (rand()/(RAND_MAX*7.737125245533627e+25))*pow(2,expon+62); + dither /= 536870912.0; //needs this to scale to 64 bit zone + inputSampleR += (dither-fpNShapeR); fpNShapeR = dither; + //end 64 bit dither *out1 = inputSampleL; *out2 = inputSampleR; -- cgit v1.2.3