aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorStrangerke2015-05-12 21:34:45 +0200
committerWillem Jan Palenstijn2015-05-13 14:43:50 +0200
commit72c9b9f56b99ca9c286de8618be4f473c0969983 (patch)
treeac785f04f7593cc707bb13db4152d3545fb599b8 /engines
parent3a74cb7b57e09e9826c6534c5d53a53753045524 (diff)
downloadscummvm-rg350-72c9b9f56b99ca9c286de8618be4f473c0969983.tar.gz
scummvm-rg350-72c9b9f56b99ca9c286de8618be4f473c0969983.tar.bz2
scummvm-rg350-72c9b9f56b99ca9c286de8618be4f473c0969983.zip
SHERLOCK: Implement sound priority
Diffstat (limited to 'engines')
-rw-r--r--engines/sherlock/animation.cpp2
-rw-r--r--engines/sherlock/objects.cpp2
-rw-r--r--engines/sherlock/scene.cpp9
-rw-r--r--engines/sherlock/sound.cpp41
-rw-r--r--engines/sherlock/sound.h9
-rw-r--r--engines/sherlock/talk.cpp2
-rw-r--r--engines/sherlock/user_interface.cpp2
7 files changed, 26 insertions, 41 deletions
diff --git a/engines/sherlock/animation.cpp b/engines/sherlock/animation.cpp
index de72de63f9..a8edf77532 100644
--- a/engines/sherlock/animation.cpp
+++ b/engines/sherlock/animation.cpp
@@ -111,7 +111,7 @@ bool Animation::play(const Common::String &filename, int minDelay, int fade,
Common::String::format("%s%02d", filename.c_str(), soundNumber);
if (sound._voices)
- sound.playSound(fname);
+ sound.playSound(fname, WAIT_RETURN_IMMEDIATELY);
}
events.wait(speed);
diff --git a/engines/sherlock/objects.cpp b/engines/sherlock/objects.cpp
index ca8ba1759a..acb13dd593 100644
--- a/engines/sherlock/objects.cpp
+++ b/engines/sherlock/objects.cpp
@@ -613,7 +613,7 @@ void Object::checkObject() {
if (sound._soundOn && !_countCAnimFrames) {
if (!scene._sounds[v - 1]._name.empty() && sound._digitized)
- sound.playLoadedSound(v - 1, 0);
+ sound.playLoadedSound(v - 1, WAIT_RETURN_IMMEDIATELY);
}
} else if (v >= FLIP_CODE && v <= (FLIP_CODE + 2)) {
// Flip code
diff --git a/engines/sherlock/scene.cpp b/engines/sherlock/scene.cpp
index ca9f19582c..4b0cbee07d 100644
--- a/engines/sherlock/scene.cpp
+++ b/engines/sherlock/scene.cpp
@@ -378,13 +378,8 @@ bool Scene::loadScene(const Common::String &filename) {
for (int idx = 0; idx < numSounds; ++idx)
_sounds[idx].synchronize(*rrmStream);
- // If sound is turned on, load the sounds into memory
- if (sound._soundOn) {
- for (int idx = 0; idx < numSounds; ++idx) {
- sound.loadSound(_sounds[idx]._name, _sounds[idx]._priority);
- _sounds[idx]._name = "";
- }
- }
+ for (int idx = 0; idx < numSounds; ++idx)
+ sound.loadSound(_sounds[idx]._name, _sounds[idx]._priority);
// Read in palette
rrmStream->read(screen._cMap, PALETTE_SIZE);
diff --git a/engines/sherlock/sound.cpp b/engines/sherlock/sound.cpp
index 51563d17a6..09e55ec82b 100644
--- a/engines/sherlock/sound.cpp
+++ b/engines/sherlock/sound.cpp
@@ -38,6 +38,7 @@ Sound::Sound(SherlockEngine *vm, Audio::Mixer *mixer): _vm(vm), _mixer(mixer) {
_diskSoundPlaying = false;
_soundPlaying = false;
_soundIsOn = &_soundPlaying;
+ _curPriority = 0;
_soundOn = true;
_musicOn = true;
@@ -57,8 +58,7 @@ void Sound::syncSoundSettings() {
}
void Sound::loadSound(const Common::String &name, int priority) {
- // TODO
- warning("TODO: Sound::loadSound");
+ // No implementation required in ScummVM
}
char Sound::decodeSample(char sample, byte& prediction, int& step) {
@@ -86,8 +86,8 @@ char Sound::decodeSample(char sample, byte& prediction, int& step) {
return prediction;
}
-bool Sound::playSound(const Common::String &name, WaitType waitType) {
- _mixer->stopHandle(_effectsHandle);
+bool Sound::playSound(const Common::String &name, WaitType waitType, int priority) {
+ stopSound();
Common::String filename = name;
if (!filename.contains('.'))
@@ -103,7 +103,7 @@ bool Sound::playSound(const Common::String &name, WaitType waitType) {
byte *decoded = (byte *)malloc((size - 1) * 2);
- // +127 to eliminate the pop when the sound starts (signed vs unsignded PCM). Still does not help with the pop at the end
+ // +127 to eliminate the pop when the sound starts (signed vs unsigned PCM). Still does not help with the pop at the end
byte prediction = (ptr[0] & 0x0f) + 127;
int step = 0;
int counter = 0;
@@ -118,6 +118,7 @@ bool Sound::playSound(const Common::String &name, WaitType waitType) {
Audio::AudioStream *audioStream = Audio::makeRawStream(decoded, (size - 2) * 2, rate, Audio::FLAG_UNSIGNED, DisposeAfterUse::YES);
_mixer->playStream(Audio::Mixer::kPlainSoundType, &_effectsHandle, audioStream, -1, Audio::Mixer::kMaxChannelVolume);
_soundPlaying = true;
+ _curPriority = priority;
if (waitType == WAIT_RETURN_IMMEDIATELY) {
_diskSoundPlaying = true;
@@ -148,34 +149,24 @@ bool Sound::playSound(const Common::String &name, WaitType waitType) {
return retval;
}
-void Sound::cacheSound(const Common::String &name, int index) {
- // TODO
- warning("TODO: Sound::cacheSound");
-}
+void Sound::playLoadedSound(int bufNum, WaitType waitType) {
+ if (_mixer->isSoundHandleActive(_effectsHandle) && (_curPriority > _vm->_scene->_sounds[bufNum]._priority))
+ return;
-void Sound::playLoadedSound(int bufNum, int waitMode) {
- // TODO
- warning("TODO: Sound::playLoadedSound");
-}
+ stopSound();
+ playSound(_vm->_scene->_sounds[bufNum]._name, waitType, _vm->_scene->_sounds[bufNum]._priority);
-void Sound::playCachedSound(int index) {
- // TODO
- warning("TODO: Sound::playCachedSound");
+ return;
}
void Sound::freeLoadedSounds() {
- // TODO
- warning("TODO: Sound::clearLoadedSound");
-}
-
-void Sound::clearCache() {
- // TODO
- warning("TODO: Sound::clearCache");
+ // As sounds are played with DisposeAfterUse::YES, stopping the sounds also
+ // frees them
+ stopSound();
}
void Sound::stopSound() {
- // TODO
- warning("TODO: Sound::stopSound");
+ _mixer->stopHandle(_effectsHandle);
}
void Sound::playMusic(const Common::String &name) {
diff --git a/engines/sherlock/sound.h b/engines/sherlock/sound.h
index 213a6f7a1e..659df57bc3 100644
--- a/engines/sherlock/sound.h
+++ b/engines/sherlock/sound.h
@@ -44,6 +44,7 @@ private:
SherlockEngine *_vm;
Audio::Mixer *_mixer;
Audio::SoundHandle _effectsHandle;
+ int _curPriority;
char decodeSample(char sample, byte& prediction, int& step);
public:
@@ -63,13 +64,11 @@ public:
void syncSoundSettings();
void loadSound(const Common::String &name, int priority);
- bool playSound(const Common::String &name, WaitType waitType = WAIT_RETURN_IMMEDIATELY);
- void cacheSound(const Common::String &name, int index);
- void playLoadedSound(int bufNum, int waitMode);
- void playCachedSound(int index);
+ bool playSound(const Common::String &name, WaitType waitType, int priority = 100);
+ void playLoadedSound(int bufNum, WaitType waitType);
void freeLoadedSounds();
- void clearCache();
void stopSound();
+
int loadSong(int songNumber);
void startSong();
void freeSong();
diff --git a/engines/sherlock/talk.cpp b/engines/sherlock/talk.cpp
index 3520a02296..61f0004fd6 100644
--- a/engines/sherlock/talk.cpp
+++ b/engines/sherlock/talk.cpp
@@ -1278,7 +1278,7 @@ void Talk::doScript(const Common::String &script) {
if (sound._voices) {
for (int idx = 0; idx < 8 && str[idx] != '~'; ++idx)
tempString += str[idx];
- sound.playSound(tempString);
+ sound.playSound(tempString, WAIT_RETURN_IMMEDIATELY);
// Set voices to wait for more
sound._voices = 2;
diff --git a/engines/sherlock/user_interface.cpp b/engines/sherlock/user_interface.cpp
index 8b3ee426a4..d65bd9c01d 100644
--- a/engines/sherlock/user_interface.cpp
+++ b/engines/sherlock/user_interface.cpp
@@ -1683,7 +1683,7 @@ void UserInterface::doTalkControl() {
people.setTalking(0);
if (!talk._statements[_selector]._voiceFile.empty() && sound._voices) {
- sound.playSound(talk._statements[_selector]._voiceFile);
+ sound.playSound(talk._statements[_selector]._voiceFile, WAIT_RETURN_IMMEDIATELY);
// Set voices as an indicator for waiting
sound._voices = 2;