Skip to content

Commit

Permalink
Handle rate = 0 in SC enveloep better (#141)
Browse files Browse the repository at this point in the history
With the new exp shape, rate = 0 means really 0. This
means we get infs in the dPhase (which is bad) if not careful
but also means we need to skip phases more consicously, so do that
here.
  • Loading branch information
baconpaul authored Sep 29, 2024
1 parent 011c7fd commit e911cc2
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions include/sst/basic-blocks/modulators/AHDSRShapedSC.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ struct AHDSRShapedSC : DiscreteStagesEnvelope<BLOCK_SIZE, RangeProvider>

if constexpr (RangeProvider::phaseStrategy == ENVTIME_EXP)
{
if (x == 0.0)
return 1.0;

static thread_local tables::TwoToTheXProvider twoToX;
if (!twoToX.isInit)
twoToX.init();
Expand All @@ -126,9 +129,19 @@ struct AHDSRShapedSC : DiscreteStagesEnvelope<BLOCK_SIZE, RangeProvider>
static float lastX = -23;
if (x != lastX)
{
std::cout << "Checkint at " << x << " " << checkV << " " << res << std::endl;
std::cout << "Checkint at x=" << x << "\n calc=" << checkV << " lut=" << res
<< "\n time=" << timeInSeconds << "\n sr=" << srProvider->sampleRate
<< " sri=" << srProvider->sampleRateInv
<< " 1/sri=" << 1.0 / srProvider->sampleRateInv << " bs=" << BLOCK_SIZE
<< "\n dPhaseLUT=" << BLOCK_SIZE * srProvider->sampleRateInv * res
<< "\n dPhaseCAL=" << BLOCK_SIZE * srProvider->sampleRateInv * checkV
<< "\n 1/dPhaseLUT="
<< 1 / (BLOCK_SIZE * srProvider->sampleRateInv * res)
<< "\n 1/dPhaseCAL="
<< 1 / (BLOCK_SIZE * srProvider->sampleRateInv * checkV) << std::endl;
lastX = x;
}

#endif

auto dPhase = BLOCK_SIZE * srProvider->sampleRateInv * res;
Expand Down Expand Up @@ -182,9 +195,33 @@ struct AHDSRShapedSC : DiscreteStagesEnvelope<BLOCK_SIZE, RangeProvider>

if (!gateActive && stage < base_t::s_release)
{
stage = base_t::s_release;
releaseStartValue = this->outputCache[0];
if (r == 0)
{
stage = base_t::s_complete;
}
else
{
stage = base_t::s_release;
releaseStartValue = this->outputCache[0];
phase = 0;
}
}

// Accelerate traversal through the state machien for the 0 case
if (a == 0.f && stage == base_t::s_attack)
{
phase = 0;
stage = base_t::s_hold;
}
if (h == 0.f && stage == base_t::s_hold)
{
phase = 0.f;
stage = base_t::s_decay;
}
if (d == 0.f && stage == base_t::s_decay)
{
phase = 0.f;
stage = base_t::s_sustain;
}

/*
Expand Down

0 comments on commit e911cc2

Please sign in to comment.