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 | 20 +++---- .../christopherjohnson.perspectivev3 | 30 +++++------ plugins/MacVST/BussColors4/source/BussColors4.cpp | 22 +------- plugins/MacVST/BussColors4/source/BussColors4.h | 7 +-- .../MacVST/BussColors4/source/BussColors4Proc.cpp | 62 +++++++--------------- 5 files changed, 47 insertions(+), 94 deletions(-) (limited to 'plugins/MacVST/BussColors4') diff --git a/plugins/MacVST/BussColors4/BussColors4.xcodeproj/christopherjohnson.pbxuser b/plugins/MacVST/BussColors4/BussColors4.xcodeproj/christopherjohnson.pbxuser index 874e77e..56965b2 100755 --- a/plugins/MacVST/BussColors4/BussColors4.xcodeproj/christopherjohnson.pbxuser +++ b/plugins/MacVST/BussColors4/BussColors4.xcodeproj/christopherjohnson.pbxuser @@ -49,11 +49,11 @@ PBXFileDataSource_Warnings_ColumnID, ); }; - PBXPerProjectTemplateStateSaveDate = 553995952; - PBXWorkspaceStateSaveDate = 553995952; + PBXPerProjectTemplateStateSaveDate = 569718632; + PBXWorkspaceStateSaveDate = 569718632; }; perUserProjectItems = { - 8BBD1972210550260015A233 /* PBXTextBookmark */ = 8BBD1972210550260015A233 /* PBXTextBookmark */; + 8B7934BC21F53792006E9731 /* PBXTextBookmark */ = 8B7934BC21F53792006E9731 /* PBXTextBookmark */; 8BBD1973210550260015A233 /* PBXTextBookmark */ = 8BBD1973210550260015A233 /* PBXTextBookmark */; }; sourceControlManager = 8B02375E1D42B1C400E1E8C8 /* Source Control */; @@ -62,9 +62,9 @@ }; 2407DEB6089929BA00EB68BF /* BussColors4.cpp */ = { uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {747, 2613}}"; + sepNavIntBoundsRect = "{{0, 0}, {747, 2392}}"; sepNavSelRange = "{6740, 15}"; - sepNavVisRange = "{44, 192}"; + sepNavVisRange = "{44, 191}"; sepNavWindowFrame = "{{545, 42}, {895, 831}}"; }; }; @@ -86,10 +86,10 @@ }; 24D8286F09A914000093AEF8 /* BussColors4Proc.cpp */ = { uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {848, 22958}}"; + sepNavIntBoundsRect = "{{0, 0}, {848, 21840}}"; sepNavSelRange = "{2156, 16}"; - sepNavVisRange = "{2297, 2204}"; - sepNavWindowFrame = "{{529, 47}, {895, 831}}"; + sepNavVisRange = "{114530, 2497}"; + sepNavWindowFrame = "{{399, 47}, {895, 831}}"; }; }; 8B02375E1D42B1C400E1E8C8 /* Source Control */ = { @@ -106,14 +106,14 @@ isa = PBXCodeSenseManager; indexTemplatePath = ""; }; - 8BBD1972210550260015A233 /* PBXTextBookmark */ = { + 8B7934BC21F53792006E9731 /* PBXTextBookmark */ = { isa = PBXTextBookmark; fRef = 2407DEB6089929BA00EB68BF /* BussColors4.cpp */; name = "BussColors4.cpp: 167"; rLen = 15; rLoc = 6740; rType = 0; - vrLen = 328; + vrLen = 191; vrLoc = 44; }; 8BBD1973210550260015A233 /* PBXTextBookmark */ = { diff --git a/plugins/MacVST/BussColors4/BussColors4.xcodeproj/christopherjohnson.perspectivev3 b/plugins/MacVST/BussColors4/BussColors4.xcodeproj/christopherjohnson.perspectivev3 index dff2c57..38ff207 100755 --- a/plugins/MacVST/BussColors4/BussColors4.xcodeproj/christopherjohnson.perspectivev3 +++ b/plugins/MacVST/BussColors4/BussColors4.xcodeproj/christopherjohnson.perspectivev3 @@ -323,7 +323,7 @@ 185 RubberWindowFrame - 567 362 810 487 0 0 1440 878 + 567 361 810 487 0 0 1440 878 Module PBXSmartGroupTreeModule @@ -351,10 +351,10 @@ _historyCapacity 0 bookmark - 8BBD1973210550260015A233 + 8B7934BC21F53792006E9731 history - 8BBD1972210550260015A233 + 8BBD1973210550260015A233 SplitCount @@ -368,18 +368,18 @@ GeometryConfiguration Frame - {{0, 0}, {603, 132}} + {{0, 0}, {603, 117}} RubberWindowFrame - 567 362 810 487 0 0 1440 878 + 567 361 810 487 0 0 1440 878 Module PBXNavigatorGroup Proportion - 132pt + 117pt Proportion - 309pt + 324pt Tabs @@ -393,9 +393,9 @@ GeometryConfiguration Frame - {{10, 27}, {603, 282}} + {{10, 27}, {603, 297}} RubberWindowFrame - 567 362 810 487 0 0 1440 878 + 567 361 810 487 0 0 1440 878 Module XCDetailModule @@ -477,11 +477,11 @@ TableOfContents - 8BBD1974210550260015A233 + 8B7934AA21F5376C006E9731 1CA23ED40692098700951B8B - 8BBD1975210550260015A233 + 8B7934AB21F5376C006E9731 8B0237581D42B1C400E1E8C8 - 8BBD1976210550260015A233 + 8B7934AC21F5376C006E9731 1CA23EDF0692099D00951B8B 1CA23EE00692099D00951B8B 1CA23EE10692099D00951B8B @@ -634,7 +634,7 @@ StatusbarIsVisible TimeStamp - 553996326.29762602 + 569718674.56684196 ToolbarConfigUserDefaultsMinorVersion 2 ToolbarDisplayMode @@ -651,11 +651,11 @@ 5 WindowOrderList - 8BBD1977210550260015A233 + 8B7934BD21F53792006E9731 /Users/christopherjohnson/Desktop/MacVST/BussColors4/BussColors4.xcodeproj WindowString - 567 362 810 487 0 0 1440 878 + 567 361 810 487 0 0 1440 878 WindowToolsV3 diff --git a/plugins/MacVST/BussColors4/source/BussColors4.cpp b/plugins/MacVST/BussColors4/source/BussColors4.cpp index 720dbf9..c7de380 100755 --- a/plugins/MacVST/BussColors4/source/BussColors4.cpp +++ b/plugins/MacVST/BussColors4/source/BussColors4.cpp @@ -44,11 +44,8 @@ BussColors4::BussColors4(audioMasterCallback audioMaster) : slowdynR = 0; gcount = 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. @@ -114,21 +111,6 @@ void BussColors4::setParameter(VstInt32 index, float value) { case kParamD: D = value; break; //this is the popup, stored as a float default: throw; // unknown parameter, shouldn't happen! } - //we can also set other defaults here, and do calculations that only have to happen - //once when parameters actually change. Here is the 'popup' setting its (global) values. - //variables can also be set in the processreplacing loop, and there they'll be set every buffersize - //here they're set when a parameter's actually changed, which should be less frequent, but - //you must use global variables in the BussColors4.h file to do it. - switch((VstInt32)( D * 3.999 )) - { - case 0: fpFlip = true; break; //choice A - case 1: fpFlip = false; break; //choice B - case 2: break; //choice C - case 3: break; //choice D - default: break; //should not happen - } - //this relates to using D as a 'popup' and changing things based on that switch. - //we are using fpFlip just because it's already there globally, as an example. } float BussColors4::getParameter(VstInt32 index) { diff --git a/plugins/MacVST/BussColors4/source/BussColors4.h b/plugins/MacVST/BussColors4/source/BussColors4.h index d07460e..6452555 100755 --- a/plugins/MacVST/BussColors4/source/BussColors4.h +++ b/plugins/MacVST/BussColors4/source/BussColors4.h @@ -68,11 +68,8 @@ private: double slowdynR; int gcount; - 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/MacVST/BussColors4/source/BussColors4Proc.cpp b/plugins/MacVST/BussColors4/source/BussColors4Proc.cpp index 2629ee8..b1b9451 100755 --- a/plugins/MacVST/BussColors4/source/BussColors4Proc.cpp +++ b/plugins/MacVST/BussColors4/source/BussColors4Proc.cpp @@ -31,9 +31,6 @@ void BussColors4::processReplacing(float **inputs, float **outputs, VstInt32 sam double gain = 0.436; double outgain = 1.0; double bridgerectifier; - float fpTemp; - long double fpOld = 0.618033988749894848204586; //golden ratio! - long double fpNew = 1.0 - fpOld; long double inputSampleL; long double inputSampleR; @@ -795,25 +792,14 @@ void BussColors4::processReplacing(float **inputs, float **outputs, VstInt32 sam inputSampleR = (inputSampleR * wet) + (drySampleR * dry); } - //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; @@ -849,9 +835,6 @@ void BussColors4::processDoubleReplacing(double **inputs, double **outputs, VstI double gain = 0.436; double outgain = 1.0; double bridgerectifier; - double fpTemp; - long double fpOld = 0.618033988749894848204586; //golden ratio! - long double fpNew = 1.0 - fpOld; long double inputSampleL; long double inputSampleR; @@ -1613,25 +1596,16 @@ void BussColors4::processDoubleReplacing(double **inputs, double **outputs, VstI inputSampleR = (inputSampleR * wet) + (drySampleR * dry); } - //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