From dab7d5427b4754d02ad8d3b8ff60836c0158b12a Mon Sep 17 00:00:00 2001 From: Daniel Hammer Date: Sat, 24 Oct 2026 20:38:35 +0200 Subject: [PATCH] fix: fix Bluetooth audio delay --- kernel/src/Api/BuildNo.hpp | 2 +- kernel/src/Drivers/USB/Bluetooth/A2dp.cpp | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/kernel/src/Api/BuildNo.hpp b/kernel/src/Api/BuildNo.hpp index 8b446bd..39cdee0 100644 --- a/kernel/src/Api/BuildNo.hpp +++ b/kernel/src/Api/BuildNo.hpp @@ -12,4 +12,4 @@ #pragma once -#define MONTAUK_BUILD_NUMBER 23 +#define MONTAUK_BUILD_NUMBER 25 diff --git a/kernel/src/Drivers/USB/Bluetooth/A2dp.cpp b/kernel/src/Drivers/USB/Bluetooth/A2dp.cpp index aabfd6d..03b05ac 100644 --- a/kernel/src/Drivers/USB/Bluetooth/A2dp.cpp +++ b/kernel/src/Drivers/USB/Bluetooth/A2dp.cpp @@ -119,7 +119,15 @@ namespace Drivers::USB::Bluetooth::A2dp { // PCM ring between WriteAudio (producer, syscall context) and PumpMedia // (consumer, idle-loop/syscall context). Absolute byte counters wrapping // mod 2^32: fill = head - tail, buffer index = counter & (SIZE - 1). - constexpr uint32_t PCM_RING_SIZE = 128 * 1024; // ~0.68 s at 48 kHz stereo + // + // The ring's size IS output latency: the mixer pumps whenever it has + // room, so in steady state the ring sits full (silence included, while a + // stream is paused) and every pause, seek and volume change is heard only + // after it drains. It was 128 KiB (~0.68 s), which with LEAD_MS and the + // sink's own buffer put the headphones ~1 s behind the app. Stall + // tolerance comes from LEAD_MS at the sink plus the mixer's per-stream + // rings upstream, so this only needs to bridge the gap between pumps. + constexpr uint32_t PCM_RING_SIZE = 16 * 1024; // ~85 ms at 48 kHz stereo constexpr uint64_t LEAD_MS = 150; // sink jitter-buffer target static uint8_t g_pcmRing[PCM_RING_SIZE]; static std::atomic g_ringHead{0}; // producer: WriteAudio