From c552cc6847710b50565cf71b6b2316c6d12c23b0 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 11 Oct 2023 09:23:23 -0700
Subject: [PATCH] We don't require the audio system to be initialized for audio
format conversion
This is helpful for tools pipelines where audio devices are never used.
---
src/audio/SDL_audio.c | 3 ---
src/audio/SDL_audiocvt.c | 6 ++----
test/testautomation_audio.c | 7 +++++++
3 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index d5475bbd8476..b6ac6517cc97 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -602,9 +602,6 @@ int SDL_InitAudio(const char *driver_name)
SDL_QuitAudio(); // shutdown driver if already running.
}
- SDL_ChooseAudioConverters();
- SDL_SetupAudioResampler();
-
SDL_RWLock *device_list_lock = SDL_CreateRWLock(); // create this early, so if it fails we don't have to tear down the whole audio subsystem.
if (!device_list_lock) {
return -1;
diff --git a/src/audio/SDL_audiocvt.c b/src/audio/SDL_audiocvt.c
index b2f74f99febc..0dc1719658ec 100644
--- a/src/audio/SDL_audiocvt.c
+++ b/src/audio/SDL_audiocvt.c
@@ -404,10 +404,8 @@ static int UpdateAudioStreamInputSpec(SDL_AudioStream *stream, const SDL_AudioSp
SDL_AudioStream *SDL_CreateAudioStream(const SDL_AudioSpec *src_spec, const SDL_AudioSpec *dst_spec)
{
- if (!SDL_WasInit(SDL_INIT_AUDIO)) {
- SDL_SetError("Audio subsystem is not initialized");
- return NULL;
- }
+ SDL_ChooseAudioConverters();
+ SDL_SetupAudioResampler();
SDL_AudioStream *retval = (SDL_AudioStream *)SDL_calloc(1, sizeof(SDL_AudioStream));
if (retval == NULL) {
diff --git a/test/testautomation_audio.c b/test/testautomation_audio.c
index 829962fe8717..7ae022684cf1 100644
--- a/test/testautomation_audio.c
+++ b/test/testautomation_audio.c
@@ -481,6 +481,10 @@ static int audio_buildAudioStream(void *arg)
SDL_AudioSpec spec2;
int i, ii, j, jj, k, kk;
+ /* Call Quit */
+ SDL_QuitSubSystem(SDL_INIT_AUDIO);
+ SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
+
/* No conversion needed */
spec1.format = SDL_AUDIO_S16LE;
spec1.channels = 2;
@@ -528,6 +532,9 @@ static int audio_buildAudioStream(void *arg)
}
}
+ /* Restart audio again */
+ audioSetUp(NULL);
+
return TEST_COMPLETED;
}