Created
May 3, 2014 20:06
-
-
Save gschwind/6ac5a2287b3963a1e606 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 192365cac8e0d6d2a19fb1a0d85b1279136ac40e Mon Sep 17 00:00:00 2001 | |
From: Benoit Gschwind <gschwind@gnu-log.net> | |
Date: Sat, 3 May 2014 21:48:24 +0200 | |
Subject: [PATCH] improve sdl audio compatibility | |
--- | |
base/PCMain.cpp | 21 +++++++++++++++++++-- | |
1 file changed, 19 insertions(+), 2 deletions(-) | |
diff --git a/base/PCMain.cpp b/base/PCMain.cpp | |
index 0e0958e..44cea00 100644 | |
--- a/base/PCMain.cpp | |
+++ b/base/PCMain.cpp | |
@@ -567,7 +567,8 @@ int main(int argc, char *argv[]) { | |
NativeInitGraphics(); | |
NativeResized(); | |
- SDL_AudioSpec fmt; | |
+ SDL_AudioSpec fmt, ret_fmt; | |
+ bzero(&fmt, sizeof(fmt)); | |
fmt.freq = 44100; | |
fmt.format = AUDIO_S16; | |
fmt.channels = 2; | |
@@ -575,8 +576,24 @@ int main(int argc, char *argv[]) { | |
fmt.callback = &mixaudio; | |
fmt.userdata = (void *)0; | |
- if (SDL_OpenAudio(&fmt, NULL) < 0) { | |
+ if (SDL_OpenAudio(&fmt, &ret_fmt) < 0) { | |
ELOG("Failed to open audio: %s", SDL_GetError()); | |
+ } else { | |
+ if(ret_fmt.freq != 44100 || ret_fmt.format != AUDIO_S16 || ret_fmt.channels != 2 || fmt.samples != 2048) { | |
+ ELOG("Sound buffer format does not match requested format."); | |
+ ELOG("Output audio freq: %d (requested: %d)", ret_fmt.freq, 44100); | |
+ ELOG("Output audio format: %d (requested: %d)", ret_fmt.format, AUDIO_S16); | |
+ ELOG("Output audio channels: %d (requested: %d)", ret_fmt.channels, 2); | |
+ ELOG("Output audio samples: %d (requested: %d)", ret_fmt.samples, 2048); | |
+ } | |
+ | |
+ if(ret_fmt.freq != 44100 || ret_fmt.format != AUDIO_S16 || ret_fmt.channels != 2) { | |
+ ELOG("Provided output format does not match requirement, turning audio off"); | |
+ SDL_CloseAudio(); | |
+ } else { | |
+ ELOG("Provided output audio format is usable, thus using it"); | |
+ } | |
+ | |
} | |
// Audio must be unpaused _after_ NativeInit() | |
-- | |
1.8.3.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment