Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Using Sustain Pedal like Soft Pedal #1276

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/synth/fluid_voice.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ fluid_voice_init(fluid_voice_t *voice, fluid_sample_t *sample,
voice->mod_count = 0;
voice->start_time = start_time;
voice->has_noteoff = 0;
voice->note_off_sustain= 0;
UPDATE_RVOICE0(fluid_rvoice_reset);

/*
Expand Down Expand Up @@ -612,6 +613,24 @@ fluid_voice_calculate_runtime_synthesis_parameters(fluid_voice_t *voice)
int dest_gen_index = mod->dest;
fluid_gen_t *dest_gen = &voice->gen[dest_gen_index];
dest_gen->mod += modval;

// Issue #1276: Using Sustain Pedal like Soft Pedal
//
// If a modulator is in use that responds
// to the CC64 and intends to manipulate the release envelope,
// It's voice should change the volume envelope during the sustain fase.
// to allow the modulator to achieve the desired behavior
// it uses this modulator amount in new decay value and set attenuation,
// creating smooth release.
//

if(mod->src1 == SUSTAIN_SWITCH &&
(mod->flags1 & FLUID_MOD_CC) &&
mod->dest == GEN_VOLENVRELEASE)
{
voice->note_off_sustain = mod->amount;
}

/* fluid_dump_modulator(mod); */
}

Expand Down Expand Up @@ -1366,7 +1385,14 @@ fluid_voice_noteoff(fluid_voice_t *voice)
/* Or sustain a note under Sustain pedal */
else if(fluid_channel_sustained(channel))
{
voice->status = FLUID_VOICE_SUSTAINED;
voice->status = FLUID_VOICE_SUSTAINED;
// Here it changes the envelope to simulate ignore_sustain
if(voice->note_off_sustain)
{
fluid_voice_gen_set(voice, GEN_VOLENVDECAY, voice->note_off_sustain);
fluid_voice_gen_set(voice, GEN_VOLENVSUSTAIN, 960);
fluid_voice_update_param(voice, GEN_VOLENVSUSTAIN);
}
}
/* Or force the voice to release stage */
else
Expand Down
1 change: 1 addition & 0 deletions src/synth/fluid_voice.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ struct _fluid_voice_t
/* rvoice control */
fluid_rvoice_t *rvoice;
fluid_rvoice_t *overflow_rvoice; /* Used temporarily and only in overflow situations */
double note_off_sustain; /* for create smooth sustain #1276 */
char can_access_rvoice; /* False if rvoice is being rendered in separate thread */
char can_access_overflow_rvoice; /* False if overflow_rvoice is being rendered in separate thread */
char has_noteoff; /* Flag set when noteoff has been sent */
Expand Down