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
This commit is contained in:
Travis Howell 2005-04-18 07:18:33 +00:00
parent 58966d6b90
commit d4ba67a497
7 changed files with 67 additions and 96 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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