JUCE  v6.1.6 (6.0.8-1114)
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 () noexcept
 Returns the next sample value for an ADSR object. More...
 
const ParametersgetParameters () const noexcept
 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 () noexcept
 Starts the release phase of the envelope. More...
 
void noteOn () noexcept
 Starts the attack phase of the envelope. More...
 
void reset () noexcept
 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 newSampleRate) noexcept
 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 goToNextState () noexcept
 
void recalculateRates () noexcept
 

Private Attributes

float attackRate = 0.0f
 
float decayRate = 0.0f
 
float envelopeVal = 0.0f
 
Parameters parameters
 
float releaseRate = 0.0f
 
double sampleRate = 44100.0
 
State state = State::idle
 

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.

@tags{Audio}

Member Enumeration Documentation

◆ State

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

Constructor & Destructor Documentation

◆ ADSR()

juce::ADSR::ADSR ( )
inline

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 juce::gl::buffer, and jassert.

◆ getNextSample()

float juce::ADSR::getNextSample ( )
inlinenoexcept

Returns the next sample value for an ADSR object.

See also
applyEnvelopeToBuffer

References juce::gl::f.

◆ getParameters()

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

Returns the parameters currently being used by an ADSR object.

See also
setParameters

◆ goToNextState()

void juce::ADSR::goToNextState ( )
inlineprivatenoexcept

References juce::gl::reset.

◆ isActive()

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

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

◆ noteOff()

void juce::ADSR::noteOff ( )
inlinenoexcept

Starts the release phase of the envelope.

References juce::gl::reset.

◆ noteOn()

void juce::ADSR::noteOn ( )
inlinenoexcept

Starts the attack phase of the envelope.

References juce::gl::f.

◆ recalculateRates()

void juce::ADSR::recalculateRates ( )
inlineprivatenoexcept

References juce::gl::distance, and juce::gl::f.

◆ reset()

void juce::ADSR::reset ( )
inlinenoexcept

Resets the envelope to an idle state.

◆ 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 jassert.

◆ setSampleRate()

void juce::ADSR::setSampleRate ( double  newSampleRate)
inlinenoexcept

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

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

References jassert.

Member Data Documentation

◆ attackRate

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

◆ decayRate

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

◆ envelopeVal

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

◆ parameters

Parameters juce::ADSR::parameters
private

◆ releaseRate

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

◆ sampleRate

double juce::ADSR::sampleRate = 44100.0
private

◆ state

State juce::ADSR::state = State::idle
private

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