summaryrefslogtreecommitdiff
path: root/games/SameBoy/sdl.patch
blob: 053a2a37472428b4a7575b3d9e0ae50abd80501f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
From 453673a2a653a45d8ee378ba5335f98df5e22efa Mon Sep 17 00:00:00 2001
From: Lior Halphon <LIJI32@gmail.com>
Date: Sat, 10 Nov 2018 18:58:22 +0200
Subject: [PATCH] Apply the SDL 2.0.6 audio workaround to everything except
 Windows, check the linked version instead of the headers version. Fixes #130

---
 SDL/main.c | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/SDL/main.c b/SDL/main.c
index c21a96f9..7db59be4 100755
--- a/SDL/main.c
+++ b/SDL/main.c
@@ -559,25 +559,31 @@ int main(int argc, char **argv)
     want_aspec.freq = AUDIO_FREQUENCY;
     want_aspec.format = AUDIO_S16SYS;
     want_aspec.channels = 2;
-#if SDL_COMPILEDVERSION >= 2005 && defined(__APPLE__)
-    /* SDL 2.0.5 on macOS introduced a bug where certain combinations of buffer lengths and frequencies 
+    want_aspec.samples = 512;
+    
+    SDL_version _sdl_version;
+    SDL_GetVersion(&_sdl_version);
+    unsigned sdl_version = _sdl_version.major * 1000 + _sdl_version.minor * 100 + _sdl_version.patch;
+    
+#ifndef _WIN32
+    /* SDL 2.0.5 on macOS and Linux introduced a bug where certain combinations of buffer lengths and frequencies
        fail to produce audio correctly. */
-    want_aspec.samples = 2048;
+    if (sdl_version >= 2005) {
+        want_aspec.samples = 2048;
+    }
 #else
-    want_aspec.samples = 512;
-#endif
-
-#if SDL_COMPILEDVERSION >= 2006 && defined(_WIN32)
-    /* SDL 2.0.6 offers WASAPI support which allows for much lower audio buffer lengths which at least
-       theoretically reduces lagging. */
-    want_aspec.samples = 32;
-#endif
-
-#if SDL_COMPILEDVERSION <= 2005 && defined(_WIN32)
-    /* Since WASAPI audio was introduced in SDL 2.0.6, we have to lower the audio frequency
-       to 44100 because otherwise we would get garbled audio output.*/
-    want_aspec.freq = 44100;
+    if (sdl_version >= 2006) {
+        /* SDL 2.0.6 offers WASAPI support which allows for much lower audio buffer lengths which at least
+         theoretically reduces lagging. */
+        want_aspec.samples = 32;
+    }
+    else {
+        /* Since WASAPI audio was introduced in SDL 2.0.6, we have to lower the audio frequency
+         to 44100 because otherwise we would get garbled audio output.*/
+        want_aspec.freq = 44100;
+    }
 #endif
+    
 
     want_aspec.callback = audio_callback;
     want_aspec.userdata = &gb;