Gin
Loading...
Searching...
No Matches
ADSR Class Reference

Linear ADSR envelope generator optimized for modulation sources. More...

#include <gin_adsr.h>

Public Types

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

Public Member Functions

 ADSR ()
 ~ADSR ()
void setSampleRate (double sr)
float process ()
float process (int num)
void process (juce::AudioSampleBuffer &buffer)
void process (juce::AudioSampleBuffer &buffer, int startSample, int numSamples)
float getOutput ()
std::pair< int, float > getCurrentPhase ()
State getState ()
void noteOn ()
void noteOff ()
void setAttack (float seconds)
void setDecay (float seconds)
void setRelease (float seconds)
void setSustainLevel (float level)
void reset ()

Protected Attributes

State state = idle
double sampleRate = 44100.0
float output = 0.0f
float attackDelta = 0.0f
float decayDelta = 0.0f
float releaseDelta = 0.0f
float sustainLevel = 0.0f

Detailed Description

Linear ADSR envelope generator optimized for modulation sources.

ADSR provides a simple, linear envelope generator with attack, decay, sustain, and release stages. Unlike AnalogADSR which uses exponential curves for audio, this class uses linear ramps making it ideal for modulation sources (LFO depth, filter cutoff, etc.) where linear response is often preferred.

Key Features:

  • Linear attack, decay, and release stages
  • Constant sustain level while note is held
  • Per-sample or block processing
  • State tracking for envelope phase
  • Can fill buffer with envelope values

Envelope Stages:

  • Attack: Linear rise from 0 to 1
  • Decay: Linear fall from 1 to sustain level
  • Sustain: Held at sustain level while note is on
  • Release: Linear fall from current level to 0

Usage:

ADSR envelope;
envelope.setSampleRate(44100.0);
envelope.setAttack(0.01f); // 10ms attack
envelope.setDecay(0.1f); // 100ms decay
envelope.setSustainLevel(0.7f); // 70% sustain
envelope.setRelease(0.5f); // 500ms release
envelope.noteOn();
float modValue = envelope.process(blockSize);
// ... later ...
envelope.noteOff();
ADSR()
Definition gin_adsr.h:58
float process()
void setAttack(float seconds)
void noteOn()
Definition gin_adsr.h:104
void noteOff()
Definition gin_adsr.h:105
void setRelease(float seconds)
void setDecay(float seconds)
void setSampleRate(double sr)
Definition gin_adsr.h:71
void setSustainLevel(float level)
See also
AnalogADSR

Member Enumeration Documentation

◆ State

Enumerator
idle 
attack 
decay 
sustain 
release 
finished 

Constructor & Destructor Documentation

◆ ADSR()

ADSR::ADSR ( )

◆ ~ADSR()

ADSR::~ADSR ( )

Member Function Documentation

◆ setSampleRate()

void ADSR::setSampleRate ( double sr)

References sampleRate.

◆ process() [1/4]

float ADSR::process ( )

◆ process() [2/4]

float ADSR::process ( int num)

◆ process() [3/4]

void ADSR::process ( juce::AudioSampleBuffer & buffer)

◆ process() [4/4]

void ADSR::process ( juce::AudioSampleBuffer & buffer,
int startSample,
int numSamples )

◆ getOutput()

float ADSR::getOutput ( )

References attackDelta, idle, output, and state.

◆ getCurrentPhase()

std::pair< int, float > ADSR::getCurrentPhase ( )

References attack, decay, output, release, state, and sustain.

◆ getState()

State ADSR::getState ( )

References state.

◆ noteOn()

void ADSR::noteOn ( )

References attack, and state.

◆ noteOff()

void ADSR::noteOff ( )

References release, and state.

◆ setAttack()

void ADSR::setAttack ( float seconds)

◆ setDecay()

void ADSR::setDecay ( float seconds)

◆ setRelease()

void ADSR::setRelease ( float seconds)

◆ setSustainLevel()

void ADSR::setSustainLevel ( float level)

◆ reset()

void ADSR::reset ( )

Member Data Documentation

◆ state

State ADSR::state = idle
protected

◆ sampleRate

double ADSR::sampleRate = 44100.0
protected

Referenced by setSampleRate().

◆ output

float ADSR::output = 0.0f
protected

Referenced by getCurrentPhase(), and getOutput().

◆ attackDelta

float ADSR::attackDelta = 0.0f
protected

Referenced by getOutput().

◆ decayDelta

float ADSR::decayDelta = 0.0f
protected

◆ releaseDelta

float ADSR::releaseDelta = 0.0f
protected

◆ sustainLevel

float ADSR::sustainLevel = 0.0f
protected

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