- LFO: added Sync modes Frequency, Phase and Frequency + Phase
- added GUI Parameter MIDISYNC_MODE and MIDISYNC_BERATDIV - wired MIDISYNC params down to global LFO git-svn-id: http://moon:8086/svn/software/trunk/projects/JaySynth@726 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+55
-19
@@ -71,15 +71,17 @@ synth_float_t phase_det(synth_float_t lo, synth_float_t ref)
|
||||
return perr;
|
||||
}
|
||||
|
||||
void Sync_init(sync_t *pObj)
|
||||
void Sync_init(sync_t *pObj, lfo_t *pLfo)
|
||||
{
|
||||
pObj->phase = 0;
|
||||
pObj->phase_int = 0;
|
||||
pObj->phase_ref = 0;
|
||||
pObj->omega = 0.0;
|
||||
pObj->accu = 0;
|
||||
pObj->klead = 1.0;
|
||||
pObj->klag = 0.04/200;
|
||||
pObj->phase_update = 0;
|
||||
pObj->pLfo = pLfo;
|
||||
}
|
||||
|
||||
void Sync_phase_update(sync_t *pObj, synth_float_t phase_ref)
|
||||
@@ -90,8 +92,35 @@ void Sync_phase_update(sync_t *pObj, synth_float_t phase_ref)
|
||||
|
||||
sync_result_t Sync_process(sync_t *pObj, synth_float_t omega_base)
|
||||
{
|
||||
int sync_mode = (int)pObj->pLfo->param[LFO_PARAM2_MIDISYNC_MODE];
|
||||
synth_float_t phase_ref = pObj->phase_ref;
|
||||
|
||||
sync_result_t result;
|
||||
result.phase = Sync_mod(pObj->phase + pObj->omega, 1.0);
|
||||
pObj->phase_int = Sync_mod(pObj->phase_int + pObj->omega, 1.0);
|
||||
|
||||
switch (sync_mode)
|
||||
{
|
||||
case LFO_SYNC_MODE_OFF:
|
||||
pObj->phase = Sync_mod(pObj->phase + omega_base, 1.0);
|
||||
break;
|
||||
|
||||
case LFO_SYNC_MODE_F:
|
||||
pObj->phase = Sync_mod(pObj->phase + pObj->omega, 1.0);
|
||||
break;
|
||||
|
||||
case LFO_SYNC_MODE_F_P:
|
||||
pObj->phase = pObj->phase_int;
|
||||
break;
|
||||
|
||||
case LFO_SYNC_MODE_P:
|
||||
pObj->phase = Sync_mod(pObj->phase + omega_base, 1.0);
|
||||
if (pObj->phase_update && phase_ref == 0)
|
||||
{
|
||||
pObj->phase = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
result.phase = Sync_mod(pObj->phase, 1.0);
|
||||
result.is_cycle_start = (pObj->phase > result.phase);
|
||||
pObj->phase = result.phase;
|
||||
|
||||
@@ -99,8 +128,8 @@ sync_result_t Sync_process(sync_t *pObj, synth_float_t omega_base)
|
||||
if (pObj->phase_update)
|
||||
{
|
||||
pObj->phase_update = 0;
|
||||
perr = phase_det(pObj->phase, pObj->phase_ref);
|
||||
SynthDebug("phase_ref=%f, phase_lo=%f, perr=%f\n", pObj->phase_ref, pObj->phase, perr);
|
||||
perr = phase_det(pObj->phase_int, phase_ref);
|
||||
SynthDebug("phase_ref=%f, phase_lo=%f, perr=%f\n", phase_ref, pObj->phase_int, perr);
|
||||
// SynthDebug("syncOnFreqUpdate(): BPM=%f\n", omega*pObj->fs*60);
|
||||
|
||||
}
|
||||
@@ -136,7 +165,7 @@ void LFO_Init(lfo_t *pObj, synth_float_t fs)
|
||||
|
||||
Noise_Init(&pObj->noise, 1+(UINT32)clock() * (UINT32)clock());
|
||||
|
||||
Sync_init(&pObj->sync);
|
||||
Sync_init(&pObj->sync, pObj);
|
||||
}
|
||||
|
||||
void LFO_Free(lfo_t *pObj)
|
||||
@@ -170,6 +199,7 @@ void LFO_SetFS(lfo_t *pObj, synth_float_t fs)
|
||||
|
||||
void LFO_Reset(lfo_t *pObj, synth_float_t initial_phase)
|
||||
{
|
||||
pObj->sync.phase = initial_phase;
|
||||
pObj->smooth_out = 0;
|
||||
pObj->delay_x = 0;
|
||||
pObj->attack_y = 0;
|
||||
@@ -180,43 +210,49 @@ void LFO_Reset(lfo_t *pObj, synth_float_t initial_phase)
|
||||
|
||||
void LFO_sync(lfo_t *pObj, synth_float_t phase_ref)
|
||||
{
|
||||
synth_float_t note_1_x = pObj->param[LFO_PARAM2_MIDISYNC_BEATDIV];
|
||||
phase_ref = Sync_mod(note_1_x*phase_ref, 1.0);
|
||||
Sync_phase_update(&pObj->sync, phase_ref);
|
||||
}
|
||||
|
||||
void LFO_Param2Set(lfo_t *pObj, UINT32 type, synth_float_t value)
|
||||
{
|
||||
int param_changed = 0;
|
||||
if (pObj->param[type] != value)
|
||||
{
|
||||
pObj->param[type] = value;
|
||||
param_changed = 1;
|
||||
}
|
||||
switch(type)
|
||||
{
|
||||
case LFO_PARAM2_WAVEFORM:
|
||||
if (pObj->param[type] == (UINT32)value)
|
||||
break;
|
||||
pObj->param[type] = (UINT32)value;
|
||||
pObj->freq_update_req = 1;
|
||||
pObj->freq_update_req = param_changed;
|
||||
break;
|
||||
|
||||
case LFO_PARAM2_FREQ:
|
||||
pObj->param[type] = value;
|
||||
pObj->freq_update_req = 1;
|
||||
pObj->freq_update_req = param_changed;
|
||||
break;
|
||||
|
||||
case LFO_PARAM2_SMOOTH:
|
||||
pObj->param[type] = value;
|
||||
LFO_smmother_update(pObj);
|
||||
if (param_changed)
|
||||
{
|
||||
LFO_smmother_update(pObj);
|
||||
}
|
||||
break;
|
||||
|
||||
case LFO_PARAM2_DELAY:
|
||||
pObj->param[type] = value;
|
||||
pObj->freq_update_req = 1;
|
||||
pObj->freq_update_req = param_changed;
|
||||
break;
|
||||
|
||||
case LFO_PARAM2_ATTACK:
|
||||
pObj->param[type] = value;
|
||||
pObj->freq_update_req = 1;
|
||||
pObj->freq_update_req = param_changed;
|
||||
break;
|
||||
|
||||
case LFO_PARAM2_SYMMETRY:
|
||||
pObj->param[type] = value;
|
||||
pObj->offset = 0.5 *value;
|
||||
if (param_changed)
|
||||
{
|
||||
pObj->offset = 0.5 *value;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
+14
-1
@@ -29,6 +29,15 @@ enum
|
||||
LFO_NUM_WAVEFORMS
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
LFO_SYNC_MODE_OFF,
|
||||
LFO_SYNC_MODE_F,
|
||||
LFO_SYNC_MODE_P,
|
||||
LFO_SYNC_MODE_F_P,
|
||||
LFO_NUM_SYNC_MODES
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
LFO_PARAM2_WAVEFORM,
|
||||
@@ -37,12 +46,15 @@ enum
|
||||
LFO_PARAM2_DELAY,
|
||||
LFO_PARAM2_ATTACK,
|
||||
LFO_PARAM2_SYMMETRY,
|
||||
LFO_PARAM2_MIDISYNC_MODE,
|
||||
LFO_PARAM2_MIDISYNC_BEATDIV,
|
||||
LFO_NUM_PARAMS
|
||||
};
|
||||
|
||||
typedef struct _ssync_t
|
||||
{
|
||||
synth_float_t phase;
|
||||
synth_float_t phase_int;
|
||||
synth_float_t phase_ref;
|
||||
synth_float_t omega;
|
||||
|
||||
@@ -51,6 +63,7 @@ typedef struct _ssync_t
|
||||
synth_float_t accu;
|
||||
|
||||
int phase_update;
|
||||
struct _slfo_t *pLfo;
|
||||
|
||||
} sync_t;
|
||||
|
||||
@@ -68,7 +81,7 @@ extern "C" {
|
||||
// --------------------------------------------------------------
|
||||
// Exported functions
|
||||
// --------------------------------------------------------------
|
||||
void Sync_init(sync_t *pObj);
|
||||
void Sync_init(sync_t *pObj, struct _slfo_t *pLfo);
|
||||
void Sync_phase_update(sync_t *pObj, synth_float_t phase_ref);
|
||||
sync_result_t Sync_process(sync_t *pObj, synth_float_t omega_base);
|
||||
synth_float_t Sync_mod(synth_float_t x, synth_float_t y);
|
||||
|
||||
@@ -672,7 +672,47 @@ static const param_info_t param_info[] =
|
||||
SYNTH_PARAM_LFO_3_SYMMETRY,
|
||||
"LFO 4 symmetry",
|
||||
/*Base*/1.0, /*kexp*/1.0, /*scenter*/0.5, /*min*/-100, /*pcenter*/0, /*max*/100, /*interval*/0.1
|
||||
}
|
||||
},
|
||||
{
|
||||
SYNTH_PARAM_LFO_0_MIDISYNC_MODE,
|
||||
"LFO 1 Midi Sync Mode",
|
||||
/*Base*/1.0, /*kexp*/1.0, /*scenter*/0.0, /*min*/0, /*pcenter*/-1, /*max*/LFO_NUM_SYNC_MODES-1, /*interval*/1
|
||||
},
|
||||
{
|
||||
SYNTH_PARAM_LFO_1_MIDISYNC_MODE,
|
||||
"LFO 2 Midi Sync Mode",
|
||||
/*Base*/1.0, /*kexp*/1.0, /*scenter*/0.0, /*min*/0, /*pcenter*/-1, /*max*/LFO_NUM_SYNC_MODES-1, /*interval*/1
|
||||
},
|
||||
{
|
||||
SYNTH_PARAM_LFO_2_MIDISYNC_MODE,
|
||||
"LFO 3 Midi Sync Mode",
|
||||
/*Base*/1.0, /*kexp*/1.0, /*scenter*/0.0, /*min*/0, /*pcenter*/-1, /*max*/LFO_NUM_SYNC_MODES-1, /*interval*/1
|
||||
},
|
||||
{
|
||||
SYNTH_PARAM_LFO_3_MIDISYNC_MODE,
|
||||
"LFO 4 Midi Sync Mode",
|
||||
/*Base*/1.0, /*kexp*/1.0, /*scenter*/0.0, /*min*/0, /*pcenter*/-1, /*max*/LFO_NUM_SYNC_MODES-1, /*interval*/1
|
||||
},
|
||||
{
|
||||
SYNTH_PARAM_LFO_0_MIDISYNC_BEATDIV,
|
||||
"LFO 1 Midi Sync Beat Divisor",
|
||||
/*Base*/1.0, /*kexp*/1.0, /*scenter*/0.0, /*min*/1, /*pcenter*/-1, /*max*/32, /*interval*/1
|
||||
},
|
||||
{
|
||||
SYNTH_PARAM_LFO_1_MIDISYNC_BEATDIV,
|
||||
"LFO 2 Midi Sync Beat Divisor",
|
||||
/*Base*/1.0, /*kexp*/1.0, /*scenter*/0.0, /*min*/1, /*pcenter*/-1, /*max*/32, /*interval*/1
|
||||
},
|
||||
{
|
||||
SYNTH_PARAM_LFO_2_MIDISYNC_BEATDIV,
|
||||
"LFO 3 Midi Sync Beat Divisor",
|
||||
/*Base*/1.0, /*kexp*/1.0, /*scenter*/0.0, /*min*/1, /*pcenter*/-1, /*max*/32, /*interval*/1
|
||||
},
|
||||
{
|
||||
SYNTH_PARAM_LFO_3_MIDISYNC_BEATDIV,
|
||||
"LFO 4 Midi Sync Beat Divisor",
|
||||
/*Base*/1.0, /*kexp*/1.0, /*scenter*/0.0, /*min*/1, /*pcenter*/-1, /*max*/32, /*interval*/1
|
||||
},
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
@@ -139,6 +139,14 @@ enum
|
||||
SYNTH_PARAM_LFO_1_SYMMETRY,
|
||||
SYNTH_PARAM_LFO_2_SYMMETRY,
|
||||
SYNTH_PARAM_LFO_3_SYMMETRY,
|
||||
SYNTH_PARAM_LFO_0_MIDISYNC_MODE,
|
||||
SYNTH_PARAM_LFO_1_MIDISYNC_MODE,
|
||||
SYNTH_PARAM_LFO_2_MIDISYNC_MODE,
|
||||
SYNTH_PARAM_LFO_3_MIDISYNC_MODE,
|
||||
SYNTH_PARAM_LFO_0_MIDISYNC_BEATDIV,
|
||||
SYNTH_PARAM_LFO_1_MIDISYNC_BEATDIV,
|
||||
SYNTH_PARAM_LFO_2_MIDISYNC_BEATDIV,
|
||||
SYNTH_PARAM_LFO_3_MIDISYNC_BEATDIV,
|
||||
SYNTH_NUM_PARAMS
|
||||
};
|
||||
|
||||
|
||||
@@ -651,6 +651,31 @@ void VoiceParam2Set(voice_t *pObj, UINT32 type, synth_float_t value)
|
||||
}
|
||||
break;
|
||||
|
||||
case VOICE_PARAM_LFO_0_MIDISYNC_MODE:
|
||||
case VOICE_PARAM_LFO_1_MIDISYNC_MODE:
|
||||
case VOICE_PARAM_LFO_2_MIDISYNC_MODE:
|
||||
case VOICE_PARAM_LFO_3_MIDISYNC_MODE:
|
||||
LFO_Param2Set(&pObj->lfo[type-VOICE_PARAM_LFO_0_MIDISYNC_MODE], LFO_PARAM2_MIDISYNC_MODE, (int)pObj->param[type]);
|
||||
|
||||
// First voice sets params for global LFOs
|
||||
if (pObj->id == 0)
|
||||
{
|
||||
LFO_Param2Set(&pObj->pCom->glfo[type-VOICE_PARAM_LFO_0_MIDISYNC_MODE], LFO_PARAM2_MIDISYNC_MODE, pObj->param[type]);
|
||||
}
|
||||
break;
|
||||
|
||||
case VOICE_PARAM_LFO_0_MIDISYNC_BEATDIV:
|
||||
case VOICE_PARAM_LFO_1_MIDISYNC_BEATDIV:
|
||||
case VOICE_PARAM_LFO_2_MIDISYNC_BEATDIV:
|
||||
case VOICE_PARAM_LFO_3_MIDISYNC_BEATDIV:
|
||||
LFO_Param2Set(&pObj->lfo[type-VOICE_PARAM_LFO_0_MIDISYNC_BEATDIV], LFO_PARAM2_MIDISYNC_BEATDIV, (int)pObj->param[type]);
|
||||
|
||||
// First voice sets params for global LFOs
|
||||
if (pObj->id == 0)
|
||||
{
|
||||
LFO_Param2Set(&pObj->pCom->glfo[type-VOICE_PARAM_LFO_0_MIDISYNC_BEATDIV], LFO_PARAM2_MIDISYNC_BEATDIV, pObj->param[type]);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -142,6 +142,14 @@ enum
|
||||
VOICE_PARAM_LFO_1_SYMMETRY,
|
||||
VOICE_PARAM_LFO_2_SYMMETRY,
|
||||
VOICE_PARAM_LFO_3_SYMMETRY,
|
||||
VOICE_PARAM_LFO_0_MIDISYNC_MODE,
|
||||
VOICE_PARAM_LFO_1_MIDISYNC_MODE,
|
||||
VOICE_PARAM_LFO_2_MIDISYNC_MODE,
|
||||
VOICE_PARAM_LFO_3_MIDISYNC_MODE,
|
||||
VOICE_PARAM_LFO_0_MIDISYNC_BEATDIV,
|
||||
VOICE_PARAM_LFO_1_MIDISYNC_BEATDIV,
|
||||
VOICE_PARAM_LFO_2_MIDISYNC_BEATDIV,
|
||||
VOICE_PARAM_LFO_3_MIDISYNC_BEATDIV,
|
||||
VOICE_NUM_PARAMS
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user