Browse Source

Add BooleanTrigger

tags/v1.0.0
Andrew Belt 6 years ago
parent
commit
21e097c8fc
1 changed files with 17 additions and 1 deletions
  1. +17
    -1
      include/dsp/digital.hpp

+ 17
- 1
include/dsp/digital.hpp View File

@@ -8,7 +8,6 @@ namespace rack {


/** Turns HIGH when value reaches 1.f, turns LOW when value reaches 0.f. */ /** Turns HIGH when value reaches 1.f, turns LOW when value reaches 0.f. */
struct SchmittTrigger { struct SchmittTrigger {
// UNKNOWN is used to represent a stable state when the previous state is not yet set
enum State { enum State {
UNKNOWN, UNKNOWN,
LOW, LOW,
@@ -58,6 +57,23 @@ struct SchmittTrigger {
}; };




struct BooleanTrigger {
bool lastState;

BooleanTrigger() {
reset();
}
void reset() {
lastState = true;
}
bool process(bool state) {
bool triggered = (state && !lastState);
lastState = state;
return triggered;
}
};


/** When triggered, holds a high value for a specified time before going low again */ /** When triggered, holds a high value for a specified time before going low again */
struct PulseGenerator { struct PulseGenerator {
float time; float time;


Loading…
Cancel
Save