summaryrefslogtreecommitdiff
path: root/src/sound
diff options
context:
space:
mode:
Diffstat (limited to 'src/sound')
-rw-r--r--src/sound/sdl_s.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/sound/sdl_s.cpp b/src/sound/sdl_s.cpp
index e3fb99eaa..b37016c24 100644
--- a/src/sound/sdl_s.cpp
+++ b/src/sound/sdl_s.cpp
@@ -14,7 +14,6 @@
#include "../stdafx.h"
#include "../mixer.h"
-#include "../sdl.h"
#include "sdl_s.h"
#include <SDL.h>
@@ -38,8 +37,14 @@ const char *SoundDriver_SDL::Start(const char * const *parm)
{
SDL_AudioSpec spec;
- const char *s = SdlOpen(SDL_INIT_AUDIO);
- if (s != NULL) return s;
+ /* Only initialise SDL if the video driver hasn't done it already */
+ int ret_code = 0;
+ if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
+ ret_code = SDL_Init(SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
+ } else if (SDL_WasInit(SDL_INIT_AUDIO) == 0) {
+ ret_code = SDL_InitSubSystem(SDL_INIT_AUDIO);
+ }
+ if (ret_code == -1) return SDL_GetError();
spec.freq = GetDriverParamInt(parm, "hz", 44100);
spec.format = AUDIO_S16SYS;
@@ -47,15 +52,18 @@ const char *SoundDriver_SDL::Start(const char * const *parm)
spec.samples = GetDriverParamInt(parm, "samples", 1024);
spec.callback = fill_sound_buffer;
MxInitialize(spec.freq);
- SDL_CALL SDL_OpenAudio(&spec, &spec);
- SDL_CALL SDL_PauseAudio(0);
+ SDL_OpenAudio(&spec, &spec);
+ SDL_PauseAudio(0);
return NULL;
}
void SoundDriver_SDL::Stop()
{
- SDL_CALL SDL_CloseAudio();
- SdlClose(SDL_INIT_AUDIO);
+ SDL_CloseAudio();
+ SDL_QuitSubSystem(SDL_INIT_AUDIO);
+ if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
+ SDL_Quit(); // If there's nothing left, quit SDL
+ }
}
#endif /* WITH_SDL */