Mozzi  version v1.1.0
sound synthesis library for Arduino
MultiLine< CONTROL_UPDATE_RATE, LERP_RATE > Class Template Reference

A simple MultiLine envelope generator. More...

#include <MultiLine.h>

Public Member Functions

 MultiLine ()
 Constructor.
 
void update ()
 Updates the internal controls of the MultiLine. More...
 
Q15n16 next ()
 Advances one step along the MultiLine and returns the level. More...
 
void start ()
 Start the target1 phase of the MultiLine. More...
 
void stop ()
 Start the target4 phase of the MultiLine. More...
 
void setTarget1Level (Q15n16 value)
 Set the target1 level of the MultiLine. More...
 
void setTarget2Level (Q15n16 value)
 Set the target2 level of the MultiLine. More...
 
void setTarget3Level (Q15n16 value)
 Set the target3 level of the MultiLine. More...
 
void setTarget4Level (Q15n16 value)
 Set the target4 level of the MultiLine. More...
 
void setIdleLevel (Q15n16 value)
 
void setLevels (Q15n16 target1, Q15n16 target2, Q15n16 target3, Q15n16 target4)
 Set the target1, target2, target3 and target4 levels. More...
 
void setTarget1Time (unsigned int msec)
 Set the target1 time of the MultiLine in milliseconds. More...
 
void setTarget2Time (unsigned int msec)
 Set the target2 time of the MultiLine in milliseconds. More...
 
void setTarget3Time (unsigned int msec)
 Set the target3 time of the MultiLine in milliseconds. More...
 
void setTarget4Time (unsigned int msec)
 Set the target4 time of the MultiLine in milliseconds. More...
 
void setIdleTime (unsigned int msec)
 
void setTimes (unsigned int target1_ms, unsigned int target2_ms, unsigned int target3_ms, unsigned int target4_ms)
 Set the target1, target2 and target4 times of the MultiLine in milliseconds. More...
 
void setTarget1UpdateSteps (unsigned int steps)
 Set the target1 time of the MultiLine, expressed as the number of update steps (not MultiLine::next() interpolation steps) in the target1 phase. More...
 
void setTarget2UpdateSteps (unsigned int steps)
 Set the target2 time of the MultiLine, expressed as the number of update steps (not MultiLine::next() interpolation steps) in the target2 phase. More...
 
void setTarget3UpdateSteps (unsigned int steps)
 Set the target3 time of the MultiLine, expressed as the number of update steps (not MultiLine::next() interpolation steps) in the target3 phase. More...
 
void setTarget4UpdateSteps (unsigned int steps)
 Set the target4 time of the MultiLine, expressed as the number of update steps (not MultiLine::next() interpolation steps) in the target4 phase. More...
 
void setIdleUpdateSteps (unsigned int steps)
 
void setAllUpdateSteps (unsigned int target1_steps, unsigned int target2_steps, unsigned int target3_steps, unsigned int target4_steps)
 Set the target1, target2 and target4 times of the MultiLine, expressed in update steps (not MultiLine::next() interpolation steps). More...
 
bool playing ()
 Tells if the envelope is currently playing. More...
 
 MultiLine ()
 Constructor.
 
void update ()
 Updates the internal controls of the MultiLine. More...
 
Q15n16 next ()
 Advances one step along the MultiLine and returns the level. More...
 
void start ()
 Start the target1 phase of the MultiLine. More...
 
void stop ()
 Jump to to the final phase in the sequence.
 
void setTargetLevel (uint8_t phase_num, Q15n16 value)
 Set the target level of one of the phases. More...
 
void setTargetTime (uint8_t phase_num, unsigned int msec)
 Set the time taken to reach the target level of a phase, in milliseconds. More...
 
void setTargetUpdateSteps (uint8_t phase_num, unsigned int steps)
 Set the target1 time of the MultiLine, expressed as the number of update steps (not MultiLine::next() interpolation steps) in the target1 phase. More...
 
bool playing ()
 Tells if the MultiLine is currently playing. More...
 

Detailed Description

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
class MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >

A simple MultiLine 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 MultiLine updates to be made even more sparsely if desired, eg. every 3rd control update.

Template Parameters
CONTROL_UPDATE_RATEThe 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_RATESets 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().

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 MultiLine updates to be made even more sparsely if desired, eg. every 3rd control update.

