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/Hermepass/.vs/VSTProject/v14/.suo | Bin 23040 -> 23040 bytes plugins/WinVST/Hermepass/Hermepass.cpp | 7 +-- plugins/WinVST/Hermepass/Hermepass.h | 9 ++-- plugins/WinVST/Hermepass/HermepassProc.cpp | 66 ++++++++--------------- 4 files changed, 28 insertions(+), 54 deletions(-) (limited to 'plugins/WinVST/Hermepass') diff --git a/plugins/WinVST/Hermepass/.vs/VSTProject/v14/.suo b/plugins/WinVST/Hermepass/.vs/VSTProject/v14/.suo index 2a195c6..3564c29 100755 Binary files a/plugins/WinVST/Hermepass/.vs/VSTProject/v14/.suo and b/plugins/WinVST/Hermepass/.vs/VSTProject/v14/.suo differ diff --git a/plugins/WinVST/Hermepass/Hermepass.cpp b/plugins/WinVST/Hermepass/Hermepass.cpp index 3bfb1aa..4e4a532 100755 --- a/plugins/WinVST/Hermepass/Hermepass.cpp +++ b/plugins/WinVST/Hermepass/Hermepass.cpp @@ -32,12 +32,9 @@ Hermepass::Hermepass(audioMasterCallback audioMaster) : iirFR = 0.0; iirGR = 0.0; iirHR = 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/Hermepass/Hermepass.h b/plugins/WinVST/Hermepass/Hermepass.h index 4f29497..1000bb9 100755 --- a/plugins/WinVST/Hermepass/Hermepass.h +++ b/plugins/WinVST/Hermepass/Hermepass.h @@ -53,11 +53,8 @@ private: char _programName[kVstMaxProgNameLen + 1]; std::set< std::string > _canDo; - long double fpNShapeLA; - long double fpNShapeLB; - long double fpNShapeRA; - long double fpNShapeRB; - bool fpFlip; + long double fpNShapeL; + long double fpNShapeR; //default stuff double iirAL; double iirBL; //first stage is the flipping one, for lowest slope. It is always engaged, and is the highest one @@ -76,7 +73,7 @@ private: double iirFR; //our slope control will have a pow() on it so that the high orders are way to the right side double iirGR; double iirHR; //seven poles max, and the final pole is always at 20hz directly. - + bool fpFlip; float A; diff --git a/plugins/WinVST/Hermepass/HermepassProc.cpp b/plugins/WinVST/Hermepass/HermepassProc.cpp index 01b35aa..fddffe3 100755 --- a/plugins/WinVST/Hermepass/HermepassProc.cpp +++ b/plugins/WinVST/Hermepass/HermepassProc.cpp @@ -17,10 +17,8 @@ void Hermepass::processReplacing(float **inputs, float **outputs, VstInt32 sampl double overallscale = 1.0; overallscale /= 44100.0; overallscale *= getSampleRate(); - float fpTemp; long double fpOld = 0.618033988749894848204586; //golden ratio! - long double fpNew = 1.0 - fpOld; - + long double fpNew = 1.0 - fpOld; double rangescale = 0.1 / overallscale; double cutoff = pow(A,3); @@ -175,26 +173,17 @@ void Hermepass::processReplacing(float **inputs, float **outputs, VstInt32 sampl inputSampleR -= correction; //end R channel - - //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; @@ -216,10 +205,8 @@ void Hermepass::processDoubleReplacing(double **inputs, double **outputs, VstInt double overallscale = 1.0; overallscale /= 44100.0; overallscale *= getSampleRate(); - double fpTemp; //this is different from singlereplacing long double fpOld = 0.618033988749894848204586; //golden ratio! long double fpNew = 1.0 - fpOld; - double rangescale = 0.1 / overallscale; double cutoff = pow(A,3); @@ -374,26 +361,19 @@ void Hermepass::processDoubleReplacing(double **inputs, double **outputs, VstInt inputSampleR -= correction; //end R channel - - //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