Skip to content

Commit

Permalink
Like this
Browse files Browse the repository at this point in the history
  • Loading branch information
baconpaul committed Jun 3, 2024
1 parent 4bc68ee commit 80187b3
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions include/sst/basic-blocks/modulators/DiscreteStagesEnvelope.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,30 @@ struct TwentyFiveSecondExp

template <int BLOCK_SIZE, typename RangeProvider> struct DiscreteStagesEnvelope
{
static constexpr float etminV()
{
if constexpr (RangeProvider::phaseStrategy == ENVTIME_2TWOX)
{
return RangeProvider::etMin;
}
else
{
return 0.f;
}
}
static constexpr float etmaxV()
{
if constexpr (RangeProvider::phaseStrategy == ENVTIME_2TWOX)
{
return RangeProvider::etMax;
}
else
{
return 1.f;
}
}
static constexpr float etMin{etminV()}, etMax{etmaxV()}, etScale{etMax - etMin};

static_assert((BLOCK_SIZE >= 8) & !(BLOCK_SIZE & (BLOCK_SIZE - 1)),
"Block size must be power of 2 8 or above.");
static constexpr float BLOCK_SIZE_INV{1.f / BLOCK_SIZE};
Expand Down Expand Up @@ -221,36 +245,21 @@ template <int BLOCK_SIZE, typename RangeProvider> struct DiscreteStagesEnvelope
if constexpr (RangeProvider::phaseStrategy == DPhaseStrategies::ENVTIME_EXP)
return r01;
else
{
static constexpr float etMin{RangeProvider::etMin}, etMax{RangeProvider::etMax},
etScale{etMax - etMin};

return r01 * etScale + etMin;
}
}
float rateTo01(float r)
{
if constexpr (RangeProvider::phaseStrategy == DPhaseStrategies::ENVTIME_EXP)
return r;
else
{
static constexpr float etMin{RangeProvider::etMin}, etMax{RangeProvider::etMax},
etScale{etMax - etMin};

return (r - etMin) / etScale;
}
}
float deltaTo01(float d)
{
if constexpr (RangeProvider::phaseStrategy == DPhaseStrategies::ENVTIME_EXP)
return d;
else
{
static constexpr float etMin{RangeProvider::etMin}, etMax{RangeProvider::etMax},
etScale{etMax - etMin};

return d / etScale;
}
}
};
} // namespace sst::basic_blocks::modulators
Expand Down

0 comments on commit 80187b3

Please sign in to comment.