Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
gate_logic.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <pulp/signal/detail/modular_sequencing_common.hpp>
5
6namespace pulp::signal {
7
8// ── Gate combinators ──────────────────────────────────────────────────────
9
20
41template <typename SampleType = float>
43public:
48 static constexpr double kLevelThreshold = kTriggerHighThreshold;
49
50 void prepare(double) {}
51
52 void set_op(GateOp op) { op_ = op; }
53 GateOp op() const { return op_; }
54
56 void reset() {}
57
58 static constexpr int latency_samples() { return 0; }
59
60 bool process(bool a, bool b) const {
61 switch (op_) {
62 case GateOp::logic_and: return a && b;
63 case GateOp::logic_or: return a || b;
64 case GateOp::logic_xor: return a != b;
65 case GateOp::logic_nand: return !(a && b);
66 case GateOp::logic_nor: return !(a || b);
67 case GateOp::logic_xnor: return a == b;
68 }
69 return false;
70 }
71
75 bool process(const bool* gates, int count) const {
76 bool all = true;
77 bool any = false;
78 bool parity = false;
79 for (int i = 0; i < count; ++i) {
80 all = all && gates[i];
81 any = any || gates[i];
82 parity = parity != gates[i];
83 }
84 switch (op_) {
85 case GateOp::logic_and: return all;
86 case GateOp::logic_or: return any;
87 case GateOp::logic_xor: return parity;
88 case GateOp::logic_nand: return !all;
89 case GateOp::logic_nor: return !any;
90 case GateOp::logic_xnor: return !parity;
91 }
92 return false;
93 }
94
96 SampleType process_levels(SampleType a, SampleType b) const {
97 const bool ha = static_cast<double>(a) >= kLevelThreshold;
98 const bool hb = static_cast<double>(b) >= kLevelThreshold;
99 return process(ha, hb) ? SampleType{1} : SampleType{0};
100 }
101
102private:
104};
105
108
109} // namespace pulp::signal
Combinational logic on gate signals.
Definition gate_logic.hpp:42
void prepare(double)
Definition gate_logic.hpp:50
GateOp op() const
Definition gate_logic.hpp:53
void set_op(GateOp op)
Definition gate_logic.hpp:52
bool process(const bool *gates, int count) const
N-input form.
Definition gate_logic.hpp:75
static constexpr int latency_samples()
Definition gate_logic.hpp:58
bool process(bool a, bool b) const
Definition gate_logic.hpp:60
static constexpr double kLevelThreshold
Definition gate_logic.hpp:48
SampleType process_levels(SampleType a, SampleType b) const
Level-domain form: thresholds both inputs and returns 0 or 1.
Definition gate_logic.hpp:96
void apply_reset_edge()
Definition gate_logic.hpp:55
void reset()
Definition gate_logic.hpp:56
Definition additive_bank.hpp:218
GateOp
Boolean operation performed by a GateLogicT.
Definition gate_logic.hpp:12
@ logic_or
Definition gate_logic.hpp:14
@ logic_xor
Definition gate_logic.hpp:15
@ logic_xnor
Definition gate_logic.hpp:18
@ logic_nor
Definition gate_logic.hpp:17
@ logic_and
Definition gate_logic.hpp:13
@ logic_nand
Definition gate_logic.hpp:16
constexpr double kTriggerHighThreshold
Definition trigger.hpp:31
@ all
Definition multi_channel_meter.hpp:51
GateLogicT< double > GateLogic64
Definition gate_logic.hpp:107
@ a
Definition formant_filter_bank.hpp:20
@ i
Definition formant_filter_bank.hpp:20
GateLogicT< float > GateLogic
Definition gate_logic.hpp:106