Remove legacy SDL_Audio functions that acts on device id == 1

This commit is contained in:
Sylvain 2023-01-05 09:57:14 +01:00 committed by Ryan C. Gordon
parent bb34441474
commit 2d7f8d7d51
10 changed files with 64 additions and 334 deletions

View file

@ -48,19 +48,21 @@ void poked(int sig)
done = 1;
}
static SDL_AudioDeviceID g_audio_id = 0;
void loop()
{
#ifdef __EMSCRIPTEN__
if (done || (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING)) {
if (done || (SDL_GetAudioDeviceStatus(g_audio_id) != SDL_AUDIO_PLAYING)) {
emscripten_cancel_main_loop();
} else
#endif
{
/* The device from SDL_OpenAudio() is always device #1. */
const Uint32 queued = SDL_GetQueuedAudioSize(1);
const Uint32 queued = SDL_GetQueuedAudioSize(g_audio_id);
SDL_Log("Device has %u bytes queued.\n", (unsigned int)queued);
if (queued <= 8192) { /* time to requeue the whole thing? */
if (SDL_QueueAudio(1, wave.sound, wave.soundlen) == 0) {
if (SDL_QueueAudio(g_audio_id, wave.sound, wave.soundlen) == 0) {
SDL_Log("Device queued %u more bytes.\n", (unsigned int)wave.soundlen);
} else {
SDL_Log("Device FAILED to queue %u more bytes: %s\n", (unsigned int)wave.soundlen, SDL_GetError());
@ -110,7 +112,9 @@ int main(int argc, char *argv[])
#endif /* HAVE_SIGNAL_H */
/* Initialize fillerup() variables */
if (SDL_OpenAudio(&wave.spec, NULL) < 0) {
g_audio_id = SDL_OpenAudioDevice(NULL, 0, &wave.spec, NULL, 0);
if (g_audio_id <= 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError());
SDL_free(wave.sound);
quit(2);
@ -119,7 +123,7 @@ int main(int argc, char *argv[])
/*static x[99999]; SDL_QueueAudio(1, x, sizeof (x));*/
/* Let the audio run */
SDL_PauseAudio(0);
SDL_PauseAudioDevice(g_audio_id, 0);
done = 0;
@ -130,7 +134,7 @@ int main(int argc, char *argv[])
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop, 0, 1);
#else
while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING)) {
while (!done && (SDL_GetAudioDeviceStatus(g_audio_id) == SDL_AUDIO_PLAYING)) {
loop();
SDL_Delay(100); /* let it play for awhile. */
@ -138,7 +142,7 @@ int main(int argc, char *argv[])
#endif
/* Clean up on signal */
SDL_CloseAudio();
SDL_CloseAudioDevice(g_audio_id);
SDL_free(wave.sound);
SDL_free(filename);
SDL_Quit();