Skip to main content

RoundTripMeasurementState

Struct RoundTripMeasurementState 

Source
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: RoundTripMeasurementPhase

Current phase in the calibration/measurement lifecycle.

§threshold: f32

Derived 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

Source

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.

Source

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 raw f32 sample captured from the audio input.
  • push_output — A closure that writes one f32 value to the output ring buffer and returns true if 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 phaseEventNext phase
CalibrationAmbientCALIBRATION_SAMPLES consumedWaitingForEcho(0)
WaitingForEcho(n)Impulse push succeeds(same, timer armed)
WaitingForEcho(n)Echo detected, more impulses remainWaitingForEcho(n+1)
WaitingForEcho(n)Echo detected, all impulses doneIdleComplete
WaitingForEcho(n)Deadline exceededIdleTimedOut
§Returns

A RoundTripTickOutcome indicating whether the session should continue, has finished successfully, or has timed out.

Trait Implementations§

Source§

impl Default for RoundTripMeasurementState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Any for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

§

impl<T> AnySync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> NoneValue for T
where T: Default,

§

type NoneType = T

§

fn null_value() -> T

The none-equivalent value.
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,