Switchboard SDK
Loading...
Searching...
No Matches
switchboard::EnvelopeGenerator Class Reference

Generates an ADSR envelope with the specified time coefficients. More...

#include <EnvelopeGenerator.hpp>

Public Member Functions

 EnvelopeGenerator (float attackSeconds=ATTACK_SECONDS, float decaySeconds=DECAY_SECONDS, float releaseSeconds=RELEASE_SECONDS, float peakLevel=PEAK_LEVEL, float sustainLevel=SUSTAIN_LEVEL)
 EnvelopeGenerator constructor.
 
void setAttackSeconds (float attackSeconds)
 Sets the attack time of the generated envelope.
 
float getAttackSeconds () const
 Gets the current attack time of the generated envelope.
 
void setDecaySeconds (float decaySeconds)
 Sets the decay time of the generated envelope.
 
float getDecaySeconds () const
 Gets the current decay time of the generated envelope.
 
void setReleaseSeconds (float releaseSeconds)
 Sets the release time of the generated envelope.
 
float getReleaseSeconds () const
 Gets the current release time of the generated envelope.
 
void setPeakLevel (float peakLevel)
 Sets the peak level of the generated envelope (the level reached by attack).
 
float getPeakLevel () const
 Gets the current peak level of the generated envelope (the level reached by attack).
 
void setSustainLevel (float sustainLevel)
 Sets the sustain level of the generated envelope.
 
float getSustainLevel () const
 Gets the current sustain level of the generated envelope.
 
template<typename T >
void generate (T *buffer, const uint numberOfSamples, const uint sampleRate)
 Generates ADSR envelope data into a data buffer.
 
void trigger ()
 Trigger the envelope generator.
 
void release ()
 Release the envelope generator.
 

Detailed Description

Generates an ADSR envelope with the specified time coefficients.

ADSR envelope generator.

Constructor & Destructor Documentation

◆ EnvelopeGenerator()

switchboard::EnvelopeGenerator::EnvelopeGenerator ( float attackSeconds = ATTACK_SECONDS,
float decaySeconds = DECAY_SECONDS,
float releaseSeconds = RELEASE_SECONDS,
float peakLevel = PEAK_LEVEL,
float sustainLevel = SUSTAIN_LEVEL )

EnvelopeGenerator constructor.

Parameters
attackSecondsThe time to reach the peak level from zero. Default is 0.0 seconds.
decaySecondsThe time to reach the sustain level from peak. Default is 0.0 seconds.
releaseSecondsThe time to reach zero from sustain level. Default is 0.0 seconds.
peakLevelThe peak level in the range of 0.0..1.0. Default is 1.0.
sustainLevelThe sustain level in the range of 0.0..1.0. Default is 1.0.

Member Function Documentation

◆ generate()

template<typename T >
template void switchboard::EnvelopeGenerator::generate< int16 > ( T * buffer,
const uint numberOfSamples,
const uint sampleRate )

Generates ADSR envelope data into a data buffer.

Parameters
bufferThe data buffer.
numberOfSamplesThe number of samples to generate.
sampleRateThe sample rate.

◆ getAttackSeconds()

float switchboard::EnvelopeGenerator::getAttackSeconds ( ) const

Gets the current attack time of the generated envelope.

Returns
The attack time in seconds.

◆ getDecaySeconds()

float switchboard::EnvelopeGenerator::getDecaySeconds ( ) const

Gets the current decay time of the generated envelope.

Returns
The decay time in seconds.

◆ getPeakLevel()

float switchboard::EnvelopeGenerator::getPeakLevel ( ) const

Gets the current peak level of the generated envelope (the level reached by attack).

Returns
The peak level in the range of 0.0..1.0.

◆ getReleaseSeconds()

float switchboard::EnvelopeGenerator::getReleaseSeconds ( ) const

Gets the current release time of the generated envelope.

Returns
The release time in seconds.

◆ getSustainLevel()

float switchboard::EnvelopeGenerator::getSustainLevel ( ) const

Gets the current sustain level of the generated envelope.

Returns
The sustain level in the range of 0.0..1.0.

◆ release()

void switchboard::EnvelopeGenerator::release ( )

Release the envelope generator.

The generator will release the sustain level in releaseSeconds time.

◆ setAttackSeconds()

void switchboard::EnvelopeGenerator::setAttackSeconds ( float attackSeconds)

Sets the attack time of the generated envelope.

Parameters
attackSecondsThe new attack time value in seconds.

◆ setDecaySeconds()

void switchboard::EnvelopeGenerator::setDecaySeconds ( float decaySeconds)

Sets the decay time of the generated envelope.

Parameters
decaySecondsThe new decay time value in seconds.

◆ setPeakLevel()

void switchboard::EnvelopeGenerator::setPeakLevel ( float peakLevel)

Sets the peak level of the generated envelope (the level reached by attack).

Parameters
peakLevelThe new peak level value in the range of 0.0..1.0.

◆ setReleaseSeconds()

void switchboard::EnvelopeGenerator::setReleaseSeconds ( float releaseSeconds)

Sets the release time of the generated envelope.

Parameters
releaseSecondsThe new release time value in seconds.

◆ setSustainLevel()

void switchboard::EnvelopeGenerator::setSustainLevel ( float sustainLevel)

Sets the sustain level of the generated envelope.

Parameters
sustainLevelThe new sustain level value in the range of 0.0..1.0.

◆ trigger()

void switchboard::EnvelopeGenerator::trigger ( )

Trigger the envelope generator.

The generator will start to generate the envelope and maintains sustain level until release() is called.