Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions modules/gin_dsp/dsp/gin_oscillators.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,16 @@ class StereoOscillator
float asym = 0.0f;
};

void setSampleRate (double sr) { sampleRate = sr; }
void setSampleRate (double sr)
{
sampleRate = sr;

if (sampleRate > 0)
{
leftGain.reset(sampleRate, 0.05);
rightGain.reset(sampleRate, 0.05);
}
}
void noteOn (float p = -1);

void process (float note, const Params& params, juce::AudioSampleBuffer& buffer)
Expand All @@ -84,11 +93,14 @@ class StereoOscillator

for (int i = 0; i < samps; i++)
{
leftGain.setTargetValue(params.leftGain);
rightGain.setTargetValue(params.rightGain);

auto s = bllt.process (params.wave, note, phase, params.pw);
postProcess (params, s);

*l++ += s * params.leftGain;
*r++ += s * params.rightGain;
*l++ += s * leftGain.getNextValue();
*r++ += s * rightGain.getNextValue();

phase += delta;
while (phase >= 1.0f)
Expand All @@ -113,6 +125,7 @@ class StereoOscillator
BandLimitedLookupTables& bllt;
double sampleRate = 44100.0;
float phase = 0.0f;
juce::SmoothedValue<float, juce::ValueSmoothingTypes::Linear> leftGain, rightGain;
};

/**
Expand Down
31 changes: 24 additions & 7 deletions modules/gin_dsp/dsp/gin_wtoscillators.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ class WTOscillator
blockerR.setSampleRate (float (sr));
blockerL.setCutoff (10.0f);
blockerR.setCutoff (10.0f);

if (sampleRate > 0)
{
leftGain.reset(sampleRate, 0.05);
rightGain.reset(sampleRate, 0.05);
}
}

void noteOn (float p = -1);
Expand Down Expand Up @@ -131,6 +137,9 @@ class WTOscillator
auto todo = std::min (samps, int ((1.0f - phase) / delta) + 1);
samps -= todo;

leftGain.setTargetValue(params.leftGain);
rightGain.setTargetValue(params.rightGain);

#if GIN_HAS_SIMD
for (; todo >= 4; todo -= 4)
{
Expand All @@ -156,8 +165,8 @@ class WTOscillator
auto s = table->processLinear (note, std::min (almostOne, phase));
postProcess (params, s);

*l++ += s * params.leftGain;
*r++ += s * params.rightGain;
*l++ += s * leftGain.getNextValue();
*r++ += s * rightGain.getNextValue();

phase += delta;
}
Expand Down Expand Up @@ -192,6 +201,9 @@ class WTOscillator
{
auto todo = std::min (samps, int ((1.0f - phase) / delta) + 1);
samps -= todo;

leftGain.setTargetValue(params.leftGain);
rightGain.setTargetValue(params.rightGain);

#if GIN_HAS_SIMD
for (; todo >= 4; todo -= 4)
Expand All @@ -205,7 +217,7 @@ class WTOscillator

lVec += s * params.leftGain;
rVec += s * params.rightGain;

lVec.store (l); l += 4;
rVec.store (r); r += 4;

Expand All @@ -218,8 +230,8 @@ class WTOscillator
auto s = table->processLinear (note, phaseDistortion (std::min (almostOne, phase), params.bend, params.formant));
postProcess (params, s);

*l++ += s * params.leftGain;
*r++ += s * params.rightGain;
*l++ += s * leftGain.getNextValue();
*r++ += s * rightGain.getNextValue();

phase += delta;
}
Expand Down Expand Up @@ -258,6 +270,9 @@ class WTOscillator
{
auto todo = std::min (samps, int ((1.0f - phase) / delta) + 1);
samps -= todo;

leftGain.setTargetValue(params.leftGain);
rightGain.setTargetValue(params.rightGain);

#if GIN_HAS_SIMD
for (; todo >= 4; todo -= 4)
Expand Down Expand Up @@ -290,8 +305,8 @@ class WTOscillator
auto s = s1 * phase + s2 * (1.0f - phase);
postProcess (params, s);

*l++ += s * params.leftGain;
*r++ += s * params.rightGain;
*l++ += s * leftGain.getNextValue();
*r++ += s * rightGain.getNextValue();

phase += delta;
}
Expand Down Expand Up @@ -371,6 +386,8 @@ class WTOscillator
DCBlocker blockerL;
DCBlocker blockerR;

juce::SmoothedValue<float, juce::ValueSmoothingTypes::Linear> leftGain, rightGain;

static constexpr float almostOne = { 1.0f - std::numeric_limits<float>::epsilon() };
};

Expand Down