Skip to main content

Module timing

Module timing 

Source
Expand description

Estimating sample acquisition times from packet arrival times.

A packet carrying samples n .. n+k cannot arrive before its last sample was acquired, and Bluetooth only adds delay. So, for a stream sampled at a steady rate, the true clock t(n) = a + b·n is the lower envelope of (index of last sample, arrival time): arrivals lie on or above it. fit_lower_envelope finds that line by iteratively refitting least squares to the earliest-arriving packets. 1/b is the measured sample rate; residuals are the delivery latency beyond the minimum (jitter).

Structs§

ClockFit
A fitted clock for one uninterrupted segment of one stream.
Placed
Where a packet’s samples sit within a stream: which uninterrupted segment, and the index of its first sample in that segment.
Segmenter
Assigns packets of one stream to segments and sample indices, one packet at a time.

Functions§

fit_lower_envelope
Fits the lower envelope of (last_sample_index, arrival_unix_s) pairs. With fewer than 20 packets, the nominal period is used and only the offset is fitted.
fit_nominal
Fits only the offset, taking the sample rate as nominal_rate_hz. For when there is too little data to trust a fitted rate.