From b646c07bf1dfeb61935faaab9381d3ca11d18282 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sun, 26 Jul 2026 21:22:37 -0500 Subject: [PATCH] Add method to get device index if using system default mode. --- Source/Engine/Audio/Audio.cpp | 14 ++++++++++++++ Source/Engine/Audio/Audio.h | 8 +++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Audio/Audio.cpp b/Source/Engine/Audio/Audio.cpp index 75645d4e8..ee71ec27d 100644 --- a/Source/Engine/Audio/Audio.cpp +++ b/Source/Engine/Audio/Audio.cpp @@ -120,6 +120,20 @@ int32 Audio::GetActiveDeviceIndex() return ActiveDeviceIndex; } +int32 Audio::GetActiveDeviceResolvedIndex() +{ + AudioDevice* active = GetActiveDevice(); + if (active != nullptr) + { + for (int32 i = 0; i < Devices.Count(); i++) + { + if (&Devices[i] == active) + return i; + } + } + return -1; +} + void Audio::SetActiveDeviceIndex(int32 index) { index = Math::Clamp(index, -1, Devices.Count() - 1); diff --git a/Source/Engine/Audio/Audio.h b/Source/Engine/Audio/Audio.h index 45a09df74..f9f03624b 100644 --- a/Source/Engine/Audio/Audio.h +++ b/Source/Engine/Audio/Audio.h @@ -61,11 +61,17 @@ public: API_PROPERTY() static AudioDevice* GetActiveDevice(); /// - /// Gets the index of the active device. + /// Gets the index of the active device. Returns -1 if set to system default mode. /// /// The active device index. API_PROPERTY() static int32 GetActiveDeviceIndex(); + /// + /// Gets the resolved index in Devices array of the device currently playing (resolves system default mode to the actual device index). + /// + /// The resolved active device index. + API_PROPERTY() static int32 GetActiveDeviceResolvedIndex(); + /// /// Sets the index of the active device. ///