Skip to content

Commit

Permalink
Non-clicky fade-out in voice terminate mode
Browse files Browse the repository at this point in the history
  • Loading branch information
baconpaul committed Dec 23, 2024
1 parent 2240f89 commit 0f943db
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/synth/synth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ void Synth::process(const clap_output_events_t *outq)
mech::accumulate_from_to<blockSize>(cvoice->output[1], lOutput[1]);

if (cvoice->out.env.stage >
sst::basic_blocks::modulators::DAHDSREnvelope<SRProvider, blockSize>::s_release)
sst::basic_blocks::modulators::DAHDSREnvelope<SRProvider,
blockSize>::s_release ||
cvoice->fadeBlocks == 0)
{
responder.doVoiceEndCallback(cvoice);
cvoice = removeFromVoiceList(cvoice);
Expand Down Expand Up @@ -134,6 +136,7 @@ Voice *Synth::removeFromVoiceList(Voice *cvoice)
}
auto nv = cvoice->next;
cvoice->used = false;
cvoice->fadeBlocks = -1;
cvoice->next = nullptr;
cvoice->prior = nullptr;
return nv;
Expand Down
3 changes: 1 addition & 2 deletions src/synth/synth.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ struct Synth
void endVoiceCreationTransaction(uint16_t, uint16_t, uint16_t, int32_t, float) {}
void terminateVoice(Voice *voice)
{
voice->used = false;
voice->gated = false;
synth.removeFromVoiceList(voice);
voice->fadeBlocks = Voice::fadeOverBlocks;
}
int32_t initializeMultipleVoices(
int32_t ct,
Expand Down
12 changes: 12 additions & 0 deletions src/synth/voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ void Voice::renderBlock()
}

out.renderBlock(gated, velocity);

if (fadeBlocks > 0)
{
for (int i = 0; i < blockSize; ++i)
{
auto fp = fadeBlocks * blockSize - i;
auto at = fp * dFade;
out.output[0][i] *= at;
out.output[1][i] *= at;
}
fadeBlocks--;
}
}

static_assert(numOps == 6, "Rebuild this table if not");
Expand Down
3 changes: 3 additions & 0 deletions src/synth/voice.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ struct Voice
void retriggerAllEnvelopes();

std::array<MixerNode, numOps> mixerNode;
static constexpr int32_t fadeOverBlocks{32};
float dFade{1.0 / (blockSize * fadeOverBlocks)};
int32_t fadeBlocks{-1};

OutputNode out;

Expand Down

0 comments on commit 0f943db

Please sign in to comment.