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.
This commit is contained in:
Torbjörn Andersson 2012-11-16 16:43:13 +01:00
parent f0c1d8dcc4
commit b6a42e9faa
2 changed files with 19 additions and 8 deletions

View File

@ -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;
}
}
}

View File

@ -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();