The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

# stk::ADSR Class Reference

STK ADSR envelope class. More...

`#include <ADSR.h>`

Inheritance diagram for stk::ADSR:

List of all members.

## Public Types
enum | { ATTACK, DECAY, SUSTAIN, RELEASE, IDLE }
| ADSR envelope states. More...
## Public Member Functions
| ADSR (void)
| Default constructor.
| ~ADSR (void)
| Class destructor.
void | keyOn (void)
| Set target = 1, state = ADSR::ATTACK.
void | keyOff (void)
| Set target = 0, state = ADSR::RELEASE.
void | setAttackRate (StkFloat rate)
| Set the attack rate (gain / sample).
void | setAttackTarget (StkFloat target)
| Set the target value for the attack (default = 1.0).
void | setDecayRate (StkFloat rate)
| Set the decay rate (gain / sample).
void | setSustainLevel (StkFloat level)
| Set the sustain level.
void | setReleaseRate (StkFloat rate)
| Set the release rate (gain / sample).
void | setAttackTime (StkFloat time)
| Set the attack rate based on a time duration (seconds).
void | setDecayTime (StkFloat time)
| Set the decay rate based on a time duration (seconds).
void | setReleaseTime (StkFloat time)
| Set the release rate based on a time duration (seconds).
void | setAllTimes (StkFloat aTime, StkFloat dTime, StkFloat sLevel, StkFloat rTime)
| Set sustain level and attack, decay, and release time durations (seconds).
void | setTarget (StkFloat target)
| Set a sustain target value and attack or decay from current value to target.
int | getState (void) const
| Return the current envelope state (ATTACK, DECAY, SUSTAIN, RELEASE, IDLE).
void | setValue (StkFloat value)
| Set to state = ADSR::SUSTAIN with current and target values of value.
StkFloat | lastOut (void) const
| Return the last computed output value.
StkFloat | tick (void)
| Compute and return one output sample.
StkFrames & | tick (StkFrames &frames, unsigned int channel=0)
| Fill a channel of the StkFrames object with computed outputs.

## Detailed Description

STK ADSR envelope class.

This class implements a traditional ADSR (Attack, Decay, Sustain, Release) envelope. It responds to simple keyOn and keyOff messages, keeping track of its state. The state = ADSR::IDLE before being triggered and after the envelope value reaches 0.0 in the ADSR::RELEASE state. All rate, target and level settings must be non-negative. All time settings are in seconds and must be positive.

by Perry R. Cook and Gary P. Scavone, 1995-2012.

## Member Enumeration Documentation

anonymous enum

ADSR envelope states.

Enumerator:

  ATTACK | Attack
  DECAY | Decay
  SUSTAIN | Sustain
  RELEASE | Release
  IDLE | Before attack / after release

    00029        {
    00030     ATTACK,
    00031     DECAY,
    00032     SUSTAIN,
    00033     RELEASE,
    00034     IDLE
    00035   };

## Member Function Documentation

StkFrames & stk::ADSR::tick | ( | StkFrames & | frames,
|  | unsigned int | channel = `0` |
| ) |  |  | `[inline, virtual]`

Fill a channel of the StkFrames object with computed outputs.

The `channel` argument must be less than the number of channels in the StkFrames argument (the first channel is specified by 0). However, range checking is only performed if _STK_DEBUG_ is defined during compilation, in which case an out-of-range value will trigger an StkError exception.

Implements stk::Generator.

    00161 {
    00162 #if defined(_STK_DEBUG_)
    00163   if ( channel >= frames.channels() ) {
    00164     oStream_ << "ADSR::tick(): channel and StkFrames arguments are incompatible!";
    00165     handleError( StkError::FUNCTION_ARGUMENT );
    00166   }
    00167 #endif
    00168
    00169   StkFloat *samples = &frames[channel];
    00170   unsigned int hop = frames.channels();
    00171   for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
    00172     *samples = ADSR::tick();
    00173
    00174   return frames;
    00175 }

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

- ADSR.h

The Synthesis ToolKit in C++ (STK)
©1995-2012 Perry R. Cook and Gary P. Scavone. All Rights Reserved.