|
| ADSR () |
| Constructor.
|
|
void | update () |
| Updates the internal controls of the ADSR. More...
|
|
unsigned char | next () |
| Advances one audio step along the ADSR and returns the level. More...
|
|
void | noteOn () |
| Start the attack phase of the ADSR. More...
|
|
void | noteOff () |
| Start the release phase of the ADSR. More...
|
|
void | setAttackLevel (byte value) |
| Set the attack level of the ADSR. More...
|
|
void | setDecayLevel (byte value) |
| Set the decay level of the ADSR. More...
|
|
void | setSustainLevel (byte value) |
| Set the sustain level of the ADSR. More...
|
|
void | setReleaseLevel (byte value) |
| Set the release level of the ADSR. More...
|
|
void | setIdleLevel (byte value) |
|
void | setADLevels (byte attack, byte decay) |
| Set the attack and decay levels of the ADSR. More...
|
|
void | setLevels (byte attack, byte decay, byte sustain, byte release) |
| Set the attack, decay, sustain and release levels. More...
|
|
void | setAttackTime (unsigned int msec) |
| Set the attack time of the ADSR in milliseconds. More...
|
|
void | setDecayTime (unsigned int msec) |
| Set the decay time of the ADSR in milliseconds. More...
|
|
void | setSustainTime (unsigned int msec) |
| Set the sustain time of the ADSR in milliseconds. More...
|
|
void | setReleaseTime (unsigned int msec) |
| Set the release time of the ADSR in milliseconds. More...
|
|
void | setIdleTime (unsigned int msec) |
|
void | setTimes (unsigned int attack_ms, unsigned int decay_ms, unsigned int sustain_ms, unsigned int release_ms) |
| Set the attack, decay and release times of the ADSR in milliseconds. More...
|
|
void | setAttackUpdateSteps (unsigned int steps) |
| Set the attack time of the ADSR, expressed as the number of update steps (not ADSR::next() interpolation steps) in the attack phase. More...
|
|
void | setDecayUpdateSteps (unsigned int steps) |
| Set the decay time of the ADSR, expressed as the number of update steps (not ADSR::next() interpolation steps) in the decay phase. More...
|
|
void | setSustainUpdateSteps (unsigned int steps) |
| Set the sustain time of the ADSR, expressed as the number of update steps (not ADSR::next() interpolation steps) in the sustain phase. More...
|
|
void | setReleaseUpdateSteps (unsigned int steps) |
| Set the release time of the ADSR, expressed as the number of update steps (not ADSR::next() interpolation steps) in the release phase. More...
|
|
void | setIdleUpdateSteps (unsigned int steps) |
|
void | setAllUpdateSteps (unsigned int attack_steps, unsigned int decay_steps, unsigned int sustain_steps, unsigned int release_steps) |
| Set the attack, decay and release times of the ADSR, expressed in update steps (not ADSR::next() interpolation steps). More...
|
|
bool | playing () |
| Tells if the envelope is currently playing. More...
|
|
template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
class ADSR< CONTROL_UPDATE_RATE, LERP_RATE >
A simple ADSR envelope generator.
This implementation has separate update() and next() methods, where next() interpolates values between each update(). The "normal" way to use this would be with update() in updateControl(), where it calculates a new internal state each control step, and then next() is in updateAudio(), called much more often, where it interpolates between the control values. This also allows the ADSR updates to be made even more sparsely if desired, eg. every 3rd control update.
- Template Parameters
-
CONTROL_UPDATE_RATE | The frequency of control updates. Ordinarily this will be CONTROL_RATE, but an alternative (amongst others) is to set this as well as the LERP_RATE parameter to AUDIO_RATE, and call both update() and next() in updateAudio(). Such a use would allow accurate envelopes with finer resolution of the control points than CONTROL_RATE. |
LERP_RATE | Sets how often next() will be called, to interpolate between updates set by CONTROL_UPDATE_RATE. This will produce the smoothest results if it's set to AUDIO_RATE, but if you need to save processor time and your envelope changes slowly or controls something like a filter where there may not be problems with glitchy or clicking transitions, LERP_RATE could be set to CONTROL_RATE (for instance). Then update() and next() could both be called in updateControl(), greatly reducing the amount of processing required compared to calling next() in updateAudio(). |
Definition at line 45 of file ADSR.h.
template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void ADSR< CONTROL_UPDATE_RATE, LERP_RATE >::setADLevels |
( |
byte |
attack, |
|
|
byte |
decay |
|
) |
| |
|
inline |
Set the attack and decay levels of the ADSR.
This assumes a conventional ADSR where the sustain continues at the same level as the decay, till the release ramps to 0.
- Parameters
-
attack | the new attack level. |
decay | the new decay level. |
Definition at line 245 of file ADSR.h.
template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void ADSR< CONTROL_UPDATE_RATE, LERP_RATE >::setAllUpdateSteps |
( |
unsigned int |
attack_steps, |
|
|
unsigned int |
decay_steps, |
|
|
unsigned int |
sustain_steps, |
|
|
unsigned int |
release_steps |
|
) |
| |
|
inline |
Set the attack, decay and release times of the ADSR, expressed in update steps (not ADSR::next() interpolation steps).
- Parameters
-
attack_steps | the number of update steps in the attack phase |
decay_steps | the number of update steps in the decay phase |
sustain_steps | the number of update steps in the sustain phase |
release_steps | the number of update steps in the release phase |
Definition at line 407 of file ADSR.h.
template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void ADSR< CONTROL_UPDATE_RATE, LERP_RATE >::setAttackTime |
( |
unsigned int |
msec | ) |
|
|
inline |
Set the attack time of the ADSR in milliseconds.
The actual time taken will be resolved within the resolution of CONTROL_RATE.
- Parameters
-
msec | the unsigned int attack time in milliseconds. |
- Note
- Beware of low values (less than 20 or so, depending on how many steps are being taken), in case internal step size gets calculated as 0, which would mean nothing happens.
Definition at line 279 of file ADSR.h.
template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void ADSR< CONTROL_UPDATE_RATE, LERP_RATE >::setDecayTime |
( |
unsigned int |
msec | ) |
|
|
inline |
Set the decay time of the ADSR in milliseconds.
The actual time taken will be resolved within the resolution of CONTROL_RATE.
- Parameters
-
msec | the unsigned int decay time in milliseconds. |
- Note
- Beware of low values (less than 20 or so, depending on how many steps are being taken), in case internal step size gets calculated as 0, which would mean nothing happens.
Definition at line 292 of file ADSR.h.
template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void ADSR< CONTROL_UPDATE_RATE, LERP_RATE >::setReleaseLevel |
( |
byte |
value | ) |
|
|
inline |
Set the release level of the ADSR.
Normally you'd make this 0, but you have the option of some other value.
- Parameters
-
value | the release level (usually 0). |
Definition at line 226 of file ADSR.h.
template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void ADSR< CONTROL_UPDATE_RATE, LERP_RATE >::setReleaseTime |
( |
unsigned int |
msec | ) |
|
|
inline |
Set the release time of the ADSR in milliseconds.
The actual time taken will be resolved within the resolution of CONTROL_RATE.
- Parameters
-
msec | the unsigned int release time in milliseconds. |
- Note
- Beware of low values (less than 20 or so, depending on how many steps are being taken), in case internal step size gets calculated as 0, which would mean nothing happens.
Definition at line 320 of file ADSR.h.
template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void ADSR< CONTROL_UPDATE_RATE, LERP_RATE >::setSustainTime |
( |
unsigned int |
msec | ) |
|
|
inline |
Set the sustain time of the ADSR in milliseconds.
The actual time taken will be resolved within the resolution of CONTROL_RATE. The sustain phase will finish if the ADSR recieves a noteOff().
- Parameters
-
msec | the unsigned int sustain time in milliseconds. |
- Note
- Beware of low values (less than 20 or so, depending on how many steps are being taken), in case internal step size gets calculated as 0, which would mean nothing happens.
Definition at line 306 of file ADSR.h.
template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void ADSR< CONTROL_UPDATE_RATE, LERP_RATE >::setTimes |
( |
unsigned int |
attack_ms, |
|
|
unsigned int |
decay_ms, |
|
|
unsigned int |
sustain_ms, |
|
|
unsigned int |
release_ms |
|
) |
| |
|
inline |
Set the attack, decay and release times of the ADSR in milliseconds.
The actual times will be resolved within the resolution of CONTROL_RATE.
- Parameters
-
attack_ms | the new attack time in milliseconds. |
decay_ms | the new decay time in milliseconds. |
sustain_ms | the new sustain time in milliseconds. |
release_ms | the new release time in milliseconds. |
- Note
- Beware of low values (less than 20 or so, depending on how many steps are being taken), in case internal step size gets calculated as 0, which would mean nothing happens.
Definition at line 343 of file ADSR.h.