rustriff_lib/services/round_trip_latency_session/constants.rs
1//! Tuning constants for the round-trip latency measurement protocol.
2//!
3//! All values here are deliberately centralised so that changing the measurement
4//! behaviour requires touching exactly one file.
5
6use std::time::Duration;
7
8/// Number of input samples collected during the ambient calibration phase.
9///
10/// At 44 100 Hz this is roughly 11 ms of listening time — long enough to capture
11/// a representative noise-floor peak without delaying the measurement significantly.
12pub const CALIBRATION_SAMPLES: usize = 512;
13
14/// Number of impulse/echo cycles to run per measurement session.
15///
16/// The final reported latency is the arithmetic mean of all [`IMPULSE_COUNT`] individual
17/// round-trip measurements, which reduces the impact of single-callback scheduling jitter.
18pub const IMPULSE_COUNT: usize = 3;
19
20/// Number of input samples to ignore immediately after emitting an impulse.
21///
22/// Electrical bleed-through and the outgoing impulse itself can appear on the input within
23/// microseconds of being written. Skipping these samples prevents a false-positive detection
24/// before the signal has had time to traverse the physical audio path.
25///
26/// At 44 100 Hz this guard window is approximately 11 ms.
27pub const GUARD_SAMPLES: usize = 512;
28
29/// Minimum quiet time enforced between consecutive impulses.
30///
31/// After an echo is detected the previous impulse's reverb tail may still be decaying.
32/// Waiting [`INTER_IMPULSE_GAP`] before the next emission prevents that tail from being
33/// mistaken for the next echo.
34pub const INTER_IMPULSE_GAP: Duration = Duration::from_millis(200);
35
36/// Peak amplitude of the synthetic test impulse written to the output ring buffer.
37///
38/// A near-full-scale value is used so the echo stands well above the noise floor even after
39/// passing through lossy physical paths. The detection threshold is clamped to at most
40/// `IMPULSE_AMPLITUDE * 0.5` so that a valid echo is always detectable.
41pub const IMPULSE_AMPLITUDE: f32 = 0.95;