@@ -367,14 +367,28 @@ static SDL_AudioDeviceID AssignAudioDeviceInstanceId(bool recording, bool islogi
367
367
368
368
bool SDL_IsAudioDevicePhysical (SDL_AudioDeviceID devid )
369
369
{
370
+ // bit #1 of devid is set for physical devices and unset for logical.
370
371
return (devid & (1 << 1 )) != 0 ;
371
372
}
372
373
374
+ bool SDL_IsAudioDeviceLogical (SDL_AudioDeviceID devid )
375
+ {
376
+ // bit #1 of devid is set for physical devices and unset for logical.
377
+ return (devid & (1 << 1 )) == 0 ;
378
+ }
379
+
373
380
bool SDL_IsAudioDevicePlayback (SDL_AudioDeviceID devid )
374
381
{
382
+ // bit #0 of devid is set for playback devices and unset for recording.
375
383
return (devid & (1 << 0 )) != 0 ;
376
384
}
377
385
386
+ bool SDL_IsAudioDeviceRecording (SDL_AudioDeviceID devid )
387
+ {
388
+ // bit #0 of devid is set for playback devices and unset for recording.
389
+ return (devid & (1 << 0 )) == 0 ;
390
+ }
391
+
378
392
static void ObtainPhysicalAudioDeviceObj (SDL_AudioDevice * device ) SDL_NO_THREAD_SAFETY_ANALYSIS // !!! FIXMEL SDL_ACQUIRE
379
393
{
380
394
if (device ) {
@@ -405,9 +419,7 @@ static SDL_LogicalAudioDevice *ObtainLogicalAudioDevice(SDL_AudioDeviceID devid,
405
419
SDL_AudioDevice * device = NULL ;
406
420
SDL_LogicalAudioDevice * logdev = NULL ;
407
421
408
- // bit #1 of devid is set for physical devices and unset for logical.
409
- const bool islogical = !(devid & (1 <<1 ));
410
- if (islogical ) { // don't bother looking if it's not a logical device id value.
422
+ if (SDL_IsAudioDeviceLogical (devid )) { // don't bother looking if it's not a logical device id value.
411
423
SDL_LockRWLockForReading (current_audio .subsystem_rwlock );
412
424
SDL_FindInHashTable (current_audio .device_hash_logical , (const void * ) (uintptr_t ) devid , (const void * * ) & logdev );
413
425
if (logdev ) {
@@ -452,9 +464,7 @@ static SDL_AudioDevice *ObtainPhysicalAudioDevice(SDL_AudioDeviceID devid) // !
452
464
{
453
465
SDL_AudioDevice * device = NULL ;
454
466
455
- // bit #1 of devid is set for physical devices and unset for logical.
456
- const bool islogical = !(devid & (1 <<1 ));
457
- if (islogical ) {
467
+ if (SDL_IsAudioDeviceLogical (devid )) {
458
468
ObtainLogicalAudioDevice (devid , & device );
459
469
} else if (!SDL_GetCurrentAudioDriver ()) { // (the `islogical` path, above, checks this in ObtainLogicalAudioDevice.)
460
470
SDL_SetError ("Audio subsystem is not initialized" );
@@ -879,12 +889,8 @@ static bool SDLCALL FindLowestDeviceID(void *userdata, const SDL_HashTable *tabl
879
889
{
880
890
FindLowestDeviceIDData * data = (FindLowestDeviceIDData * ) userdata ;
881
891
const SDL_AudioDeviceID devid = (SDL_AudioDeviceID ) (uintptr_t ) key ;
882
- // bit #0 of devid is set for playback devices and unset for recording.
883
- // bit #1 of devid is set for physical devices and unset for logical.
884
- const bool devid_recording = !(devid & (1 << 0 ));
885
- const bool isphysical = !!(devid & (1 << 1 ));
886
- SDL_assert (isphysical ); // should only be iterating device_hash_physical.
887
- if ((devid_recording == data -> recording ) && (devid < data -> highest )) {
892
+ SDL_assert (SDL_IsAudioDevicePhysical (devid )); // should only be iterating device_hash_physical.
893
+ if ((SDL_IsAudioDeviceRecording (devid ) == data -> recording ) && (devid < data -> highest )) {
888
894
data -> highest = devid ;
889
895
data -> result = (SDL_AudioDevice * ) value ;
890
896
SDL_assert (data -> result -> instance_id == devid );
@@ -1065,10 +1071,8 @@ bool SDL_InitAudio(const char *driver_name)
1065
1071
1066
1072
static bool SDLCALL DestroyOnePhysicalAudioDevice (void * userdata , const SDL_HashTable * table , const void * key , const void * value )
1067
1073
{
1068
- // bit #1 of devid is set for physical devices and unset for logical.
1069
1074
const SDL_AudioDeviceID devid = (SDL_AudioDeviceID ) (uintptr_t ) key ;
1070
- const bool isphysical = !!(devid & (1 <<1 ));
1071
- SDL_assert (isphysical );
1075
+ SDL_assert (SDL_IsAudioDevicePhysical (devid )); // should only be iterating device_hash_physical.
1072
1076
SDL_AudioDevice * dev = (SDL_AudioDevice * ) value ;
1073
1077
SDL_assert (dev -> instance_id == devid );
1074
1078
DestroyPhysicalAudioDevice (dev );
@@ -1428,12 +1432,8 @@ static bool SDLCALL CountAudioDevices(void *userdata, const SDL_HashTable *table
1428
1432
{
1429
1433
CountAudioDevicesData * data = (CountAudioDevicesData * ) userdata ;
1430
1434
const SDL_AudioDeviceID devid = (SDL_AudioDeviceID ) (uintptr_t ) key ;
1431
- // bit #0 of devid is set for playback devices and unset for recording.
1432
- // bit #1 of devid is set for physical devices and unset for logical.
1433
- const bool devid_recording = !(devid & (1 <<0 ));
1434
- const bool isphysical = !!(devid & (1 <<1 ));
1435
- SDL_assert (isphysical );
1436
- if (devid_recording == data -> recording ) {
1435
+ SDL_assert (SDL_IsAudioDevicePhysical (devid )); // should only be iterating device_hash_physical.
1436
+ if (SDL_IsAudioDeviceRecording (devid ) == data -> recording ) {
1437
1437
SDL_assert (data -> devs_seen < data -> num_devices );
1438
1438
SDL_AudioDevice * device = (SDL_AudioDevice * ) value ; // this is normally risky, but we hold the subsystem_rwlock here.
1439
1439
const bool zombie = SDL_GetAtomicInt (& device -> zombie ) != 0 ;
@@ -1500,9 +1500,7 @@ static bool SDLCALL FindAudioDeviceByCallback(void *userdata, const SDL_HashTabl
1500
1500
{
1501
1501
FindAudioDeviceByCallbackData * data = (FindAudioDeviceByCallbackData * ) userdata ;
1502
1502
const SDL_AudioDeviceID devid = (SDL_AudioDeviceID ) (uintptr_t ) key ;
1503
- // bit #1 of devid is set for physical devices and unset for logical.
1504
- const bool isphysical = !!(devid & (1 <<1 ));
1505
- SDL_assert (isphysical );
1503
+ SDL_assert (SDL_IsAudioDevicePhysical (devid )); // should only be iterating device_hash_physical.
1506
1504
SDL_AudioDevice * device = (SDL_AudioDevice * ) value ;
1507
1505
if (data -> callback (device , data -> userdata )) { // found it?
1508
1506
data -> retval = device ;
@@ -1545,13 +1543,14 @@ SDL_AudioDevice *SDL_FindPhysicalAudioDeviceByHandle(void *handle)
1545
1543
const char * SDL_GetAudioDeviceName (SDL_AudioDeviceID devid )
1546
1544
{
1547
1545
// bit #1 of devid is set for physical devices and unset for logical.
1548
- const bool islogical = !(devid & (1 <<1 ));
1549
1546
const char * result = NULL ;
1550
- const void * vdev = NULL ;
1551
1547
1552
1548
if (!SDL_GetCurrentAudioDriver ()) {
1553
1549
SDL_SetError ("Audio subsystem is not initialized" );
1554
1550
} else {
1551
+ const bool islogical = SDL_IsAudioDeviceLogical (devid );
1552
+ const void * vdev = NULL ;
1553
+
1555
1554
// This does not call ObtainPhysicalAudioDevice() because the device's name never changes, so
1556
1555
// it doesn't have to lock the whole device. However, just to make sure the device pointer itself
1557
1556
// remains valid (in case the device is unplugged at the wrong moment), we hold the
@@ -1844,8 +1843,7 @@ SDL_AudioDeviceID SDL_OpenAudioDevice(SDL_AudioDeviceID devid, const SDL_AudioSp
1844
1843
1845
1844
// this will let you use a logical device to make a new logical device on the parent physical device. Could be useful?
1846
1845
SDL_AudioDevice * device = NULL ;
1847
- const bool islogical = (!wants_default && !(devid & (1 <<1 )));
1848
- if (!islogical ) {
1846
+ if ((wants_default || SDL_IsAudioDevicePhysical (devid ))) {
1849
1847
device = ObtainPhysicalAudioDeviceDefaultAllowed (devid );
1850
1848
} else {
1851
1849
SDL_LogicalAudioDevice * logdev = ObtainLogicalAudioDevice (devid , & device );
@@ -1982,7 +1980,6 @@ bool SDL_SetAudioPostmixCallback(SDL_AudioDeviceID devid, SDL_AudioPostmixCallba
1982
1980
1983
1981
bool SDL_BindAudioStreams (SDL_AudioDeviceID devid , SDL_AudioStream * const * streams , int num_streams )
1984
1982
{
1985
- const bool islogical = !(devid & (1 <<1 ));
1986
1983
SDL_AudioDevice * device = NULL ;
1987
1984
SDL_LogicalAudioDevice * logdev = NULL ;
1988
1985
bool result = true;
@@ -1993,7 +1990,7 @@ bool SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream * const *stre
1993
1990
return SDL_InvalidParamError ("num_streams" );
1994
1991
} else if (!streams ) {
1995
1992
return SDL_InvalidParamError ("streams" );
1996
- } else if (! islogical ) {
1993
+ } else if (SDL_IsAudioDevicePhysical ( devid ) ) {
1997
1994
return SDL_SetError ("Audio streams are bound to device ids from SDL_OpenAudioDevice, not raw physical devices" );
1998
1995
}
1999
1996
@@ -2600,7 +2597,7 @@ void SDL_UpdateAudio(void)
2600
2597
SDL_zero (event );
2601
2598
event .type = i -> type ;
2602
2599
event .adevice .which = (Uint32 ) i -> devid ;
2603
- event .adevice .recording = (( i -> devid & ( 1 << 0 )) == 0 ); // bit #0 of devid is set for playback devices and unset for recording.
2600
+ event .adevice .recording = SDL_IsAudioDeviceRecording ( i -> devid ); // bit #0 of devid is set for playback devices and unset for recording.
2604
2601
SDL_PushEvent (& event );
2605
2602
}
2606
2603
SDL_free (i );
0 commit comments