public class DelayCalculator extends Object
DelayedInputStream with real-time delay.
Two parameters are necessary for creating a delayed stream: The tick interval
in nanoseconds, and the delay in ticks. A low interval has the advantage of a
more precise delay, but the disadvantage of higher CPU load.
This class uses the notion of an epsilon value to specify the allowed
error in the result delay. The error results from a higher tick interval.
The default epsilon value is DEFAULT_EPSILON.
Epsilon must be between 0 and 1, exclusively. The theoretical value of 0
means no tolerated error at all, and the value of 1 means that an error of
100% is permitted. A value of 0.01 means a permitted error of 1%, and so on.
Note that the actual error may be (much) higher than epsilon, since binding
ticks to real time is a real-time application and as such prone to the
effects of preemptive computing. However, the theoretical (optimal) error
will not exceed epsilon (except for cases where the error is due to integer
rounding, this applies to very low delay values).| Modifier and Type | Class and Description |
|---|---|
static class |
DelayCalculator.Result |
| Modifier and Type | Field and Description |
|---|---|
static float |
DEFAULT_EPSILON
The default epsilon value (see
DelayCalculator). |
static long |
MAX_INTERVAL
The highest acceptable inverval.
|
| Modifier and Type | Method and Description |
|---|---|
static DelayCalculator.Result |
calculate(long nanoseconds)
Returns a result for the given delay in nanoseconds and the default
epsilon value (
DEFAULT_EPSILON). |
static DelayCalculator.Result |
calculate(long nanoseconds,
float epsilon)
Returns a result for the given delay and epsilon (error rate).
|
public static final float DEFAULT_EPSILON
DelayCalculator).public static final long MAX_INTERVAL
public static DelayCalculator.Result calculate(long nanoseconds)
DEFAULT_EPSILON).nanoseconds - The required delay in nanosecondspublic static DelayCalculator.Result calculate(long nanoseconds, float epsilon)
DelayCalculator for
details.nanoseconds - The required delay in nanosecondsepsilon - The permitted error (0 < epsilon < 1)Copyright © 2015. All rights reserved.