Skip to content

Commit

Permalink
Repaint LFO display when receiving host automation/MIDI CC learn (#6857)
Browse files Browse the repository at this point in the history
Also clean up some formatting in DSPUtils.
  • Loading branch information
mkruselj authored Feb 24, 2023
1 parent 533f7e4 commit e46dbfc
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 41 deletions.
1 change: 0 additions & 1 deletion src/common/SurgeSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2206,7 +2206,6 @@ void SurgeSynthesizer::channelController(char channel, int cc, int value)
learn_macro_from_cc = -1;
}

// if(storage.getPatch().scene_active.val.i == 1)
for (int i = 0; i < n_global_params; i++)
{
if (storage.getPatch().param_ptr[i]->midictrl == cc_encoded)
Expand Down
52 changes: 40 additions & 12 deletions src/common/dsp/utilities/DSPUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ float correlated_noise(float lastval, float correlation)
float wfabs = fabs(wf);
float rand11 = (((float)rand() / (float)RAND_MAX) * 2.f - 1.f);
float randt = rand11 * (1 - wfabs) - wf * lastval;

return randt;
}

Expand All @@ -16,19 +17,20 @@ float correlated_noise_mk2(float &lastval, float correlation)
float wfabs = fabs(wf);
float m = 1.f / sqrt(1.f - wfabs);
float rand11 = (((float)rand() / (float)RAND_MAX) * 2.f - 1.f);

lastval = rand11 * (1 - wfabs) - wf * lastval;

return lastval * m;
}

float drift_noise(float &lastval)
{
const float filter = 0.00001f;
const float m = 1.f / sqrt(filter);
//__m128 mvec = _mm_rsqrt_ss(_mm_load_ss(&filter));
//_mm_store_ss(&m,mvec);

float rand11 = (((float)rand() / (float)RAND_MAX) * 2.f - 1.f);

lastval = lastval * (1.f - filter) + rand11 * filter;

return lastval * m;
}

Expand All @@ -38,33 +40,43 @@ float correlated_noise_o2(float lastval, float &lastval2, float correlation)
float wfabs = fabs(wf);
float rand11 = (((float)rand() / (float)RAND_MAX) * 2.f - 1.f);
float randt = rand11 * (1 - wfabs) - wf * lastval2;

lastval2 = randt;
randt = lastval2 * (1 - wfabs) - wf * lastval;

return randt;
}

float correlated_noise_o2mk2(float &lastval, float &lastval2, float correlation)
{
float wf = correlation;
float wfabs = fabs(wf) * 0.8f;
// wfabs = 1.f - (1.f-wfabs)*(1.f-wfabs);

wfabs = (2.f * wfabs - wfabs * wfabs);

if (wf > 0.f)
{
wf = wfabs;
}
else
{
wf = -wfabs;
}

#if MAC
float m = 1.f / sqrt(1.f - wfabs);
#else
float m = 1.f - wfabs;
// float m = 1.f/sqrt(1.f-wfabs);

__m128 m1 = _mm_rsqrt_ss(_mm_load_ss(&m));
_mm_store_ss(&m, m1);
// if (wf>0.f) m *= 1 + wf*8;
#endif

float rand11 = (((float)rand() / (float)RAND_MAX) * 2.f - 1.f);

lastval2 = rand11 * (1 - wfabs) - wf * lastval2;
lastval = lastval2 * (1 - wfabs) - wf * lastval;

return lastval * m;
}

Expand All @@ -73,24 +85,32 @@ float correlated_noise_o2mk2_suppliedrng(float &lastval, float &lastval2, float
{
float wf = correlation;
float wfabs = fabs(wf) * 0.8f;
// wfabs = 1.f - (1.f-wfabs)*(1.f-wfabs);

wfabs = (2.f * wfabs - wfabs * wfabs);

if (wf > 0.f)
{
wf = wfabs;
}
else
{
wf = -wfabs;
}

#if MAC
float m = 1.f / sqrt(1.f - wfabs);
#else
float m = 1.f - wfabs;
// float m = 1.f/sqrt(1.f-wfabs);

__m128 m1 = _mm_rsqrt_ss(_mm_load_ss(&m));
_mm_store_ss(&m, m1);
// if (wf>0.f) m *= 1 + wf*8;
#endif

float rand11 = urng();

lastval2 = rand11 * (1 - wfabs) - wf * lastval2;
lastval = lastval2 * (1 - wfabs) - wf * lastval;

return lastval * m;
}

Expand All @@ -99,23 +119,31 @@ float correlated_noise_o2mk2_storagerng(float &lastval, float &lastval2, float c
{
float wf = correlation;
float wfabs = fabs(wf) * 0.8f;
// wfabs = 1.f - (1.f-wfabs)*(1.f-wfabs);

wfabs = (2.f * wfabs - wfabs * wfabs);

if (wf > 0.f)
{
wf = wfabs;
}
else
{
wf = -wfabs;
}

#if MAC
float m = 1.f / sqrt(1.f - wfabs);
#else
float m = 1.f - wfabs;
// float m = 1.f/sqrt(1.f-wfabs);

__m128 m1 = _mm_rsqrt_ss(_mm_load_ss(&m));
_mm_store_ss(&m, m1);
// if (wf>0.f) m *= 1 + wf*8;
#endif

float rand11 = s->rand_pm1();

lastval2 = rand11 * (1 - wfabs) - wf * lastval2;
lastval = lastval2 * (1 - wfabs) - wf * lastval;

return lastval * m;
}
Loading

0 comments on commit e46dbfc

Please sign in to comment.