38 lines
592 B
Java
38 lines
592 B
Java
package org.hwo;
|
|
|
|
public class FastSmoother {
|
|
|
|
private float tn;
|
|
private float sum;
|
|
private float value;
|
|
|
|
public FastSmoother(float tn){
|
|
this.sum = 0;
|
|
this.tn = tn;
|
|
this.value = 0;
|
|
}
|
|
|
|
public float smooth(float sample){
|
|
this.sum += sample;
|
|
this.value = this.sum / this.tn;
|
|
this.sum -= this.value;
|
|
return this.value;
|
|
}
|
|
|
|
public float getValue() {
|
|
return value;
|
|
}
|
|
|
|
public float getSum() {
|
|
return sum;
|
|
}
|
|
public void setSum(float sum) {
|
|
this.sum = sum;
|
|
}
|
|
|
|
public void setValue(float value) {
|
|
this.value = value;
|
|
this.sum = (value * this.tn) - value;
|
|
}
|
|
}
|