From 503761c4ad77516698976f537cbc9142661a055c Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Fri, 19 Aug 2022 10:19:43 -0400 Subject: [PATCH] Also fix the unison oscillator problem and LFO shape problem which was similarly misguided, which Closes #6531 --- .../dsp/modulators/LFOModulationSource.cpp | 33 +++++++++---------- .../dsp/oscillators/AliasOscillator.cpp | 4 +-- .../dsp/oscillators/ClassicOscillator.cpp | 3 +- src/common/dsp/oscillators/FM2Oscillator.cpp | 12 +++---- .../dsp/oscillators/ModernOscillator.cpp | 2 +- .../oscillators/SampleAndHoldOscillator.cpp | 3 +- src/common/dsp/oscillators/SineOscillator.cpp | 4 +-- .../dsp/oscillators/StringOscillator.cpp | 4 +-- .../dsp/oscillators/TwistOscillator.cpp | 2 +- .../dsp/oscillators/WavetableOscillator.cpp | 3 +- .../dsp/oscillators/WindowOscillator.cpp | 6 ++-- 11 files changed, 34 insertions(+), 42 deletions(-) diff --git a/src/common/dsp/modulators/LFOModulationSource.cpp b/src/common/dsp/modulators/LFOModulationSource.cpp index 195a00585f9..9f091ecf724 100644 --- a/src/common/dsp/modulators/LFOModulationSource.cpp +++ b/src/common/dsp/modulators/LFOModulationSource.cpp @@ -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; @@ -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; } @@ -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; } @@ -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; } @@ -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; @@ -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; @@ -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; @@ -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); @@ -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; } @@ -494,8 +492,7 @@ 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(); } @@ -503,7 +500,7 @@ void LFOModulationSource::process_block() 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) @@ -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); } diff --git a/src/common/dsp/oscillators/AliasOscillator.cpp b/src/common/dsp/oscillators/AliasOscillator.cpp index f6a69a09f93..079250ab435 100644 --- a/src/common/dsp/oscillators/AliasOscillator.cpp +++ b/src/common/dsp/oscillators/AliasOscillator.cpp @@ -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(n_unison); @@ -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: \ diff --git a/src/common/dsp/oscillators/ClassicOscillator.cpp b/src/common/dsp/oscillators/ClassicOscillator.cpp index cad3f4dbb30..1fdf0ecafb9 100644 --- a/src/common/dsp/oscillators/ClassicOscillator.cpp +++ b/src/common/dsp/oscillators/ClassicOscillator.cpp @@ -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) { diff --git a/src/common/dsp/oscillators/FM2Oscillator.cpp b/src/common/dsp/oscillators/FM2Oscillator.cpp index 0e77a9261f6..2224e838a56 100644 --- a/src/common/dsp/oscillators/FM2Oscillator.cpp +++ b/src/common/dsp/oscillators/FM2Oscillator.cpp @@ -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; diff --git a/src/common/dsp/oscillators/ModernOscillator.cpp b/src/common/dsp/oscillators/ModernOscillator.cpp index e83773118f2..225e40f3b31 100644 --- a/src/common/dsp/oscillators/ModernOscillator.cpp +++ b/src/common/dsp/oscillators/ModernOscillator.cpp @@ -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(n_unison); diff --git a/src/common/dsp/oscillators/SampleAndHoldOscillator.cpp b/src/common/dsp/oscillators/SampleAndHoldOscillator.cpp index 414129518c9..290b1fc7b83 100644 --- a/src/common/dsp/oscillators/SampleAndHoldOscillator.cpp +++ b/src/common/dsp/oscillators/SampleAndHoldOscillator.cpp @@ -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; diff --git a/src/common/dsp/oscillators/SineOscillator.cpp b/src/common/dsp/oscillators/SineOscillator.cpp index c20152a46f5..66ca590b5b0 100644 --- a/src/common/dsp/oscillators/SineOscillator.cpp +++ b/src/common/dsp/oscillators/SineOscillator.cpp @@ -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) { diff --git a/src/common/dsp/oscillators/StringOscillator.cpp b/src/common/dsp/oscillators/StringOscillator.cpp index c6de8fb80ab..d3cea5c5bae 100644 --- a/src/common/dsp/oscillators/StringOscillator.cpp +++ b/src/common/dsp/oscillators/StringOscillator.cpp @@ -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) @@ -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) diff --git a/src/common/dsp/oscillators/TwistOscillator.cpp b/src/common/dsp/oscillators/TwistOscillator.cpp index bca939db40b..db2b19fc589 100644 --- a/src/common/dsp/oscillators/TwistOscillator.cpp +++ b/src/common/dsp/oscillators/TwistOscillator.cpp @@ -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)); diff --git a/src/common/dsp/oscillators/WavetableOscillator.cpp b/src/common/dsp/oscillators/WavetableOscillator.cpp index 607d3c6c0ef..f1fc10afe13 100644 --- a/src/common/dsp/oscillators/WavetableOscillator.cpp +++ b/src/common/dsp/oscillators/WavetableOscillator.cpp @@ -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) { diff --git a/src/common/dsp/oscillators/WindowOscillator.cpp b/src/common/dsp/oscillators/WindowOscillator.cpp index c5ef8fd5ff8..1a02a384a56 100644 --- a/src/common/dsp/oscillators/WindowOscillator.cpp +++ b/src/common/dsp/oscillators/WindowOscillator.cpp @@ -62,8 +62,7 @@ void WindowOscillator::init(float pitch, bool is_display, bool nonzero_init_drif l_morph.setRate(0.05); update_lagvals(); - 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) { @@ -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);