Template Parameters
CONTROL_UPDATE_RATEThe 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_RATESets 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 44 of file MultiLine.h.

Member Function Documentation

◆ next() [1/2]

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
Q15n16 MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::next ( )
inline

Advances one step along the MultiLine and returns the level.

Call this in updateAudio().

Returns
the next value, as a Q15n16 fixed-point number.

Definition at line 148 of file MultiLine2.h.

◆ next() [2/2]

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
Q15n16 MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::next ( )
inline

Advances one step along the MultiLine and returns the level.

Call this in updateAudio().

Returns
the next value, as a Q15n16 fixed-point number.

Definition at line 161 of file MultiLine.h.

◆ playing() [1/2]

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
bool MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::playing ( )
inline

Tells if the MultiLine is currently playing.

Returns
true if playing, false if in the final state

Definition at line 212 of file MultiLine2.h.

◆ playing() [2/2]

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
bool MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::playing ( )
inline

Tells if the envelope is currently playing.

Returns
true if playing, false if in IDLE state

Definition at line 403 of file MultiLine.h.

◆ setAllUpdateSteps()

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::setAllUpdateSteps ( unsigned int  target1_steps,
unsigned int  target2_steps,
unsigned int  target3_steps,
unsigned int  target4_steps 
)
inline

Set the target1, target2 and target4 times of the MultiLine, expressed in update steps (not MultiLine::next() interpolation steps).

Parameters
target1_stepsthe number of update steps in the target1 phase
target2_stepsthe number of update steps in the target2 phase
target3_stepsthe number of update steps in the target3 phase
target4_stepsthe number of update steps in the target4 phase

Definition at line 388 of file MultiLine.h.

◆ setLevels()

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::setLevels ( Q15n16  target1,
Q15n16  target2,
Q15n16  target3,
Q15n16  target4 
)
inline

Set the target1, target2, target3 and target4 levels.

Parameters
target1the new target1 level.
target2the new target3 level.
target1the new target3 level.
target2the new target4 level.

Definition at line 243 of file MultiLine.h.

◆ setTarget1Level()

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::setTarget1Level ( Q15n16  value)
inline

Set the target1 level of the MultiLine.

Parameters
valuethe target1 level.

Definition at line 191 of file MultiLine.h.

◆ setTarget1Time()

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::setTarget1Time ( unsigned int  msec)
inline

Set the target1 time of the MultiLine in milliseconds.

The actual time taken will be resolved within the resolution of CONTROL_RATE.

Parameters
msecthe unsigned int target1 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 260 of file MultiLine.h.

◆ setTarget1UpdateSteps()

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::setTarget1UpdateSteps ( unsigned int  steps)
inline

Set the target1 time of the MultiLine, expressed as the number of update steps (not MultiLine::next() interpolation steps) in the target1 phase.

Parameters
stepsthe number of times MultiLine::update() will be called in the target1 phase.

Definition at line 339 of file MultiLine.h.

◆ setTarget2Level()

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::setTarget2Level ( Q15n16  value)
inline

Set the target2 level of the MultiLine.

Parameters
valuethe target2 level.

Definition at line 202 of file MultiLine.h.

◆ setTarget2Time()

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::setTarget2Time ( unsigned int  msec)
inline

Set the target2 time of the MultiLine in milliseconds.

The actual time taken will be resolved within the resolution of CONTROL_RATE.

Parameters
msecthe unsigned int target2 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 273 of file MultiLine.h.

◆ setTarget2UpdateSteps()

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::setTarget2UpdateSteps ( unsigned int  steps)
inline

Set the target2 time of the MultiLine, expressed as the number of update steps (not MultiLine::next() interpolation steps) in the target2 phase.

Parameters
stepsthe number of times MultiLine::update() will be called in the target2 phase.

Definition at line 349 of file MultiLine.h.

◆ setTarget3Level()

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::setTarget3Level ( Q15n16  value)
inline

Set the target3 level of the MultiLine.

Parameters
valuethe target3 level. Usually the same as the target2 level, for a steady target3ed note.

Definition at line 213 of file MultiLine.h.

◆ setTarget3Time()

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::setTarget3Time ( unsigned int  msec)
inline

