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 --- .../EveryTrim.xcodeproj/christopherjohnson.pbxuser | 8 +-- .../christopherjohnson.perspectivev3 | 17 +++--- .../EveryTrim/EveryTrim.xcodeproj/project.pbxproj | 4 +- plugins/MacVST/EveryTrim/source/EveryTrim.cpp | 7 +-- plugins/MacVST/EveryTrim/source/EveryTrim.h | 7 +-- plugins/MacVST/EveryTrim/source/EveryTrimProc.cpp | 62 +++++++--------------- 6 files changed, 36 insertions(+), 69 deletions(-) (limited to 'plugins/MacVST/EveryTrim') diff --git a/plugins/MacVST/EveryTrim/EveryTrim.xcodeproj/christopherjohnson.pbxuser b/plugins/MacVST/EveryTrim/EveryTrim.xcodeproj/christopherjohnson.pbxuser index ebc50eb..b623a38 100755 --- a/plugins/MacVST/EveryTrim/EveryTrim.xcodeproj/christopherjohnson.pbxuser +++ b/plugins/MacVST/EveryTrim/EveryTrim.xcodeproj/christopherjohnson.pbxuser @@ -2,7 +2,7 @@ { 089C1669FE841209C02AAC07 /* Project object */ = { activeBuildConfigurationName = Release; - activeTarget = 8D01CCC60486CAD60068D4B7 /* EveryTrim */; + activeTarget = 8D01CCC60486CAD60068D4B7 /* AudioUnit */; codeSenseManager = 8B02375F1D42B1C400E1E8C8 /* Code sense */; perUserDictionary = { PBXConfiguration.PBXFileTableDataSource3.PBXFileTableDataSource = { @@ -49,8 +49,8 @@ PBXFileDataSource_Warnings_ColumnID, ); }; - PBXPerProjectTemplateStateSaveDate = 532471894; - PBXWorkspaceStateSaveDate = 532471894; + PBXPerProjectTemplateStateSaveDate = 569735228; + PBXWorkspaceStateSaveDate = 569735228; }; sourceControlManager = 8B02375E1D42B1C400E1E8C8 /* Source Control */; userBuildSettings = { @@ -102,7 +102,7 @@ isa = PBXCodeSenseManager; indexTemplatePath = ""; }; - 8D01CCC60486CAD60068D4B7 /* EveryTrim */ = { + 8D01CCC60486CAD60068D4B7 /* AudioUnit */ = { activeExec = 0; }; } diff --git a/plugins/MacVST/EveryTrim/EveryTrim.xcodeproj/christopherjohnson.perspectivev3 b/plugins/MacVST/EveryTrim/EveryTrim.xcodeproj/christopherjohnson.perspectivev3 index cc28805..09818e7 100755 --- a/plugins/MacVST/EveryTrim/EveryTrim.xcodeproj/christopherjohnson.perspectivev3 +++ b/plugins/MacVST/EveryTrim/EveryTrim.xcodeproj/christopherjohnson.perspectivev3 @@ -323,7 +323,7 @@ 185 RubberWindowFrame - 653 231 810 487 0 0 1440 878 + 630 231 810 487 0 0 1440 878 Module PBXSmartGroupTreeModule @@ -362,7 +362,7 @@ Frame {{0, 0}, {603, 0}} RubberWindowFrame - 653 231 810 487 0 0 1440 878 + 630 231 810 487 0 0 1440 878 Module PBXNavigatorGroup @@ -387,7 +387,7 @@ Frame {{10, 27}, {603, 414}} RubberWindowFrame - 653 231 810 487 0 0 1440 878 + 630 231 810 487 0 0 1440 878 Module XCDetailModule @@ -469,11 +469,11 @@ TableOfContents - 8BB5DD0E1FBCE05D008B4570 + 8B793A2521F57858006E9731 1CA23ED40692098700951B8B - 8BB5DD0F1FBCE05D008B4570 + 8B793A2621F57858006E9731 8B0237581D42B1C400E1E8C8 - 8BB5DD101FBCE05D008B4570 + 8B793A2721F57858006E9731 1CA23EDF0692099D00951B8B 1CA23EE00692099D00951B8B 1CA23EE10692099D00951B8B @@ -626,7 +626,7 @@ StatusbarIsVisible TimeStamp - 532472312.54818797 + 569735256.70818996 ToolbarConfigUserDefaultsMinorVersion 2 ToolbarDisplayMode @@ -643,11 +643,10 @@ 5 WindowOrderList - 8BB5DD481FBCE1F8008B4570 /Users/christopherjohnson/Desktop/MacVST/EveryTrim/EveryTrim.xcodeproj WindowString - 653 231 810 487 0 0 1440 878 + 630 231 810 487 0 0 1440 878 WindowToolsV3 diff --git a/plugins/MacVST/EveryTrim/EveryTrim.xcodeproj/project.pbxproj b/plugins/MacVST/EveryTrim/EveryTrim.xcodeproj/project.pbxproj index d45d548..e1a1fd8 100755 --- a/plugins/MacVST/EveryTrim/EveryTrim.xcodeproj/project.pbxproj +++ b/plugins/MacVST/EveryTrim/EveryTrim.xcodeproj/project.pbxproj @@ -1894,7 +1894,7 @@ /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ - 8D01CCC60486CAD60068D4B7 /* EveryTrim */ = { + 8D01CCC60486CAD60068D4B7 /* AudioUnit */ = { isa = PBXNativeTarget; buildConfigurationList = 24BEAAED08919AE700E695F9 /* Build configuration list for PBXNativeTarget "EveryTrim" */; buildPhases = ( @@ -1947,7 +1947,7 @@ ); projectRoot = ""; targets = ( - 8D01CCC60486CAD60068D4B7 /* EveryTrim */, + 8D01CCC60486CAD60068D4B7 /* AudioUnit */, ); }; /* End PBXProject section */ diff --git a/plugins/MacVST/EveryTrim/source/EveryTrim.cpp b/plugins/MacVST/EveryTrim/source/EveryTrim.cpp index 1e81d35..b0a98d4 100755 --- a/plugins/MacVST/EveryTrim/source/EveryTrim.cpp +++ b/plugins/MacVST/EveryTrim/source/EveryTrim.cpp @@ -17,11 +17,8 @@ EveryTrim::EveryTrim(audioMasterCallback audioMaster) : C = 0.5; D = 0.5; E = 0.5; - 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/EveryTrim/source/EveryTrim.h b/plugins/MacVST/EveryTrim/source/EveryTrim.h index 28d9c27..4efc3cd 100755 --- a/plugins/MacVST/EveryTrim/source/EveryTrim.h +++ b/plugins/MacVST/EveryTrim/source/EveryTrim.h @@ -56,11 +56,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 float A; diff --git a/plugins/MacVST/EveryTrim/source/EveryTrimProc.cpp b/plugins/MacVST/EveryTrim/source/EveryTrimProc.cpp index 30d764f..3c30eda 100755 --- a/plugins/MacVST/EveryTrim/source/EveryTrimProc.cpp +++ b/plugins/MacVST/EveryTrim/source/EveryTrimProc.cpp @@ -14,9 +14,6 @@ void EveryTrim::processReplacing(float **inputs, float **outputs, VstInt32 sampl float* out1 = outputs[0]; float* out2 = outputs[1]; - float fpTemp; - long double fpOld = 0.618033988749894848204586; //golden ratio! - long double fpNew = 1.0 - fpOld; double leftgain = pow(10.0,((A*24.0)-12.0)/20.0); double rightgain = pow(10.0,((B*24.0)-12.0)/20.0); @@ -83,25 +80,14 @@ void EveryTrim::processReplacing(float **inputs, float **outputs, VstInt32 sampl inputSampleR = (mid-side) * rightgain; //contains mastergain and the gain trim fixing the mid/side - //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; @@ -120,9 +106,6 @@ void EveryTrim::processDoubleReplacing(double **inputs, double **outputs, VstInt double* out1 = outputs[0]; double* out2 = outputs[1]; - double fpTemp; - long double fpOld = 0.618033988749894848204586; //golden ratio! - long double fpNew = 1.0 - fpOld; double leftgain = pow(10.0,((A*24.0)-12.0)/20.0); double rightgain = pow(10.0,((B*24.0)-12.0)/20.0); @@ -189,25 +172,16 @@ void EveryTrim::processDoubleReplacing(double **inputs, double **outputs, VstInt inputSampleR = (mid-side) * rightgain; //contains mastergain and the gain trim fixing the mid/side - //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