DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
dspark::EnvelopeFollower< T, MaxChannels > Class Template Reference

Attack/release envelope detector (Peak or RMS). More...

#include <EnvelopeFollower.h>

Public Types

enum class  Mode { Peak , RMS }
 Detection law. More...
 

Public Member Functions

 EnvelopeFollower () noexcept
 
void prepare (const AudioSpec &spec) noexcept
 Prepares the follower. Allocation-free.
 
void reset () noexcept
 Clears all envelopes.
 
void setAttack (T ms) noexcept
 Attack time in milliseconds (default 10, floor 0.01; non-finite values are ignored).
 
void setRelease (T ms) noexcept
 Release time in milliseconds (default 150, floor 0.01; non-finite values are ignored).
 
void setMode (Mode m) noexcept
 Peak (default) or RMS detection. Out-of-range values clamp.
 
void processBlock (AudioBufferView< const T > buffer) noexcept
 Analyzes a block (read-only) and updates per-channel envelopes.
 
processSample (T input) noexcept
 Single-sample path on channel 0 (for embedding in processors).
 
getEnvelope (int channel=0) const noexcept
 
getEnvelopeMax () const noexcept
 
getEnvelopeDb (int channel=0) const noexcept
 
getAttack () const noexcept
 
getRelease () const noexcept
 
Mode getMode () const noexcept
 

Detailed Description

template<FloatType T, int MaxChannels = 16>
class dspark::EnvelopeFollower< T, MaxChannels >

Attack/release envelope detector (Peak or RMS).

Template Parameters
TSample type (float or double).
MaxChannelsMaximum tracked channels.

Definition at line 55 of file EnvelopeFollower.h.

Member Enumeration Documentation

◆ Mode

template<FloatType T, int MaxChannels = 16>
enum class dspark::EnvelopeFollower::Mode
strong

Detection law.

Enumerator
Peak 
RMS 

Definition at line 59 of file EnvelopeFollower.h.

Constructor & Destructor Documentation

◆ EnvelopeFollower()

template<FloatType T, int MaxChannels = 16>
dspark::EnvelopeFollower< T, MaxChannels >::EnvelopeFollower ( )
inlinenoexcept

Definition at line 61 of file EnvelopeFollower.h.

Member Function Documentation

◆ getAttack()

template<FloatType T, int MaxChannels = 16>
T dspark::EnvelopeFollower< T, MaxChannels >::getAttack ( ) const
inlinenoexcept
Returns
Attack time in milliseconds.

Definition at line 227 of file EnvelopeFollower.h.

◆ getEnvelope()

template<FloatType T, int MaxChannels = 16>
T dspark::EnvelopeFollower< T, MaxChannels >::getEnvelope ( int  channel = 0) const
inlinenoexcept
Returns
Envelope of channel as linear amplitude.

Definition at line 202 of file EnvelopeFollower.h.

◆ getEnvelopeDb()

template<FloatType T, int MaxChannels = 16>
T dspark::EnvelopeFollower< T, MaxChannels >::getEnvelopeDb ( int  channel = 0) const
inlinenoexcept
Returns
Envelope of channel in dBFS (floor -120 dB).

Definition at line 220 of file EnvelopeFollower.h.

◆ getEnvelopeMax()

template<FloatType T, int MaxChannels = 16>
T dspark::EnvelopeFollower< T, MaxChannels >::getEnvelopeMax ( ) const
inlinenoexcept
Returns
Loudest channel envelope (useful as a mono modulation source).

Definition at line 210 of file EnvelopeFollower.h.

◆ getMode()

template<FloatType T, int MaxChannels = 16>
Mode dspark::EnvelopeFollower< T, MaxChannels >::getMode ( ) const
inlinenoexcept
Returns
Current detection law.

Definition at line 239 of file EnvelopeFollower.h.

◆ getRelease()

template<FloatType T, int MaxChannels = 16>
T dspark::EnvelopeFollower< T, MaxChannels >::getRelease ( ) const
inlinenoexcept
Returns
Release time in milliseconds.

Definition at line 233 of file EnvelopeFollower.h.

◆ prepare()

template<FloatType T, int MaxChannels = 16>
void dspark::EnvelopeFollower< T, MaxChannels >::prepare ( const AudioSpec spec)
inlinenoexcept

Prepares the follower. Allocation-free.

An invalid or non-finite specification is ignored (conservative no-op: the previous state is kept). Channels beyond MaxChannels are clamped.

Definition at line 72 of file EnvelopeFollower.h.

◆ processBlock()

template<FloatType T, int MaxChannels = 16>
void dspark::EnvelopeFollower< T, MaxChannels >::processBlock ( AudioBufferView< const T >  buffer)
inlinenoexcept

Analyzes a block (read-only) and updates per-channel envelopes.

Channels beyond the prepared count are ignored.

Definition at line 131 of file EnvelopeFollower.h.

◆ processSample()

template<FloatType T, int MaxChannels = 16>
T dspark::EnvelopeFollower< T, MaxChannels >::processSample ( input)
inlinenoexcept

Single-sample path on channel 0 (for embedding in processors).

Also publishes to the lock-free readout, so getEnvelope() stays coherent with this path.

Returns
The current envelope (linear amplitude).

Definition at line 182 of file EnvelopeFollower.h.

◆ reset()

template<FloatType T, int MaxChannels = 16>
void dspark::EnvelopeFollower< T, MaxChannels >::reset ( )
inlinenoexcept

Clears all envelopes.

Allocation-free, but it writes the same plain per-channel state the processing calls own: call it from the stream owner (or with the stream stopped).

Definition at line 89 of file EnvelopeFollower.h.

◆ setAttack()

template<FloatType T, int MaxChannels = 16>
void dspark::EnvelopeFollower< T, MaxChannels >::setAttack ( ms)
inlinenoexcept

Attack time in milliseconds (default 10, floor 0.01; non-finite values are ignored).

Definition at line 99 of file EnvelopeFollower.h.

◆ setMode()

template<FloatType T, int MaxChannels = 16>
void dspark::EnvelopeFollower< T, MaxChannels >::setMode ( Mode  m)
inlinenoexcept

Peak (default) or RMS detection. Out-of-range values clamp.

Definition at line 118 of file EnvelopeFollower.h.

◆ setRelease()

template<FloatType T, int MaxChannels = 16>
void dspark::EnvelopeFollower< T, MaxChannels >::setRelease ( ms)
inlinenoexcept

Release time in milliseconds (default 150, floor 0.01; non-finite values are ignored).

Definition at line 109 of file EnvelopeFollower.h.


The documentation for this class was generated from the following file: