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 --- plugins/MacAU/Tremolo/Tremolo.cpp | 27 +++-------- plugins/MacAU/Tremolo/Tremolo.h | 5 +- .../Tremolo.xcodeproj/christopherjohnson.pbxuser | 53 +++++++++++++--------- .../christopherjohnson.perspectivev3 | 52 ++++++++++----------- 4 files changed, 64 insertions(+), 73 deletions(-) (limited to 'plugins/MacAU/Tremolo') diff --git a/plugins/MacAU/Tremolo/Tremolo.cpp b/plugins/MacAU/Tremolo/Tremolo.cpp index e70b244..6e1f644 100755 --- a/plugins/MacAU/Tremolo/Tremolo.cpp +++ b/plugins/MacAU/Tremolo/Tremolo.cpp @@ -173,9 +173,7 @@ void Tremolo::TremoloKernel::Reset() depthAmount = 0.0; lastSpeed = 1000.0; lastDepth = 1000.0; - fpNShapeA = 0.0; - fpNShapeB = 0.0; - fpFlip = true; + fpNShape = 0.0; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -216,9 +214,6 @@ void Tremolo::TremoloKernel::Process( const Float32 *inSourceP, Float64 out; Float64 bridgerectifier; Float64 offset; - Float32 fpTemp; - Float64 fpOld = 0.618033988749894848204586; //golden ratio! - Float64 fpNew = 1.0 - fpOld; while (nSampleFrames-- > 0) { inputSample = *sourceP; @@ -289,22 +284,12 @@ void Tremolo::TremoloKernel::Process( const Float32 *inSourceP, //apply tremolo, apply gain boost to compensate for volume loss inputSample = (drySample * (1-depth)) + (inputSample*depth); - //noise shaping to 32-bit floating point - if (fpFlip) { - fpTemp = inputSample; - fpNShapeA = (fpNShapeA*fpOld)+((inputSample-fpTemp)*fpNew); - inputSample += fpNShapeA; - } - else { - fpTemp = inputSample; - fpNShapeB = (fpNShapeB*fpOld)+((inputSample-fpTemp)*fpNew); - inputSample += fpNShapeB; - } - fpFlip = !fpFlip; - //end noise shaping on 32 bit output + //32 bit dither, made small and tidy. + int expon; frexpf((Float32)inputSample, &expon); + long double dither = (rand()/(RAND_MAX*7.737125245533627e+25))*pow(2,expon+62); + inputSample += (dither-fpNShape); fpNShape = dither; + //end 32 bit dither - - *destP = inputSample; destP += inNumChannels; sourceP += inNumChannels; diff --git a/plugins/MacAU/Tremolo/Tremolo.h b/plugins/MacAU/Tremolo/Tremolo.h index 38910c3..8b4204a 100755 --- a/plugins/MacAU/Tremolo/Tremolo.h +++ b/plugins/MacAU/Tremolo/Tremolo.h @@ -136,10 +136,7 @@ public: Float64 lastSpeed; Float64 lastDepth; Float64 sweep; - Float64 fpNShapeA; - Float64 fpNShapeB; - bool fpFlip; - + Float64 fpNShape; }; }; diff --git a/plugins/MacAU/Tremolo/Tremolo.xcodeproj/christopherjohnson.pbxuser b/plugins/MacAU/Tremolo/Tremolo.xcodeproj/christopherjohnson.pbxuser index 822426d..4a72292 100755 --- a/plugins/MacAU/Tremolo/Tremolo.xcodeproj/christopherjohnson.pbxuser +++ b/plugins/MacAU/Tremolo/Tremolo.xcodeproj/christopherjohnson.pbxuser @@ -10,7 +10,7 @@ PBXFileTableDataSourceColumnSortingKey = PBXFileDataSource_Filename_ColumnID; PBXFileTableDataSourceColumnWidthsKey = ( 20, - 364, + 528, 20, 48, 43, @@ -49,43 +49,54 @@ PBXFileDataSource_Warnings_ColumnID, ); }; - PBXPerProjectTemplateStateSaveDate = 528458789; - PBXWorkspaceStateSaveDate = 528458789; + PBXPerProjectTemplateStateSaveDate = 569685954; + PBXWorkspaceStateSaveDate = 569685954; }; perUserProjectItems = { - 8B9D681F1F7C91BB007AB60F /* PBXTextBookmark */ = 8B9D681F1F7C91BB007AB60F /* PBXTextBookmark */; - 8B9D76FB1F7FA435007AB60F /* PBXTextBookmark */ = 8B9D76FB1F7FA435007AB60F /* PBXTextBookmark */; + 8B7931EE21F4B82A006E9731 /* PBXTextBookmark */ = 8B7931EE21F4B82A006E9731 /* PBXTextBookmark */; + 8B7931F021F4B82A006E9731 /* PBXTextBookmark */ = 8B7931F021F4B82A006E9731 /* PBXTextBookmark */; + 8B7931F521F4B845006E9731 /* PBXTextBookmark */ = 8B7931F521F4B845006E9731 /* PBXTextBookmark */; 8BD8CB021DF8ECAA00CC3427 /* PBXTextBookmark */ = 8BD8CB021DF8ECAA00CC3427 /* PBXTextBookmark */; }; sourceControlManager = 8BD3CCB8148830B20062E48C /* Source Control */; userBuildSettings = { }; }; - 8B9D681F1F7C91BB007AB60F /* PBXTextBookmark */ = { + 8B7931EE21F4B82A006E9731 /* PBXTextBookmark */ = { + isa = PBXTextBookmark; + fRef = 8BC6025B073B072D006C4272 /* Tremolo.h */; + name = "Tremolo.h: 139"; + rLen = 0; + rLoc = 5331; + rType = 0; + vrLen = 813; + vrLoc = 4630; + }; + 8B7931F021F4B82A006E9731 /* PBXTextBookmark */ = { isa = PBXTextBookmark; fRef = 8BA05A660720730100365D66 /* Tremolo.cpp */; - name = "Tremolo.cpp: 290"; + name = "Tremolo.cpp: 292"; rLen = 0; - rLoc = 12305; + rLoc = 12430; rType = 0; - vrLen = 145; - vrLoc = 10647; + vrLen = 1235; + vrLoc = 11280; }; - 8B9D76FB1F7FA435007AB60F /* PBXTextBookmark */ = { + 8B7931F521F4B845006E9731 /* PBXTextBookmark */ = { isa = PBXTextBookmark; fRef = 8BA05A660720730100365D66 /* Tremolo.cpp */; - name = "Tremolo.cpp: 290"; + name = "Tremolo.cpp: 292"; rLen = 0; - rLoc = 12305; + rLoc = 12430; rType = 0; - vrLen = 0; - vrLoc = 0; + vrLen = 1268; + vrLoc = 11247; }; 8BA05A660720730100365D66 /* Tremolo.cpp */ = { uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {554, 4108}}"; - sepNavSelRange = "{12305, 0}"; - sepNavVisRange = "{0, 0}"; + sepNavIntBoundsRect = "{{0, 0}, {718, 4043}}"; + sepNavSelRange = "{12430, 0}"; + sepNavVisRange = "{11247, 1268}"; sepNavWindowFrame = "{{386, 39}, {1024, 839}}"; }; }; @@ -107,9 +118,9 @@ }; 8BC6025B073B072D006C4272 /* Tremolo.h */ = { uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {922, 1885}}"; - sepNavSelRange = "{5163, 132}"; - sepNavVisRange = "{4043, 1438}"; + sepNavIntBoundsRect = "{{0, 0}, {922, 2262}}"; + sepNavSelRange = "{5331, 0}"; + sepNavVisRange = "{4630, 813}"; sepNavWindowFrame = "{{469, 34}, {679, 835}}"; }; }; diff --git a/plugins/MacAU/Tremolo/Tremolo.xcodeproj/christopherjohnson.perspectivev3 b/plugins/MacAU/Tremolo/Tremolo.xcodeproj/christopherjohnson.perspectivev3 index 0be2553..832afcd 100755 --- a/plugins/MacAU/Tremolo/Tremolo.xcodeproj/christopherjohnson.perspectivev3 +++ b/plugins/MacAU/Tremolo/Tremolo.xcodeproj/christopherjohnson.perspectivev3 @@ -225,8 +225,8 @@ PerspectiveWidths - 810 - 810 + 954 + 954 Perspectives @@ -256,8 +256,6 @@ Layout - BecomeActive - ContentConfiguration PBXBottomSmartGroupGIDs @@ -282,7 +280,7 @@ PBXSmartGroupTreeModuleColumnWidthsKey - 185 + 165 PBXSmartGroupTreeModuleColumnsKey_v4 @@ -307,7 +305,7 @@ PBXSmartGroupTreeModuleOutlineStateVisibleRectKey - {{0, 0}, {185, 428}} + {{0, 0}, {165, 635}} PBXTopSmartGroupGIDs @@ -317,19 +315,19 @@ GeometryConfiguration Frame - {{0, 0}, {202, 446}} + {{0, 0}, {182, 653}} GroupTreeTableConfiguration MainColumn - 185 + 165 RubberWindowFrame - 504 296 810 487 0 0 1440 878 + 341 162 954 694 0 0 1440 878 Module PBXSmartGroupTreeModule Proportion - 202pt + 182pt Dock @@ -352,11 +350,12 @@ _historyCapacity 0 bookmark - 8B9D76FB1F7FA435007AB60F + 8B7931F521F4B845006E9731 history 8BD8CB021DF8ECAA00CC3427 - 8B9D681F1F7C91BB007AB60F + 8B7931EE21F4B82A006E9731 + 8B7931F021F4B82A006E9731 SplitCount @@ -370,18 +369,18 @@ GeometryConfiguration Frame - {{0, 0}, {603, 32}} + {{0, 0}, {767, 469}} RubberWindowFrame - 504 296 810 487 0 0 1440 878 + 341 162 954 694 0 0 1440 878 Module PBXNavigatorGroup Proportion - 32pt + 469pt Proportion - 409pt + 179pt Tabs @@ -395,9 +394,7 @@ GeometryConfiguration Frame - {{10, 27}, {603, 382}} - RubberWindowFrame - 504 296 810 487 0 0 1440 878 + {{10, 27}, {767, 152}} Module XCDetailModule @@ -451,7 +448,9 @@ GeometryConfiguration Frame - {{10, 27}, {603, 282}} + {{10, 27}, {767, 152}} + RubberWindowFrame + 341 162 954 694 0 0 1440 878 Module PBXBuildResultsModule @@ -460,7 +459,7 @@ Proportion - 603pt + 767pt Name @@ -479,11 +478,11 @@ TableOfContents - 8B9D76FC1F7FA435007AB60F + 8B7931F621F4B845006E9731 1CA23ED40692098700951B8B - 8B9D76FD1F7FA435007AB60F + 8B7931F721F4B845006E9731 8B3ED5B51DDE654F004F9D64 - 8B9D76FE1F7FA435007AB60F + 8B7931F821F4B845006E9731 1CA23EDF0692099D00951B8B 1CA23EE00692099D00951B8B 1CA23EE10692099D00951B8B @@ -636,7 +635,7 @@ StatusbarIsVisible TimeStamp - 528458805.46372598 + 569686085.74729097 ToolbarConfigUserDefaultsMinorVersion 2 ToolbarDisplayMode @@ -653,11 +652,10 @@ 5 WindowOrderList - 8B9D76FF1F7FA435007AB60F /Users/christopherjohnson/Desktop/MacAU/Tremolo/Tremolo.xcodeproj WindowString - 504 296 810 487 0 0 1440 878 + 341 162 954 694 0 0 1440 878 WindowToolsV3 -- cgit v1.2.3