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
13
namespace
sbl::dsp::primitives
{
14
15
class
BlockGuard
{
16
public
:
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
25
private
:
26
float
sum_ = 0.0f;
27
};
28
29
}
// namespace sbl::dsp::primitives
30
31
#endif
// SBL_DSP_PRIMITIVES_BLOCK_GUARD_HPP_
sbl::dsp::primitives::BlockGuard
Definition
block_guard.hpp:15
sbl::dsp::primitives::BlockGuard::begin
void begin()
Definition
block_guard.hpp:19
sbl::dsp::primitives::BlockGuard::add
void add(float v)
Definition
block_guard.hpp:20
sbl::dsp::primitives::BlockGuard::tripped
bool tripped() const
True if anything added since begin() was non-finite.
Definition
block_guard.hpp:23
sbl::dsp::primitives
Stateful, single-concern building blocks.
Definition
allpass_filter.hpp:23
src
sbl
dsp
primitives
block_guard.hpp
Generated by
1.9.8