Skip to content

Commit

Permalink
Also fix the unison oscillator problem and LFO shape problem
Browse files Browse the repository at this point in the history
which was similarly misguided, which Closes surge-synthesizer#6531
  • Loading branch information
baconpaul committed Aug 19, 2022
1 parent 6da8e44 commit 503761c
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 42 deletions.
33 changes: 15 additions & 18 deletions src/common/dsp/modulators/LFOModulationSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ float LFOModulationSource::bend3(float x)
void LFOModulationSource::msegEnvelopePhaseAdjustment()
{
// If we have an envelope MSEG length above 1 we want phase to span the duration
if (localcopy[lfo->shape.param_id_in_scene].i == lt_mseg &&
ms->editMode == MSEGStorage::ENVELOPE && ms->totalDuration > 1.0)
if (lfo->shape.val.i == lt_mseg && ms->editMode == MSEGStorage::ENVELOPE &&
ms->totalDuration > 1.0)
{
// extend the phase
phase *= ms->totalDuration;
Expand All @@ -130,8 +130,7 @@ void LFOModulationSource::initPhaseFromStartPhase()
phase = localcopy[startphase].f;
phaseInitialized = true;

if (localcopy[lfo->shape.param_id_in_scene].i == lt_tri && lfo->rate.deactivated &&
!lfo->unipolar.val.b)
if (lfo->shape.val.i == lt_tri && lfo->rate.deactivated && !lfo->unipolar.val.b)
{
phase += 0.25;
}
Expand Down Expand Up @@ -190,7 +189,7 @@ void LFOModulationSource::attack()
{
phase = lfo->start_phase.val.f;

if (localcopy[lfo->shape.param_id_in_scene].i == lt_stepseq)
if (lfo->shape.val.i == lt_stepseq)
{
phase = 0.f;
}
Expand All @@ -204,7 +203,7 @@ void LFOModulationSource::attack()
float phaseslider;

// Use Phase as shuffle-parameter instead
if (localcopy[lfo->shape.param_id_in_scene].i == lt_stepseq)
if (lfo->shape.val.i == lt_stepseq)
{
phaseslider = 0.f;
}
Expand All @@ -224,7 +223,7 @@ void LFOModulationSource::attack()
phaseslider -= 1.f;
}

switch (localcopy[lfo->trigmode.param_id_in_scene].i)
switch (lfo->trigmode.val.i)
{
case lm_keytrigger:
phase = phaseslider;
Expand Down Expand Up @@ -268,8 +267,8 @@ void LFOModulationSource::attack()
// And so the total phase is timePassed * rate + phase0
auto startPhase = phaseslider;

if (localcopy[lfo->shape.param_id_in_scene].i == lt_mseg &&
ms->editMode == MSEGStorage::ENVELOPE && ms->totalDuration > 1.0)
if (lfo->shape.val.i == lt_mseg && ms->editMode == MSEGStorage::ENVELOPE &&
ms->totalDuration > 1.0)
{
// extend the phase
startPhase *= ms->totalDuration;
Expand All @@ -295,10 +294,10 @@ void LFOModulationSource::attack()
};
}

switch (localcopy[lfo->shape.param_id_in_scene].i)
switch (lfo->shape.val.i)
{
case lt_snh:
if (isFirstAttack || localcopy[lfo->trigmode.param_id_in_scene].i != lm_freerun)
if (isFirstAttack || lfo->trigmode.val.i != lm_freerun)
{
noise = 0.f;
noised1 = 0.f;
Expand Down Expand Up @@ -372,7 +371,7 @@ void LFOModulationSource::attack()

case lt_noise:
{
if (isFirstAttack || localcopy[lfo->trigmode.param_id_in_scene].i != lm_freerun)
if (isFirstAttack || lfo->trigmode.val.i != lm_freerun)
{
auto lid = limit_range(localcopy[ideform].f, -1.f, 1.f);

Expand Down Expand Up @@ -464,8 +463,7 @@ void LFOModulationSource::release()
env_releasestart = env_val;
env_phase = 0;
}
else if (localcopy[lfo->shape.param_id_in_scene].i == lt_mseg ||
localcopy[lfo->shape.param_id_in_scene].i == lt_formula)
else if (lfo->shape.val.i == lt_mseg || lfo->shape.val.i == lt_formula)
{
env_state = lfoeg_msegrelease;
}
Expand Down Expand Up @@ -494,16 +492,15 @@ void LFOModulationSource::retriggerEnvelope()

void LFOModulationSource::process_block()
{
if ((!phaseInitialized) ||
(localcopy[lfo->trigmode.param_id_in_scene].i == lm_keytrigger && lfo->rate.deactivated))
if ((!phaseInitialized) || (lfo->trigmode.val.i == lm_keytrigger && lfo->rate.deactivated))
{
initPhaseFromStartPhase();
}

retrigger_FEG = false;
retrigger_AEG = false;

int s = localcopy[lfo->shape.param_id_in_scene].i;
int s = lfo->shape.val.i;
float frate = 0;

if (!lfo->rate.temposync)
Expand Down Expand Up @@ -1239,7 +1236,7 @@ void LFOModulationSource::process_block()

void LFOModulationSource::completedModulation()
{
if (localcopy[lfo->shape.param_id_in_scene].i == lt_formula)
if (lfo->shape.val.i == lt_formula)
{
Surge::Formula::cleanEvaluatorState(formulastate);
}
Expand Down
4 changes: 2 additions & 2 deletions src/common/dsp/oscillators/AliasOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void AliasOscillator::init(float pitch, bool is_display, bool nonzero_init_drift
}
}

n_unison = is_display ? 1 : localcopy[oscdata->p[ao_unison_voices].param_id_in_scene].i;
n_unison = is_display ? 1 : oscdata->p[ao_unison_voices].val.i;

auto us = Surge::Oscillator::UnisonSetup<float>(n_unison);

Expand Down Expand Up @@ -411,7 +411,7 @@ void AliasOscillator::process_block(float pitch, float drift, bool stereo, bool
const float crush_bits =
limit_range(localcopy[oscdata->p[ao_bit_depth].param_id_in_scene].f, 1.f, 8.f);

const ao_waves wavetype = (ao_waves)localcopy[oscdata->p[ao_wave].param_id_in_scene].i;
const ao_waves wavetype = (ao_waves)oscdata->p[ao_wave].val.i;

#define P(m) \
case m: \
Expand Down
3 changes: 1 addition & 2 deletions src/common/dsp/oscillators/ClassicOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ void ClassicOscillator::init(float pitch, bool is_display, bool nonzero_init_dri
l_sub.setRate(rate);
l_sync.setRate(rate);

n_unison =
limit_range(localcopy[oscdata->p[co_unison_voices].param_id_in_scene].i, 1, MAX_UNISON);
n_unison = limit_range(oscdata->p[co_unison_voices].val.i, 1, MAX_UNISON);

if (is_display)
{
Expand Down
12 changes: 6 additions & 6 deletions src/common/dsp/oscillators/FM2Oscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ void FM2Oscillator::process_block(float pitch, float drift, bool stereo, bool FM
double omega = min(M_PI, (double)pitch_to_omega(pitch + driftlfo));
double sh = localcopy[oscdata->p[fm2_m12offset].param_id_in_scene].f * storage->dsamplerate_inv;

RM1.set_rate(min(M_PI, (double)pitch_to_omega(pitch + driftlfo) *
(double)localcopy[oscdata->p[fm2_m1ratio].param_id_in_scene].i +
sh));
RM2.set_rate(min(M_PI, (double)pitch_to_omega(pitch + driftlfo) *
(double)localcopy[oscdata->p[fm2_m2ratio].param_id_in_scene].i -
sh));
RM1.set_rate(
min(M_PI,
(double)pitch_to_omega(pitch + driftlfo) * (double)oscdata->p[fm2_m1ratio].val.i + sh));
RM2.set_rate(
min(M_PI,
(double)pitch_to_omega(pitch + driftlfo) * (double)oscdata->p[fm2_m2ratio].val.i - sh));

double d1 = localcopy[oscdata->p[fm2_m1amount].param_id_in_scene].f;
double d2 = localcopy[oscdata->p[fm2_m2amount].param_id_in_scene].f;
Expand Down
2 changes: 1 addition & 1 deletion src/common/dsp/oscillators/ModernOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void ModernOscillator::init(float pitch, bool is_display, bool nonzero_init_drif
pwidth.setRate(0.001); // 4x slower
sync.setRate(0.001 * BLOCK_SIZE_OS);

n_unison = is_display ? 1 : localcopy[oscdata->p[mo_unison_voices].param_id_in_scene].i;
n_unison = is_display ? 1 : oscdata->p[mo_unison_voices].val.i;

auto us = Surge::Oscillator::UnisonSetup<double>(n_unison);

Expand Down
3 changes: 1 addition & 2 deletions src/common/dsp/oscillators/SampleAndHoldOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ void SampleAndHoldOscillator::init(float pitch, bool is_display, bool nonzero_in
l_sub.setRate(rate);
l_sync.setRate(rate);

n_unison =
limit_range(localcopy[oscdata->p[shn_unison_voices].param_id_in_scene].i, 1, MAX_UNISON);
n_unison = limit_range(oscdata->p[shn_unison_voices].val.i, 1, MAX_UNISON);
if (is_display)
{
n_unison = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/common/dsp/oscillators/SineOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ void SineOscillator::prepare_unison(int voices)

void SineOscillator::init(float pitch, bool is_display, bool nonzero_init_drift)
{
n_unison =
limit_range(localcopy[oscdata->p[sine_unison_voices].param_id_in_scene].i, 1, MAX_UNISON);
n_unison = limit_range(oscdata->p[sine_unison_voices].val.i, 1, MAX_UNISON);
limit_range(oscdata->p[sine_unison_voices].val.i, 1, MAX_UNISON);

if (is_display)
{
Expand Down
4 changes: 2 additions & 2 deletions src/common/dsp/oscillators/StringOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void StringOscillator::init(float pitch, bool is_display, bool nzi)
driftLFO[i].init(nzi);
}

auto mode = (exciter_modes)localcopy[oscdata->p[str_exciter_mode].param_id_in_scene].i;
auto mode = (exciter_modes)oscdata->p[str_exciter_mode].val.i;
phase1 = 0.0, phase2 = 0.0;

if (!oscdata->retrigger.val.b && !is_display)
Expand Down Expand Up @@ -487,7 +487,7 @@ void StringOscillator::process_block(float pitch, float drift, bool stereo, bool
} \
break;

auto mode = (exciter_modes)localcopy[oscdata->p[str_exciter_mode].param_id_in_scene].i;
auto mode = (exciter_modes)oscdata->p[str_exciter_mode].val.i;
auto oss = oscdata->p[str_exciter_level].deform_type & StringOscillator::os_all;

switch (mode)
Expand Down
2 changes: 1 addition & 1 deletion src/common/dsp/oscillators/TwistOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ void TwistOscillator::process_block_internal(float pitch, float drift, bool ster

auto driftv = driftLFO.next();
patch->note = pitch + drift * driftv;
patch->engine = localcopy[oscdata->p[twist_engine].param_id_in_scene].i;
patch->engine = oscdata->p[twist_engine].val.i;

harm.newValue(fvbp(twist_harmonics));
timb.newValue(fvbp(twist_timbre));
Expand Down
3 changes: 1 addition & 2 deletions src/common/dsp/oscillators/WavetableOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ void WavetableOscillator::init(float pitch, bool is_display, bool nonzero_init_d
l_vskew.setRate(rate);
l_hskew.setRate(rate);

n_unison =
limit_range(localcopy[oscdata->p[wt_unison_voices].param_id_in_scene].i, 1, MAX_UNISON);
n_unison = limit_range(oscdata->p[wt_unison_voices].val.i, 1, MAX_UNISON);

if (oscdata->wt.flags & wtf_is_sample)
{
Expand Down
6 changes: 2 additions & 4 deletions src/common/dsp/oscillators/WindowOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ void WindowOscillator::init(float pitch, bool is_display, bool nonzero_init_drif
l_morph.setRate(0.05);
update_lagvals<true>();

NumUnison = limit_range(localcopy[oscdata->p[win_unison_voices].param_id_in_scene].i, 1,
MAX_UNISON - 1);
NumUnison = limit_range(oscdata->p[win_unison_voices].val.i, 1, MAX_UNISON - 1);

if (is_display)
{
Expand Down Expand Up @@ -196,8 +195,7 @@ void WindowOscillator::ProcessWindowOscs(bool stereo, bool FM)
unsigned int SizeMask = (oscdata->wt.size << 16) - 1;
unsigned int SizeMaskWin = (storage->WindowWT.size << 16) - 1;

unsigned char SelWindow =
limit_range(localcopy[oscdata->p[win_window].param_id_in_scene].i, 0, 8);
unsigned char SelWindow = limit_range(oscdata->p[win_window].val.i, 0, 8);

int Table = limit_range((int)(float)(oscdata->wt.n_tables * l_morph.v), 0,
(int)oscdata->wt.n_tables - 1);
Expand Down

0 comments on commit 503761c

Please sign in to comment.