[Scummvm-git-logs] scummvm master -> 059a2b375182270012d5b4313e9cd04fedf7054e

dreammaster dreammaster at scummvm.org
Thu Feb 9 02:30:27 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:
059a2b3751 TITANIC: Renamings and comments for music classes


Commit: 059a2b375182270012d5b4313e9cd04fedf7054e
    https://github.com/scummvm/scummvm/commit/059a2b375182270012d5b4313e9cd04fedf7054e
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2017-02-08T20:30:18-05:00

Commit Message:
TITANIC: Renamings and comments for music classes

Changed paths:
    engines/titanic/sound/music_room_handler.cpp
    engines/titanic/sound/music_wave.cpp
    engines/titanic/sound/music_wave.h
    engines/titanic/sound/qmixer.cpp
    engines/titanic/sound/wave_file.cpp
    engines/titanic/sound/wave_file.h


diff --git a/engines/titanic/sound/music_room_handler.cpp b/engines/titanic/sound/music_room_handler.cpp
index d3ced80..8c0ac88 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]->processArray(getPitch(index, arrIndex), size);
+		_musicWaves[index]->chooseInstrument(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 5f111a4..2b89c70 100644
--- a/engines/titanic/sound/music_wave.cpp
+++ b/engines/titanic/sound/music_wave.cpp
@@ -53,7 +53,7 @@ CMusicWave::CMusicWave(CProjectItem *project, CSoundManager *soundManager, Music
 		_project(project), _soundManager(soundManager), _instrument(instrument) {
 	Common::fill(&_gameObjects[0], &_gameObjects[4], (CGameObject *)nullptr);
 	_floatVal = 0.0;
-	_field34 = -1;
+	_waveIndex = -1;
 	_readPos = 0;
 	_readIncrement = 0;
 	_size = 0;
@@ -254,7 +254,7 @@ void CMusicWave::trigger() {
 }
 
 void CMusicWave::reset() {
-	_field34 = 0;
+	_waveIndex = 0;
 	_readPos = 0;
 	_readIncrement = 0;
 	_size = 0;
@@ -262,7 +262,7 @@ void CMusicWave::reset() {
 }
 
 void CMusicWave::setSize(uint total) {
-	_field34 = -1;
+	_waveIndex = -1;
 	_readPos = 0;
 	_readIncrement = 0;
 	_size = total;
@@ -276,8 +276,8 @@ int CMusicWave::read(uint16 *ptr, uint size) {
 	if (size >= _size)
 		size = _size;
 
-	if (_field34 != -1) {
-		const byte *data = _items[_field34]._waveFile->lock();
+	if (_waveIndex != -1) {
+		const byte *data = _items[_waveIndex]._waveFile->lock();
 		assert(data);
 		const uint16 *src = (const uint16 *)data;
 
@@ -291,14 +291,14 @@ int CMusicWave::read(uint16 *ptr, uint size) {
 			*ptr++ = val;
 		}
 
-		_items[_field34]._waveFile->unlock(data);
+		_items[_waveIndex]._waveFile->unlock(data);
 	}
 
 	_size -= size;
 	return size;
 }
 
-void CMusicWave::processArray(int index, int size) {
+void CMusicWave::chooseInstrument(int index, int size) {
 	if (!_array)
 		setupArray(-36, 36);
 
@@ -314,7 +314,7 @@ void CMusicWave::processArray(int index, int size) {
 
 	int arrIndex = _arrayIndex - _items[minIndex]._value + index;
 
-	_field34 = minIndex;
+	_waveIndex = minIndex;
 	_readPos = 0;
 	_readIncrement = (int)(_array[arrIndex] * 256);
 	_size = size;
diff --git a/engines/titanic/sound/music_wave.h b/engines/titanic/sound/music_wave.h
index d1ccb33..baed60c 100644
--- a/engines/titanic/sound/music_wave.h
+++ b/engines/titanic/sound/music_wave.h
@@ -54,7 +54,7 @@ private:
 	MusicWaveInstrument _instrument;
 	CProjectItem *_project;
 	CGameObject *_gameObjects[4];
-	int _field34;
+	int _waveIndex;
 	int _readPos;
 	int _readIncrement;
 	uint _size;
@@ -66,6 +66,11 @@ private:
 	 */
 	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;
@@ -116,7 +121,10 @@ public:
 	 */
 	int read(uint16 *ptr, uint size);
 
-	void processArray(int index, int freq);
+	/**
+	 * Figure out which wave file to use next
+	 */
+	void chooseInstrument(int index, int freq);
 };
 
 } // End of namespace Titanic
diff --git a/engines/titanic/sound/qmixer.cpp b/engines/titanic/sound/qmixer.cpp
index b3910f8..1854260 100644
--- a/engines/titanic/sound/qmixer.cpp
+++ b/engines/titanic/sound/qmixer.cpp
@@ -204,9 +204,9 @@ void QMixer::qsWaveMixPump() {
 			if (sound._started && !_mixer->isSoundHandleActive(sound._soundHandle)) {
 				if (sound._loops == -1 || sound._loops-- > 0) {
 					// Need to loop the sound again
-					sound._waveFile->_stream->rewind();
+					sound._waveFile->_audioStream->rewind();
 					_mixer->playStream(sound._waveFile->_soundType,
-						&sound._soundHandle, sound._waveFile->_stream,
+						&sound._soundHandle, sound._waveFile->_audioStream,
 						-1, channel.getRawVolume(), 0, DisposeAfterUse::NO);
 				} else {
 					// Sound is finished
@@ -230,7 +230,7 @@ void QMixer::qsWaveMixPump() {
 
 				// Calculate an effective volume based on distance of source
 				_mixer->playStream(sound._waveFile->_soundType,
-					&sound._soundHandle, sound._waveFile->_stream,
+					&sound._soundHandle, sound._waveFile->_audioStream,
 					-1, channel.getRawVolume(), 0, DisposeAfterUse::NO);
 				sound._started = true;
 			}
diff --git a/engines/titanic/sound/wave_file.cpp b/engines/titanic/sound/wave_file.cpp
index 3082bbf..5d9987a 100644
--- a/engines/titanic/sound/wave_file.cpp
+++ b/engines/titanic/sound/wave_file.cpp
@@ -28,12 +28,14 @@
 
 namespace Titanic {
 
-CWaveFile::CWaveFile() : _soundManager(nullptr), _stream(nullptr),
-		_soundType(Audio::Mixer::kPlainSoundType) {
+#define WAV_DATA_OFFSET 0x46
+
+CWaveFile::CWaveFile() : _soundManager(nullptr), _audioStream(nullptr),
+		_rawData(nullptr), _soundType(Audio::Mixer::kPlainSoundType) {
 	setup();
 }
 
-CWaveFile::CWaveFile(QSoundManager *owner) : _soundManager(owner), _stream(nullptr),
+CWaveFile::CWaveFile(QSoundManager *owner) : _soundManager(owner), _audioStream(nullptr),
 		_soundType(Audio::Mixer::kPlainSoundType) {
 	setup();
 }
@@ -49,9 +51,9 @@ void CWaveFile::setup() {
 }
 
 CWaveFile::~CWaveFile() {
-	if (_stream) {
+	if (_audioStream) {
 		_soundManager->soundFreed(_soundHandle);
-		delete _stream;
+		delete _audioStream;
 	}
 
 	if (_disposeAudioBuffer == DisposeAfterUse::YES && _audioBuffer)
@@ -59,20 +61,20 @@ CWaveFile::~CWaveFile() {
 }
 
 uint CWaveFile::getDurationTicks() const {
-	if (!_stream)
+	if (!_audioStream)
 		return 0;
 
 	// FIXME: The original uses acmStreamSize to calculate
 	// a desired size. Since I have no idea how the system API
 	// method works, for now I'm using a simple ratio of a
 	// sample output to input value
-	uint dataSize = _dataSize - 0x46;
+	uint dataSize = _dataSize - WAV_DATA_OFFSET;
 	double newSize = (double)dataSize * (1475712.0 / 199836.0);
-	return (uint)(newSize * 1000.0 / _stream->getRate());
+	return (uint)(newSize * 1000.0 / _audioStream->getRate());
 }
 
 bool CWaveFile::loadSound(const CString &name) {
-	assert(!_stream);
+	assert(!_audioStream);
 
 	StdCWadFile file;
 	if (!file.open(name))
@@ -80,7 +82,12 @@ bool CWaveFile::loadSound(const CString &name) {
 
 	Common::SeekableReadStream *stream = file.readStream();
 	_dataSize = stream->size();
-	_stream = Audio::makeWAVStream(stream->readStream(_dataSize), DisposeAfterUse::YES);
+	_rawData = new byte[_dataSize];
+	stream->read(_rawData, _dataSize);
+	
+	_audioStream = Audio::makeWAVStream(
+		new Common::MemoryReadStream(_rawData, _dataSize, DisposeAfterUse::YES),
+		DisposeAfterUse::YES);
 	_soundType = Audio::Mixer::kSFXSoundType;
 
 	return true;
@@ -95,7 +102,7 @@ bool CWaveFile::loadSpeech(CDialogueFile *dialogueFile, int speechIndex) {
 	dialogueFile->read(res, data, res->_size);
 
 	_dataSize = res->_size;
-	_stream = Audio::makeWAVStream(new Common::MemoryReadStream(data, _dataSize, DisposeAfterUse::YES),
+	_audioStream = Audio::makeWAVStream(new Common::MemoryReadStream(data, _dataSize, DisposeAfterUse::YES),
 		DisposeAfterUse::YES);
 	_soundType = Audio::Mixer::kSpeechSoundType;
 
@@ -103,7 +110,7 @@ bool CWaveFile::loadSpeech(CDialogueFile *dialogueFile, int speechIndex) {
 }
 
 bool CWaveFile::loadMusic(const CString &name) {
-	assert(!_stream);
+	assert(!_audioStream);
 
 	StdCWadFile file;
 	if (!file.open(name))
@@ -111,7 +118,7 @@ bool CWaveFile::loadMusic(const CString &name) {
 
 	Common::SeekableReadStream *stream = file.readStream();
 	_dataSize = stream->size();
-	_stream = Audio::makeWAVStream(stream->readStream(_dataSize), DisposeAfterUse::YES);
+	_audioStream = Audio::makeWAVStream(stream->readStream(_dataSize), DisposeAfterUse::YES);
 	_soundType = Audio::Mixer::kMusicSoundType;
 
 	return true;
@@ -127,19 +134,17 @@ bool CWaveFile::loadMusic(CAudioBuffer *buffer, DisposeAfterUse::Flag disposeAft
 }
 
 uint CWaveFile::getFrequency() const {
-	return _stream->getRate();
+	return _audioStream->getRate();
 }
 
 void CWaveFile::reset() {
-	_stream->rewind();
+	_audioStream->rewind();
 }
 
 const byte *CWaveFile::lock() {
 	switch (_loadMode) {
-	case LOADMODE_AUDIO_BUFFER:
-		// TODO: At this point, locking returning a pointer to a buffer
-		// into a QSound wave mixer, for pushing out
-		error("TODO: Handle pushing data to sound");
+	case LOADMODE_SCUMMVM:
+		return _rawData + WAV_DATA_OFFSET;
 
 	default:
 		return nullptr;
diff --git a/engines/titanic/sound/wave_file.h b/engines/titanic/sound/wave_file.h
index 976979b..019ee94 100644
--- a/engines/titanic/sound/wave_file.h
+++ b/engines/titanic/sound/wave_file.h
@@ -43,7 +43,8 @@ private:
 	void setup();
 public:
 	QSoundManager *_soundManager;
-	Audio::SeekableAudioStream *_stream;
+	byte *_rawData;
+	Audio::SeekableAudioStream *_audioStream;
 	Audio::SoundHandle _soundHandle;
 	Audio::Mixer::SoundType _soundType;
 
@@ -94,7 +95,7 @@ public:
 	/**
 	 * Returns true if the wave file has data loaded
 	 */
-	bool isLoaded() const { return _stream != nullptr; }
+	bool isLoaded() const { return _audioStream != nullptr; }
 
 	/**
 	 * Return the frequency of the loaded wave file





More information about the Scummvm-git-logs mailing list