From be6dcac34ecda8a5a7da81bf380146285d45056b Mon Sep 17 00:00:00 2001 From: EvilDragon Date: Mon, 7 Feb 2022 00:21:27 +0100 Subject: [PATCH] Remove manually coded denormal handling (#5796) Minor other cleanups (removing unused comments in a few places) Closes #5722 and #4900 Co-authored-by: Paul --- src/common/SurgeSynthesizer.cpp | 20 +++++------ src/common/dsp/effects/CombulatorEffect.cpp | 3 -- src/common/dsp/filters/BiquadFilter.h | 12 ------- .../dsp/oscillators/StringOscillator.cpp | 5 --- src/common/dsp/utilities/DSPUtils.h | 35 ++++--------------- src/common/dsp/vembertech/basic_dsp.cpp | 11 ------ src/common/dsp/vembertech/basic_dsp.h | 1 - 7 files changed, 17 insertions(+), 70 deletions(-) diff --git a/src/common/SurgeSynthesizer.cpp b/src/common/SurgeSynthesizer.cpp index 3d836ec6c10..49856c35f4b 100644 --- a/src/common/SurgeSynthesizer.cpp +++ b/src/common/SurgeSynthesizer.cpp @@ -3723,10 +3723,10 @@ void SurgeSynthesizer::process() } else { - clear_block_antidenormalnoise(storage.audio_in[0], BLOCK_SIZE_OS_QUAD); - clear_block_antidenormalnoise(storage.audio_in[1], BLOCK_SIZE_OS_QUAD); - clear_block_antidenormalnoise(storage.audio_in_nonOS[1], BLOCK_SIZE_QUAD); - clear_block_antidenormalnoise(storage.audio_in_nonOS[1], BLOCK_SIZE_QUAD); + clear_block(storage.audio_in[0], BLOCK_SIZE_OS_QUAD); + clear_block(storage.audio_in[1], BLOCK_SIZE_OS_QUAD); + clear_block(storage.audio_in_nonOS[1], BLOCK_SIZE_QUAD); + clear_block(storage.audio_in_nonOS[1], BLOCK_SIZE_QUAD); } // TODO: FIX SCENE ASSUMPTION @@ -3734,15 +3734,15 @@ void SurgeSynthesizer::process() bool play_scene[n_scenes]; { - clear_block_antidenormalnoise(sceneout[0][0], BLOCK_SIZE_OS_QUAD); - clear_block_antidenormalnoise(sceneout[0][1], BLOCK_SIZE_OS_QUAD); - clear_block_antidenormalnoise(sceneout[1][0], BLOCK_SIZE_OS_QUAD); - clear_block_antidenormalnoise(sceneout[1][1], BLOCK_SIZE_OS_QUAD); + clear_block(sceneout[0][0], BLOCK_SIZE_OS_QUAD); + clear_block(sceneout[0][1], BLOCK_SIZE_OS_QUAD); + clear_block(sceneout[1][0], BLOCK_SIZE_OS_QUAD); + clear_block(sceneout[1][1], BLOCK_SIZE_OS_QUAD); for (int i = 0; i < n_send_slots; ++i) { - clear_block_antidenormalnoise(fxsendout[i][0], BLOCK_SIZE_QUAD); - clear_block_antidenormalnoise(fxsendout[i][1], BLOCK_SIZE_QUAD); + clear_block(fxsendout[i][0], BLOCK_SIZE_QUAD); + clear_block(fxsendout[i][1], BLOCK_SIZE_QUAD); } } diff --git a/src/common/dsp/effects/CombulatorEffect.cpp b/src/common/dsp/effects/CombulatorEffect.cpp index fec1586dfb0..a1d21fe0919 100644 --- a/src/common/dsp/effects/CombulatorEffect.cpp +++ b/src/common/dsp/effects/CombulatorEffect.cpp @@ -337,9 +337,6 @@ void CombulatorEffect::process(float *dataL, float *dataR) lp.process_block(L, R); hp.process_block(L, R); - lp.flush_sample_denormal(); - hp.flush_sample_denormal(); - auto cm = clamp01(*f[combulator_mix]); mix.set_target_smoothed(cm); mix.fade_2_blocks_to(dataL, L, dataR, R, dataL, dataR, BLOCK_SIZE_QUAD); diff --git a/src/common/dsp/filters/BiquadFilter.h b/src/common/dsp/filters/BiquadFilter.h index 0b74eb3a970..f02c0f50a4d 100644 --- a/src/common/dsp/filters/BiquadFilter.h +++ b/src/common/dsp/filters/BiquadFilter.h @@ -106,18 +106,6 @@ class alignas(16) BiquadFilter return (float)op; } - inline void flush_sample_denormal() - { - flush_denormal(reg0.d[0]); - flush_denormal(reg1.d[0]); - } - - inline void flush_sample_denormal_aggressive() - { - flush_denormal(reg0.d[0], 1e-20); - flush_denormal(reg1.d[0], 1e-20); - } - inline void process_sample(float L, float R, float &lOut, float &rOut) { a1.process(); diff --git a/src/common/dsp/oscillators/StringOscillator.cpp b/src/common/dsp/oscillators/StringOscillator.cpp index 8885f887b8b..f7f249a7371 100644 --- a/src/common/dsp/oscillators/StringOscillator.cpp +++ b/src/common/dsp/oscillators/StringOscillator.cpp @@ -355,8 +355,6 @@ void StringOscillator::init(float pitch, bool is_display, bool nzi) delayLine[t]->write(tone.v < 0 ? lpt[t] : hpt[t]); } } - lp.flush_sample_denormal(); - hp.flush_sample_denormal(); for (int t = 0; t < 2; ++t) { @@ -653,9 +651,6 @@ void StringOscillator::process_block_internal(float pitch, float drift, bool ste outputR[i] = out; } - lp.flush_sample_denormal_aggressive(); - hp.flush_sample_denormal_aggressive(); - if (charFilt.doFilter) { if (stereo) diff --git a/src/common/dsp/utilities/DSPUtils.h b/src/common/dsp/utilities/DSPUtils.h index d192d81a68c..8fe88a7d212 100644 --- a/src/common/dsp/utilities/DSPUtils.h +++ b/src/common/dsp/utilities/DSPUtils.h @@ -38,6 +38,7 @@ class quadr_osc { dr = cos(w); di = sin(w); + // normalize vector double n = 1 / sqrt(r * r + i * i); r *= n; @@ -151,42 +152,27 @@ template class lag inline void instantize() { v = target_v; } inline T getTargetValue() { return target_v; } inline void process() { v = v * lpinv + target_v * lp; } - // void setBlockSize(int n){ bs_inv = 1/(T)n; } + T v; T target_v; private: bool first_run; - // T bs_inv; T lp, lpinv; }; -/*inline float db2linear(float db) -{ - return powf(10.f,0.05f*db); -}*/ - inline void flush_denormal(double &d) { if (fabs(d) < 1E-30) d = 0; } -inline void flush_denormal(double &d, float thresh) -{ - if (fabs(d) < thresh) - d = 0; -} - inline bool within_range(int lo, int value, int hi) { return ((value >= lo) && (value <= hi)); } -//#define limit_range(x,low,high) (max(low, min(x, high))) - inline float lerp(float a, float b, float x) { return (1 - x) * a + x * b; } -inline void trixpan( - float &L, float &R, - float x) // panning that always lets both channels through unattenuated (separate hard-panning) +// panning which always lets both channels through unattenuated (seperate hard-panning) +inline void trixpan(float &L, float &R, float x) { if (x < 0.f) { @@ -222,9 +208,9 @@ inline float tanh_fast(float in) inline double tanh_faster1(double x) { const double a = -1 / 3, b = 2 / 15; - // return tanh(x); double xs = x * x; double y = 1 + xs * a + xs * xs * b; + return y * x; } @@ -247,12 +233,12 @@ inline float clamp1bp(float in) } // Use custom format (x^3) to represent gain internally, but save as decibel in XML-data - inline float amp_to_linear(float x) { x = std::max(0.f, x); return x * x * x; } + inline float linear_to_amp(float x) { return powf(limit_range(x, 0.0000000001f, 1.f), 1.f / 3.f); } inline float amp_to_db(float x) { return limit_range((float)(18.f * log2(x)), -192.f, 96.f); } inline float db_to_amp(float x) { return limit_range(powf(2.f, x / 18.f), 0.f, 2.f); } @@ -273,42 +259,35 @@ inline double sinc(double x) inline double blackman(int i, int n) { - // if (i>=n) return 0; return (0.42 - 0.5 * cos(2 * M_PI * i / (n - 1)) + 0.08 * cos(4 * M_PI * i / (n - 1))); } inline double symmetric_blackman(double i, int n) { - // if (i>=n) return 0; i -= (n / 2); return (0.42 - 0.5 * cos(2 * M_PI * i / (n)) + 0.08 * cos(4 * M_PI * i / (n))); } inline double blackman(double i, int n) { - // if (i>=n) return 0; return (0.42 - 0.5 * cos(2 * M_PI * i / (n - 1)) + 0.08 * cos(4 * M_PI * i / (n - 1))); } inline double blackman_harris(int i, int n) { - // if (i>=n) return 0; return (0.35875 - 0.48829 * cos(2 * M_PI * i / (n - 1)) + 0.14128 * cos(4 * M_PI * i / (n - 1)) - 0.01168 * cos(6 * M_PI * i / (n - 1))); } inline double symmetric_blackman_harris(double i, int n) { - // if (i>=n) return 0; i -= (n / 2); - // return (0.42 - 0.5*cos(2*M_PI*i/(n)) + 0.08*cos(4*M_PI*i/(n))); return (0.35875 - 0.48829 * cos(2 * M_PI * i / (n)) + 0.14128 * cos(4 * M_PI * i / (n - 1)) - 0.01168 * cos(6 * M_PI * i / (n))); } inline double blackman_harris(double i, int n) { - // if (i>=n) return 0; return (0.35875 - 0.48829 * cos(2 * M_PI * i / (n - 1)) + 0.14128 * cos(4 * M_PI * i / (n - 1)) - 0.01168 * cos(6 * M_PI * i / (n - 1))); } @@ -318,7 +297,7 @@ float correlated_noise_mk2(float &lastval, float correlation); float drift_noise(float &lastval); float correlated_noise_o2(float lastval, float &lastval2, float correlation); float correlated_noise_o2mk2(float &lastval, float &lastval2, float correlation); -// An alternate version where you supply a uniform RNG on -1,1 externally +// alternative version where you supply a uniform RNG on [-1, 1] externally float correlated_noise_o2mk2_suppliedrng(float &lastval, float &lastval2, float correlation, std::function &urng); diff --git a/src/common/dsp/vembertech/basic_dsp.cpp b/src/common/dsp/vembertech/basic_dsp.cpp index 77f7f81bf93..a6ab2955b3e 100644 --- a/src/common/dsp/vembertech/basic_dsp.cpp +++ b/src/common/dsp/vembertech/basic_dsp.cpp @@ -226,17 +226,6 @@ void clear_block(float *in, unsigned int nquads) } } -void clear_block_antidenormalnoise(float *in, unsigned int nquads) -{ - const __m128 smallvalue = _mm_set_ps(1e-15f, 1e-15f, -1e-15f, -1e-15f); - - for (unsigned int i = 0; i < (nquads << 2); i += 8) - { - _mm_store_ps((float *)&in[i], smallvalue); - _mm_store_ps((float *)&in[i + 4], smallvalue); - } -} - void accumulate_block(float *__restrict src, float *__restrict dst, unsigned int nquads) // dst += src { diff --git a/src/common/dsp/vembertech/basic_dsp.h b/src/common/dsp/vembertech/basic_dsp.h index 0bfbe3af459..4eddf6fc82d 100644 --- a/src/common/dsp/vembertech/basic_dsp.h +++ b/src/common/dsp/vembertech/basic_dsp.h @@ -14,7 +14,6 @@ void hardclip_block8(float *x, unsigned int nquads); void softclip_block(float *in, unsigned int nquads); void tanh7_block(float *x, unsigned int nquads); void clear_block(float *in, unsigned int nquads); -void clear_block_antidenormalnoise(float *in, unsigned int nquads); void accumulate_block(float *src, float *dst, unsigned int nquads); void copy_block(float *src, float *dst, unsigned int nquads); // copy block (requires aligned data) void copy_block_US(float *src, float *dst, unsigned int nquads); // copy block (unaligned source)