43 template <
unsigned int CONTROL_UPDATE_RATE,
unsigned int LERP_RATE>
48 const unsigned int LERPS_PER_CONTROL;
50 unsigned int update_step_counter;
51 unsigned int num_update_steps;
53 enum {LINE1,LINE2,LINE3,LINE4,IDLE};
58 unsigned int update_steps;
61 }target1,target2,target3,target4,idle;
63 phase * current_phase;
67 unsigned int convertMsecToControlUpdateSteps(
unsigned int msec){
68 return (uint16_t) (((uint32_t)msec*CONTROL_UPDATE_RATE)>>10);
73 void setPhase(phase * next_phase) {
74 update_step_counter = 0;
75 num_update_steps = next_phase->update_steps;
76 transition.set(next_phase->level, next_phase->lerp_steps);
77 current_phase = next_phase;
83 void checkForAndSetNextPhase(phase * next_phase) {
84 if (++update_step_counter >= num_update_steps){
92 void setTime(phase * p,
unsigned int msec)
94 p->update_steps = convertMsecToControlUpdateSteps(msec);
95 p->lerp_steps = (
long) p->update_steps * LERPS_PER_CONTROL;
100 void setUpdateSteps(phase * p,
unsigned int steps)
102 p->update_steps = steps;
103 p->lerp_steps = (
long) steps * LERPS_PER_CONTROL;
112 MultiLine():LERPS_PER_CONTROL(LERP_RATE/CONTROL_UPDATE_RATE)
114 target1.phase_type = LINE1;
115 target2.phase_type = LINE2;
116 target3.phase_type = LINE3;
117 target4.phase_type = LINE4;
118 idle.phase_type = IDLE;
120 current_phase = &idle;
130 switch(current_phase->phase_type) {
133 checkForAndSetNextPhase(&target2);
137 checkForAndSetNextPhase(&target3);
141 checkForAndSetNextPhase(&target4);
145 checkForAndSetNextPhase(&idle);
163 return transition.next();
230 void setIdleLevel(
Q15n16 value)
262 setTime(&target1, msec);
275 setTime(&target2, msec);
289 setTime(&target3, msec);
303 setTime(&target4, msec);
308 void setIdleTime(
unsigned int msec)
310 setTime(&idle, msec);
324 void setTimes(
unsigned int target1_ms,
unsigned int target2_ms,
unsigned int target3_ms,
unsigned int target4_ms)
341 setUpdateSteps(&target1, steps);
351 setUpdateSteps(&target2, steps);
361 setUpdateSteps(&target3, steps);
371 setUpdateSteps(&target4, steps);
376 void setIdleUpdateSteps(
unsigned int steps)
378 setUpdateSteps(&idle, steps);
388 void setAllUpdateSteps(
unsigned int target1_steps,
unsigned int target2_steps,
unsigned int target3_steps,
unsigned int target4_steps)
394 setIdleUpdateSteps(65535);
405 return !(current_phase->phase_type==IDLE);
void setTarget3Level(Q15n16 value)
Set the target3 level of the MultiLine.
void setTarget3Time(unsigned int msec)
Set the target3 time of the MultiLine in milliseconds.
int32_t Q15n16
signed fractional number using 15 integer bits and 16 fractional bits, represents -32767...
void setTarget2Level(Q15n16 value)
Set the target2 level of the MultiLine.
void stop()
Start the target4 phase of the MultiLine.
bool playing()
Tells if the envelope is currently playing.
void setTarget4UpdateSteps(unsigned int steps)
Set the target4 time of the MultiLine, expressed as the number of update steps (not MultiLine::next()...
void setTarget4Time(unsigned int msec)
Set the target4 time of the MultiLine in milliseconds.
void update()
Updates the internal controls of the MultiLine.
void setTarget2Time(unsigned int msec)
Set the target2 time of the MultiLine in milliseconds.
A simple MultiLine envelope generator.
void setTarget1Level(Q15n16 value)
Set the target1 level of the MultiLine.
For linear changes with a minimum of calculation at each step.
void setTarget3UpdateSteps(unsigned int steps)
Set the target3 time of the MultiLine, expressed as the number of update steps (not MultiLine::next()...
Q15n16 next()
Advances one step along the MultiLine and returns the level.
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.
void setTarget4Level(Q15n16 value)
Set the target4 level of the MultiLine.
void setTarget2UpdateSteps(unsigned int steps)
Set the target2 time of the MultiLine, expressed as the number of update steps (not MultiLine::next()...
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...
void start()
Start the target1 phase of the MultiLine.
void setTarget1Time(unsigned int msec)
Set the target1 time of the MultiLine in milliseconds.
void setTarget1UpdateSteps(unsigned int steps)
Set the target1 time of the MultiLine, expressed as the number of update steps (not MultiLine::next()...
void setLevels(Q15n16 target1, Q15n16 target2, Q15n16 target3, Q15n16 target4)
Set the target1, target2, target3 and target4 levels.