DEADSOFTWARE

sdlmixer: fix sound loading (but sdlmixer still emits broken sound)
[flatwaifu.git] / src / sdlmixer / sound.c
index ec27e45f373387512c6e2422220d4c5866ee63a6..c4b9cd7473eed6cde3286c12c532ab70960a3e89 100644 (file)
 #include "glob.h"
 #include "sound.h"
 #include "music.h"
-#include "misc.h" // int2host
 #include "memory.h" // M_lock M_unlock
 #include "files.h" // F_findres
 #include "error.h"
 
+#include "common/endianness.h"
+
 #include "SDL.h"
 #include "SDL_mixer.h"
 #include <assert.h>
 
 #pragma pack(1)
 typedef struct dmi {
-  Uint32 len;    // length [bytes]
-  Uint32 rate;   // freq [Hz]
-  Uint32 lstart; // loop start offset [bytes]
-  Uint32 llen;   // loop length [bytes]
-  Uint8 data[];  // sound data
+  word len;    // length [bytes]
+  word rate;   // freq [Hz]
+  word lstart; // loop start offset [bytes]
+  word llen;   // loop length [bytes]
+  byte data[];  // sound data
 } dmi;
 #pragma pack()
 
@@ -100,7 +101,7 @@ void MUS_update (void) {
 
 /* Sound */
 
-static int sound_menu_handler (menu_msg_t *msg, const menu_t *m, void *data, int i) {
+static int sound_menu_handler (menu_msg_t *msg, const menu_t *m, int i) {
   static int cur;
   enum { VOLUME, __NUM__ };
   static const simple_menu_t sm = {
@@ -208,18 +209,18 @@ snd_t *S_get (int id) {
     handle = M_lock(id);
     if (handle != NULL) {
       void *data = handle;
-      dword len = F_getreslen(id);
-      dword rate = 11025;
-      dword lstart = 0;
-      dword llen = 0;
+      word len = F_getreslen(id);
+      word rate = 11025;
+      word lstart = 0;
+      word llen = 0;
       int sign = 0;
-      if (len > 16) {
+      if (len > 8) {
         dmi *hdr = handle;
-        dword hdr_len = int2host(hdr->len);
-        dword hdr_rate = int2host(hdr->rate);
-        dword hdr_lstart = int2host(hdr->lstart);
-        dword hdr_llen = int2host(hdr->llen);
-        if (hdr_len <= len - 8 && hdr_lstart + hdr_llen <= len - 16) {
+        word hdr_len = short2host(hdr->len);
+        word hdr_rate = short2host(hdr->rate);
+        word hdr_lstart = short2host(hdr->lstart);
+        word hdr_llen = short2host(hdr->llen);
+        if (hdr_len <= len - 4 && hdr_lstart + hdr_llen <= len - 8) {
           data = hdr->data;
           len = hdr_len;
           rate = hdr_rate;