diff options
author | Robert Göffringmann | 2004-11-15 02:48:30 +0000 |
---|---|---|
committer | Robert Göffringmann | 2004-11-15 02:48:30 +0000 |
commit | 183a11153e680a1b6cd399da09deff7a690304dc (patch) | |
tree | e92ebc67ceedab484b02215b3c9761d88288bd29 /sword1/sound.cpp | |
parent | 0b3949389e9f7a48023894174d5e8e19286c199a (diff) | |
download | scummvm-rg350-183a11153e680a1b6cd399da09deff7a690304dc.tar.gz scummvm-rg350-183a11153e680a1b6cd399da09deff7a690304dc.tar.bz2 scummvm-rg350-183a11153e680a1b6cd399da09deff7a690304dc.zip |
BS1 demo's speech and logic work now.
But there's something wrong with the SFX, which can lead to crashes.
svn-id: r15813
Diffstat (limited to 'sword1/sound.cpp')
-rw-r--r-- | sword1/sound.cpp | 53 |
1 files changed, 24 insertions, 29 deletions
diff --git a/sword1/sound.cpp b/sword1/sound.cpp index 550d8dd54b..fde2a402cc 100644 --- a/sword1/sound.cpp +++ b/sword1/sound.cpp @@ -218,36 +218,28 @@ int16 *Sound::uncompressSpeech(uint32 index, uint32 cSize, uint32 *size) { headerPos++; if (headerPos < 100) { int32 resSize; - if (_cowMode == CowDemo) { // Demo uses slightly different headers - resSize = READ_LE_UINT32(fBuf + headerPos + 6) >> 1; - headerPos += 2; - } else - resSize = READ_LE_UINT32(fBuf + headerPos + 4) >> 1; - int16 *srcData = (int16*)(fBuf + headerPos + 8); - uint32 srcPos = 0; - uint32 dstPos = 0; - cSize = (cSize - (headerPos + 8)) / 2; - if (_cowMode == CowDemo) { - // FIXME: Until someone figures out how to really - // calculate the uncompressed buffer size, use - // brute force to avoid crashes. - debug(1, "old resSize = %d", resSize); - resSize = 0; - while (srcPos < cSize) { - int16 length = (int16)READ_LE_UINT16(srcData + srcPos); - srcPos++; - if (length < 0) { - length = -length; - srcPos++; - } else { - srcPos += length; - } - resSize += length; - } - debug(1, "new resSize = %d", resSize); + headerPos += 4; // skip 'data' tag + if (_cowMode != CowDemo) { + resSize = READ_LE_UINT32(fBuf + headerPos) >> 1; + headerPos += 4; + } else { + // the demo speech files have the uncompressed size embedded + // in the compressed stream *sigh* + if (READ_LE_UINT16(fBuf + headerPos) == 1) { + resSize = READ_LE_UINT16(fBuf + headerPos + 2); + resSize |= READ_LE_UINT16(fBuf + headerPos + 6) << 16; + resSize >>= 1; + } else + resSize = READ_LE_UINT32(fBuf + headerPos + 2) >> 1; } - int16 *dstData = (int16*)malloc(resSize * 2); - srcPos = 0; + assert(!(headerPos & 1)); + int16 *srcData = (int16*)fBuf; + uint32 srcPos = headerPos >> 1; + cSize /= 2; + uint32 dstPos = 0; + /* alloc 200 additional bytes, as the demo sometimes has ASCII junk + at the end of the wave data */ + int16 *dstData = (int16*)malloc(resSize * 2 + 200); while (srcPos < cSize) { int16 length = (int16)READ_LE_UINT16(srcData + srcPos); srcPos++; @@ -262,6 +254,9 @@ int16 *Sound::uncompressSpeech(uint32 index, uint32 cSize, uint32 *size) { srcPos += length; } } + assert(dstPos < (uint32)resSize + 100); + if (_cowMode == CowDemo) // demo has wave output size embedded in the compressed data + *(uint32*)dstData = 0; free(fBuf); *size = resSize * 2; calcWaveVolume(dstData, resSize); |