pub struct RoundTripMeasurementState {
pub phase: RoundTripMeasurementPhase,
pub threshold: f32,
pub impulse_sent_at: Option<Instant>,
/* private fields */
}Expand description
All mutable state required to run one complete round-trip measurement session.
RoundTripMeasurementState is entirely owned by the session thread — there is no
shared ownership, no Arc, and no locking. It is driven sample-by-sample through
tick until a terminal outcome is reached.
Fields§
§phase: RoundTripMeasurementPhaseCurrent phase in the calibration/measurement lifecycle.
threshold: f32Derived amplitude threshold an incoming sample must exceed to be accepted as an echo.
Set at the end of CalibrationAmbient and held constant for the rest of the session.
impulse_sent_at: Option<Instant>Wall-clock time at which the currently active impulse was written to the output buffer.
None before the first impulse is emitted and between echo detection and the next
impulse emission. The elapsed time from this instant to echo detection is the raw
round-trip duration.
Implementations§
Source§impl RoundTripMeasurementState
impl RoundTripMeasurementState
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a fresh measurement state, starting in CalibrationAmbient phase.
All counters are zeroed and no impulse timer is active. The first call to tick
will begin consuming ambient samples.
Sourcepub fn tick(
&mut self,
sample: f32,
push_output: &mut impl FnMut(f32) -> bool,
per_impulse_timeout: Duration,
) -> RoundTripTickOutcome
pub fn tick( &mut self, sample: f32, push_output: &mut impl FnMut(f32) -> bool, per_impulse_timeout: Duration, ) -> RoundTripTickOutcome
Advances the measurement state machine by one input sample.
This is the core driver of the entire measurement protocol. The caller must invoke it for every sample that arrives from the input ring buffer.
§Arguments
sample— The rawf32sample captured from the audio input.push_output— A closure that writes onef32value to the output ring buffer and returnstrueif the push succeeded. The state machine uses this to emit either silence (0.0) or the test impulse (IMPULSE_AMPLITUDE).per_impulse_timeout— How long to wait for an echo after each impulse before declaring a timeout.
§State machine transitions
| Current phase | Event | Next phase |
|---|---|---|
CalibrationAmbient | CALIBRATION_SAMPLES consumed | WaitingForEcho(0) |
WaitingForEcho(n) | Impulse push succeeds | (same, timer armed) |
WaitingForEcho(n) | Echo detected, more impulses remain | WaitingForEcho(n+1) |
WaitingForEcho(n) | Echo detected, all impulses done | Idle → Complete |
WaitingForEcho(n) | Deadline exceeded | Idle → TimedOut |
§Returns
A RoundTripTickOutcome indicating whether the session should continue, has
finished successfully, or has timed out.