@@ -1523,8 +1523,10 @@ SDL_AudioDevice *SDL_FindPhysicalAudioDeviceByHandle(void *handle)
1523
1523
1524
1524
const char * SDL_GetAudioDeviceName (SDL_AudioDeviceID devid )
1525
1525
{
1526
+ // bit #1 of devid is set for physical devices and unset for logical.
1527
+ const bool islogical = !(devid & (1 <<1 ));
1526
1528
const char * result = NULL ;
1527
- SDL_AudioDevice * device = NULL ;
1529
+ const void * vdev = NULL ;
1528
1530
1529
1531
if (!SDL_GetCurrentAudioDriver ()) {
1530
1532
SDL_SetError ("Audio subsystem is not initialized" );
@@ -1534,10 +1536,14 @@ const char *SDL_GetAudioDeviceName(SDL_AudioDeviceID devid)
1534
1536
// remains valid (in case the device is unplugged at the wrong moment), we hold the
1535
1537
// device_hash_lock while we copy the string.
1536
1538
SDL_LockRWLockForReading (current_audio .device_hash_lock );
1537
- SDL_FindInHashTable (current_audio .device_hash , (const void * ) (uintptr_t ) devid , ( const void * * ) & device );
1538
- if (!device ) {
1539
+ SDL_FindInHashTable (current_audio .device_hash , (const void * ) (uintptr_t ) devid , & vdev );
1540
+ if (!vdev ) {
1539
1541
SDL_SetError ("Invalid audio device instance ID" );
1542
+ } else if (islogical ) {
1543
+ const SDL_LogicalAudioDevice * logdev = (const SDL_LogicalAudioDevice * ) vdev ;
1544
+ result = SDL_GetPersistentString (logdev -> physical_device -> name );
1540
1545
} else {
1546
+ const SDL_AudioDevice * device = (const SDL_AudioDevice * ) vdev ;
1541
1547
result = SDL_GetPersistentString (device -> name );
1542
1548
}
1543
1549
SDL_UnlockRWLock (current_audio .device_hash_lock );
0 commit comments