cleanup/sync the main loop of *_OpenDevice functions to pick audio format

This commit is contained in:
pionere
2022-01-20 12:18:59 +01:00
committed by Ryan C. Gordon
parent 3939ef72f8
commit 2eafe4340c
18 changed files with 186 additions and 307 deletions

View File

@@ -477,10 +477,9 @@ DSOUND_OpenDevice(_THIS, void *handle, const char *devname)
{
const DWORD numchunks = 8;
HRESULT result;
SDL_bool valid_format = SDL_FALSE;
SDL_bool tried_format = SDL_FALSE;
SDL_bool iscapture = this->iscapture;
SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
SDL_AudioFormat test_format;
LPGUID guid = (LPGUID) handle;
DWORD bufsize;
@@ -511,7 +510,7 @@ DSOUND_OpenDevice(_THIS, void *handle, const char *devname)
}
}
while ((!valid_format) && (test_format)) {
for (test_format = SDL_FirstAudioFormat(this->spec.format); test_format; test_format = SDL_NextAudioFormat()) {
switch (test_format) {
case AUDIO_U8:
case AUDIO_S16:
@@ -548,19 +547,21 @@ DSOUND_OpenDevice(_THIS, void *handle, const char *devname)
rc = iscapture ? CreateCaptureBuffer(this, bufsize, &wfmt) : CreateSecondary(this, bufsize, &wfmt);
if (rc == 0) {
this->hidden->num_buffers = numchunks;
valid_format = SDL_TRUE;
break;
}
}
break;
continue;
default:
continue;
}
test_format = SDL_NextAudioFormat();
break;
}
if (!valid_format) {
if (!test_format) {
if (tried_format) {
return -1; /* CreateSecondary() should have called SDL_SetError(). */
}
return SDL_SetError("DirectSound: Unsupported audio format");
return SDL_SetError("%s: Unsupported audio format", "directsound");
}
/* Playback buffers will auto-start playing in DSOUND_WaitDevice() */