shithub: zelda3

Download patch

ref: 28b7801e74995043815740c402f00517b4a559b1
parent: a0b6a04562ac936defe35233c0ef4243299d3585
author: Snesrev <snesrev@protonmail.com>
date: Sun Oct 16 21:05:24 EDT 2022

Seems like msu_unk1 can be 0xf1...

Don't cast float to uint64, it's suboptimal on x86.

--- a/audio.c
+++ b/audio.c
@@ -241,7 +241,7 @@
       dst[i * 2 + 1] += src[i * 2 + 1];
     }
   } else {
-    uint32 vol = 65536 * volume;
+    uint32 vol = (int32)(65536 * volume);
     for (size_t i = 0; i < n; i++) {
       dst[i * 2 + 0] += src[i * 2 + 0] * vol >> 16;
       dst[i * 2 + 1] += src[i * 2 + 1] * vol >> 16;
@@ -250,8 +250,8 @@
 }
 
 static void MixToBufferWithVolumeRamp(int16 *dst, const int16 *src, size_t n, float volume, float volume_step, float ideal_target) {
-  uint64 vol = volume * 281474976710656.0f;
-  uint64 step = volume_step * 281474976710656.0f;
+  int64 vol = volume * 281474976710656.0f;
+  int64 step = volume_step * 281474976710656.0f;
   for (size_t i = 0; i < n; i++) {
     uint32 v = (vol >> 32);
     dst[i * 2 + 0] += src[i * 2 + 0] * v >> 16;
@@ -480,7 +480,7 @@
   MsuPlayer *mp = &g_msu_player;
   if (mp->enabled) {
     mp->volume = 0.0;
-    MsuPlayer_Open(mp, music_unk1, true);
+    MsuPlayer_Open(mp, (music_unk1 == 0xf1) ? mp->resume_info.orig_track : music_unk1, true);
 
     // If resuming in the middle of a transition, then override
     // the volume with that of the transition.
--- a/zelda_cpu_infra.c
+++ b/zelda_cpu_infra.c
@@ -111,6 +111,7 @@
   memcpy(a->ram + 0x1dd60, b->ram + 0x1dd60, 16 * 2);  // some leftover stuff in hdma table
 
   memcpy(a->ram + 0x1db20, b->ram + 0x1db20, 64 * 2);  // msu
+  a->ram[0x654] = b->ram[0x654];  // msu_volume
 
   if (memcmp(b->ram, a->ram, 0x20000)) {
     fprintf(stderr, "@%d: Memory compare failed (mine != theirs, prev):\n", frame_counter);