Browse Source

Make SchmittTrigger a template specialization instead of a separate class.

tags/v1.1.4
Andrew Belt 5 years ago
parent
commit
ace28e4ab0
1 changed files with 22 additions and 19 deletions
  1. +22
    -19
      include/dsp/digital.hpp

+ 22
- 19
include/dsp/digital.hpp View File

@@ -23,7 +23,27 @@ struct BooleanTrigger {


/** Turns HIGH when value reaches 1.f, turns LOW when value reaches 0.f. */
struct SchmittTrigger {
template <typename T = float>
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<float> {
bool state = true;

void reset() {
@@ -60,24 +80,7 @@ struct SchmittTrigger {
}
};


template <typename T>
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 */


Loading…
Cancel
Save