[Scummvm-cvs-logs] scummvm master -> bf4562ba4f8befe9f985c464e9a5094e3e6f255d

dreammaster dreammaster at scummvm.org
Fri Aug 12 13:46:41 CEST 2016


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:
bf4562ba4f TITANIC: Further fleshing out sound manager, fixing sound looping


Commit: bf4562ba4f8befe9f985c464e9a5094e3e6f255d
    https://github.com/scummvm/scummvm/commit/bf4562ba4f8befe9f985c464e9a5094e3e6f255d
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2016-08-12T07:46:35-04:00

Commit Message:
TITANIC: Further fleshing out sound manager, fixing sound looping

Changed paths:
    engines/titanic/sound/proximity.cpp
    engines/titanic/sound/proximity.h
    engines/titanic/sound/qmixer.cpp
    engines/titanic/sound/qmixer.h
    engines/titanic/sound/sound.cpp
    engines/titanic/sound/sound.h
    engines/titanic/sound/sound_manager.cpp
    engines/titanic/sound/sound_manager.h
    engines/titanic/sound/wave_file.h



diff --git a/engines/titanic/sound/proximity.cpp b/engines/titanic/sound/proximity.cpp
index b4cd160..7f4e678 100644
--- a/engines/titanic/sound/proximity.cpp
+++ b/engines/titanic/sound/proximity.cpp
@@ -30,7 +30,7 @@ CProximity::CProximity() : _field4(0), _channelVolume(100), _fieldC(0),
 		_repeated(false), _channel(10), _positioningMode(POSMODE_NONE), _azimuth(0.0),
 		_range(0.5), _elevation(0), _posX(0.0), _posY(0.0), _posZ(0.0),
 		_hasVelocity(false), _velocityX(0), _velocityY(0), _velocityZ(0),
-		_field54(0), _field58(0), _field5C(0), _field60(0), _endTalkerFn(nullptr),
+		_field54(0), _field58(0), _field5C(0), _freeSoundFlag(false), _endTalkerFn(nullptr),
 		_talker(nullptr), _field6C(0) {
 }
 
diff --git a/engines/titanic/sound/proximity.h b/engines/titanic/sound/proximity.h
index 9335989..b728f22 100644
--- a/engines/titanic/sound/proximity.h
+++ b/engines/titanic/sound/proximity.h
@@ -58,7 +58,7 @@ public:
 	int _field54;
 	int _field58;
 	int _field5C;
-	int _field60;
+	bool _freeSoundFlag;
 	CEndTalkerFn _endTalkerFn;
 	TTtalker *_talker;
 	int _field6C;
diff --git a/engines/titanic/sound/qmixer.cpp b/engines/titanic/sound/qmixer.cpp
index 32554a5..145d142 100644
--- a/engines/titanic/sound/qmixer.cpp
+++ b/engines/titanic/sound/qmixer.cpp
@@ -118,7 +118,7 @@ int QMixer::qsWaveMixPlayEx(int iChannel, uint flags, CWaveFile *waveFile, int l
 	}
 
 	// Add the sound to the channel
-	channel._sounds.push_back(SoundEntry(waveFile, params.callback, params.dwUser));
+	channel._sounds.push_back(SoundEntry(waveFile, params.callback, loops, params.dwUser));
 	qsWaveMixPump();
 
 	return 0;
@@ -138,9 +138,21 @@ void QMixer::qsWaveMixPump() {
 		if (!channel._sounds.empty()) {
 			SoundEntry &sound = channel._sounds.front();
 			if (sound._started && !_mixer->isSoundHandleActive(sound._soundHandle)) {
-				if (sound._callback)
-					sound._callback(iChannel, sound._waveFile, sound._userData);
-				channel._sounds.erase(channel._sounds.begin());
+				if (sound._loops == -1 || sound._loops-- > 0) {
+					// Need to loop the sound again
+					sound._waveFile->_stream->rewind();
+					_mixer->playStream(sound._waveFile->_soundType,
+						&sound._soundHandle, sound._waveFile->_stream,
+						-1, 0xff, 0, DisposeAfterUse::NO);
+				} else {
+					// Sound is finished
+					if (sound._callback)
+						// Call the callback to signal end
+						sound._callback(iChannel, sound._waveFile, sound._userData);
+
+					// Remove sound record from channel
+					channel._sounds.erase(channel._sounds.begin());
+				}
 			}
 		}
 
@@ -150,7 +162,8 @@ void QMixer::qsWaveMixPump() {
 			SoundEntry &sound = channel._sounds.front();
 			if (!sound._started) {
 				_mixer->playStream(sound._waveFile->_soundType,
-					&sound._soundHandle, sound._waveFile->_stream);
+					&sound._soundHandle, sound._waveFile->_stream,
+					-1, 0xff, 0, DisposeAfterUse::NO);
 				sound._started = true;
 			}
 		}
