Skip to content

Commit

Permalink
Remove manually coded denormal handling (#5796)
Browse files Browse the repository at this point in the history
Minor other cleanups (removing unused comments in a few places)

Closes #5722 and #4900

Co-authored-by: Paul <[email protected]>
  • Loading branch information
mkruselj and baconpaul authored Feb 6, 2022
1 parent aee185a commit be6dcac
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 70 deletions.
20 changes: 10 additions & 10 deletions src/common/SurgeSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3723,26 +3723,26 @@ 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
float fxsendout alignas(16)[n_send_slots][2][BLOCK_SIZE];
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);
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/common/dsp/effects/CombulatorEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 0 additions & 12 deletions src/common/dsp/filters/BiquadFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 0 additions & 5 deletions src/common/dsp/oscillators/StringOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down
35 changes: 7 additions & 28 deletions src/common/dsp/utilities/DSPUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -151,42 +152,27 @@ template <class T, bool first_run_checks = true> 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)
{
Expand Down Expand Up @@ -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;
}

Expand All @@ -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); }
Expand All @@ -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)));
}
Expand All @@ -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<float()> &urng);

Expand Down
11 changes: 0 additions & 11 deletions src/common/dsp/vembertech/basic_dsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
1 change: 0 additions & 1 deletion src/common/dsp/vembertech/basic_dsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit be6dcac

Please sign in to comment.