#include <envelopes.h>
Peak-hold filter.
The size is variable, and can be changed instantly with .set(), or by using .push()/.pop() in an unbalanced way.
This has complexity O(1) every sample when the length remains constant (balanced .push()/.pop(), or using filter(v)), and amortised O(1) complexity otherwise. To avoid allocations while running, it pre-allocates a vector (not a std::deque) which determines the maximum length.
Methods | |
| PeakHold (int maxLength) | |
| int | size () |
| void | resize (int maxLength) |
| void | reset (Sample fill=lowest) |
| void | set (int newSize, bool preserveCurrentPeak=false) |
| Sets the size immediately. | |
| void | push (Sample v) |
| void | pop () |
| Sample | read () |
| Sample | operator() (Sample v) |
|
inline |
Sets the size immediately.
Must be 0 <= newSize <= maxLength (see constructor and .resize()).
Shrinking doesn't destroy information, and if you expand again (with preserveCurrentPeak=false), you will get the same output as before shrinking. Expanding when preserveCurrentPeak is enabled is destructive, re-writing its history such that the current output value is unchanged.