sdl2-compat: update after SDL3 SDL_MIX_MAXVOLUME removal and SDL_MixAudio api change

From 32256efbc1d83dfa6f25e32814a78fe8fdcb7108 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Fri, 17 May 2024 18:20:40 +0300
Subject: [PATCH] update after SDL3 SDL_MIX_MAXVOLUME removal and SDL_MixAudio
 api change

---
 src/sdl2_compat.c          | 7 +++++--
 src/sdl3_include_wrapper.h | 6 +++---
 src/sdl3_syms.h            | 2 +-
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 16c6d20..ef473b4 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -5356,9 +5356,12 @@ SDL_AudioStreamFlush(SDL2_AudioStream *stream2)
     return SDL3_FlushAudioStream(stream2 ? stream2->stream3 : NULL);
 }
 
+#define SDL2_MIX_MAXVOLUME 128.0f
 DECLSPEC void SDLCALL
 SDL_MixAudioFormat(Uint8 *dst, const Uint8 *src, SDL_AudioFormat format, Uint32 len, int volume)
 {
+    const float fvolume = volume / SDL2_MIX_MAXVOLUME;
+
     /* SDL3 removed U16 audio formats. Convert to S16SYS. */
     if ((format == SDL2_AUDIO_U16LSB) || (format == SDL2_AUDIO_U16MSB)) {
         const Uint32 tmpsamples = len / sizeof (Uint16);
@@ -5369,11 +5372,11 @@ SDL_MixAudioFormat(Uint8 *dst, const Uint8 *src, SDL_AudioFormat format, Uint32
             } else if (format == SDL2_AUDIO_U16MSB) {
                 AudioUi16MSBToSi16Sys(tmpbuf, (const Uint16 *) src, tmpsamples);
             }
-            SDL3_MixAudioFormat(dst, (const Uint8 *) tmpbuf, SDL_AUDIO_S16, tmpsamples * sizeof (Sint16), volume);
+            SDL3_MixAudio(dst, (const Uint8 *) tmpbuf, SDL_AUDIO_S16, tmpsamples * sizeof (Sint16), fvolume);
             SDL3_free(tmpbuf);
         }
     } else {
-        SDL3_MixAudioFormat(dst, src, format, len, volume);
+        SDL3_MixAudio(dst, src, format, len, fvolume);
     }
 }
 
diff --git a/src/sdl3_include_wrapper.h b/src/sdl3_include_wrapper.h
index 1cbf6df..bc94875 100644
--- a/src/sdl3_include_wrapper.h
+++ b/src/sdl3_include_wrapper.h
@@ -596,7 +596,7 @@
 #define SDL_Metal_DestroyView IGNORE_THIS_VERSION_OF_SDL_Metal_DestroyView
 #define SDL_Metal_GetLayer IGNORE_THIS_VERSION_OF_SDL_Metal_GetLayer
 #define SDL_MinimizeWindow IGNORE_THIS_VERSION_OF_SDL_MinimizeWindow
-#define SDL_MixAudioFormat IGNORE_THIS_VERSION_OF_SDL_MixAudioFormat
+#define SDL_MixAudio IGNORE_THIS_VERSION_OF_SDL_MixAudio
 #define SDL_OnApplicationDidBecomeActive IGNORE_THIS_VERSION_OF_SDL_OnApplicationDidBecomeActive
 #define SDL_OnApplicationDidChangeStatusBarOrientation IGNORE_THIS_VERSION_OF_SDL_OnApplicationDidChangeStatusBarOrientation
 #define SDL_OnApplicationDidEnterBackground IGNORE_THIS_VERSION_OF_SDL_OnApplicationDidEnterBackground
@@ -3318,8 +3318,8 @@
 #undef SDL_MinimizeWindow
 #endif
 
-#ifdef SDL_MixAudioFormat
-#undef SDL_MixAudioFormat
+#ifdef SDL_MixAudio
+#undef SDL_MixAudio
 #endif
 
 #ifdef SDL_OnApplicationDidBecomeActive
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 6ae1e2a..dff5b49 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -821,7 +821,7 @@ SDL3_SYM(int,SetAudioStreamGetCallback,(SDL_AudioStream *a, SDL_AudioStreamCallb
 SDL3_SYM(int,SetAudioStreamPutCallback,(SDL_AudioStream *a, SDL_AudioStreamCallback b, void *c),(a,b,c),return)
 SDL3_SYM(void,DestroyAudioStream,(SDL_AudioStream *a),(a),)
 SDL3_SYM(int,LoadWAV_IO,(SDL_IOStream *a, SDL_bool b, SDL_AudioSpec *c, Uint8 **d, Uint32 *e),(a,b,c,d,e),return)
-SDL3_SYM(int,MixAudioFormat,(Uint8 *a, const Uint8 *b, SDL_AudioFormat c, Uint32 d, int e),(a,b,c,d,e),return)
+SDL3_SYM(int,MixAudio,(Uint8 *a, const Uint8 *b, SDL_AudioFormat c, Uint32 d, float e),(a,b,c,d,e),return)
 SDL3_SYM(int,GetSilenceValueForFormat,(SDL_AudioFormat a),(a),return)
 SDL3_SYM(int,PauseAudioDevice,(SDL_AudioDeviceID a),(a),return)
 SDL3_SYM(int,ResumeAudioDevice,(SDL_AudioDeviceID a),(a),return)