From cbb297622344dda8f4641bde6c40061ac61e4868 Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Thu, 21 Mar 2024 16:40:30 -0700 Subject: [PATCH] audio: Adjust stream buffer size calculation When calculating buffer size, use powers of two for "large" buffers only on SRs >= 44100 Hz. With lower SRs, sizes rounded up to a multiple of 2 give too high latency. Bug: 328432688 Test: repro steps from b/328432688#comment3 Test: atest VtsHalAudioCoreTargetTest Change-Id: I605ef8507fef030d349e85c33ed0229c9566ddb5 --- audio/aidl/default/include/core-impl/Module.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/audio/aidl/default/include/core-impl/Module.h b/audio/aidl/default/include/core-impl/Module.h index d6e89053d9..a326217904 100644 --- a/audio/aidl/default/include/core-impl/Module.h +++ b/audio/aidl/default/include/core-impl/Module.h @@ -213,7 +213,7 @@ class Module : public BnModule { sampleRateHz); // Round up to nearest 16 frames since in the framework this is the size of a mixer burst. const int32_t multipleOf16 = (rawSizeFrames + 15) & ~15; - if (multipleOf16 <= 512) return multipleOf16; + if (sampleRateHz < 44100 || multipleOf16 <= 512) return multipleOf16; // Larger buffers should use powers of 2. int32_t powerOf2 = 1; while (powerOf2 < multipleOf16) powerOf2 <<= 1;