aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorTorbjörn Andersson2012-11-16 16:43:13 +0100
committerTorbjörn Andersson2012-11-16 16:43:13 +0100
commitb6a42e9faa4ae9b9508bba33c1adbcfd8228c56d (patch)
treef26a4a3b484ebcce277c14f0e24272d0124a80d0 /engines
parentf0c1d8dcc46b77895ad85b3cdaaf3b81e497b0d8 (diff)
downloadscummvm-rg350-b6a42e9faa4ae9b9508bba33c1adbcfd8228c56d.tar.gz
scummvm-rg350-b6a42e9faa4ae9b9508bba33c1adbcfd8228c56d.tar.bz2
scummvm-rg350-b6a42e9faa4ae9b9508bba33c1adbcfd8228c56d.zip
SCUMM: Store sample rate in Mac MI1 / Loom savegames
This keeps the music from breaking when loading a savegame that was made with a different sample rate than the current one. It also breaks all savegames made in the past eight hours, but I don't think it's necessary to maintain savegame compatibility within a pull request, as long as it still works with savegames made before it.
Diffstat (limited to 'engines')
-rw-r--r--engines/scumm/player_mac.cpp25
-rw-r--r--engines/scumm/player_mac.h2
2 files changed, 19 insertions, 8 deletions
diff --git a/engines/scumm/player_mac.cpp b/engines/scumm/player_mac.cpp
index cd1df51938..04c66c400c 100644
--- a/engines/scumm/player_mac.cpp
+++ b/engines/scumm/player_mac.cpp
@@ -107,16 +107,11 @@ void Player_Mac::saveLoadWithSerializer(Serializer *ser) {
}
} else {
static const SaveLoadEntry musicEntries[] = {
+ MKLINE(Player_Mac, _sampleRate, sleUint32, VER(94)),
MKLINE(Player_Mac, _soundPlaying, sleInt16, VER(94)),
MKEND()
};
- // Note: This will fail slightly when loading a savegame if
- // the mixer output rate has changed, because the pitch
- // modifier and remaining samples were calculated from it. As
- // a result, the first note to be played will be out of tune,
- // and the channels will probably be slightly out of sync.
-
static const SaveLoadEntry channelEntries[] = {
MKLINE(Channel, _pos, sleUint16, VER(94)),
MKLINE(Channel, _pitchModifier, sleInt32, VER(94)),
@@ -132,6 +127,9 @@ void Player_Mac::saveLoadWithSerializer(Serializer *ser) {
MKEND()
};
+ uint32 mixerSampleRate = _sampleRate;
+ int i;
+
ser->saveLoadEntries(this, musicEntries);
if (ser->isLoading() && _soundPlaying != -1) {
@@ -141,9 +139,22 @@ void Player_Mac::saveLoadWithSerializer(Serializer *ser) {
}
ser->saveLoadArrayOf(_channel, _numberOfChannels, sizeof(Channel), channelEntries);
- for (int i = 0; i < _numberOfChannels; i++) {
+ for (i = 0; i < _numberOfChannels; i++) {
ser->saveLoadEntries(&_channel[i], instrumentEntries);
}
+
+ if (ser->isLoading()) {
+ // If necessary, adjust the channel data to fit the
+ // current sample rate.
+ if (_soundPlaying != -1 && _sampleRate != mixerSampleRate) {
+ double mult = (double)_sampleRate / (double)mixerSampleRate;
+ for (i = 0; i < _numberOfChannels; i++) {
+ _channel[i]._pitchModifier = (int)((double)_channel[i]._pitchModifier * mult);
+ _channel[i]._remaining = (int)((double)_channel[i]._remaining / mult);
+ }
+ }
+ _sampleRate = mixerSampleRate;
+ }
}
}
diff --git a/engines/scumm/player_mac.h b/engines/scumm/player_mac.h
index a30111bda0..0585eb16b0 100644
--- a/engines/scumm/player_mac.h
+++ b/engines/scumm/player_mac.h
@@ -69,7 +69,7 @@ private:
Common::Mutex _mutex;
Audio::Mixer *const _mixer;
Audio::SoundHandle _soundHandle;
- const uint32 _sampleRate;
+ uint32 _sampleRate;
int _soundPlaying;
void stopAllSounds_Internal();