22 #include "mozzi_fixmath.h" 45 template <
unsigned int NUM_PHASES,
unsigned int CONTROL_UPDATE_RATE,
unsigned int LERP_RATE>
50 const unsigned int LERPS_PER_CONTROL;
52 unsigned int update_step_counter;
53 unsigned int num_update_steps;
60 unsigned int update_steps;
65 phase phases[NUM_PHASES];
66 unsigned int current_phase_num;
68 phase * current_phase;
74 unsigned int convertMsecToControlUpdateSteps(
unsigned int msec){
75 return (uint16_t) (((uint32_t)msec*CONTROL_UPDATE_RATE)>>10);
80 void setPhase(phase * next_phase) {
81 update_step_counter = 0;
82 num_update_steps = next_phase->update_steps;
83 transition.
set(next_phase->level, next_phase->lerp_steps);
84 current_phase = next_phase;
90 void checkForAndSetNextPhase() {
91 if (++update_step_counter >= num_update_steps){
92 if(current_phase_num < NUM_PHASES) current_phase_num++;
93 setPhase(&(phases[current_phase_num]));
100 void setTime(phase * p,
unsigned int msec)
102 p->update_steps = convertMsecToControlUpdateSteps(msec);
103 p->lerp_steps = (long) p->update_steps * LERPS_PER_CONTROL;
108 void setUpdateSteps(phase * p,
unsigned int steps)
110 p->update_steps = steps;
111 p->lerp_steps = (long) steps * LERPS_PER_CONTROL;
120 MultiLine():LERPS_PER_CONTROL(LERP_RATE/CONTROL_UPDATE_RATE)
137 checkForAndSetNextPhase();
174 return transition.
next();
183 current_phase_num = 0;
184 setPhase(&(phases[current_phase_num]));
194 setPhase(&(phases[NUM_PHASES-1]));
205 phases[phase_num].level=value;
235 setTime(&(phases[phase_num]), msec);
266 setUpdateSteps(&(phases[phase_num]), steps);
294 return current_phase_num != NUM_PHASES-1;
void set(T value)
Set the current value of the line.
void setTargetLevel(uint8_t phase_num, Q15n16 value)
Set the target1 level of the MultiLine.
int32_t Q15n16
signed fractional number using 15 integer bits and 16 fractional bits, represents -32767...
void stop()
Start the target4 phase of the MultiLine.
bool playing()
Set the target1, target2 and target4 times of the MultiLine, expressed in update steps (not MultiLine...
void setTargetTime(uint8_t phase_num, unsigned int msec)
Set the target levels.
void update()
Updates the internal controls of the MultiLine.
A simple MultiLine envelope generator.
void setTargetUpdateSteps(uint8_t phase_num, unsigned int steps)
Set the target1, target2 and target4 times of the MultiLine in milliseconds.
Q15n16 next()
Advances one step along the MultiLine and returns the level.
void start()
Start the target1 phase of the MultiLine.
T next()
Increments one step along the line.