diff options
author | Travis Howell | 2005-04-18 07:18:33 +0000 |
---|---|---|
committer | Travis Howell | 2005-04-18 07:18:33 +0000 |
commit | d4ba67a49793677a19680f72f9e7fb14fc6c747c (patch) | |
tree | d2ae230e59de767b4ae1a6388a16df8b21ca7044 /scumm | |
parent | 58966d6b90cf79ad7d6ed9ffb6e44eb74d38815f (diff) | |
download | scummvm-rg350-d4ba67a49793677a19680f72f9e7fb14fc6c747c.tar.gz scummvm-rg350-d4ba67a49793677a19680f72f9e7fb14fc6c747c.tar.bz2 scummvm-rg350-d4ba67a49793677a19680f72f9e7fb14fc6c747c.zip |
Use correct music offsets for HE games, only a few demos use wrong tunes now.
Get all music details for HE games from one function only.
svn-id: r17662
Diffstat (limited to 'scumm')
-rw-r--r-- | scumm/intern.h | 1 | ||||
-rw-r--r-- | scumm/resource_v7he.cpp | 54 | ||||
-rw-r--r-- | scumm/script_v100he.cpp | 4 | ||||
-rw-r--r-- | scumm/script_v72he.cpp | 4 | ||||
-rw-r--r-- | scumm/script_v80he.cpp | 4 | ||||
-rw-r--r-- | scumm/sound.cpp | 94 | ||||
-rw-r--r-- | scumm/sound.h | 2 |
7 files changed, 67 insertions, 96 deletions
diff --git a/scumm/intern.h b/scumm/intern.h index 792f68abec..089270a3d3 100644 --- a/scumm/intern.h +++ b/scumm/intern.h @@ -812,7 +812,6 @@ protected: byte *heFindResource(uint32 tag, byte *ptr); byte *findWrappedBlock(uint32 tag, byte *ptr, int state, bool flagError); int findObject(int x, int y, int num, int *args); - int getMusicResourceSize(int id); /* HE version 72 script opcodes */ void o72_pushDWord(); diff --git a/scumm/resource_v7he.cpp b/scumm/resource_v7he.cpp index 4b6eab74d6..52e92518b5 100644 --- a/scumm/resource_v7he.cpp +++ b/scumm/resource_v7he.cpp @@ -1753,58 +1753,4 @@ byte *ScummEngine_v72he::getStringAddress(int i) { return ((ScummEngine_v72he::ArrayHeader *)addr)->data; } -int ScummEngine_v72he::getMusicResourceSize(int id) { - int size, total_size; - uint tracks, skip; - char buf[32], buf1[128]; - File musicFile; - - sprintf(buf, "%s.he4", getGameName()); - - if (_substResFileNameIndex > 0) { - generateSubstResFileName(buf, buf1, sizeof(buf1)); - strcpy(buf, buf1); - } - if (musicFile.open(buf) == false) { - warning("getMusicResourceSize: Music file is not open"); - return 0; - } - musicFile.seek(4, SEEK_SET); - total_size = musicFile.readUint32BE(); - musicFile.seek(+8, SEEK_CUR); - tracks = musicFile.readUint32LE(); - - skip = 0; - if (id >= 8500) - skip = (id - 8500); - else if (id >= 8000) - skip = (id - 8000); - else if (id >= 4000) - skip = (id - 4000); - - if (skip > tracks - 1) - skip = 0; - - if (_heversion >= 80) { - // Skip to offsets - musicFile.seek(+40, SEEK_CUR); - - // Skip to correct music header - skip *= 21; - } else { - // Skip to offsets - musicFile.seek(+4, SEEK_CUR); - - // Skip to correct music header - skip *= 25; - } - - musicFile.seek(+skip, SEEK_CUR); - musicFile.readUint32LE(); - size = musicFile.readUint32LE(); - musicFile.close(); - - return size; -} - } // End of namespace Scumm diff --git a/scumm/script_v100he.cpp b/scumm/script_v100he.cpp index 893f7066af..9fd166246d 100644 --- a/scumm/script_v100he.cpp +++ b/scumm/script_v100he.cpp @@ -2211,7 +2211,9 @@ void ScummEngine_v100he::o100_getResourceSize() { break; case 72: if (resid > _numSounds) { - push(getMusicResourceSize(resid)); + int offs; + _sound->getHEMusicDetails(resid, offs, size); + push(size); return; } type = rtSound; diff --git a/scumm/script_v72he.cpp b/scumm/script_v72he.cpp index 4c3e19b6c0..f69587084b 100644 --- a/scumm/script_v72he.cpp +++ b/scumm/script_v72he.cpp @@ -2160,7 +2160,9 @@ void ScummEngine_v72he::o72_getResourceSize() { resid = pop(); if (resid > _numSounds) { - push(getMusicResourceSize(resid)); + int offs; + _sound->getHEMusicDetails(resid, offs, size); + push(size); return; } diff --git a/scumm/script_v80he.cpp b/scumm/script_v80he.cpp index 9a3755bbb4..875d900091 100644 --- a/scumm/script_v80he.cpp +++ b/scumm/script_v80he.cpp @@ -814,7 +814,9 @@ void ScummEngine_v80he::o80_getResourceSize() { switch (subOp) { case 13: if (resid > _numSounds) { - push(getMusicResourceSize(resid)); + int offs; + _sound->getHEMusicDetails(resid, offs, size); + push(size); return; } type = rtSound; diff --git a/scumm/sound.cpp b/scumm/sound.cpp index f15adef42c..24fdb6e187 100644 --- a/scumm/sound.cpp +++ b/scumm/sound.cpp @@ -161,6 +161,60 @@ void Sound::setOverrideFreq(int freq) { _overrideFreq = freq; } +void Sound::getHEMusicDetails(int id, int &musicOffs, int &musicSize) { + int musicID, offs, tracks, total_size; + char buf[32], buf1[128]; + File musicFile; + + sprintf(buf, "%s.he4", _vm->getGameName()); + + if (_vm->_substResFileNameIndex > 0) { + _vm->generateSubstResFileName(buf, buf1, sizeof(buf1)); + strcpy(buf, buf1); + } + if (musicFile.open(buf) == false) { + warning("getHEMusicDetails: Music file is not open"); + return; + } + musicFile.seek(4, SEEK_SET); + total_size = musicFile.readUint32BE(); + musicFile.seek(16, SEEK_SET); + tracks = musicFile.readUint32LE(); + + int musicStart = (_vm->_heversion >= 80) ? 56 : 20; + + musicFile.seek(musicStart, SEEK_SET); + int musicStartID = musicFile.readUint32LE(); + + // Music is off by one in freddi2/puttzoo + offs = id - musicStartID - 1; + if (offs < 0 || offs > tracks) + offs = 0; + + offs *= (_vm->_heversion >= 80) ? 21 : 25; + musicFile.seek(musicStart + offs, SEEK_SET); + + // Adjust all other games. + musicID = musicFile.readUint32LE(); + if (id == musicID + 1) { + offs += (_vm->_heversion >= 80) ? 21 : 25; + musicFile.seek(musicStart + offs, SEEK_SET); + musicID = musicFile.readUint32LE(); + } + + musicOffs = musicFile.readUint32LE(); + musicSize = musicFile.readUint32LE(); + + if (id != musicID) { + debug(0, "getHEMusicDetails: Music track doesn't match (%d, %d)", id, musicID); + } + if (musicOffs > total_size || (musicSize + musicOffs > total_size) || musicSize < 0) { + error("getHEMusicDetails: Invalid music offset (%d) in music %d", id); + } + + musicFile.close(); +} + void Sound::playSound(int soundID, int heOffset, int heChannel, int heFlags) { debug(5,"playSound: soundID %d heOffset %d heChannel %d heFlags %d\n", soundID, heOffset, heChannel, heFlags); byte *mallocedPtr = NULL; @@ -176,8 +230,7 @@ void Sound::playSound(int soundID, int heOffset, int heChannel, int heFlags) { if (_vm->_heversion >= 70 && soundID > _vm->_numSounds) { debug(1, "playSound #%d", soundID); - int music_offs, total_size; - uint tracks, skip = 0; + int music_offs; char buf[32], buf1[128]; File musicFile; @@ -191,43 +244,8 @@ void Sound::playSound(int soundID, int heOffset, int heChannel, int heFlags) { warning("playSound: Music file is not open"); return; } - musicFile.seek(4, SEEK_SET); - total_size = musicFile.readUint32BE(); - musicFile.seek(+8, SEEK_CUR); - tracks = musicFile.readUint32LE(); - - if (soundID >= 8500) - skip = (soundID - 8500); - else if (soundID >= 8000) - skip = (soundID - 8000); - else if (soundID >= 4000) - skip = (soundID - 4000); - - if (skip > tracks - 1) - skip = 0; - - if (_vm->_heversion >= 80) { - // Skip to offsets - musicFile.seek(+40, SEEK_CUR); - - // Skip to correct music header - skip *= 21; - } else { - // Skip to offsets - musicFile.seek(+4, SEEK_CUR); - - // Skip to correct music header - skip *= 25; - } - - musicFile.seek(+skip, SEEK_CUR); - music_offs = musicFile.readUint32LE(); - size = musicFile.readUint32LE(); - - if (music_offs > total_size || (size + music_offs > total_size) || size < 0) { - error("playSound: Invalid music offset (%d) in music %d", soundID); - } + getHEMusicDetails(soundID, music_offs, size); musicFile.seek(music_offs, SEEK_SET); ptr = (byte *)malloc(size); musicFile.read(ptr, size); diff --git a/scumm/sound.h b/scumm/sound.h index 88bf463d92..900250525f 100644 --- a/scumm/sound.h +++ b/scumm/sound.h @@ -120,6 +120,8 @@ public: void updateCD(); int getCurrentCDSound() const { return _currentCDSound; } + void getHEMusicDetails(int id, int &musicOffs, int &musicSize); + // Used by the save/load system: const SaveLoadEntry *getSaveLoadEntries(); |