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/Drive/.vs/VSTProject/v14/.suo | Bin 22528 -> 24576 bytes plugins/WinVST/Drive/Drive.cpp | 7 +-- plugins/WinVST/Drive/Drive.h | 9 ++-- plugins/WinVST/Drive/DriveProc.cpp | 64 +++++++++------------------ 4 files changed, 25 insertions(+), 55 deletions(-) (limited to 'plugins/WinVST/Drive') diff --git a/plugins/WinVST/Drive/.vs/VSTProject/v14/.suo b/plugins/WinVST/Drive/.vs/VSTProject/v14/.suo index da1c31d..7c0342c 100755 Binary files a/plugins/WinVST/Drive/.vs/VSTProject/v14/.suo and b/plugins/WinVST/Drive/.vs/VSTProject/v14/.suo differ diff --git a/plugins/WinVST/Drive/Drive.cpp b/plugins/WinVST/Drive/Drive.cpp index 35d0594..ac5f228 100755 --- a/plugins/WinVST/Drive/Drive.cpp +++ b/plugins/WinVST/Drive/Drive.cpp @@ -20,12 +20,9 @@ Drive::Drive(audioMasterCallback audioMaster) : iirSampleBL = 0.0; iirSampleAR = 0.0; iirSampleBR = 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/Drive/Drive.h b/plugins/WinVST/Drive/Drive.h index c7039c5..525a09e 100755 --- a/plugins/WinVST/Drive/Drive.h +++ b/plugins/WinVST/Drive/Drive.h @@ -55,17 +55,14 @@ 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 iirSampleAL; double iirSampleBL; double iirSampleAR; double iirSampleBR; - + bool fpFlip; float A; float B; float C; diff --git a/plugins/WinVST/Drive/DriveProc.cpp b/plugins/WinVST/Drive/DriveProc.cpp index 3670e85..074ccfd 100755 --- a/plugins/WinVST/Drive/DriveProc.cpp +++ b/plugins/WinVST/Drive/DriveProc.cpp @@ -26,9 +26,6 @@ void Drive::processReplacing(float **inputs, float **outputs, VstInt32 sampleFra double glitch = 0.60; double out; - float fpTemp; - long double fpOld = 0.618033988749894848204586; //golden ratio! - long double fpNew = 1.0 - fpOld; long double inputSampleL; long double inputSampleR; @@ -95,6 +92,7 @@ void Drive::processReplacing(float **inputs, float **outputs, VstInt32 sampleFra inputSampleR -= iirSampleBR; } //highpass section + fpFlip = !fpFlip; if (inputSampleL > 1.0) inputSampleL = 1.0; @@ -129,25 +127,14 @@ void Drive::processReplacing(float **inputs, float **outputs, VstInt32 sampleFra //nice little output stage template: if we have another scale of floating point //number, we really don't want to meaninglessly multiply that by 1.0. - //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; @@ -178,9 +165,6 @@ void Drive::processDoubleReplacing(double **inputs, double **outputs, VstInt32 s double glitch = 0.60; double out; - double fpTemp; //this is different from singlereplacing - long double fpOld = 0.618033988749894848204586; //golden ratio! - long double fpNew = 1.0 - fpOld; long double inputSampleL; long double inputSampleR; @@ -247,6 +231,7 @@ void Drive::processDoubleReplacing(double **inputs, double **outputs, VstInt32 s inputSampleR -= iirSampleBR; } //highpass section + fpFlip = !fpFlip; if (inputSampleL > 1.0) inputSampleL = 1.0; @@ -281,25 +266,16 @@ void Drive::processDoubleReplacing(double **inputs, double **outputs, VstInt32 s //nice little output stage template: if we have another scale of floating point //number, we really don't want to meaninglessly multiply that by 1.0. - //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