[Scummvm-cvs-logs] scummvm master -> 7820bd5aed9d19fe09b910d1e6cc7ae1aa010631

dreammaster dreammaster at scummvm.org
Mon Dec 7 03:57:04 CET 2015


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:
7820bd5aed ACCESS: Prevent multiple copies of the same sound being queued


Commit: 7820bd5aed9d19fe09b910d1e6cc7ae1aa010631
    https://github.com/scummvm/scummvm/commit/7820bd5aed9d19fe09b910d1e6cc7ae1aa010631
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2015-12-06T21:56:28-05:00

Commit Message:
ACCESS: Prevent multiple copies of the same sound being queued

Changed paths:
    engines/access/sound.cpp
    engines/access/sound.h



diff --git a/engines/access/sound.cpp b/engines/access/sound.cpp
index 5fb9711..38f544d 100644
--- a/engines/access/sound.cpp
+++ b/engines/access/sound.cpp
@@ -51,11 +51,20 @@ void SoundManager::clearSounds() {
 		_mixer->stopHandle(_effectsHandle);
 
 	while (_queue.size()) {
-		delete _queue[0];
+		delete _queue[0]._stream;
 		_queue.remove_at(0);
 	}
 }
 
+bool SoundManager::isSoundQueued(int soundId) const {
+	for (uint idx = 0; idx < _queue.size(); ++idx) {
+		if (_queue[idx]._soundId == soundId)
+			return true;
+	}
+
+	return false;
+}
+
 void SoundManager::loadSoundTable(int idx, int fileNum, int subfile, int priority) {
 	debugC(1, kDebugSound, "loadSoundTable(%d, %d, %d)", idx, fileNum, subfile);
 
@@ -77,12 +86,15 @@ Resource *SoundManager::loadSound(int fileNum, int subfile) {
 
 void SoundManager::playSound(int soundIndex, bool loop) {
 	debugC(1, kDebugSound, "playSound(%d, %d)", soundIndex, loop);
+	if (isSoundQueued(soundIndex))
+		// Prevent duplicate copies of a sound from being queued
+		return;
 
 	int priority = _soundTable[soundIndex]._priority;
-	playSound(_soundTable[soundIndex]._res, priority, loop);
+	playSound(_soundTable[soundIndex]._res, priority, loop, soundIndex);
 }
 
-void SoundManager::playSound(Resource *res, int priority, bool loop) {
+void SoundManager::playSound(Resource *res, int priority, bool loop, int soundIndex) {
 	debugC(1, kDebugSound, "playSound");
 
 	byte *resourceData = res->data();
@@ -139,14 +151,15 @@ void SoundManager::playSound(Resource *res, int priority, bool loop) {
 		error("Unknown format");
 
 	if (loop) {
-		_queue.push_back(new Audio::LoopingAudioStream(audioStream, 0, DisposeAfterUse::NO));
+		_queue.push_back(QueuedSound(new Audio::LoopingAudioStream(audioStream, 0, 
+			DisposeAfterUse::NO), soundIndex));
 	} else {
-		_queue.push_back(audioStream);
+		_queue.push_back(QueuedSound(audioStream, soundIndex));
 	}
 
 	if (!_mixer->isSoundHandleActive(_effectsHandle))
 		_mixer->playStream(Audio::Mixer::kSFXSoundType, &_effectsHandle,
-						_queue[0], -1, _mixer->kMaxChannelVolume, 0,
+						_queue[0]._stream, -1, _mixer->kMaxChannelVolume, 0,
 						DisposeAfterUse::NO);
 }
 
@@ -156,12 +169,12 @@ void SoundManager::checkSoundQueue() {
 	if (_queue.empty() || _mixer->isSoundHandleActive(_effectsHandle))
 		return;
 
-	delete _queue[0];
+	delete _queue[0]._stream;
 	_queue.remove_at(0);
 
-	if (_queue.size() && _queue[0])
+	if (_queue.size() && _queue[0]._stream)
 		_mixer->playStream(Audio::Mixer::kSFXSoundType, &_effectsHandle,
-		   _queue[0], -1, _mixer->kMaxChannelVolume, 0,
+		   _queue[0]._stream, -1, _mixer->kMaxChannelVolume, 0,
 		   DisposeAfterUse::NO);
 }
 
diff --git a/engines/access/sound.h b/engines/access/sound.h
index e11a6b9..b372e56 100644
--- a/engines/access/sound.h
+++ b/engines/access/sound.h
@@ -45,15 +45,24 @@ struct SoundEntry {
 };
 
 class SoundManager {
+	struct QueuedSound {
+		Audio::AudioStream *_stream;
+		int _soundId;
+
+		QueuedSound() : _stream(nullptr), _soundId(-1) {}
+		QueuedSound(Audio::AudioStream *stream, int soundId) : _stream(stream), _soundId(soundId) {}
+	};
 private:
 	AccessEngine *_vm;
 	Audio::Mixer *_mixer;
 	Audio::SoundHandle _effectsHandle;
-	Common::Array<Audio::AudioStream *> _queue;
+	Common::Array<QueuedSound> _queue;
 
 	void clearSounds();
 
-	void playSound(Resource *res, int priority, bool loop);
+	void playSound(Resource *res, int priority, bool loop, int soundIndex = -1);
+
+	bool isSoundQueued(int soundId) const;
 public:
 	Common::Array<SoundEntry> _soundTable;
 	bool _playingSound;






More information about the Scummvm-git-logs mailing list