Set the target3 time of the MultiLine in milliseconds.

The actual time taken will be resolved within the resolution of CONTROL_RATE. The target3 phase will finish if the MultiLine recieves a stop().

Parameters
msecthe unsigned int target3 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 287 of file MultiLine.h.

◆ setTarget3UpdateSteps()

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::setTarget3UpdateSteps ( unsigned int  steps)
inline

Set the target3 time of the MultiLine, expressed as the number of update steps (not MultiLine::next() interpolation steps) in the target3 phase.

Parameters
stepsthe number of times MultiLine::update() will be called in the target3 phase.

Definition at line 359 of file MultiLine.h.

◆ setTarget4Level()

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::setTarget4Level ( Q15n16  value)
inline

Set the target4 level of the MultiLine.

Normally you'd make this 0, but you have the option of some other value.

Parameters
valuethe target4 level (usually 0).

Definition at line 223 of file MultiLine.h.

◆ setTarget4Time()

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::setTarget4Time ( unsigned int  msec)
inline

Set the target4 time of the MultiLine in milliseconds.

The actual time taken will be resolved within the resolution of CONTROL_RATE.

Parameters
msecthe unsigned int target4 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 301 of file MultiLine.h.

◆ setTarget4UpdateSteps()

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::setTarget4UpdateSteps ( unsigned int  steps)
inline

Set the target4 time of the MultiLine, expressed as the number of update steps (not MultiLine::next() interpolation steps) in the target4 phase.

Parameters
stepsthe number of times MultiLine::update() will be called in the target4 phase.

Definition at line 369 of file MultiLine.h.

◆ setTargetLevel()

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::setTargetLevel ( uint8_t  phase_num,
Q15n16  value 
)
inline

Set the target level of one of the phases.

Parameters
phase_numwhich phase to edit.
valuethe target level of the phase being edited.

Definition at line 179 of file MultiLine2.h.

◆ setTargetTime()

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::setTargetTime ( uint8_t  phase_num,
unsigned int  msec 
)
inline

Set the time taken to reach the target level of a phase, in milliseconds.

The actual time taken will be resolved within the resolution of CONTROL_RATE.

Parameters
phase_numwhich phase to edit.
msecthe target time in milliseconds.
Note
Beware of low time values in case internal step size gets calculated as 0, which would mean nothing happens.

Definition at line 192 of file MultiLine2.h.

◆ setTargetUpdateSteps()

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::setTargetUpdateSteps ( uint8_t  phase_num,
unsigned int  steps 
)
inline

Set the target1 time of the MultiLine, expressed as the number of update steps (not MultiLine::next() interpolation steps) in the target1 phase.

Parameters
stepsthe number of times MultiLine::update() will be called in the target1 phase.

Definition at line 202 of file MultiLine2.h.

◆ setTimes()

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::setTimes ( unsigned int  target1_ms,
unsigned int  target2_ms,
unsigned int  target3_ms,
unsigned int  target4_ms 
)
inline

Set the target1, target2 and target4 times of the MultiLine in milliseconds.

The actual times will be resolved within the resolution of CONTROL_RATE.

Parameters
target1_msthe new target1 time in milliseconds.
target2_msthe new target2 time in milliseconds.
target3_msthe new target3 time in milliseconds.
target4_msthe new target4 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 324 of file MultiLine.h.

◆ start() [1/2]

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::start ( )
inline

Start the target1 phase of the MultiLine.

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

Definition at line 158 of file MultiLine2.h.

◆ start() [2/2]

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::start ( )
inline

Start the target1 phase of the MultiLine.

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

Definition at line 171 of file MultiLine.h.

◆ stop()

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::stop ( )
inline

Start the target4 phase of the MultiLine.

Definition at line 181 of file MultiLine.h.

◆ update() [1/2]

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::update ( )
inline

Updates the internal controls of the MultiLine.

Call this in updateControl().

Definition at line 128 of file MultiLine.h.

◆ update() [2/2]

template<unsigned int CONTROL_UPDATE_RATE, unsigned int LERP_RATE>
void MultiLine< CONTROL_UPDATE_RATE, LERP_RATE >::update ( )
inline

Updates the internal controls of the MultiLine.

Call this in updateControl().

Definition at line 137 of file MultiLine2.h.