From 08152a6a6d640bac4a8455a9434be84c798eddcf Mon Sep 17 00:00:00 2001 From: David Reid Date: Sat, 4 Jan 2025 10:05:37 +1000 Subject: [PATCH] AAudio: Adjustments to a compatibility workaround. This change makes it so that setBufferCapacityInFrames() and setFramesPerDataCallback() can be opted-in if explicitly requested in the device config. This also adds back enableCompatibilityWorkarounds in order to prevent anyone's build from breaking when updating. This will be removed again in the 0.12 branch. --- miniaudio.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index 3d4b5ca8..20b61065 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -7119,6 +7119,7 @@ struct ma_device_config { ma_opensl_stream_type streamType; ma_opensl_recording_preset recordingPreset; + ma_bool32 enableCompatibilityWorkarounds; } opensl; struct { @@ -7127,6 +7128,8 @@ struct ma_device_config ma_aaudio_input_preset inputPreset; ma_aaudio_allowed_capture_policy allowedCapturePolicy; ma_bool32 noAutoStartAfterReroute; + ma_bool32 enableCompatibilityWorkarounds; + ma_bool32 allowSetBufferCapacity; } aaudio; }; @@ -37846,10 +37849,11 @@ static ma_result ma_create_and_configure_AAudioStreamBuilder__aaudio(ma_context* /* There have been reports where setting the frames per data callback results in an error. In particular, re-routing may inadvertently switch from low-latency mode, resulting in a less stable - stream from the legacy path (AudioStreamLegacy). To address this, we simply don't set the value. + stream from the legacy path (AudioStreamLegacy). To address this, we simply don't set the value. It + can still be set if it's explicitly requested via the aaudio.allowSetBufferCapacity variable in the + device config. */ - #if 0 - { + if ((!pConfig->aaudio.enableCompatibilityWorkarounds || ma_android_sdk_version() > 30) && pConfig->aaudio.allowSetBufferCapacity) { /* AAudio is annoying when it comes to its buffer calculation stuff because it doesn't let you retrieve the actual sample rate until after you've opened the stream. But you need to configure @@ -37862,7 +37866,6 @@ static ma_result ma_create_and_configure_AAudioStreamBuilder__aaudio(ma_context* ((MA_PFN_AAudioStreamBuilder_setBufferCapacityInFrames)pContext->aaudio.AAudioStreamBuilder_setBufferCapacityInFrames)(pBuilder, bufferCapacityInFrames); ((MA_PFN_AAudioStreamBuilder_setFramesPerDataCallback)pContext->aaudio.AAudioStreamBuilder_setFramesPerDataCallback)(pBuilder, bufferCapacityInFrames / pDescriptor->periodCount); } - #endif if (deviceType == ma_device_type_capture) { if (pConfig->aaudio.inputPreset != ma_aaudio_input_preset_default && pContext->aaudio.AAudioStreamBuilder_setInputPreset != NULL) {