From a678a0b27bb0f116833d4164e61414348d67fc2e Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 9 Feb 2017 19:41:04 -0500 Subject: TITANIC: Fixes to choosing wave files for instruments --- engines/titanic/sound/music_room_handler.cpp | 2 +- engines/titanic/sound/music_wave.cpp | 21 +++++++++++---------- engines/titanic/sound/music_wave.h | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/engines/titanic/sound/music_room_handler.cpp b/engines/titanic/sound/music_room_handler.cpp index cbef0ce02b..c99370f4ac 100644 --- a/engines/titanic/sound/music_room_handler.cpp +++ b/engines/titanic/sound/music_room_handler.cpp @@ -290,7 +290,7 @@ bool CMusicRoomHandler::fn2(int index) { if (vp._field0 == 0x7FFFFFFF || _array1[index]._muteControl) _musicWaves[index]->setSize(size); else - _musicWaves[index]->chooseInstrument(getPitch(index, arrIndex), size); + _musicWaves[index]->chooseWaveFile(getPitch(index, arrIndex), size); if (_array1[index]._directionControl == _array2[index]._directionControl) { ++arrIndex; diff --git a/engines/titanic/sound/music_wave.cpp b/engines/titanic/sound/music_wave.cpp index 2b89c700b2..0f88c32632 100644 --- a/engines/titanic/sound/music_wave.cpp +++ b/engines/titanic/sound/music_wave.cpp @@ -298,27 +298,28 @@ int CMusicWave::read(uint16 *ptr, uint size) { return size; } -void CMusicWave::chooseInstrument(int index, int size) { +void CMusicWave::chooseWaveFile(int index, int size) { if (!_array) setupArray(-36, 36); - int minVal = _items[0]._value - index; - int minIndex = 0; + int minDiff = ABS(_items[0]._value - index); + int waveIndex = 0; + for (uint idx = 1; idx < _items.size(); ++idx) { - int val = _items[idx]._value - index; - if (val < minVal) { - minVal = val; - minIndex = idx; + int diff = ABS(_items[idx]._value - index); + if (diff < minDiff) { + minDiff = diff; + waveIndex = idx; } } - int arrIndex = _arrayIndex - _items[minIndex]._value + index; + int arrIndex = _arrayIndex - _items[waveIndex]._value + index; - _waveIndex = minIndex; + _waveIndex = waveIndex; _readPos = 0; _readIncrement = (int)(_array[arrIndex] * 256); _size = size; - _count = _items[minIndex]._waveFile->size() / 2; + _count = _items[waveIndex]._waveFile->size() / 2; } void CMusicWave::setupArray(int minVal, int maxVal) { diff --git a/engines/titanic/sound/music_wave.h b/engines/titanic/sound/music_wave.h index baed60c907..5b63c74f7f 100644 --- a/engines/titanic/sound/music_wave.h +++ b/engines/titanic/sound/music_wave.h @@ -124,7 +124,7 @@ public: /** * Figure out which wave file to use next */ - void chooseInstrument(int index, int freq); + void chooseWaveFile(int index, int freq); }; } // End of namespace Titanic -- cgit v1.2.3