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/EQ/.vs/VSTProject/v14/.suo | Bin 22528 -> 22528 bytes plugins/WinVST/EQ/EQ.cpp | 7 +--- plugins/WinVST/EQ/EQ.h | 7 +--- plugins/WinVST/EQ/EQProc.cpp | 62 +++++++++--------------------- 4 files changed, 22 insertions(+), 54 deletions(-) (limited to 'plugins/WinVST/EQ') diff --git a/plugins/WinVST/EQ/.vs/VSTProject/v14/.suo b/plugins/WinVST/EQ/.vs/VSTProject/v14/.suo index faccb3d..fec6949 100755 Binary files a/plugins/WinVST/EQ/.vs/VSTProject/v14/.suo and b/plugins/WinVST/EQ/.vs/VSTProject/v14/.suo differ diff --git a/plugins/WinVST/EQ/EQ.cpp b/plugins/WinVST/EQ/EQ.cpp index ebdadaa..f2e4e01 100755 --- a/plugins/WinVST/EQ/EQ.cpp +++ b/plugins/WinVST/EQ/EQ.cpp @@ -111,11 +111,8 @@ EQ::EQ(audioMasterCallback audioMaster) : flip = false; flipthree = 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/EQ/EQ.h b/plugins/WinVST/EQ/EQ.h index 4317a2d..26fade4 100755 --- a/plugins/WinVST/EQ/EQ.h +++ b/plugins/WinVST/EQ/EQ.h @@ -59,11 +59,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 lastSampleL; diff --git a/plugins/WinVST/EQ/EQProc.cpp b/plugins/WinVST/EQ/EQProc.cpp index 6d994a9..917dc7e 100755 --- a/plugins/WinVST/EQ/EQProc.cpp +++ b/plugins/WinVST/EQ/EQProc.cpp @@ -20,9 +20,6 @@ void EQ::processReplacing(float **inputs, float **outputs, VstInt32 sampleFrames overallscale = getSampleRate(); compscale = compscale * overallscale; //compscale is the one that's 1 or something like 2.2 for 96K rates - float fpTemp; - long double fpOld = 0.618033988749894848204586; //golden ratio! - long double fpNew = 1.0 - fpOld; long double inputSampleL; long double inputSampleR; @@ -434,25 +431,14 @@ void EQ::processReplacing(float **inputs, float **outputs, VstInt32 sampleFrames inputSampleR *= outputgain; } - //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; @@ -477,9 +463,6 @@ void EQ::processDoubleReplacing(double **inputs, double **outputs, VstInt32 samp overallscale = getSampleRate(); compscale = compscale * overallscale; //compscale is the one that's 1 or something like 2.2 for 96K rates - double fpTemp; - long double fpOld = 0.618033988749894848204586; //golden ratio! - long double fpNew = 1.0 - fpOld; long double inputSampleL; long double inputSampleR; @@ -891,25 +874,16 @@ void EQ::processDoubleReplacing(double **inputs, double **outputs, VstInt32 samp inputSampleR *= outputgain; } - //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