From 4c578bc0033faf1022a2a6b37228e8eee63f636c Mon Sep 17 00:00:00 2001 From: Anshul Jain Date: Thu, 9 Jul 2026 00:18:01 +0530 Subject: [PATCH] Fix: Make WASAPI loopback buffer size adaptive to device capabilities The WASAPI loopback buffer was using a fixed size that could be incompatible with high-performance audio devices. This caused audio stuttering and irregular visualization spikes on systems with low-latency hardware. Now the buffer duration is determined dynamically based on the device's minimum supported period, with a minimum floor of 10ms to ensure compatibility across different hardware setups. Fixes #331 Signed-off-by: Anshul Jain --- audio-helper/Program.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/audio-helper/Program.cs b/audio-helper/Program.cs index acea3f2..f7433ff 100644 --- a/audio-helper/Program.cs +++ b/audio-helper/Program.cs @@ -123,11 +123,14 @@ public WasapiLoopbackCapture() (_sampleFormat, _bytesPerSample) = DetectSampleFormat(_mixFormatPointer, _mixFormat); _channelCount = _mixFormat.nChannels; + Marshal.ThrowExceptionForHR(_audioClient.GetDevicePeriod(out var defaultPeriod, out var minimumPeriod)); + var bufferDuration = Math.Max(minimumPeriod, TimeSpan.FromMilliseconds(10).Ticks); + Marshal.ThrowExceptionForHR( _audioClient.Initialize( AudioClientShareMode.Shared, AudioClientStreamFlags.Loopback, - 0, + bufferDuration, 0, _mixFormatPointer, IntPtr.Zero));