Skip to content

Commit

Permalink
Add an initial-phase argument to the OSC::init
Browse files Browse the repository at this point in the history
Don't expose it to the VST.

Addresses surge-synthesizer#7220
  • Loading branch information
baconpaul committed Sep 24, 2023
1 parent bced64f commit 1731cd5
Show file tree
Hide file tree
Showing 22 changed files with 67 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,4 @@ __pycache__
minst.sh

Testing/
installer-tmp/
3 changes: 2 additions & 1 deletion src/common/dsp/oscillators/AudioInputOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ AudioInputOscillator::AudioInputOscillator(SurgeStorage *storage, OscillatorStor
}
}

void AudioInputOscillator::init(float pitch, bool is_display, bool nonzero_init_drift)
void AudioInputOscillator::init(float pitch, bool is_display, bool nonzero_init_drift,
float initialPhase)
{
hp.coeff_instantize();
lp.coeff_instantize();
Expand Down
4 changes: 2 additions & 2 deletions src/common/dsp/oscillators/AudioInputOscillator.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class AudioInputOscillator : public Oscillator
*/

AudioInputOscillator(SurgeStorage *storage, OscillatorStorage *oscdata, pdata *localcopy);
virtual void init(float pitch, bool is_display = false,
bool nonzero_init_drift = true) override;
virtual void init(float pitch, bool is_display = false, bool nonzero_init_drift = true,
float initialPhase = 0.f) override;
virtual void process_block(float pitch, float drift = 0.f, bool stereo = false, bool FM = false,
float FMdepth = 0.f) override;
virtual ~AudioInputOscillator();
Expand Down
14 changes: 9 additions & 5 deletions src/common/dsp/oscillators/ClassicOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ ClassicOscillator::ClassicOscillator(SurgeStorage *storage, OscillatorStorage *o

ClassicOscillator::~ClassicOscillator() {}

void ClassicOscillator::init(float pitch, bool is_display, bool nonzero_init_drift)
void ClassicOscillator::init(float pitch, bool is_display, bool nonzero_init_drift,
float initialPhase)
{
assert(storage);
first_run = true;
Expand Down Expand Up @@ -227,17 +228,20 @@ void ClassicOscillator::init(float pitch, bool is_display, bool nonzero_init_dri

for (int i = 0; i < n_unison; i++)
{
double detune = oscdata->p[co_unison_detune].get_extended(localcopy[id_detune].f) *
(detune_bias * float(i) + detune_offset);

if (oscdata->retrigger.val.b || is_display)
{
oscstate[i] = 0.f;
syncstate[i] = 0.f;
double st = 0.5 * initialPhase * storage->note_to_pitch_inv_tuningctr(detune);

oscstate[i] = st;
syncstate[i] = st;
last_level[i] = 0.f;
}
else
{
double drand = (double)storage->rand_01();
double detune = oscdata->p[co_unison_detune].get_extended(localcopy[id_detune].f) *
(detune_bias * float(i) + detune_offset);
double st = 0.5 * drand * storage->note_to_pitch_inv_tuningctr(detune);
oscstate[i] = st;
syncstate[i] = st;
Expand Down
4 changes: 2 additions & 2 deletions src/common/dsp/oscillators/ClassicOscillator.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class ClassicOscillator : public AbstractBlitOscillator
};

ClassicOscillator(SurgeStorage *storage, OscillatorStorage *oscdata, pdata *localcopy);
virtual void init(float pitch, bool is_display = false,
bool nonzero_init_drift = true) override;
virtual void init(float pitch, bool is_display = false, bool nonzero_init_drift = true,
float initialPhase = 0.f) override;
virtual void init_ctrltypes() override;
virtual void init_default_values() override;
virtual void process_block(float pitch, float drift = 0.f, bool stereo = false, bool FM = false,
Expand Down
6 changes: 3 additions & 3 deletions src/common/dsp/oscillators/FM2Oscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ FM2Oscillator::FM2Oscillator(SurgeStorage *storage, OscillatorStorage *oscdata,

double calcmd(double x) { return x * x * x * 8.0 * M_PI; }

void FM2Oscillator::init(float pitch, bool is_display, bool nonzero_init_drift)
void FM2Oscillator::init(float pitch, bool is_display, bool nonzero_init_drift, float initialPhase)
{
phase =
(is_display || oscdata->retrigger.val.b) ? 0.f : (2.0 * M_PI * storage->rand_01() - M_PI);
phase = (is_display || oscdata->retrigger.val.b) ? (2.0 * M_PI * initialPhase)
: (2.0 * M_PI * storage->rand_01() - M_PI);
oldout1 = 0.0;
oldout2 = 0.0;
driftLFO.init(nonzero_init_drift);
Expand Down
4 changes: 2 additions & 2 deletions src/common/dsp/oscillators/FM2Oscillator.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class FM2Oscillator : public Oscillator
};

FM2Oscillator(SurgeStorage *storage, OscillatorStorage *oscdata, pdata *localcopy);
virtual void init(float pitch, bool is_display = false,
bool nonzero_init_drift = true) override;
virtual void init(float pitch, bool is_display = false, bool nonzero_init_drift = true,
float initialPhase = 0.f) override;
virtual void process_block(float pitch, float drift = 0.f, bool stereo = false, bool FM = false,
float FMdepth = 0.f) override;
virtual ~FM2Oscillator();
Expand Down
6 changes: 3 additions & 3 deletions src/common/dsp/oscillators/FM3Oscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ FM3Oscillator::FM3Oscillator(SurgeStorage *storage, OscillatorStorage *oscdata,
{
}

void FM3Oscillator::init(float pitch, bool is_display, bool nonzero_init_drift)
void FM3Oscillator::init(float pitch, bool is_display, bool nonzero_init_drift, float initialPhase)
{
phase =
(is_display || oscdata->retrigger.val.b) ? 0.f : (2.0 * M_PI * storage->rand_01() - M_PI);
phase = (is_display || oscdata->retrigger.val.b) ? (2.0 * M_PI * initialPhase)
: (2.0 * M_PI * storage->rand_01() - M_PI);
oldout1 = 0.f;
oldout2 = 0.f;
driftLFO.init(nonzero_init_drift);
Expand Down
4 changes: 2 additions & 2 deletions src/common/dsp/oscillators/FM3Oscillator.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class FM3Oscillator : public Oscillator
};

FM3Oscillator(SurgeStorage *storage, OscillatorStorage *oscdata, pdata *localcopy);
virtual void init(float pitch, bool is_display = false,
bool nonzero_init_drift = true) override;
virtual void init(float pitch, bool is_display = false, bool nonzero_init_drift = true,
float initialPhase = 0.f) override;
virtual void process_block(float pitch, float drift = 0.f, bool stereo = false, bool FM = false,
float FMdepth = 0.f) override;
virtual ~FM3Oscillator();
Expand Down
3 changes: 2 additions & 1 deletion src/common/dsp/oscillators/OscillatorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class alignas(16) Oscillator

Oscillator(SurgeStorage *storage, OscillatorStorage *oscdata, pdata *localcopy);
virtual ~Oscillator();
virtual void init(float pitch, bool is_display = false, bool nonzero_init_drift = true){};
virtual void init(float pitch, bool is_display = false, bool nonzero_init_drift = true,
float initialPhase = 0.f){};
virtual void init_ctrltypes(int scene, int oscnum) { init_ctrltypes(); };
virtual void init_ctrltypes(){};
virtual void init_default_values(){};
Expand Down
16 changes: 9 additions & 7 deletions src/common/dsp/oscillators/SampleAndHoldOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ SampleAndHoldOscillator::SampleAndHoldOscillator(SurgeStorage *storage, Oscillat

SampleAndHoldOscillator::~SampleAndHoldOscillator() {}

void SampleAndHoldOscillator::init(float pitch, bool is_display, bool nonzero_init_drift)
void SampleAndHoldOscillator::init(float pitch, bool is_display, bool nonzero_init_drift,
float initialPhase)
{
assert(storage);
first_run = true;
Expand Down Expand Up @@ -105,19 +106,20 @@ void SampleAndHoldOscillator::init(float pitch, bool is_display, bool nonzero_in
int i;
for (i = 0; i < n_unison; i++)
{
double detune = oscdata->p[shn_unison_detune].get_extended(localcopy[id_detune].f) *
(detune_bias * float(i) + detune_offset);

if (oscdata->retrigger.val.b || is_display)
{
oscstate[i] = 0;
syncstate[i] = 0;
double st = initialPhase * storage->note_to_pitch_tuningctr(detune) * 0.5;

oscstate[i] = st;
syncstate[i] = st;
}
else
{
double drand = (double)storage->rand_01();
double detune = oscdata->p[shn_unison_detune].get_extended(localcopy[id_detune].f) *
(detune_bias * float(i) + detune_offset);
double st = drand * storage->note_to_pitch_tuningctr(detune) * 0.5;
drand = (double)storage->rand_01();
double ot = drand * storage->note_to_pitch_tuningctr(detune);
oscstate[i] = st;
syncstate[i] = st;
}
Expand Down
4 changes: 2 additions & 2 deletions src/common/dsp/oscillators/SampleAndHoldOscillator.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class SampleAndHoldOscillator : public AbstractBlitOscillator
};

SampleAndHoldOscillator(SurgeStorage *storage, OscillatorStorage *oscdata, pdata *localcopy);
virtual void init(float pitch, bool is_display = false,
bool nonzero_init_drift = true) override;
virtual void init(float pitch, bool is_display = false, bool nonzero_init_drift = true,
float initialPhase = 0.f) override;
virtual void init_ctrltypes() override;
virtual void init_default_values() override;
virtual void process_block(float pitch, float drift = 0.f, bool stereo = false, bool FM = false,
Expand Down
5 changes: 3 additions & 2 deletions src/common/dsp/oscillators/SineOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void SineOscillator::prepare_unison(int voices)
playingramp[i] = 0;
}

void SineOscillator::init(float pitch, bool is_display, bool nonzero_init_drift)
void SineOscillator::init(float pitch, bool is_display, bool nonzero_init_drift, float initialPhase)
{
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);
Expand All @@ -119,7 +119,8 @@ void SineOscillator::init(float pitch, bool is_display, bool nonzero_init_drift)
for (int i = 0; i < n_unison; i++)
{
phase[i] = // phase in range -PI to PI
(oscdata->retrigger.val.b || is_display) ? 0.f : 2.0 * M_PI * storage->rand_01() - M_PI;
(oscdata->retrigger.val.b || is_display) ? (2.0 * M_PI * initialPhase)
: 2.0 * M_PI * storage->rand_01() - M_PI;
lastvalue[0][i] = 0.f;
lastvalue[1][i] = 0.f;
driftLFO[i].init(nonzero_init_drift);
Expand Down
4 changes: 2 additions & 2 deletions src/common/dsp/oscillators/SineOscillator.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class SineOscillator : public Oscillator
};

SineOscillator(SurgeStorage *storage, OscillatorStorage *oscdata, pdata *localcopy);
virtual void init(float pitch, bool is_display = false,
bool nonzero_init_drift = true) override;
virtual void init(float pitch, bool is_display = false, bool nonzero_init_drift = true,
float initialPhase = 0.f) override;
virtual void process_block(float pitch, float drift = 0.f, bool stereo = false, bool FM = false,
float FMdepth = 0.f) override;
template <int mode, bool stereo, bool FM>
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 @@ -106,7 +106,7 @@ StringOscillator::~StringOscillator()
}
};

void StringOscillator::init(float pitch, bool is_display, bool nzi)
void StringOscillator::init(float pitch, bool is_display, bool nzi, float initialPhase)
{
// fixme - alloc in is_display but for now just deal with the race
// delayLine[0] = std::make_unique<SSESincDelayLine<16384>>();
Expand Down Expand Up @@ -190,7 +190,7 @@ void StringOscillator::init(float pitch, bool is_display, bool nzi)
}

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

if (!oscdata->retrigger.val.b && !is_display)
{
Expand Down
3 changes: 2 additions & 1 deletion src/common/dsp/oscillators/StringOscillator.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class StringOscillator : public Oscillator

~StringOscillator();

virtual void init(float pitch, bool is_display = false, bool nonzero_drift = true) override;
virtual void init(float pitch, bool is_display = false, bool nonzero_drift = true,
float initialPhase = 0.f) override;
virtual void init_ctrltypes(int scene, int oscnum) override { init_ctrltypes(); };
virtual void init_ctrltypes() override;
virtual void init_default_values() override;
Expand Down
6 changes: 5 additions & 1 deletion src/common/dsp/oscillators/TwistOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ float TwistOscillator::tuningAwarePitch(float pitch)
return pitch;
}

void TwistOscillator::init(float pitch, bool is_display, bool nonzero_drift)
void TwistOscillator::init(float pitch, bool is_display, bool nonzero_drift, float initialPhase)
{
voice->Init(alloc.get());

Expand All @@ -345,6 +345,10 @@ void TwistOscillator::init(float pitch, bool is_display, bool nonzero_drift)
{
cycleInSamples *= (1.0 + storage->rand_01());
}
else
{
cycleInSamples *= (1.0 + initialPhase);
}

memset(fmlagbuffer, 0, (BLOCK_SIZE_OS << 1) * sizeof(float));
fmrp = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/common/dsp/oscillators/TwistOscillator.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class TwistOscillator : public Oscillator
void process_block_internal(float pitch, float drift, bool stereo, float FMdepth,
int throwawayBlocks = -1);

virtual void init(float pitch, bool is_display = false, bool nonzero_drift = true) override;
virtual void init(float pitch, bool is_display = false, bool nonzero_drift = true,
float initialPhase = 0.f) override;
virtual void init_ctrltypes(int scene, int oscnum) override { init_ctrltypes(); };
virtual void init_ctrltypes() override;
virtual void init_default_values() override;
Expand Down
5 changes: 3 additions & 2 deletions src/common/dsp/oscillators/WavetableOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ WavetableOscillator::WavetableOscillator(SurgeStorage *storage, OscillatorStorag

WavetableOscillator::~WavetableOscillator() {}

void WavetableOscillator::init(float pitch, bool is_display, bool nonzero_init_drift)
void WavetableOscillator::init(float pitch, bool is_display, bool nonzero_init_drift,
float initialPhase)
{
assert(storage);
first_run = true;
Expand Down Expand Up @@ -105,7 +106,7 @@ void WavetableOscillator::init(float pitch, bool is_display, bool nonzero_init_d
{
if (oscdata->retrigger.val.b || is_display)
{
oscstate[i] = 0.f;
oscstate[i] = initialPhase;
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/common/dsp/oscillators/WavetableOscillator.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class WavetableOscillator : public AbstractBlitOscillator

lipol_ps li_hpf, li_DC, li_integratormult;
WavetableOscillator(SurgeStorage *storage, OscillatorStorage *oscdata, pdata *localcopy);
virtual void init(float pitch, bool is_display = false,
bool nonzero_init_drift = true) override;
virtual void init(float pitch, bool is_display = false, bool nonzero_init_drift = true,
float initialPhase = 0.f) override;
virtual void init_ctrltypes() override;
virtual void init_default_values() override;
virtual void process_block(float pitch, float drift = 0.f, bool stereo = false, bool FM = false,
Expand Down
7 changes: 5 additions & 2 deletions src/common/dsp/oscillators/WindowOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ template <bool is_init> void WindowOscillator::update_lagvals()
}
}

void WindowOscillator::init(float pitch, bool is_display, bool nonzero_init_drift)
void WindowOscillator::init(float pitch, bool is_display, bool nonzero_init_drift,
float initialPhase)
{
memset(&Window, 0, sizeof(Window));

Expand All @@ -89,7 +90,9 @@ void WindowOscillator::init(float pitch, bool is_display, bool nonzero_init_drif

if (oscdata->retrigger.val.b || is_display)
{
Window.Pos[0] = (storage->WindowWT.size + storage->WindowWT.size) << 16;
// Check this
Window.Pos[0] =
(storage->WindowWT.size + (int)((1 + initialPhase) * storage->WindowWT.size)) << 16;
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/common/dsp/oscillators/WindowOscillator.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class WindowOscillator : public Oscillator
};

WindowOscillator(SurgeStorage *storage, OscillatorStorage *oscdata, pdata *localcopy);
virtual void init(float pitch, bool is_display = false,
bool nonzero_init_drift = true) override;
virtual void init(float pitch, bool is_display = false, bool nonzero_init_drift = true,
float initialPhase = 0.f) override;
virtual void init_ctrltypes() override;
virtual void init_default_values() override;
virtual void process_block(float pitch, float drift = 0.f, bool stereo = false, bool FM = false,
Expand Down

0 comments on commit 1731cd5

Please sign in to comment.