From caa8293fcec4441bd0470ba545877aaf8145d81f Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Sun, 4 Jun 2017 22:04:46 -0500 Subject: SCI32: Make sure audio is not paused from the future This can occur when a save game from the past is loaded and the audio system was paused prior to loading the save game. This was fixed eventually in SSCI somewhere around GK2, since it pauses all audio before restoring a game and then resumes it after the save game is loaded (after all of the audio channels have been added from the save game). Since this would seem to be a problem for earlier games as well, this change is applied universally instead of being conditionally applied only to the games with interpreters containing this change. This patch contains some additional sanity checks that emit warnings if individual channels end up being started from the future. There was never such checking in SSCI, and it does not seem likely to ever happen, but it is unclear right now if this is an actual problem or not. --- engines/sci/sound/audio32.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'engines/sci/sound/audio32.cpp') diff --git a/engines/sci/sound/audio32.cpp b/engines/sci/sound/audio32.cpp index be3f99dcea..7622305adb 100644 --- a/engines/sci/sound/audio32.cpp +++ b/engines/sci/sound/audio32.cpp @@ -842,6 +842,9 @@ uint16 Audio32::play(int16 channelIndex, const ResourceId resourceId, const bool channel.startedAtTick = now; if (_numActiveChannels == 1) { + if (_pausedAtTick) { + _pausedAtTick = now; + } _startedAtTick = now; } @@ -868,18 +871,29 @@ bool Audio32::resume(const int16 channelIndex) { AudioChannel &channel = getChannel(i); if (!channel.pausedAtTick) { channel.startedAtTick += now - _pausedAtTick; + if (channel.startedAtTick > now) { + warning("%s is being resumed in the future", channel.id.toString().c_str()); + } } } _startedAtTick += now - _pausedAtTick; + if (_startedAtTick > now) { + warning("Audio32 is being resumed in the future"); + } _pausedAtTick = 0; return true; } else if (channelIndex == kRobotChannel) { for (int i = 0; i < _numActiveChannels; ++i) { AudioChannel &channel = getChannel(i); if (channel.robot) { - channel.startedAtTick += now - channel.pausedAtTick; - channel.pausedAtTick = 0; + if (channel.pausedAtTick) { + channel.startedAtTick += now - channel.pausedAtTick; + if (channel.startedAtTick > now) { + warning("Robot audio is being resumed in the future"); + } + channel.pausedAtTick = 0; + } return true; } } @@ -887,6 +901,9 @@ bool Audio32::resume(const int16 channelIndex) { AudioChannel &channel = getChannel(channelIndex); if (channel.pausedAtTick) { channel.startedAtTick += now - channel.pausedAtTick; + if (channel.startedAtTick > now) { + warning("%s is being resumed in the future", channel.id.toString().c_str()); + } channel.pausedAtTick = 0; return true; } -- cgit v1.2.3