From 80187b3f06fca78dd43bd9c8c82515eba22a121f Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Mon, 3 Jun 2024 11:58:30 -0400 Subject: [PATCH] Like this --- .../modulators/DiscreteStagesEnvelope.h | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/include/sst/basic-blocks/modulators/DiscreteStagesEnvelope.h b/include/sst/basic-blocks/modulators/DiscreteStagesEnvelope.h index 02da5aa..aaf2aae 100644 --- a/include/sst/basic-blocks/modulators/DiscreteStagesEnvelope.h +++ b/include/sst/basic-blocks/modulators/DiscreteStagesEnvelope.h @@ -70,6 +70,30 @@ struct TwentyFiveSecondExp template 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}; @@ -221,36 +245,21 @@ template 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