A very simple ADSR envelope class. More...
#include <juce_ADSR.h>
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 Parameters & | getParameters () 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 ¶meters) |
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 |
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.
|
strongprivate |
|
inline |
References setParameters(), and setSampleRate().
|
inline |
This method will conveniently apply the next numSamples number of envelope values to an AudioBuffer.
References getNextSample(), juce::AudioBuffer< Type >::getNumChannels(), juce::AudioBuffer< Type >::getNumSamples(), juce::AudioBuffer< Type >::getWritePointer(), and jassert.
|
inlineprivate |
References juce::ADSR::Parameters::attack, attackRate, juce::ADSR::Parameters::decay, decayRate, jassert, juce::ADSR::Parameters::release, releaseRate, sr, and sustainLevel.
Referenced by setParameters().
|
inline |
Returns the next sample value for an ADSR object.
References attack, attackRate, currentState, decay, decayRate, envelopeVal, idle, release, releaseRate, reset(), sustain, and sustainLevel.
Referenced by applyEnvelopeToBuffer().
|
inline |
Returns the parameters currently being used by an ADSR object.
References currentParameters.
|
inlinenoexcept |
Returns true if the envelope is in its attack, decay, sustain or release stage.
References currentState, and idle.
|
inline |
Starts the release phase of the envelope.
References currentState, idle, release, releaseRate, and reset().
|
inline |
Starts the attack phase of the envelope.
References attack, attackRate, currentState, decay, decayRate, and sustain.
|
inline |
Resets the envelope to an idle state.
References currentState, envelopeVal, and idle.
Referenced by getNextSample(), and noteOff().
|
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!
References calculateRates(), currentParameters, juce::ADSR::Parameters::sustain, and sustainLevel.
Referenced by ADSR().
|
inline |
Sets the sample rate that will be used for the envelope.
This must be called before the getNextSample() or setParameters() methods.
Referenced by ADSR().
|
private |
Referenced by calculateRates(), getNextSample(), and noteOn().
|
private |
Referenced by getParameters(), and setParameters().
|
private |
Referenced by getNextSample(), isActive(), noteOff(), noteOn(), and reset().
|
private |
Referenced by calculateRates(), getNextSample(), and noteOn().
|
private |
Referenced by getNextSample(), and reset().
|
private |
Referenced by calculateRates(), getNextSample(), and noteOff().
|
private |
Referenced by calculateRates(), and setSampleRate().
|
private |
Referenced by calculateRates(), getNextSample(), and setParameters().