[Scummvm-git-logs] scummvm master -> a542104f3ceb69086c8b4f2ea259bacb93f719ed

dreammaster dreammaster at scummvm.org
Sun Feb 12 18:51:56 CET 2017


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
a542104f3c TITANIC: Rename CMusicWave to CMusicRoomInstrument


Commit: a542104f3ceb69086c8b4f2ea259bacb93f719ed
    https://github.com/scummvm/scummvm/commit/a542104f3ceb69086c8b4f2ea259bacb93f719ed
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2017-02-12T12:51:47-05:00

Commit Message:
TITANIC: Rename CMusicWave to CMusicRoomInstrument

Changed paths:
  A engines/titanic/sound/music_room_instrument.cpp
  A engines/titanic/sound/music_room_instrument.h
  R engines/titanic/sound/music_wave.cpp
  R engines/titanic/sound/music_wave.h
    engines/titanic/module.mk
    engines/titanic/sound/music_player.cpp
    engines/titanic/sound/music_room_handler.cpp
    engines/titanic/sound/music_room_handler.h
    engines/titanic/titanic.cpp


diff --git a/engines/titanic/module.mk b/engines/titanic/module.mk
index 08a65a2..6aadf5d 100644
--- a/engines/titanic/module.mk
+++ b/engines/titanic/module.mk
@@ -412,8 +412,8 @@ MODULE_OBJS := \
 	sound/music_object.o \
 	sound/music_room.o \
 	sound/music_room_handler.o \
+	sound/music_room_instrument.o \
 	sound/music_player.o \
-	sound/music_wave.o \
 	sound/node_auto_sound_player.o \
 	sound/proximity.o \
 	sound/qmixer.o \
diff --git a/engines/titanic/sound/music_player.cpp b/engines/titanic/sound/music_player.cpp
index c05a519..fe75382 100644
--- a/engines/titanic/sound/music_player.cpp
+++ b/engines/titanic/sound/music_player.cpp
@@ -127,36 +127,36 @@ bool CMusicPlayer::CreateMusicPlayerMsg(CCreateMusicPlayerMsg *msg) {
 	}
 
 	CMusicRoomHandler *musicHandler = getMusicRoom()->createMusicHandler();
-	CMusicWave *wave;
+	CMusicRoomInstrument *ins;
 
 	if (musicHandler) {
-		wave = musicHandler->createMusicWave(BELLS, 3);
-		wave->load(0, "z#490.wav", 60);
-		wave->load(1, "z#488.wav", 62);
-		wave->load(2, "z#489.wav", 63);
-
-		wave = musicHandler->createMusicWave(SNAKE, 5);
-		wave->load(0, "z#493.wav", 22);
-		wave->load(1, "z#495.wav", 29);
-		wave->load(2, "z#492.wav", 34);
-		wave->load(3, "z#494.wav", 41);
-		wave->load(4, "z#491.wav", 46);
-
-		wave = musicHandler->createMusicWave(PIANO, 5);
-		wave->load(0, "z#499.wav", 26);
-		wave->load(1, "z#497.wav", 34);
-		wave->load(2, "z#498.wav", 38);
-		wave->load(3, "z#496.wav", 46);
-		wave->load(4, "z#500.wav", 60);
-
-		wave = musicHandler->createMusicWave(BASS, 7);
-		wave->load(0, "z#504.wav", 22);
-		wave->load(1, "z#507.wav", 29);
-		wave->load(2, "z#503.wav", 34);
-		wave->load(3, "z#506.wav", 41);
-		wave->load(4, "z#502.wav", 46);
-		wave->load(5, "z#505.wav", 53);
-		wave->load(6, "z#501.wav", 58);
+		ins = musicHandler->createInstrument(BELLS, 3);
+		ins->load(0, "z#490.wav", 60);
+		ins->load(1, "z#488.wav", 62);
+		ins->load(2, "z#489.wav", 63);
+
+		ins = musicHandler->createInstrument(SNAKE, 5);
+		ins->load(0, "z#493.wav", 22);
+		ins->load(1, "z#495.wav", 29);
+		ins->load(2, "z#492.wav", 34);
+		ins->load(3, "z#494.wav", 41);
+		ins->load(4, "z#491.wav", 46);
+
+		ins = musicHandler->createInstrument(PIANO, 5);
+		ins->load(0, "z#499.wav", 26);
+		ins->load(1, "z#497.wav", 34);
+		ins->load(2, "z#498.wav", 38);
+		ins->load(3, "z#496.wav", 46);
+		ins->load(4, "z#500.wav", 60);
+
+		ins = musicHandler->createInstrument(BASS, 7);
+		ins->load(0, "z#504.wav", 22);
+		ins->load(1, "z#507.wav", 29);
+		ins->load(2, "z#503.wav", 34);
+		ins->load(3, "z#506.wav", 41);
+		ins->load(4, "z#502.wav", 46);
+		ins->load(5, "z#505.wav", 53);
+		ins->load(6, "z#501.wav", 58);
 
 		CMusicRoom::_musicHandler->setActive(_musicActive);
 	}
