Audio Sample Clock Drift: Measure and Correct Accumulating Timing Error
Independent audio devices can run at slightly different real sample rates even when both say 48 kHz. Their relative timing then drifts over time. Measure the lag slope, distinguish it from a fixed offset or jitter, and use a shared clock or adaptive sample-rate conversion to correct it.
Sample clock drift occurs when unsynchronized devices generate or consume samples at slightly different rates, so their streams move out of alignment over time. Two files can both be labeled 48 kHz while their real capture or playback clocks differ. Unlike a fixed starting delay, drift accumulates; long-running streams may need a shared clock or asynchronous sample-rate conversion (ASRC).
Cause and similar timing errors
Real oscillators are never perfectly identical. Their relative frequency error is commonly expressed in parts per million (ppm). A 100 ppm difference corresponds to about 100 microseconds of timing change per second. At 16 kHz, that is about 1.6 samples per second, or about 60 ms and 960 samples over 10 minutes. This is arithmetic based on the 100 ppm example in an INTERSPEECH 2024 paper, not a measurement of a particular device. Nayak & Shaik, INTERSPEECH 2024
A 30 ms delay that stays constant is a fixed offset. A lag that grows or shrinks over time indicates rate drift. Rapid irregular changes may be jitter or another time variation. A fixed offset can be aligned once; drift requires ongoing rate matching.
Estimate drift from lag change
Compare the relative lag of the same recognizable reference signal near the start and end:
Drift (ppm) = (end lag − start lag) / elapsed time × 1,000,000
Accumulated sample difference = lag change in seconds × sample rate in hertz
If the lag is 4 ms at the start and 64 ms after 10 minutes, it changed by 60 ms. A change of 0.06 seconds over 600 seconds is 100 ppm. At 16 kHz, 0.06 × 16,000 = 960 samples. Record which device is the reference and the sign convention, because the sign determines which clock is faster.
This estimate assumes both lag measurements are reliable and refer to the same signal. Room reflections, a moving talker, wireless latency changes, and packet loss can affect lag estimates. Use a controlled pulse/chirp or shared timestamps and check several points for a persistent slope.
Symptoms
A real-time buffer gradually fills or empties when its producer and consumer run at different rates, causing overrun or underrun.
Long recordings from separate devices align at first but diverge later.
Microphone-array channels with independent clocks lose relative timing or phase alignment, affecting beamforming and analysis.
A playback reference and microphone capture can slowly change their timing relationship, reducing echo-canceller alignment. A 2024 study examines clock drift between wireless playback and a smart device in asynchronous echo cancellation; its findings are specific to that setup. [Nayak & Shaik](https://www.isca-archive.org/interspeech_2024/nayak24b_interspeech.pdf)
Aligning streams once at startup or clearing a buffer does not continuously correct real-time drift. If device clocks remain independent, the error can build again.
Measure and correct
**Choose a reference clock.** Use a shared hardware clock or device synchronization feature when available.
**Record a repeatable reference.** Capture the same identifiable click, pulse, or chirp at the beginning, middle, and end. For acoustic tests, keep speaker and microphone positions fixed.
**Estimate lag at multiple times.** Use cross-correlation or known timestamps. Separate a steady slope from short irregular fluctuation; do not set a correction ratio from one measurement.
**Record the trend.** Log sample rate, elapsed time, start/end lags, reference device, sign convention, and estimated ppm. Repeat the recording to see whether the trend is consistent.
**Choose a correction path.** Connect devices to a common hardware clock if possible. Otherwise, use ASRC or system adaptive resampling to adjust one stream’s effective rate gradually to the reference. For offline files, resample one stream against the reference signal. Changing only the sample-rate number in a file header is not a correction.
**Verify afterward.** Check that the residual lag stays stable and the accumulated error is smaller in a long recording. Listen for clicks, dropouts, pitch changes, buffer problems, and quality loss.
PipeWire documentation notes that adaptive resampling may be needed when hardware and graph clocks differ. It also says that in a Pro Audio profile, nodes from one device may be assumed to share a clock and linked streams may not be resampled; this behavior is specific to PipeWire configuration. PipeWire clock and resampling documentation
Common misdiagnoses and recovery
**Mistaking initial delay for drift:** compare start and end lag. Align a constant offset once; correct the clock-rate relationship when lag grows.
**Changing metadata only:** playback speed or pitch can change. Preserve the original samples and apply actual resampling/ASRC.
**Measuring at only one point:** the result may be jitter or timestamp error. Estimate the trend from several reference signals.
**Correcting each channel independently:** this can damage inter-channel phase and arrival-time relationships. Keep channels that must remain synchronized on a common reference and verify residual alignment.
The key is the changing rate between real device clocks, not the nominal sample-rate label. Measure the lag slope, correct with a shared clock or adaptive conversion, then check that long-term drift has decreased.
References
Premanand Nayak & M. Ali Basha Shaik, [INTERSPEECH 2024 paper](https://www.isca-archive.org/interspeech_2024/nayak24b_interspeech.pdf).
Hannes Gamper, [Clock drift estimation and compensation for asynchronous impulse response measurements](https://www.microsoft.com/en-us/research/wp-content/uploads/2017/03/Clock_drift_estimation_HSCMA_2017.pdf).
[PipeWire pipewire-props: clock.name and adaptive resampling](https://docs.pipewire.org/page_man_pipewire-props_7.html)