ADSREnvelopGenerator

ADSR Envelop generator struct.

Uses floating-point arithmetics, since most targets will use that. Shaping is done through the shpF() and shp() functions. A 0.5 value should return a mostly linear output, and a 0.25 an "audio-grade logarithmic" for volume, but since the calculation is optimized for speed rather than accuracy, there will be imperfections.

Members

Enums

Stage
enum Stage

Indicates the current stage of the envelop.

Functions

advance
double advance()

Advances the main counter by one amount.

isRunning
bool isRunning()

Returns true if the envelop generator is running

keyOff
void keyOff()

Sets the key position to off.

keyOn
void keyOn()

Sets the key position to on.

keyOnNoReset
void keyOnNoReset()

Sets the key position to on (no reset of counter).

keypos
bool keypos()

Returns true if key is on

output
double output()

Returns the current output as a floating-point value, between 0.0 and 1.0

position
ubyte position()

Returns the current stage

shp
double shp(double g)

Changes the shape of the output using a fast and very crude power of function. Output is returned as a floating-point value between 0.0 and 1.0

Static variables

maxOutput
double maxOutput;

The maximum possible output of the envelop generator

minOutput
double minOutput;

The minimum possible output of the envelop generator.

Variables

_isRunning
bool _isRunning;

If set, then the envelop is running

_keyState
bool _keyState;

If key is on, then it's set to true

attackRate
double attackRate;

Sets how long the attack phase will last (less = longer)

counter
double counter;

The current position of the counter + unshaped output

currStage
ubyte currStage;

The current stage of the envelop generator

decayRate
double decayRate;

Sets how long the decay phase will last (less = longer)

isPercussive
bool isPercussive;

If true, then the sustain stage is skipped

releaseRate
double releaseRate;

Sets how long the release phase will last (less = longer)

sustainControl
double sustainControl;

Controls how the sustain level will change (between -1.0 and 1.0)

sustainLevel
double sustainLevel;

Sets the level of sustain.

Meta