diff --git a/engines/titanic/sound/qmixer.h b/engines/titanic/sound/qmixer.h
index edb20b7..4ba76a8 100644
--- a/engines/titanic/sound/qmixer.h
+++ b/engines/titanic/sound/qmixer.h
@@ -177,12 +177,13 @@ class QMixer {
 		CWaveFile *_waveFile;
 		Audio::SoundHandle _soundHandle;
 		LPQMIXDONECALLBACK _callback;
+		int _loops;
 		void *_userData;
 		SoundEntry() : _started(false), _waveFile(nullptr), _callback(nullptr),
-			_userData(nullptr) {}
+			_loops(0), _userData(nullptr) {}
 
-		SoundEntry(CWaveFile *waveFile, LPQMIXDONECALLBACK callback, void *userData) :
-			_started(false), _waveFile(waveFile), _callback(callback), _userData(userData) {}
+		SoundEntry(CWaveFile *waveFile, LPQMIXDONECALLBACK callback, int loops, void *userData) :
+			_started(false), _waveFile(waveFile), _callback(callback), _loops(loops), _userData(userData) {}
 	};
 	struct ChannelEntry {
 		Common::List<SoundEntry> _sounds;
diff --git a/engines/titanic/sound/sound.cpp b/engines/titanic/sound/sound.cpp
index d14c628..7e791c2 100644
--- a/engines/titanic/sound/sound.cpp
+++ b/engines/titanic/sound/sound.cpp
@@ -68,8 +68,18 @@ void CSound::setVolume(uint handle, uint volume, uint seconds) {
 	_soundManager.setVolume(handle, volume, seconds);
 }
 
-void CSound::fn4(CWaveFile *waveFile, int val) {	
-	// TODO
+void CSound::activateSound(CWaveFile *waveFile, bool freeFlag) {	
+	for (CSoundItemList::iterator i = _sounds.begin(); i != _sounds.end(); ++i) {
+		CSoundItem *sound = *i;
+		if (sound->_waveFile == waveFile) {
+			sound->_active = true;
+			sound->_freeFlag = freeFlag;
+
+			if (!freeFlag && waveFile->size() > 51200)
+				sound->_freeFlag = true;
+			break;
+		}
+	}
 }
 
 void CSound::stopChannel(int channel) {
@@ -79,7 +89,7 @@ void CSound::stopChannel(int channel) {
 void CSound::checkSounds() {
 	for (CSoundItemList::iterator i = _sounds.begin(); i != _sounds.end(); ++i) {
 		CSoundItem *soundItem = *i;
-		if (soundItem->_field24 && soundItem->_field28) {
+		if (soundItem->_active && soundItem->_freeFlag) {
 			if (_soundManager.isActive(soundItem->_waveFile)) {
 				_sounds.remove(soundItem);
 				delete soundItem;
@@ -92,7 +102,7 @@ void CSound::removeOldest() {
 	for (CSoundItemList::iterator i = _sounds.reverse_begin();
 			i != _sounds.end(); --i) {
 		CSoundItem *soundItem = *i;
-		if (soundItem->_field28 && !_soundManager.isActive(soundItem->_waveFile)) {
+		if (soundItem->_active && !_soundManager.isActive(soundItem->_waveFile)) {
 			_sounds.remove(soundItem);
 			delete soundItem;
 			break;
@@ -145,7 +155,7 @@ int CSound::playSound(const CString &name, CProximity &prox) {
 		return -1;
 
 	prox._field6C = waveFile->fn1();
-	fn4(waveFile, prox._field60);
+	activateSound(waveFile, prox._freeSoundFlag);
 
 	return _soundManager.playSound(*waveFile, prox);
 }
@@ -192,7 +202,7 @@ int CSound::playSpeech(CDialogueFile *dialogueFile, int speechId, CProximity &pr
 		return -1;
 
 	prox._field6C = waveFile->fn1();
-	fn4(waveFile, prox._field60);
+	activateSound(waveFile, prox._freeSoundFlag);
 
 	return _soundManager.playSound(*waveFile, prox);
 }
diff --git a/engines/titanic/sound/sound.h b/engines/titanic/sound/sound.h
index b6c77e7..de95f9e 100644
--- a/engines/titanic/sound/sound.h
+++ b/engines/titanic/sound/sound.h
@@ -41,15 +41,15 @@ public:
 	CWaveFile *_waveFile;
 	File *_dialogueFileHandle;
 	int _speechId;
-	int _field24;
-	int _field28;
+	bool _freeFlag;
+	bool _active;
 public:
 	CSoundItem() : ListItem(), _waveFile(nullptr), _dialogueFileHandle(nullptr),
-		_speechId(0), _field24(0), _field28(0) {}
+		_speechId(0), _freeFlag(false), _active(false) {}
 	CSoundItem(const CString &name) : ListItem(), _name(name), _waveFile(nullptr),
-		_dialogueFileHandle(nullptr), _speechId(0), _field24(0), _field28(0) {}
+		_dialogueFileHandle(nullptr), _speechId(0), _freeFlag(false), _active(false) {}
 	CSoundItem(File *dialogueFile, int speechId) : ListItem(), _waveFile(nullptr),
-		_dialogueFileHandle(dialogueFile), _speechId(speechId), _field24(0), _field28(0) {}
+		_dialogueFileHandle(dialogueFile), _speechId(speechId), _freeFlag(false), _active(false) {}
 };
 
 class CSoundItemList : public List<CSoundItem> {
@@ -123,7 +123,10 @@ public:
 	 */
 	void setVolume(uint handle, uint volume, uint seconds);
 
-	void fn4(CWaveFile *waveFile, int val);
+	/**
+	 * Flags a sound about to be played as activated
+	 */
+	void activateSound(CWaveFile *waveFile, bool freeFlag);
 
 	/**
 	 * Stops any sounds attached to a given channel
diff --git a/engines/titanic/sound/sound_manager.cpp b/engines/titanic/sound/sound_manager.cpp
index 18ad970..84d38ed 100644
--- a/engines/titanic/sound/sound_manager.cpp
+++ b/engines/titanic/sound/sound_manager.cpp
@@ -32,7 +32,7 @@ CSoundManager::CSoundManager() : _musicPercent(75.0), _speechPercent(75.0),
 	_masterPercent(75.0), _parrotPercent(75.0), _handleCtr(1) {
 }
 
-uint CSoundManager::getModeVolume(int mode) {
+double CSoundManager::getModeVolume(int mode) {
 	switch (mode) {
 	case -1:
 		return _masterPercent;
@@ -414,7 +414,7 @@ int QSoundManager::playWave(CWaveFile *waveFile, int iChannel, uint flags, CProx
 		return slot._handle;
 	} else {
 		_sounds.flushChannel(waveFile, iChannel);
-		if (prox._field60)
+		if (prox._freeSoundFlag)
 			delete waveFile;
 		return 0;
 	}
diff --git a/engines/titanic/sound/sound_manager.h b/engines/titanic/sound/sound_manager.h
index d1afdb4..3dfba92 100644
--- a/engines/titanic/sound/sound_manager.h
+++ b/engines/titanic/sound/sound_manager.h
@@ -214,7 +214,7 @@ public:
 	/**
 	 * Gets the volume for a given mode? value
 	 */
-	uint getModeVolume(int mode);
+	double getModeVolume(int mode);
 };
 
 class QSoundManagerSound : public ListItem {
diff --git a/engines/titanic/sound/wave_file.h b/engines/titanic/sound/wave_file.h
index 8c86c50..aede0c9 100644
--- a/engines/titanic/sound/wave_file.h
+++ b/engines/titanic/sound/wave_file.h
@@ -37,7 +37,7 @@ private:
 	uint _size;
 public:
 	QSoundManager *_owner;
-	Audio::AudioStream *_stream;
+	Audio::SeekableAudioStream *_stream;
 	Audio::SoundHandle _soundHandle;
 	Audio::Mixer::SoundType _soundType;
 public:






More information about the Scummvm-git-logs mailing list