JUCE  v5.4.1-191-g0ab5e696f
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::ADSR Class Reference

A very simple ADSR envelope class. More...

#include <juce_ADSR.h>

Collaboration diagram for juce::ADSR:

Classes

struct  Parameters
 Holds the parameters being used by an ADSR object. More...
 

Public Member Functions

 ADSR ()
 
template<typename FloatType >
void applyEnvelopeToBuffer (AudioBuffer< FloatType > &buffer, int startSample, int numSamples)
 This method will conveniently apply the next numSamples number of envelope values to an AudioBuffer. More...
 
float getNextSample ()
 Returns the next sample value for an ADSR object. More...
 
const ParametersgetParameters () const
 Returns the parameters currently being used by an ADSR object. More...
 
bool isActive () const noexcept
 Returns true if the envelope is in its attack, decay, sustain or release stage. More...
 
void noteOff ()
 Starts the release phase of the envelope. More...
 
void noteOn ()
 Starts the attack phase of the envelope. More...
 
void reset ()
 Resets the envelope to an idle state. More...
 
void setParameters (const Parameters &newParameters)
 Sets the parameters that will be used by an ADSR object. More...
 
void setSampleRate (double sampleRate)
 Sets the sample rate that will be used for the envelope. More...
 

Private Types

enum  State {
  State::idle,
  State::attack,
  State::decay,
  State::sustain,
  State::release
}
 

Private Member Functions

void calculateRates (const Parameters &parameters)
 

Private Attributes

float attackRate = 0.0f
 
Parameters currentParameters
 
State currentState = State::idle
 
float decayRate = 0.0f
 
float envelopeVal = 0.0f
 
float releaseRate = 0.0f
 
double sr = 0.0
 
float sustainLevel = 0.0f
 

Detailed Description

A very simple ADSR envelope class.

To use it, call setSampleRate() with the current sample rate and give it some parameters with setParameters() then call getNextSample() to get the envelope value to be applied to each audio sample or applyEnvelopeToBuffer() to apply the envelope to a whole buffer.

Member Enumeration Documentation

◆ State

enum juce::ADSR::State
strongprivate
Enumerator
idle 
attack 
decay 
sustain 
release 

Constructor & Destructor Documentation

◆ ADSR()

juce::ADSR::ADSR ( )
inline

References setParameters(), and setSampleRate().

Member Function Documentation

◆ applyEnvelopeToBuffer()

template<typename FloatType >
void juce::ADSR::applyEnvelopeToBuffer ( AudioBuffer< FloatType > &  buffer,
int  startSample,
int  numSamples 
)
inline

This method will conveniently apply the next numSamples number of envelope values to an AudioBuffer.

See also
getNextSample

References getNextSample(), juce::AudioBuffer< Type >::getNumChannels(), juce::AudioBuffer< Type >::getNumSamples(), juce::AudioBuffer< Type >::getWritePointer(), and jassert.

◆ calculateRates()

void juce::ADSR::calculateRates ( const Parameters parameters)
inlineprivate

◆ getNextSample()

float juce::ADSR::getNextSample ( )
inline

Returns the next sample value for an ADSR object.

See also
applyEnvelopeToBuffer

References attack, attackRate, currentState, decay, decayRate, envelopeVal, idle, release, releaseRate, reset(), sustain, and sustainLevel.

Referenced by applyEnvelopeToBuffer().

◆ getParameters()

const Parameters& juce::ADSR::getParameters ( ) const
inline

Returns the parameters currently being used by an ADSR object.

See also
setParameters

References currentParameters.

◆ isActive()

bool juce::ADSR::isActive ( ) const
inlinenoexcept

Returns true if the envelope is in its attack, decay, sustain or release stage.

References currentState, and idle.

◆ noteOff()

void juce::ADSR::noteOff ( )
inline

Starts the release phase of the envelope.

References currentState, idle, release, releaseRate, and reset().

◆ noteOn()

void juce::ADSR::noteOn ( )
inline

Starts the attack phase of the envelope.

References attack, attackRate, currentState, decay, decayRate, and sustain.

◆ reset()

void juce::ADSR::reset ( )
inline

Resets the envelope to an idle state.

References currentState, envelopeVal, and idle.

Referenced by getNextSample(), and noteOff().

◆ setParameters()

void juce::ADSR::setParameters ( const Parameters newParameters)
inline

Sets the parameters that will be used by an ADSR object.

You must have called setSampleRate() with the correct sample rate before this otherwise the values may be incorrect!

See also
getParameters

References calculateRates(), currentParameters, juce::ADSR::Parameters::sustain, and sustainLevel.

Referenced by ADSR().

◆ setSampleRate()

void juce::ADSR::setSampleRate ( double  sampleRate)
inline

Sets the sample rate that will be used for the envelope.

This must be called before the getNextSample() or setParameters() methods.

References jassert, and sr.

Referenced by ADSR().

Member Data Documentation

◆ attackRate

float juce::ADSR::attackRate = 0.0f
private

◆ currentParameters

Parameters juce::ADSR::currentParameters
private

Referenced by getParameters(), and setParameters().

◆ currentState

State juce::ADSR::currentState = State::idle
private

◆ decayRate

float juce::ADSR::decayRate = 0.0f
private

◆ envelopeVal

float juce::ADSR::envelopeVal = 0.0f
private

Referenced by getNextSample(), and reset().

◆ releaseRate

float juce::ADSR::releaseRate = 0.0f
private

◆ sr

double juce::ADSR::sr = 0.0
private

Referenced by calculateRates(), and setSampleRate().

◆ sustainLevel

float juce::ADSR::sustainLevel = 0.0f
private

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