Skip to content

Commit

Permalink
SIN backwards compatibility
Browse files Browse the repository at this point in the history
The changes to Sin to make the FM feedback and the like work
properly were too big a change for old patches. So add a mode
where FM is legacy or consistent mode. In legacy mode we exactly
match 1.6.1.1 and earlier; old patches load in legacy mode automatically.
New instances load in consistent mode. Streamed patches at version
11 (this version) and higher save properly.

Addresses surge-synthesizer#1035
  • Loading branch information
baconpaul committed Aug 19, 2019
1 parent 9f4a358 commit af4bbd3
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/common/Parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,12 @@ void Parameter::set_type(int ctrltype)
valtype = vt_int;
val_default.i = 0;
break;
case ct_sinefmlegacy:
val_min.i = 0;
val_max.i = 1;
valtype = vt_int;
val_default.i = 0;
break;
case ct_vocoder_bandcount:
val_min.i = 4;
val_max.i = 20;
Expand Down Expand Up @@ -996,6 +1002,12 @@ void Parameter::get_display(char* txt, bool external, float ef)
// FIXME - do better than this of course
sprintf(txt, "%d", i);
break;
case ct_sinefmlegacy:
if( i == 0 )
sprintf( txt, "Legacy (1.6.1.1 and earlier)");
else
sprintf( txt, "Consistent w. FM2/3" );
break;
case ct_vocoder_bandcount:
// FIXME - do better than this of course
sprintf(txt, "%d bands", i);
Expand Down
1 change: 1 addition & 0 deletions src/common/Parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ enum ctrltypes
ct_bool_fm,
ct_character,
ct_sineoscmode,
ct_sinefmlegacy,
ct_countedset_percent, // what % through a counted set are you
ct_vocoder_bandcount,
num_ctrltypes,
Expand Down
64 changes: 64 additions & 0 deletions src/common/dsp/Oscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void osc_sine::init(float pitch, bool is_display)

id_mode = oscdata->p[0].param_id_in_scene;
id_fb = oscdata->p[1].param_id_in_scene;
id_fmlegacy = oscdata->p[2].param_id_in_scene;
lastvalue = 0;
}

Expand All @@ -73,6 +74,12 @@ osc_sine::~osc_sine()

void osc_sine::process_block(float pitch, float drift, bool stereo, bool FM, float fmdepth)
{
if( localcopy[id_fmlegacy].i == 0 )
{
process_block_legacy(pitch, drift, stereo, FM, fmdepth );
return;
}

driftlfo = drift_noise(driftlfo2);
double omega = min(M_PI, (double)pitch_to_omega(pitch + drift * driftlfo));
// FMdepth.newValue(fmdepth);
Expand All @@ -98,6 +105,58 @@ void osc_sine::process_block(float pitch, float drift, bool stereo, bool FM, flo
}
}

void osc_sine::process_block_legacy(float pitch, float drift, bool stereo, bool FM, float fmdepth)
{
if (FM)
{
driftlfo = drift_noise(driftlfo2);
double omega = min(M_PI, (double)pitch_to_omega(pitch + drift * driftlfo));
FMdepth.newValue(fmdepth);

for (int k = 0; k < BLOCK_SIZE_OS; k++)
{
output[k] = valueFromSinAndCos(sin(phase), cos(phase));
phase += omega + master_osc[k] * FMdepth.v;
FMdepth.process();
}
}
else
{
driftlfo = drift_noise(driftlfo2);
sinus.set_rate(min(M_PI, (double)pitch_to_omega(pitch + drift * driftlfo)));

for (int k = 0; k < BLOCK_SIZE_OS; k++)
{
sinus.process();
float svalue = sinus.r;
float cvalue = sinus.i;

output[k] = valueFromSinAndCos(svalue, cvalue);

// const __m128 scale = _mm_set1_ps(0.000030517578125);

// HACK for testing sine(__m64)
// const __m64 rate = _mm_set1_pi16(0x0040);

/*m64phase = _mm_add_pi16(m64phase,rate);
__m64 a = sine(m64phase);
__m128 b = _mm_cvtpi16_ps(a);
_mm_store_ss(&output[k],_mm_mul_ss(b,scale));*/

// int
/*m64phase.m64_i32[0] = (m64phase.m64_i32[0] + 0x40);
int a = sine(m64phase.m64_i32[0]);
__m128 b = _mm_cvtsi32_ss(b,a);
_mm_store_ss(&output[k],_mm_mul_ss(b,scale));*/
}
//_mm_empty(); // HACK MMX
}
if (stereo)
{
memcpy(outputR, output, sizeof(float) * BLOCK_SIZE_OS);
}
}

float osc_sine::valueFromSinAndCos(float svalue, float cvalue)
{
int wfMode = localcopy[id_mode].i;
Expand Down Expand Up @@ -191,6 +250,7 @@ void osc_sine::handleStreamingMismatches(int streamingRevision, int currentSynth
if( streamingRevision <= 10 )
{
oscdata->p[1].val.f = 0;
oscdata->p[2].val.i = 0;
}
if( streamingRevision <= 9 )
{
Expand All @@ -205,12 +265,16 @@ void osc_sine::init_ctrltypes()

oscdata->p[1].set_name("Feedback");
oscdata->p[1].set_type(ct_percent);

oscdata->p[2].set_name("FM Behaviour");
oscdata->p[2].set_type(ct_sinefmlegacy);
}

void osc_sine::init_default_values()
{
oscdata->p[0].val.i = 0;
oscdata->p[1].val.f = 0;
oscdata->p[2].val.i = 1;
}
/* audio input osc */

Expand Down
4 changes: 3 additions & 1 deletion src/common/dsp/Oscillator.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class osc_sine : public Oscillator
virtual void init(float pitch, bool is_display = false) override;
virtual void process_block(
float pitch, float drift = 0.f, bool stereo = false, bool FM = false, float FMdepth = 0.f) override;
virtual void process_block_legacy(
float pitch, float drift = 0.f, bool stereo = false, bool FM = false, float FMdepth = 0.f);
virtual ~osc_sine();
virtual void init_ctrltypes() override;
virtual void init_default_values() override;
Expand All @@ -65,7 +67,7 @@ class osc_sine : public Oscillator
lag<double> FMdepth;
lag<double> FB;

int id_mode, id_fb;
int id_mode, id_fb, id_fmlegacy;
float lastvalue = 0;

float valueFromSinAndCos(float svalue, float cvalue);
Expand Down

0 comments on commit af4bbd3

Please sign in to comment.