smooth( var* value,var factor);

Smoothes out the given value using the given smoothing factor. This function can be used for letting a parameter - such as an angle - softly approach a target value, or for smoothing jerky input values.

Parameters:

value Variable to be smoothed out.
factor Smoothing factor in the range of 0..0.999. 0 means no smoothing, 0.999 means extreme smoothing.

Returns:

Smoothed value.

Speed:

Fast

Remarks:

The previous smoothing values are stored in an internal 64-variable buffer, meaning that up to 64 variables can be smoothed by this function. Smoothing more variables leads to a non-smoothed return value.

Algorithm:

value = var * (1-factor) + last_value * factor

Example (lite-C):

function approach_target_angle(angle)
{
  proc_kill(5);	// prevent other function instances from changing the same angle
  while (abs(my.pan - angle) > 0.1) {
	  my.pan = smooth(angle,0.95);
    wait(1);
  }
}

See also:

accelerate, clamp

► latest version online