From c2b3abd676a194138849252a3e37d6cb977a343c Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 9 Feb 2017 19:54:13 -0500 Subject: TITANIC: Fix calculation of wave file size --- engines/titanic/sound/music_wave.cpp | 6 ++++-- engines/titanic/sound/wave_file.cpp | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'engines/titanic') diff --git a/engines/titanic/sound/music_wave.cpp b/engines/titanic/sound/music_wave.cpp index 0f88c32632..8f3f3005ba 100644 --- a/engines/titanic/sound/music_wave.cpp +++ b/engines/titanic/sound/music_wave.cpp @@ -313,13 +313,15 @@ void CMusicWave::chooseWaveFile(int index, int size) { } } - int arrIndex = _arrayIndex - _items[waveIndex]._value + index; + const CMusicWaveFile &wf = _items[waveIndex]; + int arrIndex = _arrayIndex - wf._value + index; + uint waveSize = wf._waveFile->size(); _waveIndex = waveIndex; _readPos = 0; _readIncrement = (int)(_array[arrIndex] * 256); _size = size; - _count = _items[waveIndex]._waveFile->size() / 2; + _count = waveSize / 2; } void CMusicWave::setupArray(int minVal, int maxVal) { diff --git a/engines/titanic/sound/wave_file.cpp b/engines/titanic/sound/wave_file.cpp index 5d9987a33f..04800b6157 100644 --- a/engines/titanic/sound/wave_file.cpp +++ b/engines/titanic/sound/wave_file.cpp @@ -81,12 +81,14 @@ bool CWaveFile::loadSound(const CString &name) { return false; Common::SeekableReadStream *stream = file.readStream(); - _dataSize = stream->size(); - _rawData = new byte[_dataSize]; - stream->read(_rawData, _dataSize); + uint dataSize = stream->size(); + _dataSize = dataSize - 44; + + _rawData = new byte[dataSize]; + stream->read(_rawData, dataSize); _audioStream = Audio::makeWAVStream( - new Common::MemoryReadStream(_rawData, _dataSize, DisposeAfterUse::YES), + new Common::MemoryReadStream(_rawData, dataSize, DisposeAfterUse::YES), DisposeAfterUse::YES); _soundType = Audio::Mixer::kSFXSoundType; -- cgit v1.2.3