Interface IWaveLatency
Interface for audio players and captures that can report the latency between a sample entering the audio pipeline and emerging from (or being delivered by) the hardware. Implement alongside IWavePlayer or IWaveIn to let downstream code synchronise visualisations, lighting, video, recording timecode, or any other time-aligned consumer with audible output or captured input.
public interface IWaveLatency
Remarks
Latency values are only meaningful during uninterrupted operation. When the device is stopped or paused, or when an underrun has occurred, implementations should return their best steady-state estimate rather than throw — consumers driving visualisations need a stable value to fall back on.
The two properties answer different questions. AverageLatency describes the pipeline (it changes only when buffer settings change), so it is the right value for scheduling. CurrentLatency describes the live state of the pipeline at this instant and is the right value for drift detection or per-frame correction.
CurrentLatency may be computed either as the forward queue depth (e.g. WASAPI
GetCurrentPadding divided by sample rate — "if I queued a sample now, this is how
long until I'd hear it") or as the wall-clock age of the sample currently at the play /
capture head (timestamping each buffer fill). The two values converge in steady state and
diverge only under irregular feed patterns; this interface deliberately permits either,
so implementations can use whichever the underlying driver exposes most cheaply.
For drivers whose buffer scheduling is fully predictable (notably ASIO, which always swaps fixed-size buffers at regular intervals), CurrentLatency may simply return AverageLatency. The approximation is exact to within half a buffer.
Properties
AverageLatency
The steady-state latency from a sample being queued for output to it being emitted by the audio hardware, assuming uninterrupted playback. This is a property of the buffer configuration and the driver, not of the current playback state.
TimeSpan AverageLatency { get; }
Property Value
CurrentLatency
The time that has elapsed since the sample currently emerging from the hardware was queued for output. In steady state this is approximately equal to AverageLatency; it differs during start-up, after an underrun, or when the host is filling buffers irregularly. Implementations that cannot meaningfully distinguish from the average are permitted to return AverageLatency.
TimeSpan CurrentLatency { get; }