Skip to main content
Technical Deep Dive

How Multiout Solves Audio Clock Drift

Why routing audio to two soundcards is physically difficult, and how our closed-loop PI resampler and per-device delay lines achieve glitch-free synchronization.

Real-Time Control Loop

Multiout Audio Routing & Clock Drift Architecture

How Multiout routes one stream across unsynchronized DAC crystal clocks without buffer underrun crackles or latency lag.

🔊System AudioDesktop sound, browser,VLC, Spotify, games48,000 Hz · Stereomultiout Core Engine (Go + miniaudio)WASAPI / PipeWire Loopback CaptureZero-copy capture into lock-free atomic ring buffersClosed-Loop PI Drift Controller• Exponential Moving Average (EMA) fill-level filter• Fractional resampler steers within ±5000 ppmPer-Device Latency Delay Sync (0–300 ms)Aligns Bluetooth codec delay (120ms) with wired 3.5mmLogarithmic Decibel Volume (-60 dB to +12 dB)🎧Wired EarphonesPhysical DAC: 3.5 mm JackHardware Clock: 48,001 HzAdded +120ms delay · Zero crackle📶Bluetooth HeadsetWireless Codec: LDAC / AACHardware Clock: 47,998 HzPI Resampled: -42 ppm · Zero drift
1. Clock Drift EliminatedHardware crystals drift apart by tens of Hertz. The PI controller resamples continuously within ±5000 ppm so buffers never starve or overflow.
2. Latency Mismatch SolvedBluetooth packets lag by 80–200ms. Multiout applies millisecond delay lines to low-latency devices, bringing dialogue in sync.
3. Zero-Allocation RealtimeThe audio engine uses lock-free atomic ring buffers with 0.0 heap allocations during streaming, preventing garbage collection stutter.

01The Physics of Hardware Clock Drift

Every audio device plugged into your computer—whether a 3.5 mm motherboard DAC, a USB gaming headset, or a Bluetooth transmitter—relies on an independent physical quartz crystal oscillator to clock its Digital-to-Analog Converter (DAC).

Even when both devices are configured at a standard sample rate of 48,000 Hz, temperature variations, manufacturing tolerances, and voltage fluctuations ensure that neither runs at precisely 48,000.000 Hz. One device might consume samples at 48,001.2 Hz while the second consumes at 47,998.7 Hz.

The Mathematical Consequence
Drift Rate = 48,001.2 - 47,998.7 = 2.5 samples per second
In 10 minutes: 2.5 × 600 = 1,500 samples discrepancy (~31.25 milliseconds)
Without active correction, the faster soundcard drains its buffer completely (buffer underrun), resulting in loud popping/crackling audio artifacts. Meanwhile, the slower soundcard builds up latency or drops samples (buffer overrun).

02Closed-Loop Proportional-Integral (PI) Resampling

Multiout treats clock synchronization as a real-time feedback control system. Rather than crudely dropping or duplicating audio frames, Multiout tracks the fill level of each output device's ring buffer:

  • Exponential Moving Average (EMA) Low-Pass Filter: Filters out high-frequency jitter caused by thread scheduling and operating system buffer dispatch cycles, deriving the true long-term buffer trend.
  • Proportional-Integral (PI) Controller: Computes the error between the target buffer midpoint and the filtered fill level. The proportional term reacts to sudden drift, while the integral term cancels steady-state frequency errors.
  • Fractional Linear Resampler: Continuously modulates the resampling ratio within a narrow window of ±5000 ppm (±0.5%). Because the speed adjustment is micro-scale, it is completely imperceptible to the human ear with zero pitch warble.

03Per-Device Delay Alignment for Bluetooth Lag

Clock drift is only half the battle. If you connect one wired earphone via a 3.5 mm jack and one wireless earbud via Bluetooth, you will immediately notice an annoying room echo.

This happens because Bluetooth audio codecs (such as SBC, AAC, or LDAC) require packetization, radio transmission, and receiver decompression, introducing 80 ms to 200 ms of latency. The analog jack, by contrast, has virtually zero latency (sub-5 ms).

Multiout incorporates a dedicated 0 to 300 ms millisecond delay line for each output channel. By adding a 120 ms buffer to the low-latency wired output, both listeners hear explosions, dialogue, and beats at the exact same millisecond.

04Zero-Allocation Real-Time Audio Architecture

Many audio utilities written in high-level managed languages suffer from micro-stutter when the runtime garbage collector triggers a heap sweep.

Multiout is engineered in Go and miniaudio with a strict zero-allocation real-time design pattern:

Lock-Free Atomic Rings
Audio callbacks push and pop PCM frames using single-producer single-consumer lock-free atomic pointers, preventing OS thread blocking.
0.0 Heap Allocs During Streaming
All intermediate audio buffers, resampler states, and delay lines are pre-allocated during device initialization. Zero garbage collection pressure.

Experience Clock-Synchronized Audio

Download Multiout today for Windows and Linux. Plug in your headphones and enjoy perfect sync.

SS
Built by Sagar Sharma·@codesbysagar

Go backend and systems developer. Passionate about real-time audio synchronization and lightweight software.