From 8e9f9481c460b4ef9f57f1a95706e0f1a529bf78 Mon Sep 17 00:00:00 2001 From: Tobias Hienzsch Date: Sat, 17 Feb 2024 03:42:32 +0100 Subject: [PATCH] Revert AirWindowsGrindAmp optimizations --- .../audio/airwindows/airwindows_grind_amp.hpp | 220 +++++++++++++----- lib/grit/eurorack/hades.hpp | 2 +- 2 files changed, 163 insertions(+), 59 deletions(-) diff --git a/lib/grit/audio/airwindows/airwindows_grind_amp.hpp b/lib/grit/audio/airwindows/airwindows_grind_amp.hpp index 5e697b6..7726983 100644 --- a/lib/grit/audio/airwindows/airwindows_grind_amp.hpp +++ b/lib/grit/audio/airwindows/airwindows_grind_amp.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include @@ -35,7 +34,7 @@ struct AirWindowsGrindAmp auto reset() -> void; private: - static constexpr auto sineLUT = StaticLookupTableTransform{ + static constexpr auto sineLUT = StaticLookupTableTransform{ [](auto x) { return etl::sin(x); }, Float(0), Float(1.57079633), @@ -159,29 +158,42 @@ auto AirWindowsGrindAmp::setParameter(Parameter parameter) -> void auto const c = _parameter.output; auto const d = _parameter.mix; - auto const overallscale = Float(1) / Float(44100.0) * _sampleRate; - - _cycleEnd = etl::clamp(static_cast(etl::floor(overallscale)), 1, 4); + Float overallscale = Float(1) / Float(44100.0); + overallscale *= _sampleRate; + _cycleEnd = etl::floor(overallscale); + if (_cycleEnd < 1) { + _cycleEnd = 1; + } + if (_cycleEnd > 4) { + _cycleEnd = 4; + } // this is going to be 2 for 88.1 or 96k, 3 for silly people, 4 for 176 or 192k if (_cycle > _cycleEnd - 1) { _cycle = _cycleEnd - 1; // sanity check } - _trimEq = Float(1.1) - b; - _toneEq = _trimEq / Float(1.2); + _inputlevel = etl::pow(a, Float(2)); + Float samplerate = _sampleRate; + _trimEq = Float(1.1) - b; + _toneEq = _trimEq / Float(1.2); _trimEq /= Float(50.0); _trimEq += Float(0.165); - _eq = ((_trimEq - (_toneEq / Float(6.1))) / _sampleRate) * Float(22050); - _beq = ((_trimEq + (_toneEq / Float(2.1))) / _sampleRate) * Float(22050); - - _inputlevel = etl::pow(a, Float(2)); + _eq = ((_trimEq - (_toneEq / Float(6.1))) / samplerate) * Float(22050); + _beq = ((_trimEq + (_toneEq / Float(2.1))) / samplerate) * Float(22050); _outputlevel = c; _wet = d; _bassdrive = Float(1.57079633) * (Float(2.5) - _toneEq); - auto const cutoff = etl::clamp((Float(18000) + (b * Float(1000))) / _sampleRate, Float(0.001), Float(0.49)); + Float cutoff = (Float(18000) + (b * Float(1000))) / _sampleRate; + if (cutoff > Float(0.49)) { + cutoff = Float(0.49); // don't crash if run at 44.1k + } + if (cutoff < Float(0.001)) { + cutoff = Float(0.001); // or if cutoff's too low + } _fixF[FixFreq] = _fixE[FixFreq] = _fixD[FixFreq] = _fixC[FixFreq] = _fixB[FixFreq] = _fixA[FixFreq] = cutoff; + _fixA[FixReso] = Float(4.46570214); _fixB[FixReso] = Float(1.51387132); _fixC[FixReso] = Float(0.93979296); @@ -259,8 +271,14 @@ auto AirWindowsGrindAmp::operator()(Float const x) -> Float input *= _inputlevel; _iirSampleA = (_iirSampleA * (Float(1) - _eq)) + (input * _eq); - input = etl::clamp(input - (_iirSampleA * Float(0.92)), Float(-1), Float(+1)); - + input = input - (_iirSampleA * Float(0.92)); + // highpass + if (input > Float(1)) { + input = Float(1); + } + if (input < Float(-1)) { + input = Float(-1); + } auto bridgerectifier = etl::abs(input); auto inverse = (bridgerectifier + Float(1)) * Float(0.5); bridgerectifier = (_smoothA + (_secondA * inverse) + (_thirdA * bridgerectifier) + input); @@ -277,9 +295,14 @@ auto AirWindowsGrindAmp::operator()(Float const x) -> Float input *= _inputlevel; _iirSampleB = (_iirSampleB * (Float(1) - _eq)) + (input * _eq); - input = etl::clamp(input - (_iirSampleB * Float(0.79)), Float(-1), Float(+1)); + input = input - (_iirSampleB * Float(0.79)); // highpass - + if (input > Float(1)) { + input = Float(1); + } + if (input < Float(-1)) { + input = Float(-1); + } // overdrive bridgerectifier = etl::abs(input); inverse = (bridgerectifier + Float(1)) * Float(0.5); @@ -292,11 +315,22 @@ auto AirWindowsGrindAmp::operator()(Float const x) -> Float _iirSampleC = (_iirSampleC * (Float(1) - _beq)) + (basscatchL * _beq); basscatchL = _iirSampleC * _bassdrive; - bridgerectifier = etl::clamp(etl::abs(basscatchL), Float(0), Float(1.57079633)); - - bridgerectifier = sineLUT(bridgerectifier) * sign(basscatchL); - - input = etl::clamp(input, Float(-1), Float(+1)); + bridgerectifier = etl::abs(basscatchL); + if (bridgerectifier > 1.57079633) { + bridgerectifier = 1.57079633; + } + bridgerectifier = sineLUT(bridgerectifier); + if (basscatchL > 0.0) { + basscatchL = bridgerectifier; + } else { + basscatchL = -bridgerectifier; + } + if (input > Float(1)) { + input = Float(1); + } + if (input < Float(-1)) { + input = Float(-1); + } // overdrive inverse = (bridgerectifier + Float(1)) * Float(0.5); bridgerectifier = (_smoothC + (_secondC * inverse) + (_thirdC * bridgerectifier) + input); @@ -313,11 +347,22 @@ auto AirWindowsGrindAmp::operator()(Float const x) -> Float _iirSampleD = (_iirSampleD * (Float(1) - _beq)) + (basscatchL * _beq); basscatchL = _iirSampleD * _bassdrive; - bridgerectifier = etl::clamp(etl::abs(basscatchL), Float(0), Float(1.57079633)); - - bridgerectifier = sineLUT(bridgerectifier) * sign(basscatchL); - - input = etl::clamp(input, Float(-1), Float(+1)); + bridgerectifier = etl::abs(basscatchL); + if (bridgerectifier > 1.57079633) { + bridgerectifier = 1.57079633; + } + bridgerectifier = sineLUT(bridgerectifier); + if (basscatchL > Float(0.0)) { + basscatchL = bridgerectifier; + } else { + basscatchL = -bridgerectifier; + } + if (input > Float(1.0)) { + input = Float(1.0); + } + if (input < Float(-1.0)) { + input = Float(-1.0); + } // overdrive inverse = (bridgerectifier + Float(1.0)) * Float(0.5); bridgerectifier = (_smoothD + (_secondD * inverse) + (_thirdD * bridgerectifier) + input); @@ -334,12 +379,22 @@ auto AirWindowsGrindAmp::operator()(Float const x) -> Float _iirSampleE = (_iirSampleE * (1.0 - _beq)) + (basscatchL * _beq); basscatchL = _iirSampleE * _bassdrive; - bridgerectifier = etl::clamp(etl::abs(basscatchL), Float(0), Float(1.57079633)); - - bridgerectifier = sineLUT(bridgerectifier) * sign(basscatchL); - - input = etl::clamp(input, Float(-1), Float(+1)); - + bridgerectifier = etl::abs(basscatchL); + if (bridgerectifier > 1.57079633) { + bridgerectifier = 1.57079633; + } + bridgerectifier = sineLUT(bridgerectifier); + if (basscatchL > 0.0) { + basscatchL = bridgerectifier; + } else { + basscatchL = -bridgerectifier; + } + if (input > 1.0) { + input = 1.0; + } + if (input < -1.0) { + input = -1.0; + } // overdrive inverse = (bridgerectifier + Float(1)) * Float(0.5); bridgerectifier = (_smoothE + (_secondE * inverse) + (_thirdE * bridgerectifier) + input); @@ -351,12 +406,22 @@ auto AirWindowsGrindAmp::operator()(Float const x) -> Float _iirSampleF = (_iirSampleF * (Float(1) - _beq)) + (basscatchL * _beq); basscatchL = _iirSampleF * _bassdrive; - bridgerectifier = etl::clamp(etl::abs(basscatchL), Float(0), Float(1.57079633)); - - bridgerectifier = sineLUT(bridgerectifier) * sign(basscatchL); - - input = etl::clamp(input, Float(-1), Float(+1)); - + bridgerectifier = etl::abs(basscatchL); + if (bridgerectifier > 1.57079633) { + bridgerectifier = 1.57079633; + } + bridgerectifier = sineLUT(bridgerectifier); + if (basscatchL > 0.0) { + basscatchL = bridgerectifier; + } else { + basscatchL = -bridgerectifier; + } + if (input > 1.0) { + input = 1.0; + } + if (input < -1.0) { + input = -1.0; + } // overdrive inverse = (bridgerectifier + Float(1)) * Float(0.5); bridgerectifier = (_smoothF + (_secondF * inverse) + (_thirdF * bridgerectifier) + input); @@ -371,14 +436,24 @@ auto AirWindowsGrindAmp::operator()(Float const x) -> Float _fixE[FixS2] = (input * _fixE[FixA2]) - (outSample * _fixE[FixB2]); input = outSample; // fixed biquad filtering ultrasonics - _iirSampleG = (_iirSampleG * (Float(1) - _beq)) + (basscatchL * _beq); + _iirSampleG = (_iirSampleG * (1.0 - _beq)) + (basscatchL * _beq); basscatchL = _iirSampleG * _bassdrive; - bridgerectifier = etl::clamp(etl::abs(basscatchL), Float(0), Float(1.57079633)); - - bridgerectifier = sineLUT(bridgerectifier) * sign(basscatchL); - - input = etl::clamp(input, Float(-1), Float(+1)); - + bridgerectifier = etl::abs(basscatchL); + if (bridgerectifier > 1.57079633) { + bridgerectifier = 1.57079633; + } + bridgerectifier = sineLUT(bridgerectifier); + if (basscatchL > 0.0) { + basscatchL = bridgerectifier; + } else { + basscatchL = -bridgerectifier; + } + if (input > 1.0) { + input = 1.0; + } + if (input < -1.0) { + input = -1.0; + } // overdrive inverse = (bridgerectifier + Float(1)) * Float(0.5); bridgerectifier = (_smoothG + (_secondG * inverse) + (_thirdG * bridgerectifier) + input); @@ -390,11 +465,22 @@ auto AirWindowsGrindAmp::operator()(Float const x) -> Float _iirSampleH = (_iirSampleH * (Float(1) - _beq)) + (basscatchL * _beq); basscatchL = _iirSampleH * _bassdrive; - bridgerectifier = etl::clamp(etl::abs(basscatchL), Float(0), Float(1.57079633)); - - bridgerectifier = sineLUT(bridgerectifier) * sign(basscatchL); - - input = etl::clamp(input, Float(-1), Float(+1)); + bridgerectifier = etl::abs(basscatchL); + if (bridgerectifier > 1.57079633) { + bridgerectifier = 1.57079633; + } + bridgerectifier = sineLUT(bridgerectifier); + if (basscatchL > 0.0) { + basscatchL = bridgerectifier; + } else { + basscatchL = -bridgerectifier; + } + if (input > Float(1)) { + input = Float(1); + } + if (input < Float(-1)) { + input = Float(-1); + } // overdrive inverse = (bridgerectifier + Float(1)) * Float(0.5); bridgerectifier = (_smoothH + (_secondH * inverse) + (_thirdH * bridgerectifier) + input); @@ -411,11 +497,22 @@ auto AirWindowsGrindAmp::operator()(Float const x) -> Float _iirSampleI = (_iirSampleI * (Float(1) - _beq)) + (basscatchL * _beq); basscatchL = _iirSampleI * _bassdrive; - bridgerectifier = etl::clamp(etl::abs(basscatchL), Float(0), Float(1.57079633)); - - bridgerectifier = sineLUT(bridgerectifier) * sign(basscatchL); - - input = etl::clamp(input, Float(-1), Float(+1)); + bridgerectifier = etl::abs(basscatchL); + if (bridgerectifier > 1.57079633) { + bridgerectifier = 1.57079633; + } + bridgerectifier = sineLUT(bridgerectifier); + if (basscatchL > 0.0) { + basscatchL = bridgerectifier; + } else { + basscatchL = -bridgerectifier; + } + if (input > Float(1)) { + input = Float(1); + } + if (input < Float(-1)) { + input = Float(-1); + } // overdrive inverse = (bridgerectifier + Float(1)) * Float(0.5); bridgerectifier = (_smoothI + (_secondI * inverse) + (_thirdI * bridgerectifier) + input); @@ -445,9 +542,16 @@ auto AirWindowsGrindAmp::operator()(Float const x) -> Float input = (input * _toneEq) + basscatchL; // extra lowpass for 4*12" speakers - bridgerectifier = etl::clamp(etl::abs(input * _outputlevel), Float(0), Float(1.57079633)); - bridgerectifier = sineLUT(bridgerectifier) * sign(input); - + bridgerectifier = etl::abs(input * _outputlevel); + if (bridgerectifier > 1.57079633) { + bridgerectifier = 1.57079633; + } + bridgerectifier = sineLUT(bridgerectifier); + if (input > 0.0) { + input = bridgerectifier; + } else { + input = -bridgerectifier; + } input += basscatchL; // split bass between overdrive and clean input /= (Float(1) + _toneEq); diff --git a/lib/grit/eurorack/hades.hpp b/lib/grit/eurorack/hades.hpp index 3922e00..13af83c 100644 --- a/lib/grit/eurorack/hades.hpp +++ b/lib/grit/eurorack/hades.hpp @@ -81,7 +81,7 @@ struct Hades }; Index _index{TanhIndex}; - TanhClipper _tanh{}; + TanhClipperADAA1 _tanh{}; HardClipper _hard{}; FullWaveRectifier _fullWave{}; HalfWaveRectifier _halfWave{};