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 --- .../Density.xcodeproj/christopherjohnson.pbxuser | 72 ++++++++++++++++++---- .../christopherjohnson.perspectivev3 | 47 ++++++++------ .../Density/Density.xcodeproj/project.pbxproj | 4 +- plugins/MacVST/Density/source/Density.cpp | 7 +-- plugins/MacVST/Density/source/Density.h | 9 +-- plugins/MacVST/Density/source/DensityProc.cpp | 64 ++++++------------- 6 files changed, 114 insertions(+), 89 deletions(-) (limited to 'plugins/MacVST/Density') diff --git a/plugins/MacVST/Density/Density.xcodeproj/christopherjohnson.pbxuser b/plugins/MacVST/Density/Density.xcodeproj/christopherjohnson.pbxuser index 514aca1..86b1d22 100755 --- a/plugins/MacVST/Density/Density.xcodeproj/christopherjohnson.pbxuser +++ b/plugins/MacVST/Density/Density.xcodeproj/christopherjohnson.pbxuser @@ -2,7 +2,7 @@ { 089C1669FE841209C02AAC07 /* Project object */ = { activeBuildConfigurationName = Release; - activeTarget = 8D01CCC60486CAD60068D4B7 /* AudioUnit */; + activeTarget = 8D01CCC60486CAD60068D4B7 /* Density */; codeSenseManager = 8B02375F1D42B1C400E1E8C8 /* Code sense */; perUserDictionary = { PBXConfiguration.PBXFileTableDataSource3.PBXFileTableDataSource = { @@ -49,8 +49,14 @@ PBXFileDataSource_Warnings_ColumnID, ); }; - PBXPerProjectTemplateStateSaveDate = 528459901; - PBXWorkspaceStateSaveDate = 528459901; + PBXPerProjectTemplateStateSaveDate = 569734277; + PBXWorkspaceStateSaveDate = 569734277; + }; + perUserProjectItems = { + 8B79379F21F574D1006E9731 /* PBXTextBookmark */ = 8B79379F21F574D1006E9731 /* PBXTextBookmark */; + 8B7937A021F574D1006E9731 /* PBXTextBookmark */ = 8B7937A021F574D1006E9731 /* PBXTextBookmark */; + 8B7937A121F574D1006E9731 /* PBXTextBookmark */ = 8B7937A121F574D1006E9731 /* PBXTextBookmark */; + 8B7937A221F574D1006E9731 /* PBXTextBookmark */ = 8B7937A221F574D1006E9731 /* PBXTextBookmark */; }; sourceControlManager = 8B02375E1D42B1C400E1E8C8 /* Source Control */; userBuildSettings = { @@ -58,17 +64,17 @@ }; 2407DEB6089929BA00EB68BF /* Density.cpp */ = { uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {848, 2054}}"; - sepNavSelRange = "{505, 0}"; - sepNavVisRange = "{0, 1934}"; + sepNavIntBoundsRect = "{{0, 0}, {719, 1989}}"; + sepNavSelRange = "{631, 0}"; + sepNavVisRange = "{322, 786}"; sepNavWindowFrame = "{{545, 36}, {895, 831}}"; }; }; 245463B80991757100464AD3 /* Density.h */ = { uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {866, 1001}}"; - sepNavSelRange = "{2548, 85}"; - sepNavVisRange = "{425, 2333}"; + sepNavIntBoundsRect = "{{0, 0}, {866, 962}}"; + sepNavSelRange = "{2579, 0}"; + sepNavVisRange = "{2169, 536}"; sepNavWindowFrame = "{{593, 47}, {895, 831}}"; }; }; @@ -82,9 +88,9 @@ }; 24D8286F09A914000093AEF8 /* DensityProc.cpp */ = { uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {848, 4602}}"; - sepNavSelRange = "{7190, 0}"; - sepNavVisRange = "{7245, 2459}"; + sepNavIntBoundsRect = "{{0, 0}, {684, 4225}}"; + sepNavSelRange = "{8807, 0}"; + sepNavVisRange = "{8744, 275}"; sepNavWindowFrame = "{{545, 39}, {895, 831}}"; }; }; @@ -102,7 +108,47 @@ isa = PBXCodeSenseManager; indexTemplatePath = ""; }; - 8D01CCC60486CAD60068D4B7 /* AudioUnit */ = { + 8B79379F21F574D1006E9731 /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = 24D8286F09A914000093AEF8 /* DensityProc.cpp */; + name = "DensityProc.cpp: 240"; + rLen = 0; + rLoc = 8807; + rType = 0; + vrLen = 275; + vrLoc = 8744; + }; + 8B7937A021F574D1006E9731 /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = 2407DEB6089929BA00EB68BF /* Density.cpp */; + name = "Density.cpp: 23"; + rLen = 0; + rLoc = 631; + rType = 0; + vrLen = 786; + vrLoc = 322; + }; + 8B7937A121F574D1006E9731 /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = 245463B80991757100464AD3 /* Density.h */; + name = "Density.h: 1"; + rLen = 0; + rLoc = 0; + rType = 0; + vrLen = 446; + vrLoc = 0; + }; + 8B7937A221F574D1006E9731 /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = 245463B80991757100464AD3 /* Density.h */; + name = "Density.h: 65"; + rLen = 0; + rLoc = 2579; + rType = 0; + vrLen = 536; + vrLoc = 2169; + }; + 8D01CCC60486CAD60068D4B7 /* Density */ = { activeExec = 0; }; } diff --git a/plugins/MacVST/Density/Density.xcodeproj/christopherjohnson.perspectivev3 b/plugins/MacVST/Density/Density.xcodeproj/christopherjohnson.perspectivev3 index 3decba3..26b67da 100755 --- a/plugins/MacVST/Density/Density.xcodeproj/christopherjohnson.perspectivev3 +++ b/plugins/MacVST/Density/Density.xcodeproj/christopherjohnson.perspectivev3 @@ -256,8 +256,6 @@ Layout - BecomeActive - ContentConfiguration PBXBottomSmartGroupGIDs @@ -300,7 +298,7 @@ PBXSmartGroupTreeModuleOutlineStateSelectionKey - 6 + 7 4 0 @@ -323,7 +321,7 @@ 185 RubberWindowFrame - 612 109 810 487 0 0 1440 878 + 374 322 810 487 0 0 1440 878 Module PBXSmartGroupTreeModule @@ -334,12 +332,14 @@ Dock + BecomeActive + ContentConfiguration PBXProjectModuleGUID 8B0237581D42B1C400E1E8C8 PBXProjectModuleLabel - + Density.h PBXSplitModuleInNavigatorKey Split0 @@ -347,7 +347,17 @@ PBXProjectModuleGUID 8B0237591D42B1C400E1E8C8 PBXProjectModuleLabel - + Density.h + _historyCapacity + 0 + bookmark + 8B7937A221F574D1006E9731 + history + + 8B79379F21F574D1006E9731 + 8B7937A021F574D1006E9731 + 8B7937A121F574D1006E9731 + SplitCount 1 @@ -360,18 +370,18 @@ GeometryConfiguration Frame - {{0, 0}, {603, 0}} + {{0, 0}, {603, 331}} RubberWindowFrame - 612 109 810 487 0 0 1440 878 + 374 322 810 487 0 0 1440 878 Module PBXNavigatorGroup Proportion - 0pt + 331pt Proportion - 441pt + 110pt Tabs @@ -386,8 +396,6 @@ Frame {{10, 27}, {603, 414}} - RubberWindowFrame - 612 109 810 487 0 0 1440 878 Module XCDetailModule @@ -441,7 +449,9 @@ GeometryConfiguration Frame - {{10, 27}, {603, 363}} + {{10, 27}, {603, 83}} + RubberWindowFrame + 374 322 810 487 0 0 1440 878 Module PBXBuildResultsModule @@ -469,11 +479,11 @@ TableOfContents - 8B9D79111F7FA891007AB60F + 8B7937A321F574D1006E9731 1CA23ED40692098700951B8B - 8B9D79121F7FA891007AB60F + 8B7937A421F574D1006E9731 8B0237581D42B1C400E1E8C8 - 8B9D79131F7FA891007AB60F + 8B7937A521F574D1006E9731 1CA23EDF0692099D00951B8B 1CA23EE00692099D00951B8B 1CA23EE10692099D00951B8B @@ -626,7 +636,7 @@ StatusbarIsVisible TimeStamp - 528459921.00240701 + 569734353.80657697 ToolbarConfigUserDefaultsMinorVersion 2 ToolbarDisplayMode @@ -643,11 +653,10 @@ 5 WindowOrderList - 8B9D79141F7FA891007AB60F /Users/christopherjohnson/Desktop/MacVST/Density/Density.xcodeproj WindowString - 612 109 810 487 0 0 1440 878 + 374 322 810 487 0 0 1440 878 WindowToolsV3 diff --git a/plugins/MacVST/Density/Density.xcodeproj/project.pbxproj b/plugins/MacVST/Density/Density.xcodeproj/project.pbxproj index 649faa8..929f8f7 100755 --- a/plugins/MacVST/Density/Density.xcodeproj/project.pbxproj +++ b/plugins/MacVST/Density/Density.xcodeproj/project.pbxproj @@ -1894,7 +1894,7 @@ /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ - 8D01CCC60486CAD60068D4B7 /* AudioUnit */ = { + 8D01CCC60486CAD60068D4B7 /* Density */ = { isa = PBXNativeTarget; buildConfigurationList = 24BEAAED08919AE700E695F9 /* Build configuration list for PBXNativeTarget "Density" */; buildPhases = ( @@ -1947,7 +1947,7 @@ ); projectRoot = ""; targets = ( - 8D01CCC60486CAD60068D4B7 /* AudioUnit */, + 8D01CCC60486CAD60068D4B7 /* Density */, ); }; /* End PBXProject section */ diff --git a/plugins/MacVST/Density/source/Density.cpp b/plugins/MacVST/Density/source/Density.cpp index 1ecafde..bac4fb2 100755 --- a/plugins/MacVST/Density/source/Density.cpp +++ b/plugins/MacVST/Density/source/Density.cpp @@ -20,12 +20,9 @@ Density::Density(audioMasterCallback audioMaster) : iirSampleBL = 0.0; iirSampleAR = 0.0; iirSampleBR = 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/Density/source/Density.h b/plugins/MacVST/Density/source/Density.h index 377d25d..b634c44 100755 --- a/plugins/MacVST/Density/source/Density.h +++ b/plugins/MacVST/Density/source/Density.h @@ -55,17 +55,14 @@ 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 iirSampleAL; double iirSampleBL; double iirSampleAR; double iirSampleBR; - + bool fpFlip; float A; float B; float C; diff --git a/plugins/MacVST/Density/source/DensityProc.cpp b/plugins/MacVST/Density/source/DensityProc.cpp index 1e968c7..f229a9d 100755 --- a/plugins/MacVST/Density/source/DensityProc.cpp +++ b/plugins/MacVST/Density/source/DensityProc.cpp @@ -26,9 +26,6 @@ void Density::processReplacing(float **inputs, float **outputs, VstInt32 sampleF double out = fabs(density); density = density * fabs(density); double count; - float fpTemp; - long double fpOld = 0.618033988749894848204586; //golden ratio! - long double fpNew = 1.0 - fpOld; long double inputSampleL; long double inputSampleR; @@ -95,6 +92,7 @@ void Density::processReplacing(float **inputs, float **outputs, VstInt32 sampleF inputSampleR -= iirSampleBR; } //highpass section + fpFlip = !fpFlip; count = density; while (count > 1.0) @@ -150,25 +148,14 @@ void Density::processReplacing(float **inputs, float **outputs, VstInt32 sampleF //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; @@ -199,9 +186,6 @@ void Density::processDoubleReplacing(double **inputs, double **outputs, VstInt32 double out = fabs(density); density = density * fabs(density); double count; - double fpTemp; - long double fpOld = 0.618033988749894848204586; //golden ratio! - long double fpNew = 1.0 - fpOld; long double inputSampleL; long double inputSampleR; @@ -268,6 +252,7 @@ void Density::processDoubleReplacing(double **inputs, double **outputs, VstInt32 inputSampleR -= iirSampleBR; } //highpass section + fpFlip = !fpFlip; count = density; while (count > 1.0) @@ -323,25 +308,16 @@ void Density::processDoubleReplacing(double **inputs, double **outputs, VstInt32 //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