Debugging timing information is frequently hard to read. This is far from the best method, but tends to spew out more readable results than raw data. Of course usage isn't limited to filtering timing information.
This example snippet implements a two-speed adaptive IIR (infinite impulse response filter). A base IIR simply lerps the current input toward current filtered value with a constant lerp constant. The 'heavier' the filter, the slow the output adapts to the input. Here we have a version with two compile time constant speed which are selected by the percent difference between the current filter and actual.
private static final float FILTER_P = 0.1f;
private static final float FILTER_S = 0x1p-6f;
private static final float FILTER_F = 0x1p-2f;
public static float twospeedIIR(float filtered, float current)
float diff = Math.abs(filtered-current);
if (diff < FILTER_P*filtered)
return (1-FILTER_S)*filtered + FILTER_S*current;
return(1-FILTER_F)*filtered + FILTER_F*current;