From 9cf47af49045adae791b1b08cf7d93fca22f2b4b Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Fri, 19 Jan 2024 17:01:36 +0000 Subject: [PATCH] Change: Invalidate music volume when restarting music playback on Windows. (#11836) --- src/music/dmusic.cpp | 3 +++ src/music/win32_m.cpp | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/music/dmusic.cpp b/src/music/dmusic.cpp index eaf616c535..640a0c771e 100644 --- a/src/music/dmusic.cpp +++ b/src/music/dmusic.cpp @@ -651,6 +651,9 @@ static void MidiThreadProc() TransmitNotesOff(_buffer, block_time, cur_time); MemSetT(channel_volumes, 127, lengthof(channel_volumes)); + /* Invalidate current volume. */ + current_volume = UINT8_MAX; + last_volume_time = 0; /* Take the current time plus the preload time as the music start time. */ clock->GetTime(&playback_start_time); diff --git a/src/music/win32_m.cpp b/src/music/win32_m.cpp index 2dd16b9c75..d07c7214a7 100644 --- a/src/music/win32_m.cpp +++ b/src/music/win32_m.cpp @@ -110,6 +110,8 @@ static void TransmitStandardSysex(MidiSysexMessage msg) */ void CALLBACK TimerCallback(UINT uTimerID, UINT, DWORD_PTR, DWORD_PTR, DWORD_PTR) { + static int volume_throttle = 0; + /* Ensure only one timer callback is running at once, and prevent races on status flags */ std::unique_lock mutex_lock(_midi.lock, std::defer_lock); if (!mutex_lock.try_lock()) return; @@ -163,6 +165,9 @@ void CALLBACK TimerCallback(UINT uTimerID, UINT, DWORD_PTR, DWORD_PTR, DWORD_PTR _midi.current_block = 0; MemSetT(_midi.channel_volumes, 127, lengthof(_midi.channel_volumes)); + /* Invalidate current volume. */ + _midi.current_volume = UINT8_MAX; + volume_throttle = 0; } } else if (!_midi.playing) { /* not playing, stop the timer */ @@ -173,7 +178,6 @@ void CALLBACK TimerCallback(UINT uTimerID, UINT, DWORD_PTR, DWORD_PTR, DWORD_PTR } /* check for volume change */ - static int volume_throttle = 0; if (_midi.current_volume != _midi.new_volume) { if (volume_throttle == 0) { Debug(driver, 2, "Win32-MIDI: timer: volume change");