From 1bcc36242582cd56f70f0725957a7c541c7cbb93 Mon Sep 17 00:00:00 2001 From: Tarkan Al-Kazily Date: Sat, 22 Apr 2023 21:54:41 -0700 Subject: [PATCH] Fix issue 118 - multiple definitions when compiling AdsrEnvelope This fixes the linker issue where multiple definitions are present for the specialized AdsrEnvelope functions, by moving these specialized functions into a new .cpp file. Because these are specialized for specific types, they shouldn't be included in multiple source files. Tested using the repro steps in issue #118. --- LibSource/AdsrEnvelope.cpp | 38 ++++++++++++++++++++++++++++++++++++++ LibSource/AdsrEnvelope.h | 37 ------------------------------------- 2 files changed, 38 insertions(+), 37 deletions(-) create mode 100644 LibSource/AdsrEnvelope.cpp diff --git a/LibSource/AdsrEnvelope.cpp b/LibSource/AdsrEnvelope.cpp new file mode 100644 index 00000000..0d2e6f3a --- /dev/null +++ b/LibSource/AdsrEnvelope.cpp @@ -0,0 +1,38 @@ +#include "AdsrEnvelope.h" + +template<> +float AdsrEnvelope::increment(float level, float amount){ + return level + amount; +} + +template<> +float AdsrEnvelope::decrement(float level, float amount){ + return level + amount; +} + +template<> +float AdsrEnvelope::increment(float level, float amount){ + return level + (1.01-level)*amount; // aim slightly higher to ensure we reach 1.0 +} + +template<> +float AdsrEnvelope::decrement(float level, float amount){ + return level + level * amount; +} + +template<> +float AdsrEnvelope::calculateIncrement(float startValue, float endValue, float time){ + return (endValue-startValue)/(sampleRate*time+1); +} + +template<> +float AdsrEnvelope::calculateIncrement(float startValue, float endValue, float time) { + // Ref: Christian Schoenebeck http://www.musicdsp.org/showone.php?id=189 + return (logf(endValue) - logf(startValue)) / (time*sampleRate+10); +} + +template<> +const float AdsrEnvelope::MINLEVEL = 0; + +template<> +const float AdsrEnvelope::MINLEVEL = 0.00001; // -100dB diff --git a/LibSource/AdsrEnvelope.h b/LibSource/AdsrEnvelope.h index 21e57f6e..d918e92f 100644 --- a/LibSource/AdsrEnvelope.h +++ b/LibSource/AdsrEnvelope.h @@ -168,43 +168,6 @@ class AdsrEnvelope : public Envelope { int gateTime; }; -template<> -float AdsrEnvelope::increment(float level, float amount){ - return level + amount; -} - -template<> -float AdsrEnvelope::decrement(float level, float amount){ - return level + amount; -} - -template<> -float AdsrEnvelope::increment(float level, float amount){ - return level + (1.01-level)*amount; // aim slightly higher to ensure we reach 1.0 -} - -template<> -float AdsrEnvelope::decrement(float level, float amount){ - return level + level * amount; -} - -template<> -float AdsrEnvelope::calculateIncrement(float startValue, float endValue, float time){ - return (endValue-startValue)/(sampleRate*time+1); -} - -template<> -float AdsrEnvelope::calculateIncrement(float startValue, float endValue, float time) { - // Ref: Christian Schoenebeck http://www.musicdsp.org/showone.php?id=189 - return (logf(endValue) - logf(startValue)) / (time*sampleRate+10); -} - -template<> -const float AdsrEnvelope::MINLEVEL = 0; - -template<> -const float AdsrEnvelope::MINLEVEL = 0.00001; // -100dB - typedef AdsrEnvelope LinearAdsrEnvelope; typedef AdsrEnvelope ExponentialAdsrEnvelope;