Skip to content

Commit

Permalink
improve noise AM
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreya-Autumn committed Jul 23, 2024
1 parent 484d111 commit 2ddf0c1
Showing 1 changed file with 58 additions and 14 deletions.
72 changes: 58 additions & 14 deletions include/sst/voice-effects/modulation/NoiseAM.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ template <typename VFXConfig> struct NoiseAM : core::VoiceEffectTemplateBase<VFX
{
threshold *= 2.f;
threshold -= 1.f;
depth *= .5;
}

float noiseL alignas(16)[VFXConfig::blockSize];
Expand All @@ -224,17 +223,47 @@ template <typename VFXConfig> struct NoiseAM : core::VoiceEffectTemplateBase<VFX

for (int i = 0; i < VFXConfig::blockSize; i++)
{
noiseL[i] *= depth;
noiseR[i] *= depth;
auto envL = datainL[i];
auto envR = datainR[i];

auto envL = mode ? datainL[i] : fabsf(datainL[i]);
auto envR = mode ? datainR[i] : fabsf(datainR[i]);
float overL = 0.f;
float overR = 0.f;

auto overL = std::max(envL - threshold, 0.f);
auto overR = std::max(envR - threshold, 0.f);
if (!mode) // in bipolar mode
{
// the env is absolute
envL = fabsf(envL);
envR = fabsf(envR);

// and we add some offset to the noise, more so at high depth
noiseL[i] = noiseL[i] + (0.75f * (depth * depth * depth));
noiseR[i] = noiseR[i] + (0.75f * (depth * depth * depth));

// subtracting the noise if the input is positive
if (datainL[i] > 0)
{
noiseL[i] *= -1;
}
if (datainR[i] > 0)
{
noiseR[i] *= -1;
}
// this keeps the combined peaks under control and saturates the signal a bit

// this is the overshoot calculation
overL = std::max(envL - threshold, 0.f);
overR = std::max(envR - threshold, 0.f);
}
else
{
// which is reversed in unipolar mode, just so it plays nicer with asym waveshapes
overL = std::min(envL + threshold, 0.f);
overR = std::min(envR + threshold, 0.f);
// runaway peaks are a bit less problematic here so don't mess with the noise
}

noiseL[i] *= overL;
noiseR[i] *= overR;
noiseL[i] *= depth * overL;
noiseR[i] *= depth * overR;

dataoutL[i] = datainL[i] + noiseL[i];
dataoutR[i] = datainR[i] + noiseR[i];
Expand All @@ -251,7 +280,6 @@ template <typename VFXConfig> struct NoiseAM : core::VoiceEffectTemplateBase<VFX
{
threshold *= 2.f;
threshold -= 1.f;
depth *= .5f;
}

float noise alignas(16)[VFXConfig::blockSize];
Expand All @@ -261,13 +289,29 @@ template <typename VFXConfig> struct NoiseAM : core::VoiceEffectTemplateBase<VFX

for (int i = 0; i < VFXConfig::blockSize; i++)
{
noise[i] *= depth;
auto env = datain[i];

float over = 0.f;

if (!mode)
{
env = fabsf(env);

noise[i] = noise[i] + (0.75f * (depth * depth * depth));

auto env = mode ? datain[i] : fabsf(datain[i]);
if (datain[i] > 0)
{
noise[i] *= -1;
}

auto over = std::max(env - threshold, 0.f);
over = std::max(env - threshold, 0.f);
}
else
{
over = std::min(env + threshold, 0.f);
}

noise[i] *= over;
noise[i] *= depth * over;

dataout[i] = datain[i] + noise[i];
}
Expand Down

0 comments on commit 2ddf0c1

Please sign in to comment.