[Commits] SDL_mixer: Initialize the SDL audio subsystem if necessary.

libsdl.org revision control commits-owner at libsdl.org
Wed May 24 13:48:52 PDT 2017


details:   https://hg.libsdl.org/SDL_mixer/rev/119df1a05eb7
changeset: 727:119df1a05eb7
user:      Ryan C. Gordon <icculus at icculus.org>
date:      Wed May 24 16:41:47 2017 -0400
description:
Initialize the SDL audio subsystem if necessary.

SDL_OpenAudio() did this for us (legacy 1.2 behavior), but
SDL_OpenAudioDevice() doesn't, leaving us to manage it.

Fixes Bugzilla #3596.

diffstat:

 mixer.c |  13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diffs (30 lines):

diff -r 298d69a81cc9 -r 119df1a05eb7 mixer.c
--- a/mixer.c	Fri Jan 20 02:23:51 2017 -0500
+++ b/mixer.c	Wed May 24 16:41:47 2017 -0400
@@ -25,9 +25,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "SDL_mutex.h"
-#include "SDL_endian.h"
-#include "SDL_timer.h"
+#include "SDL.h"
 
 #include "SDL_mixer.h"
 #include "mixer.h"
@@ -435,6 +433,15 @@
     int i;
     SDL_AudioSpec desired;
 
+    /* This used to call SDL_OpenAudio(), which initializes the audio
+       subsystem if necessary. Since SDL_OpenAudioDevice() doesn't,
+       we have to handle this case here. */
+    if (!SDL_WasInit(SDL_INIT_AUDIO)) {
+        if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
+            return -1;
+        }
+    }
+
     /* If the mixer is already opened, increment open count */
     if ( audio_opened ) {
         if ( format == mixer.format && nchannels == mixer.channels ) {


More information about the commits mailing list