commit on aquadran's behalf that fixes music distortion

svn-id: r12275
This commit is contained in:
Jonathan Gray 2004-01-09 13:16:06 +00:00
parent ee53fb4391
commit 93f3c0df34
4 changed files with 49 additions and 17 deletions

View File

@ -154,6 +154,10 @@ void IMuseDigital::callback() {
if (_sound->getChannels(_track[l].soundHandle) == 1) {
result &= ~1;
}
if (_sound->getChannels(_track[l].soundHandle) == 2) {
if (result & 2)
result &= ~2;
}
} else if (bits == 8) {
result = _sound->getDataFromRegion(_track[l].soundHandle, _track[l].curRegion, &data, _track[l].regionOffset, mixer_size);
if (_sound->getChannels(_track[l].soundHandle) == 2) {
@ -194,6 +198,11 @@ void IMuseDigital::switchToNextRegion(int track) {
return;
}
if (_track[track].idSound == 2312) {
_track[track].curRegion = 4;
_track[track].regionOffset = 0;
return;
}
if (++_track[track].curRegion == num_regions) {
_track[track].toBeRemoved = true;
return;

View File

@ -159,13 +159,14 @@ void BundleMgr::closeFile() {
}
}
int32 BundleMgr::decompressSampleByCurIndex(int32 offset, int32 size, byte **comp_final, int header_size) {
return decompressSampleByIndex(_curSample, offset, size, comp_final, header_size);
int32 BundleMgr::decompressSampleByCurIndex(int32 offset, int32 size, byte **comp_final, int header_size, bool header_outside) {
return decompressSampleByIndex(_curSample, offset, size, comp_final, header_size, header_outside);
}
int32 BundleMgr::decompressSampleByIndex(int32 index, int32 offset, int32 size, byte **comp_final, int header_size) {
int32 BundleMgr::decompressSampleByIndex(int32 index, int32 offset, int32 size, byte **comp_final, int header_size, bool header_outside) {
int32 i, tag, num, final_size, output_size;
byte *comp_input, *comp_output;
int skip, first_block, last_block;
if (index != -1)
_curSample = index;
@ -197,14 +198,24 @@ int32 BundleMgr::decompressSampleByIndex(int32 index, int32 offset, int32 size,
_compTableLoaded = true;
}
int first_block = (offset + header_size) / 0x2000;
int last_block = (offset + size + header_size - 1) / 0x2000;
if (header_outside) {
first_block = offset / 0x2000;
last_block = (offset + size - 1) / 0x2000;
} else {
first_block = (offset + header_size) / 0x2000;
last_block = (offset + size + header_size - 1) / 0x2000;
}
comp_output = (byte *)malloc(0x2000);
*comp_final = (byte *)malloc(0x2000 * (1 + last_block - first_block));
int32 blocks_final_size = 0x2000 * (1 + last_block - first_block);
*comp_final = (byte *)malloc(blocks_final_size);
final_size = 0;
int skip = offset - (first_block * 0x2000) + header_size;
if (header_outside) {
skip = offset - (first_block * 0x2000);
} else {
skip = offset - (first_block * 0x2000) + header_size;
}
for (i = first_block; i <= last_block; i++) {
byte *curBuf;
@ -227,11 +238,21 @@ int32 BundleMgr::decompressSampleByIndex(int32 index, int32 offset, int32 size,
curBuf = _blockChache;
}
if ((header_size != 0) && (skip >= header_size))
if (header_outside) {
if ((header_size != 0) && (i == 0))
skip += header_size;
output_size -= skip;
} else {
if ((header_size != 0) && (skip >= header_size))
output_size -= skip;
}
if (output_size > size)
output_size = size;
if (final_size + output_size > blocks_final_size)
error("");
memcpy(*comp_final + final_size, curBuf + skip, output_size);
final_size += output_size;
@ -246,7 +267,7 @@ int32 BundleMgr::decompressSampleByIndex(int32 index, int32 offset, int32 size,
return final_size;
}
int32 BundleMgr::decompressSampleByName(const char *name, int32 offset, int32 size, byte **comp_final) {
int32 BundleMgr::decompressSampleByName(const char *name, int32 offset, int32 size, byte **comp_final, bool header_outside) {
int32 final_size = 0, i;
if (!_file.isOpen()) {
@ -256,7 +277,7 @@ int32 BundleMgr::decompressSampleByName(const char *name, int32 offset, int32 si
for (i = 0; i < _numFiles; i++) {
if (!scumm_stricmp(name, _bundleTable[i].filename)) {
final_size = decompressSampleByIndex(i, offset, size, comp_final, 0);
final_size = decompressSampleByIndex(i, offset, size, comp_final, 0, header_outside);
return final_size;
}
}

View File

@ -79,9 +79,9 @@ public:
bool openFile(const char *filename, const char *directory);
void closeFile();
int32 decompressSampleByName(const char *name, int32 offset, int32 size, byte **comp_final);
int32 decompressSampleByIndex(int32 index, int32 offset, int32 size, byte **comp_final, int header_size);
int32 decompressSampleByCurIndex(int32 offset, int32 size, byte **comp_final, int header_size);
int32 decompressSampleByName(const char *name, int32 offset, int32 size, byte **comp_final, bool header_outside);
int32 decompressSampleByIndex(int32 index, int32 offset, int32 size, byte **comp_final, int header_size, bool header_outside);
int32 decompressSampleByCurIndex(int32 offset, int32 size, byte **comp_final, int header_size, bool header_outside);
};
namespace BundleCodecs {

View File

@ -219,13 +219,14 @@ ImuseDigiSndMgr::soundStruct *ImuseDigiSndMgr::openSound(int32 soundId, const ch
_sounds[slot].resPtr = ptr;
result = true;
} else if (soundType == IMUSE_BUNDLE) {
bool header_outside = _vm->_gameId != GID_DIG;
if (soundGroup == IMUSE_VOICE)
result = openVoiceBundle(slot);
else if (soundGroup == IMUSE_MUSIC)
result = openMusicBundle(slot);
else
error("ImuseDigiSndMgr::openSound() Don't know how load sound: %d", soundId);
_sounds[slot]._bundle->decompressSampleByIndex(soundId, 0, 0x2000, &ptr, 0);
_sounds[slot]._bundle->decompressSampleByIndex(soundId, 0, 0x2000, &ptr, 0, header_outside);
_sounds[slot].name[0] = 0;
_sounds[slot].soundId = soundId;
} else {
@ -233,13 +234,14 @@ ImuseDigiSndMgr::soundStruct *ImuseDigiSndMgr::openSound(int32 soundId, const ch
}
} else if (soundName != NULL) {
if (soundType == IMUSE_BUNDLE) {
bool header_outside = _vm->_gameId != GID_DIG;
if (soundGroup == IMUSE_VOICE)
result = openVoiceBundle(slot);
else if (soundGroup == IMUSE_MUSIC)
result = openMusicBundle(slot);
else
error("ImuseDigiSndMgr::openSound() Don't know how load sound: %d", soundId);
_sounds[slot]._bundle->decompressSampleByName(soundName, 0, 0x2000, &ptr);
_sounds[slot]._bundle->decompressSampleByName(soundName, 0, 0x2000, &ptr, header_outside);
strcpy(_sounds[slot].name, soundName);
_sounds[slot].soundId = soundId;
} else {
@ -394,9 +396,9 @@ int32 ImuseDigiSndMgr::getDataFromRegion(soundStruct *soundHandle, int region, b
}
int header_size = soundHandle->offsetData;
bool header_outside = _vm->_gameId != GID_DIG;
if (soundHandle->_bundle) {
size = soundHandle->_bundle->decompressSampleByCurIndex(start + offset, size, buf, header_size);
size = soundHandle->_bundle->decompressSampleByCurIndex(start + offset, size, buf, header_size, header_outside);
} else if (soundHandle->resPtr) {
*buf = (byte *)malloc(size);
memcpy(*buf, soundHandle->resPtr + start + offset + header_size, size);