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 --- .../christopherjohnson.pbxuser | 4 +- .../christopherjohnson.perspectivev3 | 9 ++-- plugins/MacVST/HighImpact/source/HighImpact.cpp | 7 +-- plugins/MacVST/HighImpact/source/HighImpact.h | 7 +-- .../MacVST/HighImpact/source/HighImpactProc.cpp | 62 +++++++--------------- 5 files changed, 28 insertions(+), 61 deletions(-) (limited to 'plugins/MacVST/HighImpact') diff --git a/plugins/MacVST/HighImpact/HighImpact.xcodeproj/christopherjohnson.pbxuser b/plugins/MacVST/HighImpact/HighImpact.xcodeproj/christopherjohnson.pbxuser index ebcffae..b8832a5 100755 --- a/plugins/MacVST/HighImpact/HighImpact.xcodeproj/christopherjohnson.pbxuser +++ b/plugins/MacVST/HighImpact/HighImpact.xcodeproj/christopherjohnson.pbxuser @@ -49,8 +49,8 @@ PBXFileDataSource_Warnings_ColumnID, ); }; - PBXPerProjectTemplateStateSaveDate = 528460737; - PBXWorkspaceStateSaveDate = 528460737; + PBXPerProjectTemplateStateSaveDate = 569768208; + PBXWorkspaceStateSaveDate = 569768208; }; sourceControlManager = 8B02375E1D42B1C400E1E8C8 /* Source Control */; userBuildSettings = { diff --git a/plugins/MacVST/HighImpact/HighImpact.xcodeproj/christopherjohnson.perspectivev3 b/plugins/MacVST/HighImpact/HighImpact.xcodeproj/christopherjohnson.perspectivev3 index 437b8d3..f860614 100755 --- a/plugins/MacVST/HighImpact/HighImpact.xcodeproj/christopherjohnson.perspectivev3 +++ b/plugins/MacVST/HighImpact/HighImpact.xcodeproj/christopherjohnson.perspectivev3 @@ -469,11 +469,11 @@ TableOfContents - 8B9D7ACE1F7FABD1007AB60F + 8B793BAE21F5F91A006E9731 1CA23ED40692098700951B8B - 8B9D7ACF1F7FABD1007AB60F + 8B793BAF21F5F91A006E9731 8B0237581D42B1C400E1E8C8 - 8B9D7AD01F7FABD1007AB60F + 8B793BB021F5F91A006E9731 1CA23EDF0692099D00951B8B 1CA23EE00692099D00951B8B 1CA23EE10692099D00951B8B @@ -626,7 +626,7 @@ StatusbarIsVisible TimeStamp - 528460753.11869597 + 569768218.37077904 ToolbarConfigUserDefaultsMinorVersion 2 ToolbarDisplayMode @@ -643,7 +643,6 @@ 5 WindowOrderList - 8B9D7AD11F7FABD1007AB60F /Users/christopherjohnson/Desktop/MacVST/HighImpact/HighImpact.xcodeproj WindowString diff --git a/plugins/MacVST/HighImpact/source/HighImpact.cpp b/plugins/MacVST/HighImpact/source/HighImpact.cpp index 0944b18..960d80c 100755 --- a/plugins/MacVST/HighImpact/source/HighImpact.cpp +++ b/plugins/MacVST/HighImpact/source/HighImpact.cpp @@ -17,11 +17,8 @@ HighImpact::HighImpact(audioMasterCallback audioMaster) : C = 0.0; lastSampleL = 0.0; lastSampleR = 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/MacVST/HighImpact/source/HighImpact.h b/plugins/MacVST/HighImpact/source/HighImpact.h index 9c7a4a0..a57230b 100755 --- a/plugins/MacVST/HighImpact/source/HighImpact.h +++ b/plugins/MacVST/HighImpact/source/HighImpact.h @@ -54,11 +54,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/MacVST/HighImpact/source/HighImpactProc.cpp b/plugins/MacVST/HighImpact/source/HighImpactProc.cpp index 037bbe9..f24804a 100755 --- a/plugins/MacVST/HighImpact/source/HighImpactProc.cpp +++ b/plugins/MacVST/HighImpact/source/HighImpactProc.cpp @@ -14,9 +14,6 @@ void HighImpact::processReplacing(float **inputs, float **outputs, VstInt32 samp float* out1 = outputs[0]; float* out2 = outputs[1]; - float fpTemp; - long double fpOld = 0.618033988749894848204586; //golden ratio! - long double fpNew = 1.0 - fpOld; long double inputSampleL; long double inputSampleR; @@ -161,25 +158,14 @@ void HighImpact::processReplacing(float **inputs, float **outputs, VstInt32 samp //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; @@ -201,9 +187,6 @@ void HighImpact::processDoubleReplacing(double **inputs, double **outputs, VstIn 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; long double inputSampleL; long double inputSampleR; @@ -348,25 +331,16 @@ void HighImpact::processDoubleReplacing(double **inputs, double **outputs, VstIn //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