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 | 8 +-- .../christopherjohnson.perspectivev3 | 10 ++-- .../C5RawChannel.xcodeproj/project.pbxproj | 4 +- .../MacVST/C5RawChannel/source/C5RawChannel.cpp | 7 +-- plugins/MacVST/C5RawChannel/source/C5RawChannel.h | 7 +-- .../C5RawChannel/source/C5RawChannelProc.cpp | 62 +++++++--------------- 6 files changed, 33 insertions(+), 65 deletions(-) (limited to 'plugins/MacVST/C5RawChannel') diff --git a/plugins/MacVST/C5RawChannel/C5RawChannel.xcodeproj/christopherjohnson.pbxuser b/plugins/MacVST/C5RawChannel/C5RawChannel.xcodeproj/christopherjohnson.pbxuser index 2c29100..6a38937 100755 --- a/plugins/MacVST/C5RawChannel/C5RawChannel.xcodeproj/christopherjohnson.pbxuser +++ b/plugins/MacVST/C5RawChannel/C5RawChannel.xcodeproj/christopherjohnson.pbxuser @@ -2,7 +2,7 @@ { 089C1669FE841209C02AAC07 /* Project object */ = { activeBuildConfigurationName = Release; - activeTarget = 8D01CCC60486CAD60068D4B7 /* C5RawChannel */; + activeTarget = 8D01CCC60486CAD60068D4B7 /* AudioUnit */; codeSenseManager = 8B02375F1D42B1C400E1E8C8 /* Code sense */; perUserDictionary = { PBXConfiguration.PBXFileTableDataSource3.PBXFileTableDataSource = { @@ -49,8 +49,8 @@ PBXFileDataSource_Warnings_ColumnID, ); }; - PBXPerProjectTemplateStateSaveDate = 538698973; - PBXWorkspaceStateSaveDate = 538698973; + PBXPerProjectTemplateStateSaveDate = 569733279; + PBXWorkspaceStateSaveDate = 569733279; }; sourceControlManager = 8B02375E1D42B1C400E1E8C8 /* Source Control */; userBuildSettings = { @@ -102,7 +102,7 @@ isa = PBXCodeSenseManager; indexTemplatePath = ""; }; - 8D01CCC60486CAD60068D4B7 /* C5RawChannel */ = { + 8D01CCC60486CAD60068D4B7 /* AudioUnit */ = { activeExec = 0; }; } diff --git a/plugins/MacVST/C5RawChannel/C5RawChannel.xcodeproj/christopherjohnson.perspectivev3 b/plugins/MacVST/C5RawChannel/C5RawChannel.xcodeproj/christopherjohnson.perspectivev3 index b091f94..cd0fdba 100755 --- a/plugins/MacVST/C5RawChannel/C5RawChannel.xcodeproj/christopherjohnson.perspectivev3 +++ b/plugins/MacVST/C5RawChannel/C5RawChannel.xcodeproj/christopherjohnson.perspectivev3 @@ -469,11 +469,11 @@ TableOfContents - 8B4E577C201BE4F400B5DC2A + 8B79353421F570A9006E9731 1CA23ED40692098700951B8B - 8B4E577D201BE4F400B5DC2A + 8B79353521F570A9006E9731 8B0237581D42B1C400E1E8C8 - 8B4E577E201BE4F400B5DC2A + 8B79353621F570A9006E9731 1CA23EDF0692099D00951B8B 1CA23EE00692099D00951B8B 1CA23EE10692099D00951B8B @@ -626,7 +626,7 @@ StatusbarIsVisible TimeStamp - 538705094.40063703 + 569733289.17203903 ToolbarConfigUserDefaultsMinorVersion 2 ToolbarDisplayMode @@ -643,7 +643,7 @@ 5 WindowOrderList - /Users/christopherjohnson/Desktop/C5RawChannel/C5RawChannel.xcodeproj + /Users/christopherjohnson/Desktop/MacVST/C5RawChannel/C5RawChannel.xcodeproj WindowString 24 126 701 419 0 0 1440 878 diff --git a/plugins/MacVST/C5RawChannel/C5RawChannel.xcodeproj/project.pbxproj b/plugins/MacVST/C5RawChannel/C5RawChannel.xcodeproj/project.pbxproj index e73c1b3..5287fa9 100755 --- a/plugins/MacVST/C5RawChannel/C5RawChannel.xcodeproj/project.pbxproj +++ b/plugins/MacVST/C5RawChannel/C5RawChannel.xcodeproj/project.pbxproj @@ -1894,7 +1894,7 @@ /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ - 8D01CCC60486CAD60068D4B7 /* C5RawChannel */ = { + 8D01CCC60486CAD60068D4B7 /* AudioUnit */ = { isa = PBXNativeTarget; buildConfigurationList = 24BEAAED08919AE700E695F9 /* Build configuration list for PBXNativeTarget "C5RawChannel" */; buildPhases = ( @@ -1947,7 +1947,7 @@ ); projectRoot = ""; targets = ( - 8D01CCC60486CAD60068D4B7 /* C5RawChannel */, + 8D01CCC60486CAD60068D4B7 /* AudioUnit */, ); }; /* End PBXProject section */ diff --git a/plugins/MacVST/C5RawChannel/source/C5RawChannel.cpp b/plugins/MacVST/C5RawChannel/source/C5RawChannel.cpp index b02a07d..ffc2ecf 100755 --- a/plugins/MacVST/C5RawChannel/source/C5RawChannel.cpp +++ b/plugins/MacVST/C5RawChannel/source/C5RawChannel.cpp @@ -17,11 +17,8 @@ C5RawChannel::C5RawChannel(audioMasterCallback audioMaster) : lastSampleChannelL = 0.0; lastFXChannelR = 0.0; lastSampleChannelR = 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/C5RawChannel/source/C5RawChannel.h b/plugins/MacVST/C5RawChannel/source/C5RawChannel.h index 2281961..3ce3e84 100755 --- a/plugins/MacVST/C5RawChannel/source/C5RawChannel.h +++ b/plugins/MacVST/C5RawChannel/source/C5RawChannel.h @@ -52,11 +52,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 double lastFXChannelL; double lastSampleChannelL; diff --git a/plugins/MacVST/C5RawChannel/source/C5RawChannelProc.cpp b/plugins/MacVST/C5RawChannel/source/C5RawChannelProc.cpp index 41f949e..b2679ff 100755 --- a/plugins/MacVST/C5RawChannel/source/C5RawChannelProc.cpp +++ b/plugins/MacVST/C5RawChannel/source/C5RawChannelProc.cpp @@ -14,9 +14,6 @@ void C5RawChannel::processReplacing(float **inputs, float **outputs, VstInt32 sa float* out1 = outputs[0]; float* out2 = outputs[1]; - float fpTemp; - long double fpOld = 0.618033988749894848204586; //golden ratio! - long double fpNew = 1.0 - fpOld; long double centering = A * 0.5; centering = 1.0 - pow(centering,5); @@ -110,25 +107,14 @@ void C5RawChannel::processReplacing(float **inputs, float **outputs, VstInt32 sa inputSampleR = sin(inputSampleR); //amplitude aspect - //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; @@ -147,9 +133,6 @@ void C5RawChannel::processDoubleReplacing(double **inputs, double **outputs, Vst double* out1 = outputs[0]; double* out2 = outputs[1]; - double fpTemp; - long double fpOld = 0.618033988749894848204586; //golden ratio! - long double fpNew = 1.0 - fpOld; long double centering = A * 0.5; centering = 1.0 - pow(centering,5); @@ -243,25 +226,16 @@ void C5RawChannel::processDoubleReplacing(double **inputs, double **outputs, Vst inputSampleR = sin(inputSampleR); //amplitude aspect - //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