From ace28e4ab09d93be2411814e065a61983f72ba11 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 20 Aug 2019 18:42:23 -0400 Subject: [PATCH] Make SchmittTrigger a template specialization instead of a separate class. --- include/dsp/digital.hpp | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/include/dsp/digital.hpp b/include/dsp/digital.hpp index 066c56ac..91a93f39 100644 --- a/include/dsp/digital.hpp +++ b/include/dsp/digital.hpp @@ -23,7 +23,27 @@ struct BooleanTrigger { /** Turns HIGH when value reaches 1.f, turns LOW when value reaches 0.f. */ -struct SchmittTrigger { +template +struct TSchmittTrigger { + T state; + TSchmittTrigger() { + reset(); + } + void reset() { + state = T::mask(); + } + T process(T in) { + T on = (in >= 1.f); + T off = (in <= 0.f); + T triggered = ~state & on; + state = on | (state & ~off); + return triggered; + } +}; + + +template <> +struct TSchmittTrigger { bool state = true; void reset() { @@ -60,24 +80,7 @@ struct SchmittTrigger { } }; - -template -struct TSchmittTrigger { - T state; - TSchmittTrigger() { - reset(); - } - void reset() { - state = T::mask(); - } - T process(T in) { - T on = (in >= 1.f); - T off = (in <= 0.f); - T triggered = ~state & on; - state = on | (state & ~off); - return triggered; - } -}; +typedef TSchmittTrigger<> SchmittTrigger; /** When triggered, holds a high value for a specified time before going low again */