Mozzi  alpha 0.01.1t
sound synthesis library for Arduino
 All Classes Functions Typedefs
Classes | Public Member Functions
ADSR< CONTROL_UPDATE_RATE > Class Template Reference

A simple ADSR envelope generator. More...

List of all members.

Classes

struct  phase

Public Member Functions

 ADSR ()
 Constructor.
void update ()
 Updates the internal controls of the ADSR.
unsigned int next ()
 Advances one audio step along the ADSR and returns the level.
void noteOn ()
 Start the attack phase of the ADSR.
void noteOff ()
 Start the release phase of the ADSR.
void setAttackLevel (byte value)
 Set the attack level of the ADSR.
void setDecayLevel (byte value)
 Set the decay level of the ADSR.
void setSustainLevel (byte value)
 Set the sustain level of the ADSR.
void setReleaseLevel (byte value)
 Set the release level of the ADSR.
void setADLevels (byte attack, byte decay)
 Set the attack and decay levels of the ADSR.
void setAttackTime (unsigned int msec)
 Set the attack time of the ADSR in milliseconds.
void setDecayTime (unsigned int msec)
 Set the decay time of the ADSR in milliseconds.
void setSustainTime (unsigned int msec)
 Set the sustain time of the ADSR in milliseconds.
void setReleaseTime (unsigned int msec)
 Set the release time of the ADSR in milliseconds.
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.

Detailed Description

template<unsigned int CONTROL_UPDATE_RATE>
class ADSR< CONTROL_UPDATE_RATE >

A simple ADSR envelope generator.

Todo:
Test whether using the template parameter makes any difference to speed, and rationalise which units which do and don't need them. Template objects are messy when you try to use pointers to them, you have to include the whole template shebang in the pointer handling.

Definition at line 38 of file ADSR.h.


Member Function Documentation

template<unsigned int CONTROL_UPDATE_RATE>
unsigned int ADSR< CONTROL_UPDATE_RATE >::next ( ) [inline]

Advances one audio step along the ADSR and returns the level.

Call this in updateAudio().

Returns:
the next value, as an unsigned int.

Definition at line 149 of file ADSR.h.

template<unsigned int CONTROL_UPDATE_RATE>
void ADSR< CONTROL_UPDATE_RATE >::noteOff ( ) [inline]

Start the release phase of the ADSR.

Todo:
fix release for rate rather than steps (time), so it releases at the same rate whatever the current level.

Definition at line 169 of file ADSR.h.

template<unsigned int CONTROL_UPDATE_RATE>
void ADSR< CONTROL_UPDATE_RATE >::noteOn ( ) [inline]

Start the attack phase of the ADSR.

THis will restart the ADSR no matter what phase it is up to.

Definition at line 159 of file ADSR.h.

template<unsigned int CONTROL_UPDATE_RATE>
void ADSR< CONTROL_UPDATE_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:
attackthe new attack level.
valuethe new sustain level.

Definition at line 226 of file ADSR.h.

template<unsigned int CONTROL_UPDATE_RATE>
void ADSR< CONTROL_UPDATE_RATE >::setAttackLevel ( byte  value) [inline]

Set the attack level of the ADSR.

Parameters:
valuethe attack level.

Definition at line 181 of file ADSR.h.

template<unsigned int CONTROL_UPDATE_RATE>
void ADSR< CONTROL_UPDATE_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:
valuethe unsigned int attack time in milliseconds.

Definition at line 245 of file ADSR.h.

template<unsigned int CONTROL_UPDATE_RATE>
void ADSR< CONTROL_UPDATE_RATE >::setDecayLevel ( byte  value) [inline]

Set the decay level of the ADSR.

Parameters:
valuethe decay level.

Definition at line 192 of file ADSR.h.

template<unsigned int CONTROL_UPDATE_RATE>
void ADSR< CONTROL_UPDATE_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:
valuethe unsigned int decay time in milliseconds.

Definition at line 256 of file ADSR.h.

template<unsigned int CONTROL_UPDATE_RATE>
void ADSR< CONTROL_UPDATE_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:
valuethe release level (normally 0).

Definition at line 213 of file ADSR.h.

template<unsigned int CONTROL_UPDATE_RATE>
void ADSR< CONTROL_UPDATE_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:
valuethe unsigned int release time in milliseconds.

Definition at line 280 of file ADSR.h.

template<unsigned int CONTROL_UPDATE_RATE>
void ADSR< CONTROL_UPDATE_RATE >::setSustainLevel ( byte  value) [inline]

Set the sustain level of the ADSR.

Parameters:
valuethe sustain level. Usually the same as the decay level, for a steady sustained note.

Definition at line 203 of file ADSR.h.

template<unsigned int CONTROL_UPDATE_RATE>
void ADSR< CONTROL_UPDATE_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:
valuethe unsigned int sustain time in milliseconds.

Definition at line 268 of file ADSR.h.

template<unsigned int CONTROL_UPDATE_RATE>
void ADSR< CONTROL_UPDATE_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_msthe new attack time in milliseconds.
decay_msthe new decay time in milliseconds.
decay_msthe new sustain time in milliseconds.
release_msthe new release time in milliseconds.

Definition at line 295 of file ADSR.h.

template<unsigned int CONTROL_UPDATE_RATE>
void ADSR< CONTROL_UPDATE_RATE >::update ( ) [inline]

Updates the internal controls of the ADSR.

Call this in updateControl().

Definition at line 121 of file ADSR.h.


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