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 --- .../MacVST/uLawEncode/source/uLawEncodeProc.cpp | 54 ++++++++-------------- .../christopherjohnson.pbxuser | 4 +- .../christopherjohnson.perspectivev3 | 9 ++-- 3 files changed, 24 insertions(+), 43 deletions(-) (limited to 'plugins/MacVST/uLawEncode') diff --git a/plugins/MacVST/uLawEncode/source/uLawEncodeProc.cpp b/plugins/MacVST/uLawEncode/source/uLawEncodeProc.cpp index 3d86a7f..c5dd74d 100755 --- a/plugins/MacVST/uLawEncode/source/uLawEncodeProc.cpp +++ b/plugins/MacVST/uLawEncode/source/uLawEncodeProc.cpp @@ -88,18 +88,14 @@ void uLawEncode::processReplacing(float **inputs, float **outputs, VstInt32 samp inputSampleR = (inputSampleR * wet) + (drySampleR * dry); } - //noise shaping to 32-bit floating point - float fpTemp = inputSampleL; - fpNShapeL += (inputSampleL-fpTemp); - inputSampleL += fpNShapeL; - //if this confuses you look at the wordlength for fpTemp :) - fpTemp = inputSampleR; - fpNShapeR += (inputSampleR-fpTemp); - inputSampleR += fpNShapeR; - //for deeper space and warmth, we try a non-oscillating noise shaping - //that is kind of ruthless: it will forever retain the rounding errors - //except we'll dial it back a hair at the end of every buffer processed - //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; @@ -109,12 +105,6 @@ void uLawEncode::processReplacing(float **inputs, float **outputs, VstInt32 samp *out1++; *out2++; } - fpNShapeL *= 0.999999; - fpNShapeR *= 0.999999; - //we will just delicately dial back the FP noise shaping, not even every sample - //this is a good place to put subtle 'no runaway' calculations, though bear in mind - //that it will be called more often when you use shorter sample buffers in the DAW. - //So, very low latency operation will call these calculations more often. } void uLawEncode::processDoubleReplacing(double **inputs, double **outputs, VstInt32 sampleFrames) @@ -198,18 +188,16 @@ void uLawEncode::processDoubleReplacing(double **inputs, double **outputs, VstIn inputSampleR = (inputSampleR * wet) + (drySampleR * dry); } - //noise shaping to 64-bit floating point - double fpTemp = inputSampleL; - fpNShapeL += (inputSampleL-fpTemp); - inputSampleL += fpNShapeL; - //if this confuses you look at the wordlength for fpTemp :) - fpTemp = inputSampleR; - fpNShapeR += (inputSampleR-fpTemp); - inputSampleR += fpNShapeR; - //for deeper space and warmth, we try a non-oscillating noise shaping - //that is kind of ruthless: it will forever retain the rounding errors - //except we'll dial it back a hair at the end of every buffer processed - //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; @@ -219,10 +207,4 @@ void uLawEncode::processDoubleReplacing(double **inputs, double **outputs, VstIn *out1++; *out2++; } - fpNShapeL *= 0.999999; - fpNShapeR *= 0.999999; - //we will just delicately dial back the FP noise shaping, not even every sample - //this is a good place to put subtle 'no runaway' calculations, though bear in mind - //that it will be called more often when you use shorter sample buffers in the DAW. - //So, very low latency operation will call these calculations more often. } diff --git a/plugins/MacVST/uLawEncode/uLawEncode.xcodeproj/christopherjohnson.pbxuser b/plugins/MacVST/uLawEncode/uLawEncode.xcodeproj/christopherjohnson.pbxuser index 37fd5e3..4382acd 100755 --- a/plugins/MacVST/uLawEncode/uLawEncode.xcodeproj/christopherjohnson.pbxuser +++ b/plugins/MacVST/uLawEncode/uLawEncode.xcodeproj/christopherjohnson.pbxuser @@ -49,8 +49,8 @@ PBXFileDataSource_Warnings_ColumnID, ); }; - PBXPerProjectTemplateStateSaveDate = 561241903; - PBXWorkspaceStateSaveDate = 561241903; + PBXPerProjectTemplateStateSaveDate = 569773438; + PBXWorkspaceStateSaveDate = 569773438; }; sourceControlManager = 8B02375E1D42B1C400E1E8C8 /* Source Control */; userBuildSettings = { diff --git a/plugins/MacVST/uLawEncode/uLawEncode.xcodeproj/christopherjohnson.perspectivev3 b/plugins/MacVST/uLawEncode/uLawEncode.xcodeproj/christopherjohnson.perspectivev3 index 01f5c6f..6742d70 100755 --- a/plugins/MacVST/uLawEncode/uLawEncode.xcodeproj/christopherjohnson.perspectivev3 +++ b/plugins/MacVST/uLawEncode/uLawEncode.xcodeproj/christopherjohnson.perspectivev3 @@ -469,11 +469,11 @@ TableOfContents - 8B2721BE2173DF3C00396442 + 8B79428E21F60D86006E9731 1CA23ED40692098700951B8B - 8B2721BF2173DF3C00396442 + 8B79428F21F60D86006E9731 8B0237581D42B1C400E1E8C8 - 8B2721C02173DF3C00396442 + 8B79429021F60D86006E9731 1CA23EDF0692099D00951B8B 1CA23EE00692099D00951B8B 1CA23EE10692099D00951B8B @@ -626,7 +626,7 @@ StatusbarIsVisible TimeStamp - 561241916.28170097 + 569773446.35580504 ToolbarConfigUserDefaultsMinorVersion 2 ToolbarDisplayMode @@ -643,7 +643,6 @@ 5 WindowOrderList - 8B2721C12173DF3C00396442 /Users/christopherjohnson/Desktop/MacVST/uLawEncode/uLawEncode.xcodeproj WindowString -- cgit v1.2.3