Sound Byte Libs 0.5.1-121-g3358a44
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
block_guard.hpp
Go to the documentation of this file.
1// sbl/dsp/primitives/block_guard.hpp — Did a non-finite sample get into this block?
2//
3// A widget with feedback cannot let a NaN or an Inf recirculate. Summing
4// every sample the block produced (and any state that feeds back) and
5// testing the sum once catches a burst anywhere in the block — NaN and Inf
6// both survive a sum — for the cost of an add per sample.
7
8#ifndef SBL_DSP_PRIMITIVES_BLOCK_GUARD_HPP_
9#define SBL_DSP_PRIMITIVES_BLOCK_GUARD_HPP_
10
11#include <cmath>
12
13namespace sbl::dsp::primitives {
14
16public:
17 /// @note All public methods are ISR-safe — bounded computation, no I/O.
18
19 void begin() { sum_ = 0.0f; }
20 void add(float v) { sum_ += v; }
21
22 /// True if anything added since begin() was non-finite.
23 bool tripped() const { return !std::isfinite(sum_); }
24
25private:
26 float sum_ = 0.0f;
27};
28
29} // namespace sbl::dsp::primitives
30
31#endif // SBL_DSP_PRIMITIVES_BLOCK_GUARD_HPP_
bool tripped() const
True if anything added since begin() was non-finite.
Stateful, single-concern building blocks.