SDL: audio: Opening via a logical device ID should also track default device.

From d96a1db7d752ed99cba8c5da2f664f57b0981dcb Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Wed, 21 Jun 2023 00:05:10 -0400
Subject: [PATCH] audio: Opening via a logical device ID should also track
 default device.

As these will change devices as the default device changes, in the future,
we would want the original and new logical device to stay together.
---
 src/audio/SDL_audio.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 96fe7fa7decd..2c4748ffbeb2 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -1160,10 +1160,21 @@ SDL_AudioDeviceID SDL_OpenAudioDevice(SDL_AudioDeviceID devid, const SDL_AudioSp
         is_default = SDL_TRUE;
     }
 
+    // this will let you use a logical device to make a new logical device on the parent physical device. Could be useful?
+    SDL_AudioDevice *device = NULL;
+    const SDL_bool islogical = (devid & (1<<1)) ? SDL_FALSE : SDL_TRUE;
+    if (!islogical) {
+        device = ObtainPhysicalAudioDevice(devid);
+    } else {
+        SDL_LogicalAudioDevice *logdev = ObtainLogicalAudioDevice(devid);  // this locks the physical device, too.
+        if (logdev) {
+            is_default = logdev->is_default;  // was the original logical device meant to be a default? Make this one, too.
+            device = logdev->physical_device;
+        }
+    }
+
     SDL_AudioDeviceID retval = 0;
 
-    // this will let you use a logical device to make a new logical device on the parent physical device. Could be useful?
-    SDL_AudioDevice *device = ObtainPhysicalAudioDevice(devid);
     if (device) {
         SDL_LogicalAudioDevice *logdev = (SDL_LogicalAudioDevice *) SDL_calloc(1, sizeof (SDL_LogicalAudioDevice));
         if (!logdev) {