Mozzi  version v1.1.0
sound synthesis library for Arduino
Line< T > Class Template Reference

For linear changes with a minimum of calculation at each step. More...

#include <Line.h>

Public Member Functions

 Line ()
 Constructor. More...
 
next ()
 Increments one step along the line. More...
 
void set (T value)
 Set the current value of the line. More...
 
void set (T targetvalue, T num_steps)
 Given a target value and the number of steps to take on the way, this calculates the step size needed to get there from the current value. More...
 
void set (T startvalue, T targetvalue, T num_steps)
 Given a new starting value, target value and the number of steps to take on the way, this sets the step size needed to get there. More...
 

Detailed Description

template<class T>
class Line< T >

For linear changes with a minimum of calculation at each step.

For instance, you can use Line to make an oscillator glide from one frequency to another, pre-calculating the required phase increments for each end and then letting your Line change the phase increment with only a simple addition at each step.

Template Parameters
Tthe type of numbers to use. For example, Line <int> myline; makes a Line which uses ints.
Note
Watch out for underflows in the internal calcualtion of Line() if you're not using floats (but on the other hand try to avoid lots of floats, they're too slow!). If it seems like the Line() is not working, there's a good chance you need to scale up the numbers you're using, so internal calculations don't get truncated away. Use Mozzi's fixed-point number types in mozzi_fixmath.h, which enable you to represent fractional numbers. Google "fixed point arithmetic" if this is new to you.

Definition at line 37 of file Line.h.

Constructor & Destructor Documentation

◆ Line()

template<class T>
Line< T >::Line ( )
inline

Constructor.

Use the template parameter to set the type of numbers you want to use. For example, Line <int> myline; makes a Line which uses ints.

Definition at line 47 of file Line.h.

Member Function Documentation

◆ next()

template<class T>
T Line< T >::next ( )
inline

Increments one step along the line.

Returns
the next value.

Definition at line 58 of file Line.h.

◆ set() [1/3]

template<class T>
void Line< T >::set ( value)
inline

Set the current value of the line.

The Line will continue incrementing from this value using any previously calculated step size.

Parameters
valuethe number to set the Line's current_value to.

Definition at line 73 of file Line.h.

◆ set() [2/3]

template<class T>
void Line< T >::set ( targetvalue,
num_steps 
)
inline

Given a target value and the number of steps to take on the way, this calculates the step size needed to get there from the current value.

Parameters
targetvaluethe value to move towards.
num_stepshow many steps to take to reach the target.

Definition at line 85 of file Line.h.

◆ set() [3/3]

template<class T>
void Line< T >::set ( startvalue,
targetvalue,
num_steps 
)
inline

Given a new starting value, target value and the number of steps to take on the way, this sets the step size needed to get there.

Parameters
startvaluethe number to set the Line's current_value to.
targetvaluethe value to move towards.
num_stepshow many steps to take to reach the target.

Definition at line 102 of file Line.h.