Skip to content

Commit

Permalink
Absolute Pitch Shift
Browse files Browse the repository at this point in the history
Addressing surge-synthesizer#865, we want to be able to shift pitch by either a
relative (note space) frequency or an absolute (frequency space)
frequency amount.

This change is incomplete, and edit this when rebasing but here we do
the following

1. Make the pitch parameter allow absolute for pitch_semi_7b
2. Make sure the absolute property saves and restores
3. In SurgeVoice plumb through a note-setter function which
   will allow us to find the note equivalent to the absolute
   shift from a base

We do not in this change find that note equivalent. So absolute
right now is same as pitch = 0 in an oscillator.
  • Loading branch information
baconpaul committed Jul 13, 2019
1 parent 42078ac commit b039ee6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
6 changes: 5 additions & 1 deletion src/common/Parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ bool Parameter::can_be_absolute()
switch (ctrltype)
{
case ct_oscspread:
case ct_pitch_semi7bp:
return true;
}
return false;
Expand Down Expand Up @@ -798,7 +799,10 @@ void Parameter::get_display(char* txt, bool external, float ef)
sprintf(txt, "%.2f semitones", f);
break;
case ct_pitch_semi7bp:
sprintf(txt, "%.2f", get_extended(f));
if(absolute)
sprintf(txt, "%.1f Hz", 10 * get_extended(f));
else
sprintf(txt, "%.2f", get_extended(f));
break;
default:
sprintf(txt, "%.2f", f);
Expand Down
43 changes: 19 additions & 24 deletions src/common/dsp/SurgeVoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,9 @@ bool SurgeVoice::process_block(QuadFilterChainState& Q, int Qe)
if (osc3 || ring23 || ((osc1 || osc2) && (FMmode == fm_3to2to1)) ||
(osc1 && (FMmode == fm_2and3to1)))
{
osc[2]->process_block((scene->osc[2].keytrack.val.b ? state.pitch : ktrkroot) +
localcopy[scene->osc[2].pitch.param_id_in_scene].f *
(scene->osc[2].pitch.extend_range ? 12.f : 1.f) +
12 * scene->osc[2].octave.val.i,
osc[2]->process_block(noteShiftFromPitchParam( (scene->osc[2].keytrack.val.b ? state.pitch : ktrkroot) +
12 * scene->osc[2].octave.val.i,
2 ),
drift, is_wide);

if (osc3)
Expand All @@ -518,19 +517,18 @@ bool SurgeVoice::process_block(QuadFilterChainState& Q, int Qe)
{
if (FMmode == fm_3to2to1)
{
osc[1]->process_block((scene->osc[1].keytrack.val.b ? state.pitch : ktrkroot) +
localcopy[scene->osc[1].pitch.param_id_in_scene].f *
(scene->osc[1].pitch.extend_range ? 12.f : 1.f) +
12 * scene->osc[1].octave.val.i,
osc[1]->process_block(noteShiftFromPitchParam((scene->osc[1].keytrack.val.b ? state.pitch : ktrkroot) +
12 * scene->osc[1].octave.val.i,
1 ),

drift, is_wide, true,
db_to_linear(localcopy[scene->fm_depth.param_id_in_scene].f));
}
else
{
osc[1]->process_block((scene->osc[1].keytrack.val.b ? state.pitch : ktrkroot) +
localcopy[scene->osc[1].pitch.param_id_in_scene].f *
(scene->osc[1].pitch.extend_range ? 12.f : 1.f) +
12 * scene->osc[1].octave.val.i,
osc[1]->process_block(noteShiftFromPitchParam((scene->osc[1].keytrack.val.b ? state.pitch : ktrkroot) +
12 * scene->osc[1].octave.val.i,
1),
drift, is_wide);
}
if (osc2)
Expand All @@ -557,28 +555,25 @@ bool SurgeVoice::process_block(QuadFilterChainState& Q, int Qe)
if (FMmode == fm_2and3to1)
{
add_block(osc[1]->output, osc[2]->output, fmbuffer, BLOCK_SIZE_OS_QUAD);
osc[0]->process_block((scene->osc[0].keytrack.val.b ? state.pitch : ktrkroot) +
localcopy[scene->osc[0].pitch.param_id_in_scene].f *
(scene->osc[0].pitch.extend_range ? 12.f : 1.f) +
12 * scene->osc[0].octave.val.i,
osc[0]->process_block(noteShiftFromPitchParam((scene->osc[0].keytrack.val.b ? state.pitch : ktrkroot) +
12 * scene->osc[0].octave.val.i, 0 ),
drift, is_wide, true,
db_to_linear(localcopy[scene->fm_depth.param_id_in_scene].f));
}
else if (FMmode)
{
osc[0]->process_block((scene->osc[0].keytrack.val.b ? state.pitch : 60) +
localcopy[scene->osc[0].pitch.param_id_in_scene].f *
(scene->osc[0].pitch.extend_range ? 12.f : 1.f) +
12 * scene->osc[0].octave.val.i,
osc[0]->process_block(noteShiftFromPitchParam((scene->osc[0].keytrack.val.b ? state.pitch : 60) +
12 * scene->osc[0].octave.val.i,
0),

drift, is_wide, true,
db_to_linear(localcopy[scene->fm_depth.param_id_in_scene].f));
}
else
{
osc[0]->process_block((scene->osc[0].keytrack.val.b ? state.pitch : ktrkroot) +
localcopy[scene->osc[0].pitch.param_id_in_scene].f *
(scene->osc[0].pitch.extend_range ? 12.f : 1.f) +
12 * scene->osc[0].octave.val.i,
osc[0]->process_block(noteShiftFromPitchParam((scene->osc[0].keytrack.val.b ? state.pitch : ktrkroot) +
12 * scene->osc[0].octave.val.i,
0),
drift, is_wide);
}
if (osc1)
Expand Down
13 changes: 13 additions & 0 deletions src/common/dsp/SurgeVoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ class alignas(16) SurgeVoice
SurgeVoiceState state;
int age, age_release;

inline float noteShiftFromPitchParam( float pitch0 /* the key + octave */, int oscNum /* The osc for pitch diffs */)
{
if( scene->osc[oscNum].pitch.absolute )
{
return pitch0;
}
else
{
return pitch0 + localcopy[scene->osc[oscNum].pitch.param_id_in_scene].f *
(scene->osc[oscNum].pitch.extend_range ? 12.f : 1.f);
}
}

private:
template <bool first> void calc_ctrldata(QuadFilterChainState*, int);
void update_portamento();
Expand Down

0 comments on commit b039ee6

Please sign in to comment.