diff --git a/engines/titanic/sound/music_room_handler.cpp b/engines/titanic/sound/music_room_handler.cpp
index d464a1d..b013bb1 100644
--- a/engines/titanic/sound/music_room_handler.cpp
+++ b/engines/titanic/sound/music_room_handler.cpp
@@ -33,7 +33,7 @@ CMusicRoomHandler::CMusicRoomHandler(CProjectItem *project, CSoundManager *sound
 	_field108 = 0;
 	_field118 = 0;
 	_startTicks = _soundStartTicks = 0;
-	Common::fill(&_musicWaves[0], &_musicWaves[4], (CMusicWave *)nullptr);
+	Common::fill(&_instruments[0], &_instruments[4], (CMusicRoomInstrument *)nullptr);
 	for (int idx = 0; idx < 4; ++idx)
 		_musicObjs[idx] = new CMusicObject(idx);
 	Common::fill(&_startPos[0], &_startPos[4], 0);
@@ -51,26 +51,26 @@ CMusicRoomHandler::~CMusicRoomHandler() {
 	delete _audioBuffer;
 }
 
-CMusicWave *CMusicRoomHandler::createMusicWave(MusicInstrument instrument, int count) {
+CMusicRoomInstrument *CMusicRoomHandler::createInstrument(MusicInstrument instrument, int count) {
 	switch (instrument) {
 	case BELLS:
-		_musicWaves[BELLS] = new CMusicWave(_project, _soundManager, MV_BELLS);
+		_instruments[BELLS] = new CMusicRoomInstrument(_project, _soundManager, MV_BELLS);
 		break;
 	case SNAKE:
-		_musicWaves[SNAKE] = new CMusicWave(_project, _soundManager, MV_SNAKE);
+		_instruments[SNAKE] = new CMusicRoomInstrument(_project, _soundManager, MV_SNAKE);
 		break;
 	case PIANO:
-		_musicWaves[PIANO] = new CMusicWave(_project, _soundManager, MV_PIANO);
+		_instruments[PIANO] = new CMusicRoomInstrument(_project, _soundManager, MV_PIANO);
 		break;
 	case BASS:
-		_musicWaves[BASS] = new CMusicWave(_project, _soundManager, MV_BASS);
+		_instruments[BASS] = new CMusicRoomInstrument(_project, _soundManager, MV_BASS);
 		break;
 	default:
 		return nullptr;
 	}
 
-	_musicWaves[instrument]->setFilesCount(count);
-	return _musicWaves[instrument];
+	_instruments[instrument]->setFilesCount(count);
+	return _instruments[instrument];
 }
 
 void CMusicRoomHandler::setup(int volume) {
@@ -108,9 +108,9 @@ void CMusicRoomHandler::stop() {
 	}
 
 	for (int idx = 0; idx < 4; ++idx) {
-		_musicWaves[idx]->reset();
-		if (_active && _musicWaves[idx])
-			_musicWaves[idx]->stop();
+		_instruments[idx]->reset();
+		if (_active && _instruments[idx])
+			_instruments[idx]->stop();
 	}
 
 	_field108 = 0;
@@ -174,7 +174,7 @@ void CMusicRoomHandler::setMuteControl(MusicInstrument instrument, bool value) {
 void CMusicRoomHandler::trigger() {
 	if (_active) {
 		for (int idx = 0; idx < 4; ++idx)
-			_musicWaves[idx]->trigger();
+			_instruments[idx]->trigger();
 	}
 }
 
@@ -214,7 +214,7 @@ void CMusicRoomHandler::updateAudio() {
 
 		for (MusicInstrument instrument = BELLS; instrument <= BASS;
 				instrument = (MusicInstrument)((int)instrument + 1)) {
-			CMusicWave *musicWave = _musicWaves[instrument];
+			CMusicRoomInstrument *musicWave = _instruments[instrument];
 
 			// Iterate through each of the four instruments and do an additive
 			// read that will merge their data onto the output buffer
@@ -243,7 +243,7 @@ void CMusicRoomHandler::fn1() {
 				instrument = (MusicInstrument)((int)instrument + 1)) {
 			MusicRoomInstrument &ins1 = _array1[instrument];
 			MusicRoomInstrument &ins2 = _array2[instrument];
-			CMusicWave *musicWave = _musicWaves[instrument];
+			CMusicRoomInstrument *musicWave = _instruments[instrument];
 
 			// Is this about checking playback position?
 			if (_position[instrument] < 0 || ins1._muteControl || _position[instrument] >= _musicObjs[instrument]->size()) {
@@ -260,7 +260,7 @@ void CMusicRoomHandler::fn1() {
 				const CValuePair &vp = (*_musicObjs[instrument])[_position[instrument]];
 				if (vp._field0 != 0x7FFFFFFF) {
 					int amount = getPitch(instrument, _position[instrument]);
-					_musicWaves[instrument]->start(amount);
+					_instruments[instrument]->start(amount);
 				}
 
 				if (ins1._directionControl == ins2._directionControl) {
@@ -276,14 +276,14 @@ void CMusicRoomHandler::fn1() {
 bool CMusicRoomHandler::updateInstrument(MusicInstrument instrument) {
 	int &arrIndex = _startPos[instrument];
 	if (arrIndex < 0) {
-		_musicWaves[instrument]->reset();
+		_instruments[instrument]->reset();
 		return false;
 	}
 
 	const CMusicObject &mObj = *_musicObjs[instrument];
 	if (arrIndex >= mObj.size()) {
 		arrIndex = -1;
-		_musicWaves[instrument]->reset();
+		_instruments[instrument]->reset();
 		return false;
 	}
 
@@ -291,9 +291,9 @@ bool CMusicRoomHandler::updateInstrument(MusicInstrument instrument) {
 	int size = static_cast<int>(fn3(instrument, arrIndex) * 44100.0) & ~1;
 
 	if (vp._field0 == 0x7FFFFFFF || _array1[instrument]._muteControl)
-		_musicWaves[instrument]->setSize(size);
+		_instruments[instrument]->setSize(size);
 	else
-		_musicWaves[instrument]->chooseWaveFile(getPitch(instrument, arrIndex), size);
+		_instruments[instrument]->chooseWaveFile(getPitch(instrument, arrIndex), size);
 
 	if (_array1[instrument]._directionControl == _array2[instrument]._directionControl) {
 		++arrIndex;
diff --git a/engines/titanic/sound/music_room_handler.h b/engines/titanic/sound/music_room_handler.h
index ed87f33..999784e 100644
--- a/engines/titanic/sound/music_room_handler.h
+++ b/engines/titanic/sound/music_room_handler.h
@@ -25,7 +25,7 @@
 
 #include "titanic/sound/audio_buffer.h"
 #include "titanic/sound/music_object.h"
-#include "titanic/sound/music_wave.h"
+#include "titanic/sound/music_room_instrument.h"
 #include "titanic/sound/wave_file.h"
 
 namespace Titanic {
@@ -49,7 +49,7 @@ class CMusicRoomHandler {
 private:
 	CProjectItem *_project;
 	CSoundManager *_soundManager;
-	CMusicWave *_musicWaves[4];
+	CMusicRoomInstrument *_instruments[4];
 	MusicRoomInstrument _array1[4];
 	MusicRoomInstrument _array2[4];
 	CMusicObject *_musicObjs[4];
@@ -86,12 +86,12 @@ public:
 	~CMusicRoomHandler();
 
 	/**
-	 * Creates a new music wave class instance, and assigns it to a slot
-	 * in the music handler
-	 * @param instrument	Which instrument instance is for
-	 * @param count			Number of files the new instance will contain
+	 * Creates a new music room instrument class to handle the operation of one
+	 * of the instruments in the music room.
+	 * @param instrument	Which instrument to create for
+	 * @param count			Number of Wave files the new instance will contain
 	 */
-	CMusicWave *createMusicWave(MusicInstrument instrument, int count);
+	CMusicRoomInstrument *createInstrument(MusicInstrument instrument, int count);
 
 	/**
 	 * Main setup for the music room handler
diff --git a/engines/titanic/sound/music_room_instrument.cpp b/engines/titanic/sound/music_room_instrument.cpp
new file mode 100644
index 0000000..5ec158f
--- /dev/null
+++ b/engines/titanic/sound/music_room_instrument.cpp
@@ -0,0 +1,353 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "titanic/sound/music_room_instrument.h"
+#include "titanic/sound/sound_manager.h"
+#include "titanic/core/project_item.h"
+#include "titanic/core/game_object.h"
+
+namespace Titanic {
+
+bool CMusicRoomInstrument::_pianoToggle;
+int CMusicRoomInstrument::_pianoCtr;
+int CMusicRoomInstrument::_bassCtr;
+byte *CMusicRoomInstrument::_buffer;
+double *CMusicRoomInstrument::_array;
+int CMusicRoomInstrument::_arrayIndex;
+
+void CMusicRoomInstrument::init() {
+	_pianoToggle = false;
+	_pianoCtr = 0;
+	_bassCtr = 0;
+	_buffer = nullptr;
+	_array = nullptr;
+	_arrayIndex = 0;
+}
+
+void CMusicRoomInstrument::deinit() {
+	delete[] _buffer;
+	delete[] _array;
+	_buffer = nullptr;
+}
+
+CMusicRoomInstrument::CMusicRoomInstrument(CProjectItem *project, CSoundManager *soundManager, MusicWaveInstrument instrument) :
+		_project(project), _soundManager(soundManager), _instrument(instrument) {
+	Common::fill(&_gameObjects[0], &_gameObjects[4], (CGameObject *)nullptr);
+	_floatVal = 0.0;
+	_waveIndex = -1;
+	_readPos = 0;
+	_readIncrement = 0;
+	_size = 0;
+	_count = 0;
+	_field4C = 0;
+
+	switch (instrument) {
+	case MV_PIANO:
+		_gameObjects[0] = static_cast<CGameObject *>(_project->findByName("Piano Man"));
+		_gameObjects[1] = static_cast<CGameObject *>(_project->findByName("Piano Mouth"));
+		_gameObjects[2] = static_cast<CGameObject *>(_project->findByName("Piano Left Arm"));
+		_gameObjects[3] = static_cast<CGameObject *>(_project->findByName("Piano Right Arm"));
+		_floatVal = 0.45;
+		break;
+
+	case MV_BASS:
+		_gameObjects[0] = static_cast<CGameObject *>(_project->findByName("Bass Player"));
+		break;
+
+	case MV_BELLS:
+		_gameObjects[0] = static_cast<CGameObject *>(_project->findByName("Tubular Bells"));
+		_floatVal = 0.4;
+		break;
+	
+	case MV_SNAKE:
+		_gameObjects[0] = static_cast<CGameObject *>(_project->findByName("Snake_Hammer"));
+		_gameObjects[1] = static_cast<CGameObject *>(_project->findByName("Snake_Glass"));
+		_gameObjects[2] = static_cast<CGameObject *>(_project->findByName("Snake_Head"));
+		_floatVal = 0.17;
+		break;
+	}
+}
+
+void CMusicRoomInstrument::setFilesCount(uint count) {
+	assert(_items.empty());
+	_items.resize(count);
+}
+
+void CMusicRoomInstrument::load(int index, const CString &filename, int v3) {
+	assert(!_items[index]._waveFile);
+	_items[index]._waveFile = createWaveFile(filename);
+	_items[index]._value = v3;
+}
+
+CWaveFile *CMusicRoomInstrument::createWaveFile(const CString &name) {
+	if (name.empty())
+		return nullptr;
+	return _soundManager->loadSound(name);
+}
+
+void CMusicRoomInstrument::start(int val) {
+	if (_gameObjects[0]) {
+		switch (_instrument) {
+		case MV_PIANO:
+			_gameObjects[1]->setVisible(true);
+			_gameObjects[2]->setVisible(true);
+			_gameObjects[3]->setVisible(true);
+			_gameObjects[_pianoToggle ? 3 : 2]->playMovie(MOVIE_STOP_PREVIOUS);
+			_pianoToggle = !_pianoToggle;
+
+			switch (_pianoCtr) {
+			case 0:
+				_gameObjects[1]->playMovie(0, 4, MOVIE_STOP_PREVIOUS);
+				break;
+			case 1:
+				_gameObjects[1]->playMovie(4, 8, MOVIE_STOP_PREVIOUS);
+				break;
+			case 2:
+				_gameObjects[1]->playMovie(8, 12, MOVIE_STOP_PREVIOUS);
+				break;
+			case 3:
+				_gameObjects[1]->playMovie(12, 16, MOVIE_STOP_PREVIOUS);
+				break;
+			default:
+				break;
+			}
+
+			_pianoCtr = (_pianoCtr + 1) % 4;
+			break;
+
+		case MV_BASS:
+			switch (_bassCtr) {
+			case 0:
+				_gameObjects[0]->playMovie(0, 7, MOVIE_STOP_PREVIOUS);
+				break;
+			case 1:
+				_gameObjects[0]->playMovie(7, 14, MOVIE_STOP_PREVIOUS);
+				break;
+			case 2:
+				_gameObjects[0]->playMovie(15, 24, MOVIE_STOP_PREVIOUS);
+				break;
+			case 3:
+				_gameObjects[0]->playMovie(25, 33, MOVIE_STOP_PREVIOUS);
+				break;
+			default:
+				break;
+			}
+
+			// WORKAROUND: Original didn't change the selected bass animation
+			_bassCtr = (_bassCtr + 1) % 4;
+			break;
+
+		case MV_BELLS:
+			switch (val) {
+			case 60:
+				_gameObjects[0]->movieSetAudioTiming(true);
+				_gameObjects[0]->playMovie(0, 512, MOVIE_STOP_PREVIOUS);
+				_floatVal = 0.6;
+				break;
+
+			case 62:
+				_gameObjects[0]->playMovie(828, 1023, MOVIE_STOP_PREVIOUS);
+				_floatVal = 0.3;
+				break;
+
+			case 63:
+				_gameObjects[0]->playMovie(1024, 1085, MOVIE_STOP_PREVIOUS);
+				break;
+
+			default:
+				break;
+			}
+			break;
+
+		case MV_SNAKE: {
+			_gameObjects[0]->playMovie(0, 7, MOVIE_STOP_PREVIOUS);
+
+			double tempVal = 46.0 - ((double)(val - 14) * 1.43);
+			int frameNum = _field4C;
+			int frameNum1 = (tempVal - frameNum) * 0.25;
+			_gameObjects[1]->playMovie(frameNum1, frameNum1, MOVIE_STOP_PREVIOUS);
+
+			frameNum += frameNum1;
+			_gameObjects[1]->playMovie(frameNum, frameNum, 0);
+
+			frameNum += frameNum1;
+			_gameObjects[1]->playMovie(frameNum, frameNum, 0);
+
+			_gameObjects[2]->playMovie(45, 49, MOVIE_STOP_PREVIOUS);
+			break;
+		}
+
+		default:
+			break;
+		}
+	}
+}
+
+void CMusicRoomInstrument::stop() {
+	if (_gameObjects[0]) {
+		switch (_instrument) {
+		case MV_PIANO:
+			_gameObjects[1]->setVisible(false);
+			_gameObjects[2]->setVisible(false);
+			_gameObjects[3]->setVisible(false);
+			_gameObjects[0]->playMovie(29, 58, MOVIE_STOP_PREVIOUS);
+			break;
+
+		case MV_BELLS:
+			_gameObjects[0]->stopMovie();
+			break;
+
+		default:
+			break;
+		}
+	}
+}
+
+void CMusicRoomInstrument::trigger() {
+	if (_gameObjects[0]) {
+		switch (_instrument) {
+		case MV_PIANO:
+			_gameObjects[0]->playMovie(0, 29, MOVIE_STOP_PREVIOUS);
+			_gameObjects[2]->loadFrame(14);
+			_gameObjects[3]->loadFrame(22);
+			break;
+
+		case MV_BELLS:
+			_gameObjects[0]->loadFrame(0);
+			_gameObjects[0]->movieSetAudioTiming(true);
+			break;
+		
+		case MV_SNAKE:
+			_field4C = 22;
+			_gameObjects[1]->playMovie(0, 22, 0);
+			_gameObjects[2]->playMovie(0, 35, MOVIE_STOP_PREVIOUS);
+			_gameObjects[0]->playMovie(0, 1, MOVIE_STOP_PREVIOUS);
+			_gameObjects[0]->playMovie(0, 1, 0);
+			_gameObjects[0]->playMovie(0, 1, 0);
+			_gameObjects[0]->playMovie(0, 1, 0);
+			_gameObjects[0]->playMovie(0, 1, 0);
+			break;
+
+		default:
+			break;
+		}
+	}
+}
+
+void CMusicRoomInstrument::reset() {
+	_waveIndex = 0;
+	_readPos = 0;
+	_readIncrement = 0;
+	_size = 0;
+	_count = 0;
+}
+
+void CMusicRoomInstrument::setSize(uint total) {
+	_waveIndex = -1;
+	_readPos = 0;
+	_readIncrement = 0;
+	_size = total;
+	_count = 0;
+}
+
+int CMusicRoomInstrument::read(int16 *ptr, uint size) {
+	if (!_size)
+		return 0;
+
+	if (size >= _size)
+		size = _size;
+
+	if (_waveIndex != -1) {
+		// Lock the specified wave file for access
+		const int16 *data = _items[_waveIndex]._waveFile->lock();
+		assert(data);
+		const int16 *src = data;
+
+		// Loop through merging data from the wave file into the dest buffer
+		for (uint idx = 0; idx < (size / sizeof(int16)); ++idx, _readPos += _readIncrement) {
+			uint srcPos = _readPos >> 8;
+			if (srcPos >= _count)
+				break;
+
+			int16 val = READ_LE_UINT16(src + srcPos);
+			*ptr++ += val;
+		}
+
+		// Unlock the wave file
+		_items[_waveIndex]._waveFile->unlock(data);
+	}
+
+	_size -= size;
+	return size;
+}
+
+void CMusicRoomInstrument::chooseWaveFile(int index, int size) {
+	if (!_array)
+		setupArray(-36, 36);
+
+	int minDiff = ABS(_items[0]._value - index);
+	int waveIndex = 0;
+
+	for (uint idx = 1; idx < _items.size(); ++idx) {
+		int diff = ABS(_items[idx]._value - index);
+		if (diff < minDiff) {
+			minDiff = diff;
+			waveIndex = idx;
+		}
+	}
+
+	const CInstrumentWaveFile &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 = waveSize / 2;
+}
+
+void CMusicRoomInstrument::setupArray(int minVal, int maxVal) {
+	// Delete any prior array and recreate it
+	delete[] _array;
+
+	int arrSize = maxVal - minVal + 1;
+	_array = new double[arrSize];
+	_arrayIndex = ABS(minVal);
+
+	// Setup array contents
+	_array[_arrayIndex] = 1.0;
+
+	double val = 1.0594634;
+	for (int idx = 1; idx <= maxVal; ++idx) {
+		_array[_arrayIndex + idx] = val;
+		val *= 1.0594634;
+	}
+
+	val = 0.94387404038686;
+	for (int idx = -1; idx >= minVal; --idx) {
+		_array[_arrayIndex + idx] = val;
+		val *= 0.94387404038686;
+	}
+}
+
+} // End of namespace Titanic
diff --git a/engines/titanic/sound/music_room_instrument.h b/engines/titanic/sound/music_room_instrument.h
new file mode 100644
index 0000000..0a8ff16
--- /dev/null
+++ b/engines/titanic/sound/music_room_instrument.h
@@ -0,0 +1,133 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef TITANIC_MUSIC_ROOM_INSTRUMENT_H
+#define TITANIC_MUSIC_ROOM_INSTRUMENT_H
+
+#include "common/array.h"
+#include "titanic/support/string.h"
+
+namespace Titanic {
+
+enum MusicWaveInstrument { MV_PIANO = 0, MV_BASS = 1, MV_BELLS = 2, MV_SNAKE = 3 };
+
+class CProjectItem;
+class CSoundManager;
+class CWaveFile;
+class CGameObject;
+
+class CMusicRoomInstrument {
+	struct CInstrumentWaveFile {
+		CWaveFile *_waveFile;
+		int _value;
+		CInstrumentWaveFile() : _waveFile(nullptr), _value(0) {}
+	};
+private:
+	static bool _pianoToggle;
+	static int _pianoCtr;
+	static int _bassCtr;
+	static byte *_buffer;
+	static double *_array;
+	static int _arrayIndex;
+private:
+	CSoundManager *_soundManager;
+	Common::Array<CInstrumentWaveFile> _items;
+	MusicWaveInstrument _instrument;
+	CProjectItem *_project;
+	CGameObject *_gameObjects[4];
+	int _waveIndex;
+	int _readPos;
+	int _readIncrement;
+	uint _size;
+	uint _count;
+	int _field4C;
+private:
+	/**
+	 * Loads the specified wave file, and returns a CWaveFile instance for it
+	 */
+	CWaveFile *createWaveFile(const CString &name);
+
+	/**
+	 * Sets up an array used for figuring out the sequence in which to
+	 * play the different wave files for each instrument to give the
+	 * music based on the console's settings
+	 */
+	void setupArray(int minVal, int maxVal);
+public:
+	double _floatVal;
+public:
+	/**
+	 * Handles initialization of static fields
+	 */
+	static void init();
+
+	/**
+	 * Deinitialization of static fields
+	 */
+	static void deinit();
+public:
+	CMusicRoomInstrument(CProjectItem *project, CSoundManager *soundManager, MusicWaveInstrument instrument);
+
+	/**
+	 * Sets the maximum number of allowed files that be defined
+	 */
+	void setFilesCount(uint count);
+
+	/**
+	 * Loads a new file into the list of available entries
+	 */
+	void load(int index, const CString &filename, int v3);
+
+	/**
+	 * Starts the music and associated animations
+	 */
+	void start(int val);
+
+	/**
+	 * Stops the music and associated animations
+	 */
+	void stop();
+
+	/**
+	 * Called regularly to handle triggering the animation of the
+	 * musical instrument associated with the instance
+	 */
+	void trigger();
+
+	void reset();
+	void setSize(uint total);
+
+	/**
+	 * If there is any wave file currently specified, reads it in
+	 * and merges it into the supplied buffer
+	 */
+	int read(int16 *ptr, uint size);
+
+	/**
+	 * Figure out which wave file to use next
+	 */
+	void chooseWaveFile(int index, int freq);
+};
+
+} // End of namespace Titanic
+
+#endif /* TITANIC_MUSIC_ROOM_INSTRUMENT_H */
diff --git a/engines/titanic/sound/music_wave.cpp b/engines/titanic/sound/music_wave.cpp
deleted file mode 100644
index f6ea612..0000000
--- a/engines/titanic/sound/music_wave.cpp
+++ /dev/null
@@ -1,353 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "titanic/sound/music_wave.h"
-#include "titanic/sound/sound_manager.h"
-#include "titanic/core/project_item.h"
-#include "titanic/core/game_object.h"
-
-namespace Titanic {
-
-bool CMusicWave::_pianoToggle;
-int CMusicWave::_pianoCtr;
-int CMusicWave::_bassCtr;
-byte *CMusicWave::_buffer;
-double *CMusicWave::_array;
-int CMusicWave::_arrayIndex;
-
-void CMusicWave::init() {
-	_pianoToggle = false;
-	_pianoCtr = 0;
-	_bassCtr = 0;
-	_buffer = nullptr;
-	_array = nullptr;
-	_arrayIndex = 0;
-}
-
-void CMusicWave::deinit() {
-	delete[] _buffer;
-	delete[] _array;
-	_buffer = nullptr;
-}
-
-CMusicWave::CMusicWave(CProjectItem *project, CSoundManager *soundManager, MusicWaveInstrument instrument) :
-		_project(project), _soundManager(soundManager), _instrument(instrument) {
-	Common::fill(&_gameObjects[0], &_gameObjects[4], (CGameObject *)nullptr);
-	_floatVal = 0.0;
-	_waveIndex = -1;
-	_readPos = 0;
-	_readIncrement = 0;
-	_size = 0;
-	_count = 0;
-	_field4C = 0;
-
-	switch (instrument) {
-	case MV_PIANO:
-		_gameObjects[0] = static_cast<CGameObject *>(_project->findByName("Piano Man"));
-		_gameObjects[1] = static_cast<CGameObject *>(_project->findByName("Piano Mouth"));
-		_gameObjects[2] = static_cast<CGameObject *>(_project->findByName("Piano Left Arm"));
-		_gameObjects[3] = static_cast<CGameObject *>(_project->findByName("Piano Right Arm"));
-		_floatVal = 0.45;
-		break;
-
-	case MV_BASS:
-		_gameObjects[0] = static_cast<CGameObject *>(_project->findByName("Bass Player"));
-		break;
-
-	case MV_BELLS:
-		_gameObjects[0] = static_cast<CGameObject *>(_project->findByName("Tubular Bells"));
-		_floatVal = 0.4;
-		break;
-	
-	case MV_SNAKE:
-		_gameObjects[0] = static_cast<CGameObject *>(_project->findByName("Snake_Hammer"));
-		_gameObjects[1] = static_cast<CGameObject *>(_project->findByName("Snake_Glass"));
-		_gameObjects[2] = static_cast<CGameObject *>(_project->findByName("Snake_Head"));
-		_floatVal = 0.17;
-		break;
-	}
-}
-
-void CMusicWave::setFilesCount(uint count) {
-	assert(_items.empty());
-	_items.resize(count);
-}
-
-void CMusicWave::load(int index, const CString &filename, int v3) {
-	assert(!_items[index]._waveFile);
-	_items[index]._waveFile = createWaveFile(filename);
-	_items[index]._value = v3;
-}
-
-CWaveFile *CMusicWave::createWaveFile(const CString &name) {
-	if (name.empty())
-		return nullptr;
-	return _soundManager->loadSound(name);
-}
-
-void CMusicWave::start(int val) {
-	if (_gameObjects[0]) {
-		switch (_instrument) {
-		case MV_PIANO:
-			_gameObjects[1]->setVisible(true);
-			_gameObjects[2]->setVisible(true);
-			_gameObjects[3]->setVisible(true);
-			_gameObjects[_pianoToggle ? 3 : 2]->playMovie(MOVIE_STOP_PREVIOUS);
-			_pianoToggle = !_pianoToggle;
-
-			switch (_pianoCtr) {
-			case 0:
-				_gameObjects[1]->playMovie(0, 4, MOVIE_STOP_PREVIOUS);
-				break;
-			case 1:
-				_gameObjects[1]->playMovie(4, 8, MOVIE_STOP_PREVIOUS);
-				break;
-			case 2:
-				_gameObjects[1]->playMovie(8, 12, MOVIE_STOP_PREVIOUS);
-				break;
-			case 3:
-				_gameObjects[1]->playMovie(12, 16, MOVIE_STOP_PREVIOUS);
-				break;
-			default:
-				break;
-			}
-
-			_pianoCtr = (_pianoCtr + 1) % 4;
-			break;
-
-		case MV_BASS:
-			switch (_bassCtr) {
-			case 0:
-				_gameObjects[0]->playMovie(0, 7, MOVIE_STOP_PREVIOUS);
-				break;
-			case 1:
-				_gameObjects[0]->playMovie(7, 14, MOVIE_STOP_PREVIOUS);
-				break;
-			case 2:
-				_gameObjects[0]->playMovie(15, 24, MOVIE_STOP_PREVIOUS);
-				break;
-			case 3:
-				_gameObjects[0]->playMovie(25, 33, MOVIE_STOP_PREVIOUS);
-				break;
-			default:
-				break;
-			}
-
-			// WORKAROUND: Original didn't change the selected bass animation
-			_bassCtr = (_bassCtr + 1) % 4;
-			break;
-
-		case MV_BELLS:
-			switch (val) {
-			case 60:
-				_gameObjects[0]->movieSetAudioTiming(true);
-				_gameObjects[0]->playMovie(0, 512, MOVIE_STOP_PREVIOUS);
-				_floatVal = 0.6;
-				break;
-
-			case 62:
-				_gameObjects[0]->playMovie(828, 1023, MOVIE_STOP_PREVIOUS);
-				_floatVal = 0.3;
-				break;
-
-			case 63:
-				_gameObjects[0]->playMovie(1024, 1085, MOVIE_STOP_PREVIOUS);
-				break;
-
-			default:
-				break;
-			}
-			break;
-
-		case MV_SNAKE: {
-			_gameObjects[0]->playMovie(0, 7, MOVIE_STOP_PREVIOUS);
-
-			double tempVal = 46.0 - ((double)(val - 14) * 1.43);
-			int frameNum = _field4C;
-			int frameNum1 = (tempVal - frameNum) * 0.25;
-			_gameObjects[1]->playMovie(frameNum1, frameNum1, MOVIE_STOP_PREVIOUS);
-
-			frameNum += frameNum1;
-			_gameObjects[1]->playMovie(frameNum, frameNum, 0);
-
-			frameNum += frameNum1;
-			_gameObjects[1]->playMovie(frameNum, frameNum, 0);
-
-			_gameObjects[2]->playMovie(45, 49, MOVIE_STOP_PREVIOUS);
-			break;
-		}
-
-		default:
-			break;
-		}
-	}
-}
-
-void CMusicWave::stop() {
-	if (_gameObjects[0]) {
-		switch (_instrument) {
-		case MV_PIANO:
-			_gameObjects[1]->setVisible(false);
-			_gameObjects[2]->setVisible(false);
-			_gameObjects[3]->setVisible(false);
-			_gameObjects[0]->playMovie(29, 58, MOVIE_STOP_PREVIOUS);
-			break;
-
-		case MV_BELLS:
-			_gameObjects[0]->stopMovie();
-			break;
-
-		default:
-			break;
-		}
-	}
-}
-
-void CMusicWave::trigger() {
-	if (_gameObjects[0]) {
-		switch (_instrument) {
-		case MV_PIANO:
-			_gameObjects[0]->playMovie(0, 29, MOVIE_STOP_PREVIOUS);
-			_gameObjects[2]->loadFrame(14);
-			_gameObjects[3]->loadFrame(22);
-			break;
-
-		case MV_BELLS:
-			_gameObjects[0]->loadFrame(0);
-			_gameObjects[0]->movieSetAudioTiming(true);
-			break;
-		
-		case MV_SNAKE:
-			_field4C = 22;
-			_gameObjects[1]->playMovie(0, 22, 0);
-			_gameObjects[2]->playMovie(0, 35, MOVIE_STOP_PREVIOUS);
-			_gameObjects[0]->playMovie(0, 1, MOVIE_STOP_PREVIOUS);
-			_gameObjects[0]->playMovie(0, 1, 0);
-			_gameObjects[0]->playMovie(0, 1, 0);
-			_gameObjects[0]->playMovie(0, 1, 0);
-			_gameObjects[0]->playMovie(0, 1, 0);
-			break;
-
-		default:
-			break;
-		}
-	}
-}
-
-void CMusicWave::reset() {
-	_waveIndex = 0;
-	_readPos = 0;
-	_readIncrement = 0;
-	_size = 0;
-	_count = 0;
-}
-
-void CMusicWave::setSize(uint total) {
-	_waveIndex = -1;
-	_readPos = 0;
-	_readIncrement = 0;
-	_size = total;
-	_count = 0;
-}
-
-int CMusicWave::read(int16 *ptr, uint size) {
-	if (!_size)
-		return 0;
-
-	if (size >= _size)
-		size = _size;
-
-	if (_waveIndex != -1) {
-		// Lock the specified wave file for access
-		const int16 *data = _items[_waveIndex]._waveFile->lock();
-		assert(data);
-		const int16 *src = data;
-
-		// Loop through merging data from the wave file into the dest buffer
-		for (uint idx = 0; idx < (size / sizeof(int16)); ++idx, _readPos += _readIncrement) {
-			uint srcPos = _readPos >> 8;
-			if (srcPos >= _count)
-				break;
-
-			int16 val = READ_LE_UINT16(src + srcPos);
-			*ptr++ += val;
-		}
-
-		// Unlock the wave file
-		_items[_waveIndex]._waveFile->unlock(data);
-	}
-
-	_size -= size;
-	return size;
-}
-
-void CMusicWave::chooseWaveFile(int index, int size) {
-	if (!_array)
-		setupArray(-36, 36);
-
-	int minDiff = ABS(_items[0]._value - index);
-	int waveIndex = 0;
-
-	for (uint idx = 1; idx < _items.size(); ++idx) {
-		int diff = ABS(_items[idx]._value - index);
-		if (diff < minDiff) {
-			minDiff = diff;
-			waveIndex = idx;
-		}
-	}
-
-	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 = waveSize / 2;
-}
-
-void CMusicWave::setupArray(int minVal, int maxVal) {
-	// Delete any prior array and recreate it
-	delete[] _array;
-
-	int arrSize = maxVal - minVal + 1;
-	_array = new double[arrSize];
-	_arrayIndex = ABS(minVal);
-
-	// Setup array contents
-	_array[_arrayIndex] = 1.0;
-
-	double val = 1.0594634;
-	for (int idx = 1; idx <= maxVal; ++idx) {
-		_array[_arrayIndex + idx] = val;
-		val *= 1.0594634;
-	}
-
-	val = 0.94387404038686;
-	for (int idx = -1; idx >= minVal; --idx) {
-		_array[_arrayIndex + idx] = val;
-		val *= 0.94387404038686;
-	}
-}
-
-} // End of namespace Titanic
diff --git a/engines/titanic/sound/music_wave.h b/engines/titanic/sound/music_wave.h
deleted file mode 100644
index f378257..0000000
--- a/engines/titanic/sound/music_wave.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef TITANIC_MUSIC_WAVE_H
-#define TITANIC_MUSIC_WAVE_H
-
-#include "common/array.h"
-#include "titanic/support/string.h"
-
-namespace Titanic {
-
-enum MusicWaveInstrument { MV_PIANO = 0, MV_BASS = 1, MV_BELLS = 2, MV_SNAKE = 3 };
-
-class CProjectItem;
-class CSoundManager;
-class CWaveFile;
-class CGameObject;
-
-class CMusicWave {
-	struct CMusicWaveFile {
-		CWaveFile *_waveFile;
-		int _value;
-		CMusicWaveFile() : _waveFile(nullptr), _value(0) {}
-	};
-private:
-	static bool _pianoToggle;
-	static int _pianoCtr;
-	static int _bassCtr;
-	static byte *_buffer;
-	static double *_array;
-	static int _arrayIndex;
-private:
-	CSoundManager *_soundManager;
-	Common::Array<CMusicWaveFile> _items;
-	MusicWaveInstrument _instrument;
-	CProjectItem *_project;
-	CGameObject *_gameObjects[4];
-	int _waveIndex;
-	int _readPos;
-	int _readIncrement;
-	uint _size;
-	uint _count;
-	int _field4C;
-private:
-	/**
-	 * Loads the specified wave file, and returns a CWaveFile instance for it
-	 */
-	CWaveFile *createWaveFile(const CString &name);
-
-	/**
-	 * Sets up an array used for figuring out the sequence in which to
-	 * play the different wave files for each instrument to give the
-	 * music based on the console's settings
-	 */
-	void setupArray(int minVal, int maxVal);
-public:
-	double _floatVal;
-public:
-	/**
-	 * Handles initialization of static fields
-	 */
-	static void init();
-
-	/**
-	 * Deinitialization of static fields
-	 */
-	static void deinit();
-public:
-	CMusicWave(CProjectItem *project, CSoundManager *soundManager, MusicWaveInstrument instrument);
-
-	/**
-	 * Sets the maximum number of allowed files that be defined
-	 */
-	void setFilesCount(uint count);
-
-	/**
-	 * Loads a new file into the list of available entries
-	 */
-	void load(int index, const CString &filename, int v3);
-
-	/**
-	 * Starts the music and associated animations
-	 */
-	void start(int val);
-
-	/**
-	 * Stops the music and associated animations
-	 */
-	void stop();
-
-	/**
-	 * Called regularly to handle triggering the animation of the
-	 * musical instrument associated with the instance
-	 */
-	void trigger();
-
-	void reset();
-	void setSize(uint total);
-
-	/**
-	 * If there is any wave file currently specified, reads it in
-	 * and merges it into the supplied buffer
-	 */
-	int read(int16 *ptr, uint size);
-
-	/**
-	 * Figure out which wave file to use next
-	 */
-	void chooseWaveFile(int index, int freq);
-};
-
-} // End of namespace Titanic
-
-#endif /* TITANIC_MUSIC_WAVE_H */
diff --git a/engines/titanic/titanic.cpp b/engines/titanic/titanic.cpp
index 5c84bde..116c334 100644
--- a/engines/titanic/titanic.cpp
+++ b/engines/titanic/titanic.cpp
@@ -41,7 +41,7 @@
 #include "titanic/moves/enter_exit_sec_class_mini_lift.h"
 #include "titanic/moves/exit_pellerator.h"
 #include "titanic/pet_control/pet_control.h"
-#include "titanic/sound/music_wave.h"
+#include "titanic/sound/music_room_instrument.h"
 #include "titanic/support/simple_file.h"
 #include "titanic/true_talk/tt_npc_script.h"
 
@@ -87,7 +87,7 @@ void TitanicEngine::initialize() {
 	CGetLiftEye2::init();
 	CHose::init();
 	CMovie::init();
-	CMusicWave::init();
+	CMusicRoomInstrument::init();
 	CParrotLobbyObject::init();
 	CSGTNavigation::init();
 	CSGTStateRoom::init();





More information about the Scummvm-git-logs mailing list