audio: Fixed GetFirstAudioDeviceAdded().

It forgot to check for the type of device needed.
This commit is contained in:
Ryan C. Gordon
2023-11-01 00:39:51 -04:00
parent 0e614d9179
commit 759cdf6159

View File

@@ -761,9 +761,11 @@ static SDL_AudioDevice *GetFirstAddedAudioDevice(const SDL_bool iscapture)
void *iter = NULL;
while (SDL_IterateHashTable(current_audio.device_hash, &key, &value, &iter)) {
const SDL_AudioDeviceID devid = (SDL_AudioDeviceID) (uintptr_t) key;
// bit #0 of devid is set for output devices and unset for capture.
// bit #1 of devid is set for physical devices and unset for logical.
const SDL_bool isphysical = (devid & (1<<1)) ? SDL_TRUE : SDL_FALSE;
if (isphysical && (devid < highest)) {
const SDL_bool devid_iscapture = (devid & (1 << 0)) ? SDL_FALSE : SDL_TRUE;
const SDL_bool isphysical = (devid & (1 << 1)) ? SDL_TRUE : SDL_FALSE;
if (isphysical && (devid_iscapture == iscapture) && (devid < highest)) {
highest = devid;
retval = (SDL_AudioDevice *) value;
}