mirror of
https://github.com/Ryujinx/SDL.git
synced 2024-12-23 10:55:33 +00:00
cleanup SDL_GetAudioDeviceSpec
- drop unnecessary hascapture check - call SDL_InvalidParamError and return -1 in case the index is out of range - do not zfill SDL_AudioSpec - adjust documentation to reflect the behavior
This commit is contained in:
parent
113109f839
commit
3939ef72f8
|
@ -500,9 +500,7 @@ extern DECLSPEC const char *SDLCALL SDL_GetAudioDeviceName(int index,
|
||||||
* hardware.
|
* hardware.
|
||||||
*
|
*
|
||||||
* `spec` will be filled with the sample rate, sample format, and channel
|
* `spec` will be filled with the sample rate, sample format, and channel
|
||||||
* count. All other values in the structure are filled with 0. When the
|
* count.
|
||||||
* supported struct members are 0, SDL was unable to get the property from the
|
|
||||||
* backend.
|
|
||||||
*
|
*
|
||||||
* \param index the index of the audio device; valid values range from 0 to
|
* \param index the index of the audio device; valid values range from 0 to
|
||||||
* SDL_GetNumAudioDevices() - 1
|
* SDL_GetNumAudioDevices() - 1
|
||||||
|
|
|
@ -1112,38 +1112,33 @@ SDL_GetAudioDeviceName(int index, int iscapture)
|
||||||
int
|
int
|
||||||
SDL_GetAudioDeviceSpec(int index, int iscapture, SDL_AudioSpec *spec)
|
SDL_GetAudioDeviceSpec(int index, int iscapture, SDL_AudioSpec *spec)
|
||||||
{
|
{
|
||||||
|
SDL_AudioDeviceItem *item;
|
||||||
|
int i, retval;
|
||||||
|
|
||||||
if (spec == NULL) {
|
if (spec == NULL) {
|
||||||
return SDL_InvalidParamError("spec");
|
return SDL_InvalidParamError("spec");
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_zerop(spec);
|
|
||||||
|
|
||||||
if (!SDL_GetCurrentAudioDriver()) {
|
if (!SDL_GetCurrentAudioDriver()) {
|
||||||
return SDL_SetError("Audio subsystem is not initialized");
|
return SDL_SetError("Audio subsystem is not initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iscapture && !current_audio.impl.HasCaptureSupport) {
|
SDL_LockMutex(current_audio.detectionLock);
|
||||||
return SDL_SetError("No capture support");
|
item = iscapture ? current_audio.inputDevices : current_audio.outputDevices;
|
||||||
}
|
i = iscapture ? current_audio.inputDeviceCount : current_audio.outputDeviceCount;
|
||||||
|
if (index >= 0 && index < i) {
|
||||||
if (index >= 0) {
|
for (i--; i > index; i--, item = item->next) {
|
||||||
SDL_AudioDeviceItem *item;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
SDL_LockMutex(current_audio.detectionLock);
|
|
||||||
item = iscapture ? current_audio.inputDevices : current_audio.outputDevices;
|
|
||||||
i = iscapture ? current_audio.inputDeviceCount : current_audio.outputDeviceCount;
|
|
||||||
if (index < i) {
|
|
||||||
for (i--; i > index; i--, item = item->next) {
|
|
||||||
SDL_assert(item != NULL);
|
|
||||||
}
|
|
||||||
SDL_assert(item != NULL);
|
SDL_assert(item != NULL);
|
||||||
SDL_memcpy(spec, &item->spec, sizeof(SDL_AudioSpec));
|
|
||||||
}
|
}
|
||||||
SDL_UnlockMutex(current_audio.detectionLock);
|
SDL_assert(item != NULL);
|
||||||
|
SDL_memcpy(spec, &item->spec, sizeof(SDL_AudioSpec));
|
||||||
|
retval = 0;
|
||||||
|
} else {
|
||||||
|
retval = SDL_InvalidParamError("index");
|
||||||
}
|
}
|
||||||
|
SDL_UnlockMutex(current_audio.detectionLock);
|
||||||
|
|
||||||
return 0;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue