Signalsmith Audio's DSP Library  1.2.1
Useful C++ classes/templates for audio effects
signalsmith::envelopes::PeakHold< Sample > Class Template Reference

#include <envelopes.h>

Detailed Description

template<typename Sample>
class signalsmith::envelopes::PeakHold< Sample >

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.


 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. More...
void push (Sample v)
void pop ()
Sample read ()
Sample operator() (Sample v)

Method Details

◆ set()

template<typename Sample >
void signalsmith::envelopes::PeakHold< Sample >::set ( int  newSize,
bool  preserveCurrentPeak = false 

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.