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/Air/.vs/VSTProject/v14/.suo | Bin 22528 -> 22528 bytes plugins/WinVST/Air/Air.cpp | 7 +--- plugins/WinVST/Air/Air.h | 7 +--- plugins/WinVST/Air/AirProc.cpp | 62 +++++++++-------------------- 4 files changed, 22 insertions(+), 54 deletions(-) (limited to 'plugins/WinVST/Air') diff --git a/plugins/WinVST/Air/.vs/VSTProject/v14/.suo b/plugins/WinVST/Air/.vs/VSTProject/v14/.suo index 5e12ea1..50bebe3 100755 Binary files a/plugins/WinVST/Air/.vs/VSTProject/v14/.suo and b/plugins/WinVST/Air/.vs/VSTProject/v14/.suo differ diff --git a/plugins/WinVST/Air/Air.cpp b/plugins/WinVST/Air/Air.cpp index ebe8adc..ea52c26 100755 --- a/plugins/WinVST/Air/Air.cpp +++ b/plugins/WinVST/Air/Air.cpp @@ -61,11 +61,8 @@ Air::Air(audioMasterCallback audioMaster) : D = 0.0; E = 1.0; F = 1.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/Air/Air.h b/plugins/WinVST/Air/Air.h index 00c0b76..a713cf2 100755 --- a/plugins/WinVST/Air/Air.h +++ b/plugins/WinVST/Air/Air.h @@ -100,11 +100,8 @@ private: bool flop; int count; - 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/Air/AirProc.cpp b/plugins/WinVST/Air/AirProc.cpp index f73e7d8..f5eb39f 100755 --- a/plugins/WinVST/Air/AirProc.cpp +++ b/plugins/WinVST/Air/AirProc.cpp @@ -22,9 +22,6 @@ void Air::processReplacing(float **inputs, float **outputs, VstInt32 sampleFrame double wet = F; double dry = 1.0-wet; - float fpTemp; - long double fpOld = 0.618033988749894848204586; //golden ratio! - long double fpNew = 1.0 - fpOld; long double inputSampleL; long double inputSampleR; @@ -260,25 +257,14 @@ void Air::processReplacing(float **inputs, float **outputs, VstInt32 sampleFrame //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; @@ -305,9 +291,6 @@ void Air::processDoubleReplacing(double **inputs, double **outputs, VstInt32 sam double wet = F; double dry = 1.0-wet; - 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; @@ -543,25 +526,16 @@ void Air::processDoubleReplacing(double **inputs, double **outputs, VstInt32 sam //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