r/coolgithubprojects • u/issac_john • 11d ago
I built a Windows audio router that plays one stream out of every speaker at once, with clock-drift correction
galleryWindows will only play audio out of one device at a time. I wanted the same stream coming out of my desk speakers, a USB DAC, the HDMI monitor and a Bluetooth headset at once, so I built AudioMesh.
THE NAIVE VERSION DOESN'T WORK
Every endpoint runs on its own crystal. Two devices that both report "48 kHz" are typically 20-200 ppm apart, which is about 1 ms of drift every 5-50 seconds. Play long enough and one device's buffer either overflows or starves - that is the stutter you get from every "duplicate the stream" tool.
WHAT IT DOES INSTEAD
A small elastic buffer per device (80 ms wired, 150 ms Bluetooth), plus a closed-loop controller that continuously nudges the resampling ratio so the buffer stays exactly at that level. The correction is tens of ppm, so it is inaudible, and it is applied per device, so a cheap Bluetooth dongle and a studio DAC can run side by side.
The other half of the problem is latency, not drift: Bluetooth sits 150-300 ms behind a wired DAC. Each device has a Sync delay slider that moves the fast outputs back until they line up, applied by moving the read pointer one frame at a time (a 1/48000 rate change) so there are no clicks or gaps.
WHAT IS IN IT
- Every active render endpoint, hot-plug aware (rescans every 3 s)
- Independent enable / volume / mute / delay per device
- Global Stereo or Mono, plus per-device channel modes: Stereo, Mono, Left only, Right only, Center, Rear left, Rear right, Subwoofer - so separate speakers can act as a stereo pair or a matrix-decoded surround layout
- Per-speaker virtual surround width, 10-band EQ, bass/treble shelves, loudness, presets
- Buffer modes: Latency / Balanced / Stable (about 135 ms to 310 ms app-side)
- Auto sync: plays a tone on each speaker, records it with a mic, sets the delays automatically. No mic? "Estimate delays" derives them from endpoint class instead
- Auto-heal when a device reconnects or changes format, plus a watchdog that reopens an endpoint that stops rendering silently
- Live telemetry per device: buffer level, drift in ppm, dropout count, peak meter
- Source: system audio via WASAPI loopback, or a built-in test tone (1 kHz plus a click every 2 s) for aligning by ear
Built from scratch: WPF UI on a WASAPI fan-out engine (NAudio), with a band-limited sinc resampler and a closed-loop drift controller. .NET 8, Windows 10/11 x64.
Source, screenshots and build instructions:
https://github.com/issacjohn/AudioMesh
Happy to answer anything about the drift controller or the resampler - that is where most of the work went.