aboutsummaryrefslogtreecommitdiff
path: root/engines/access/sound.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2015-12-06 21:56:28 -0500
committerPaul Gilbert2015-12-06 21:56:28 -0500
commit7820bd5aed9d19fe09b910d1e6cc7ae1aa010631 (patch)
treef29cae8f707077d6c929cef13cda5214c21ef43c /engines/access/sound.cpp
parentc76059eaf9666058fa0b8fb6e8165d703d366a55 (diff)
downloadscummvm-rg350-7820bd5aed9d19fe09b910d1e6cc7ae1aa010631.tar.gz
scummvm-rg350-7820bd5aed9d19fe09b910d1e6cc7ae1aa010631.tar.bz2
scummvm-rg350-7820bd5aed9d19fe09b910d1e6cc7ae1aa010631.zip
ACCESS: Prevent multiple copies of the same sound being queued
Diffstat (limited to 'engines/access/sound.cpp')
-rw-r--r--engines/access/sound.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/engines/access/sound.cpp b/engines/access/sound.cpp
index 5fb971188a..38f544de4e 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);
}