diff options
author | Chris Johnson <jinx6568@sover.net> | 2018-09-03 16:35:36 -0400 |
---|---|---|
committer | Chris Johnson <jinx6568@sover.net> | 2018-09-03 16:35:36 -0400 |
commit | 3dd30d920a374ba31994f784fadd5ee130752247 (patch) | |
tree | 4a8350099d829390fc1e75234875ff76a82ec9e9 /plugins/MacAU/Ditherbox | |
parent | b4f55328448d087a68e6f658638fb3d38d86be12 (diff) | |
download | airwindows-lv2-port-3dd30d920a374ba31994f784fadd5ee130752247.tar.gz airwindows-lv2-port-3dd30d920a374ba31994f784fadd5ee130752247.tar.bz2 airwindows-lv2-port-3dd30d920a374ba31994f784fadd5ee130752247.zip |
Ditherbox update
Diffstat (limited to 'plugins/MacAU/Ditherbox')
4 files changed, 178 insertions, 91 deletions
diff --git a/plugins/MacAU/Ditherbox/Ditherbox.cpp b/plugins/MacAU/Ditherbox/Ditherbox.cpp index 6cd002b..a4b1edf 100755 --- a/plugins/MacAU/Ditherbox/Ditherbox.cpp +++ b/plugins/MacAU/Ditherbox/Ditherbox.cpp @@ -83,6 +83,9 @@ ComponentResult Ditherbox::GetParameterValueStrings(AudioUnitScope inScope, kMenuItem_Truncate, kMenuItem_Flat, kMenuItem_TPDF, + kMenuItem_Paul, + kMenuItem_DoublePaul, + kMenuItem_Tape, kMenuItem_Quadratic, kMenuItem_TenNines, kMenuItem_Contingent, @@ -91,6 +94,9 @@ ComponentResult Ditherbox::GetParameterValueStrings(AudioUnitScope inScope, kMenuItem_TruncateHR, kMenuItem_FlatHR, kMenuItem_TPDFHR, + kMenuItem_PaulHR, + kMenuItem_DoublePaulHR, + kMenuItem_TapeHR, kMenuItem_QuadraticHR, kMenuItem_TenNinesHR, kMenuItem_ContingentHR, @@ -298,13 +304,39 @@ void Ditherbox::DitherboxKernel::Process( const Float32 *inSourceP, Float32 drySample; //should be the same as what the native DAW buss is - if (dtype > 8){highRes = true; dtype -= 8;} + if (dtype > 11){highRes = true; dtype -= 11;} - if (dtype > 8){dithering = false; highRes = false;} + if (dtype > 11){dithering = false; highRes = false;} //follow up by switching high res back off for the monitoring while (nSampleFrames-- > 0) { - drySample = inputSample = *sourceP; + inputSample = *sourceP; + if (inputSample<1.2e-38 && -inputSample<1.2e-38) { + static int noisesource = 0; + //this declares a variable before anything else is compiled. It won't keep assigning + //it to 0 for every sample, it's as if the declaration doesn't exist in this context, + //but it lets me add this denormalization fix in a single place rather than updating + //it in three different locations. The variable isn't thread-safe but this is only + //a random seed and we can share it with whatever. + noisesource = noisesource % 1700021; noisesource++; + int residue = noisesource * noisesource; + residue = residue % 170003; residue *= residue; + residue = residue % 17011; residue *= residue; + residue = residue % 1709; residue *= residue; + residue = residue % 173; residue *= residue; + residue = residue % 17; + double applyresidue = residue; + applyresidue *= 0.00000001; + applyresidue *= 0.00000001; + inputSample = applyresidue; + //this denormalization routine produces a white noise at -300 dB which the noise + //shaping will interact with to produce a bipolar output, but the noise is actually + //all positive. That should stop any variables from going denormal, and the routine + //only kicks in if digital black is input. As a final touch, if you save to 24-bit + //the silence will return to being digital black again. + } + drySample = inputSample; + sourceP += inNumChannels; if (dtype == 8) inputSample -= noiseShaping; @@ -327,16 +359,62 @@ void Ditherbox::DitherboxKernel::Process( const Float32 *inSourceP, //flat dither break; - case 3: - inputSample += (rand()/(double)RAND_MAX); - inputSample += (rand()/(double)RAND_MAX); - inputSample -= 1.0; - inputSample = floor(inputSample); - //TPDF dither - break; - - - case 4: + case 3: + inputSample += (rand()/(double)RAND_MAX); + inputSample += (rand()/(double)RAND_MAX); + inputSample -= 1.0; + inputSample = floor(inputSample); + //TPDF dither + break; + + case 4: + currentDither = (rand()/(double)RAND_MAX); + inputSample += currentDither; + inputSample -= lastSample; + inputSample = floor(inputSample); + lastSample = currentDither; + //Paul dither + break; + + case 5: + ns[9] = ns[8]; ns[8] = ns[7]; ns[7] = ns[6]; ns[6] = ns[5]; + ns[5] = ns[4]; ns[4] = ns[3]; ns[3] = ns[2]; ns[2] = ns[1]; + ns[1] = ns[0]; ns[0] = (rand()/(double)RAND_MAX); + + currentDither = (ns[0] * 0.061); + currentDither -= (ns[1] * 0.11); + currentDither += (ns[8] * 0.126); + currentDither -= (ns[7] * 0.23); + currentDither += (ns[2] * 0.25); + currentDither -= (ns[3] * 0.43); + currentDither += (ns[6] * 0.5); + currentDither -= ns[5]; + currentDither += ns[4]; + //this sounds different from doing it in order of sample position + //cumulative tiny errors seem to build up even at this buss depth + //considerably more pronounced at 32 bit float. + //Therefore we add the most significant components LAST. + //trying to keep values on like exponents of the floating point value. + inputSample += currentDither; + + inputSample = floor(inputSample); + //DoublePaul dither + break; + + case 6: + currentDither = (rand()/(double)RAND_MAX); + inputSample += currentDither; + inputSample -= ns[4]; + inputSample = floor(inputSample); + ns[4] = ns[3]; + ns[3] = ns[2]; + ns[2] = ns[1]; + ns[1] = currentDither; + //Tape dither + break; + + + case 7: Position += 1; //Note- uses integer overflow as a 'mod' operator hotbinA = Position * Position; @@ -356,7 +434,7 @@ void Ditherbox::DitherboxKernel::Process( const Float32 *inSourceP, //Quadratic dither break; - case 5: + case 8: absSample = ((rand()/(double)RAND_MAX) - 0.5); ns[0] += absSample; ns[0] /= 2; absSample -= ns[0]; absSample += ((rand()/(double)RAND_MAX) - 0.5); @@ -406,7 +484,7 @@ void Ditherbox::DitherboxKernel::Process( const Float32 *inSourceP, //TenNines dither break; - case 6: + case 9: if (inputSample > 0) inputSample += 0.383; if (inputSample < 0) inputSample -= 0.383; //adjusting to permit more information drug outta the noisefloor @@ -428,7 +506,7 @@ void Ditherbox::DitherboxKernel::Process( const Float32 *inSourceP, //and does a teeny parallel-compression thing when almost at digital black. break; - case 7: + case 10: if (inputSample > 0) inputSample += (0.3333333333); if (inputSample < 0) inputSample -= (0.3333333333); @@ -508,7 +586,7 @@ void Ditherbox::DitherboxKernel::Process( const Float32 *inSourceP, byn[10] /= 2; //catchall for garbage data break; - case 8: //this one is the Not Just Another Dither + case 11: //this one is the Not Just Another Dither benfordize = floor(inputSample); while (benfordize >= 1.0) {benfordize /= 10;} @@ -590,7 +668,7 @@ void Ditherbox::DitherboxKernel::Process( const Float32 *inSourceP, byn[10] /= 2; //catchall for garbage data break; - case 9: + case 12: //slew only outputSample = (inputSample - lastSample)*trim; lastSample = inputSample; @@ -599,7 +677,7 @@ void Ditherbox::DitherboxKernel::Process( const Float32 *inSourceP, inputSample = outputSample; break; - case 10: + case 13: //subs only gain = gaintarget; inputSample *= gain; gain = ((gain-1)*0.75)+1; @@ -708,7 +786,7 @@ void Ditherbox::DitherboxKernel::Process( const Float32 *inSourceP, if (inputSample < -1.0) inputSample = -1.0; break; - case 11: + case 14: //silhouette bridgerectifier = fabs(inputSample)*1.57079633; if (bridgerectifier > 1.57079633) bridgerectifier = 1.57079633; diff --git a/plugins/MacAU/Ditherbox/Ditherbox.h b/plugins/MacAU/Ditherbox/Ditherbox.h index a45a8e3..1e22c4d 100755 --- a/plugins/MacAU/Ditherbox/Ditherbox.h +++ b/plugins/MacAU/Ditherbox/Ditherbox.h @@ -58,28 +58,37 @@ static CFStringRef kParameterOneName = CFSTR("Dither Type"); static const int kTruncate = 1; static const int kFlat = 2; static const int kTPDF = 3; -static const int kQuadratic = 4; -static const int kTenNines = 5; -static const int kContingent = 6; -static const int kNaturalize = 7; -static const int kNJAD = 8; -static const int kTruncateHR = 9; -static const int kFlatHR = 10; -static const int kTPDFHR = 11; -static const int kQuadraticHR = 12; -static const int kTenNinesHR = 13; -static const int kContingentHR = 14; -static const int kNaturalizeHR = 15; -static const int kNJADHR = 16; -static const int kSlewOnly = 17; -static const int kSubsOnly = 18; -static const int kSilhouette = 19; -static const int kDefaultValue_ParamOne = 16; +static const int kPaul = 4; +static const int kDoublePaul = 5; +static const int kTape = 6; +static const int kQuadratic = 7; +static const int kTenNines = 8; +static const int kContingent = 9; +static const int kNaturalize = 10; +static const int kNJAD = 11; +static const int kTruncateHR = 12; +static const int kFlatHR = 13; +static const int kTPDFHR = 14; +static const int kPaulHR = 15; +static const int kDoublePaulHR = 16; +static const int kTapeHR = 17; +static const int kQuadraticHR = 18; +static const int kTenNinesHR = 19; +static const int kContingentHR = 20; +static const int kNaturalizeHR = 21; +static const int kNJADHR = 22; +static const int kSlewOnly = 23; +static const int kSubsOnly = 24; +static const int kSilhouette = 25; +static const int kDefaultValue_ParamOne = 22; static CFStringRef kMenuItem_Truncate = CFSTR ("16 Bit Truncation"); static CFStringRef kMenuItem_Flat = CFSTR ("16 bit Flat Dither"); static CFStringRef kMenuItem_TPDF = CFSTR ("16 bit TPDF Dither"); +static CFStringRef kMenuItem_Paul = CFSTR ("16 bit Paul Dither"); +static CFStringRef kMenuItem_DoublePaul = CFSTR ("16 bit DoublePaul Dither"); +static CFStringRef kMenuItem_Tape = CFSTR ("16 bit Tape Dither"); static CFStringRef kMenuItem_Quadratic = CFSTR ("16 bit High Gloss Dither"); static CFStringRef kMenuItem_TenNines = CFSTR ("16 bit Vinyl Dither"); static CFStringRef kMenuItem_Contingent = CFSTR ("16 bit Spatialize Dither"); @@ -88,6 +97,9 @@ static CFStringRef kMenuItem_NJAD = CFSTR ("16 bit Not Just Another Dither"); static CFStringRef kMenuItem_TruncateHR = CFSTR ("24 bit Truncation"); static CFStringRef kMenuItem_FlatHR = CFSTR ("24 bit Flat Dither"); static CFStringRef kMenuItem_TPDFHR = CFSTR ("24 bit TPDF Dither"); +static CFStringRef kMenuItem_PaulHR = CFSTR ("24 bit Paul Dither"); +static CFStringRef kMenuItem_DoublePaulHR = CFSTR ("24 bit DoublePaul Dither"); +static CFStringRef kMenuItem_TapeHR = CFSTR ("24 bit Tape Dither"); static CFStringRef kMenuItem_QuadraticHR = CFSTR ("24 bit High Gloss Dither"); static CFStringRef kMenuItem_TenNinesHR = CFSTR ("24 bit Vinyl Dither"); static CFStringRef kMenuItem_ContingentHR = CFSTR ("24 bit Spatialize Dither"); @@ -167,6 +179,7 @@ public: long double byn[13]; long double noiseShaping; long double contingentErr; + double currentDither; long double NSOdd; long double NSEven; long double prev; @@ -202,7 +215,6 @@ public: long double iirSampleY; long double iirSampleZ; - }; }; diff --git a/plugins/MacAU/Ditherbox/Ditherbox.xcodeproj/christopherjohnson.pbxuser b/plugins/MacAU/Ditherbox/Ditherbox.xcodeproj/christopherjohnson.pbxuser index a27e362..3c31d7a 100755 --- a/plugins/MacAU/Ditherbox/Ditherbox.xcodeproj/christopherjohnson.pbxuser +++ b/plugins/MacAU/Ditherbox/Ditherbox.xcodeproj/christopherjohnson.pbxuser @@ -51,54 +51,54 @@ PBXFileDataSource_Warnings_ColumnID, ); }; - PBXPerProjectTemplateStateSaveDate = 557542996; - PBXWorkspaceStateSaveDate = 557542996; + PBXPerProjectTemplateStateSaveDate = 557696136; + PBXWorkspaceStateSaveDate = 557696136; }; perUserProjectItems = { - 8B39A1A7213B713300112CCA /* PBXTextBookmark */ = 8B39A1A7213B713300112CCA /* PBXTextBookmark */; - 8B6DBA05213B3F1800E44739 /* PBXTextBookmark */ = 8B6DBA05213B3F1800E44739 /* PBXTextBookmark */; - 8B6DBA3D213B4F3600E44739 /* PBXTextBookmark */ = 8B6DBA3D213B4F3600E44739 /* PBXTextBookmark */; + 8B913FA3213DBD2F00BA6EEC /* PBXTextBookmark */ = 8B913FA3213DBD2F00BA6EEC /* PBXTextBookmark */; + 8B913FE1213DC54C00BA6EEC /* PBXTextBookmark */ = 8B913FE1213DC54C00BA6EEC /* PBXTextBookmark */; + 8B913FEB213DC5A500BA6EEC /* PBXTextBookmark */ = 8B913FEB213DC5A500BA6EEC /* PBXTextBookmark */; }; sourceControlManager = 8BD3CCB8148830B20062E48C /* Source Control */; userBuildSettings = { }; }; - 8B39A1A7213B713300112CCA /* PBXTextBookmark */ = { + 8B913FA3213DBD2F00BA6EEC /* PBXTextBookmark */ = { isa = PBXTextBookmark; fRef = 8BA05A660720730100365D66 /* Ditherbox.cpp */; - name = "Ditherbox.cpp: 295"; + name = "Ditherbox.cpp: 302"; rLen = 79; - rLoc = 10697; + rLoc = 10835; rType = 0; - vrLen = 355; - vrLoc = 10542; + vrLen = 342; + vrLoc = 10516; }; - 8B6DBA05213B3F1800E44739 /* PBXTextBookmark */ = { + 8B913FE1213DC54C00BA6EEC /* PBXTextBookmark */ = { isa = PBXTextBookmark; fRef = 8BC6025B073B072D006C4272 /* Ditherbox.h */; - name = "Ditherbox.h: 167"; - rLen = 921; - rLoc = 6924; + name = "Ditherbox.h: 216"; + rLen = 0; + rLoc = 8486; rType = 0; - vrLen = 304; - vrLoc = 3; + vrLen = 209; + vrLoc = 129; }; - 8B6DBA3D213B4F3600E44739 /* PBXTextBookmark */ = { + 8B913FEB213DC5A500BA6EEC /* PBXTextBookmark */ = { isa = PBXTextBookmark; - fRef = 8BA05A660720730100365D66 /* Ditherbox.cpp */; - name = "Ditherbox.cpp: 295"; - rLen = 79; - rLoc = 10697; + fRef = 8BC6025B073B072D006C4272 /* Ditherbox.h */; + name = "Ditherbox.h: 216"; + rLen = 0; + rLoc = 8486; rType = 0; - vrLen = 355; - vrLoc = 10542; + vrLen = 209; + vrLoc = 129; }; 8BA05A660720730100365D66 /* Ditherbox.cpp */ = { uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {607, 9711}}"; - sepNavSelRange = "{10697, 79}"; - sepNavVisRange = "{10542, 355}"; - sepNavWindowFrame = "{{644, -12}, {816, 833}}"; + sepNavIntBoundsRect = "{{0, 0}, {978, 11076}}"; + sepNavSelRange = "{11237, 0}"; + sepNavVisRange = "{1680, 2418}"; + sepNavWindowFrame = "{{471, 45}, {816, 833}}"; }; }; 8BA05A670720730100365D66 /* Ditherbox.exp */ = { @@ -127,10 +127,10 @@ }; 8BC6025B073B072D006C4272 /* Ditherbox.h */ = { uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {974, 2756}}"; - sepNavSelRange = "{6924, 921}"; - sepNavVisRange = "{3099, 2208}"; - sepNavWindowFrame = "{{802, 68}, {1021, 800}}"; + sepNavIntBoundsRect = "{{0, 0}, {803, 3003}}"; + sepNavSelRange = "{8486, 0}"; + sepNavVisRange = "{129, 209}"; + sepNavWindowFrame = "{{419, 78}, {1021, 800}}"; }; }; 8BD3CCB8148830B20062E48C /* Source Control */ = { diff --git a/plugins/MacAU/Ditherbox/Ditherbox.xcodeproj/christopherjohnson.perspectivev3 b/plugins/MacAU/Ditherbox/Ditherbox.xcodeproj/christopherjohnson.perspectivev3 index f9417a5..efe3540 100755 --- a/plugins/MacAU/Ditherbox/Ditherbox.xcodeproj/christopherjohnson.perspectivev3 +++ b/plugins/MacAU/Ditherbox/Ditherbox.xcodeproj/christopherjohnson.perspectivev3 @@ -256,8 +256,6 @@ <key>Layout</key> <array> <dict> - <key>BecomeActive</key> - <true/> <key>ContentConfiguration</key> <dict> <key>PBXBottomSmartGroupGIDs</key> @@ -324,7 +322,7 @@ <real>185</real> </array> <key>RubberWindowFrame</key> - <string>617 355 810 487 0 0 1440 878 </string> + <string>468 237 810 487 0 0 1440 878 </string> </dict> <key>Module</key> <string>PBXSmartGroupTreeModule</string> @@ -340,7 +338,7 @@ <key>PBXProjectModuleGUID</key> <string>8B9E7EE61DDE28AC006035FA</string> <key>PBXProjectModuleLabel</key> - <string>Ditherbox.cpp</string> + <string>Ditherbox.h</string> <key>PBXSplitModuleInNavigatorKey</key> <dict> <key>Split0</key> @@ -348,15 +346,15 @@ <key>PBXProjectModuleGUID</key> <string>8B9E7EE71DDE28AC006035FA</string> <key>PBXProjectModuleLabel</key> - <string>Ditherbox.cpp</string> + <string>Ditherbox.h</string> <key>_historyCapacity</key> <integer>0</integer> <key>bookmark</key> - <string>8B39A1A7213B713300112CCA</string> + <string>8B913FEB213DC5A500BA6EEC</string> <key>history</key> <array> - <string>8B6DBA05213B3F1800E44739</string> - <string>8B6DBA3D213B4F3600E44739</string> + <string>8B913FA3213DBD2F00BA6EEC</string> + <string>8B913FE1213DC54C00BA6EEC</string> </array> </dict> <key>SplitCount</key> @@ -370,18 +368,18 @@ <key>GeometryConfiguration</key> <dict> <key>Frame</key> - <string>{{0, 0}, {603, 102}}</string> + <string>{{0, 0}, {603, 69}}</string> <key>RubberWindowFrame</key> - <string>617 355 810 487 0 0 1440 878 </string> + <string>468 237 810 487 0 0 1440 878 </string> </dict> <key>Module</key> <string>PBXNavigatorGroup</string> <key>Proportion</key> - <string>102pt</string> + <string>69pt</string> </dict> <dict> <key>Proportion</key> - <string>339pt</string> + <string>372pt</string> <key>Tabs</key> <array> <dict> @@ -395,9 +393,7 @@ <key>GeometryConfiguration</key> <dict> <key>Frame</key> - <string>{{10, 27}, {603, 312}}</string> - <key>RubberWindowFrame</key> - <string>617 355 810 487 0 0 1440 878 </string> + <string>{{10, 27}, {603, 345}}</string> </dict> <key>Module</key> <string>XCDetailModule</string> @@ -451,7 +447,9 @@ <key>GeometryConfiguration</key> <dict> <key>Frame</key> - <string>{{10, 27}, {603, 401}}</string> + <string>{{10, 27}, {603, 345}}</string> + <key>RubberWindowFrame</key> + <string>468 237 810 487 0 0 1440 878 </string> </dict> <key>Module</key> <string>PBXBuildResultsModule</string> @@ -479,11 +477,11 @@ </array> <key>TableOfContents</key> <array> - <string>8B39A1A8213B713300112CCA</string> + <string>8B913FB1213DC48A00BA6EEC</string> <string>1CA23ED40692098700951B8B</string> - <string>8B39A1A9213B713300112CCA</string> + <string>8B913FB2213DC48A00BA6EEC</string> <string>8B9E7EE61DDE28AC006035FA</string> - <string>8B39A1AA213B713300112CCA</string> + <string>8B913FB3213DC48A00BA6EEC</string> <string>1CA23EDF0692099D00951B8B</string> <string>1CA23EE00692099D00951B8B</string> <string>1CA23EE10692099D00951B8B</string> @@ -636,7 +634,7 @@ <key>StatusbarIsVisible</key> <true/> <key>TimeStamp</key> - <real>557543731.48686099</real> + <real>557696421.06510198</real> <key>ToolbarConfigUserDefaultsMinorVersion</key> <string>2</string> <key>ToolbarDisplayMode</key> @@ -653,11 +651,10 @@ <integer>5</integer> <key>WindowOrderList</key> <array> - <string>8B39A1AB213B713300112CCA</string> <string>/Users/christopherjohnson/Desktop/MacAU/Ditherbox/Ditherbox.xcodeproj</string> </array> <key>WindowString</key> - <string>617 355 810 487 0 0 1440 878 </string> + <string>468 237 810 487 0 0 1440 878 </string> <key>WindowToolsV3</key> <array> <dict> |