aboutsummaryrefslogtreecommitdiff
path: root/engines/lab
diff options
context:
space:
mode:
authorFilippos Karapetis2015-12-26 12:45:48 +0200
committerFilippos Karapetis2015-12-26 12:45:48 +0200
commitd1b5d41005ea89e20ae449e6ea815b1dfb5997e6 (patch)
treee64a1e3613cd74d1f4c5daa223fb4ab9b55d9d0f /engines/lab
parente231c6753bdc9ccdcae5497ef55af9afcd74edca (diff)
downloadscummvm-rg350-d1b5d41005ea89e20ae449e6ea815b1dfb5997e6.tar.gz
scummvm-rg350-d1b5d41005ea89e20ae449e6ea815b1dfb5997e6.tar.bz2
scummvm-rg350-d1b5d41005ea89e20ae449e6ea815b1dfb5997e6.zip
LAB: Clean up sound effect looping, starting and stopping code
Diffstat (limited to 'engines/lab')
-rw-r--r--engines/lab/anim.cpp4
-rw-r--r--engines/lab/music.cpp16
-rw-r--r--engines/lab/music.h9
-rw-r--r--engines/lab/processroom.cpp29
4 files changed, 19 insertions, 39 deletions
diff --git a/engines/lab/anim.cpp b/engines/lab/anim.cpp
index eb825fb4c0..92ca49b95d 100644
--- a/engines/lab/anim.cpp
+++ b/engines/lab/anim.cpp
@@ -217,7 +217,9 @@ void Anim::diffNextFrame(bool onlyDiffData) {
_sampleSpeed = _diffFile->readUint16LE();
_diffFile->skip(2);
- _vm->_music->playSoundEffect(_sampleSpeed, _size, _diffFile);
+ // Sound effects embedded in animations are started here. These are
+ // usually animation-specific, like door opening sounds, and are not looped
+ _vm->_music->playSoundEffect(_sampleSpeed, _size, false, _diffFile);
break;
case 65535:
diff --git a/engines/lab/music.cpp b/engines/lab/music.cpp
index 95581aec5c..c46e3a10ec 100644
--- a/engines/lab/music.cpp
+++ b/engines/lab/music.cpp
@@ -56,7 +56,6 @@ Music::Music(LabEngine *vm) : _vm(vm) {
_leftInFile = 0;
_musicOn = false;
- _loopSoundEffect = false;
_queuingAudioStream = nullptr;
_lastMusicRoom = 1;
_doReset = true;
@@ -95,7 +94,7 @@ uint16 Music::getPlayingBufferCount() {
return (_queuingAudioStream) ? _queuingAudioStream->numQueuedStreams() : 0;
}
-void Music::playSoundEffect(uint16 sampleSpeed, uint32 length, Common::File *dataFile) {
+void Music::playSoundEffect(uint16 sampleSpeed, uint32 length, bool loop, Common::File *dataFile) {
pauseBackMusic();
stopSoundEffect();
@@ -114,7 +113,7 @@ void Music::playSoundEffect(uint16 sampleSpeed, uint32 length, Common::File *dat
dataFile->read(soundData, length);
Audio::SeekableAudioStream *audioStream = Audio::makeRawStream((const byte *)soundData, length, sampleSpeed, soundFlags);
- uint loops = (_loopSoundEffect) ? 0 : 1;
+ uint loops = (loop) ? 0 : 1;
Audio::LoopingAudioStream *loopingAudioStream = new Audio::LoopingAudioStream(audioStream, loops);
_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_sfxHandle, loopingAudioStream);
}
@@ -274,22 +273,21 @@ void Music::resetMusic() {
_tFile = 0;
}
-bool Music::readMusic(const Common::String filename, bool waitTillFinished) {
+bool Music::readMusic(const Common::String filename, bool loop, bool waitTillFinished) {
Common::File *file = _vm->_resource->openDataFile(filename, MKTAG('D', 'I', 'F', 'F'));
_vm->updateMusicAndEvents();
- if (!_loopSoundEffect)
- stopSoundEffect();
+ stopSoundEffect();
if (!file)
return false;
_vm->_anim->_doBlack = false;
- readSound(waitTillFinished, file);
+ readSound(waitTillFinished, loop, file);
return true;
}
-void Music::readSound(bool waitTillFinished, Common::File *file) {
+void Music::readSound(bool waitTillFinished, bool loop, Common::File *file) {
uint32 magicBytes = file->readUint32LE();
if (magicBytes != 1219009121) {
warning("readSound: Bad signature, skipping");
@@ -320,7 +318,7 @@ void Music::readSound(bool waitTillFinished, Common::File *file) {
uint16 sampleRate = file->readUint16LE();
file->skip(2);
- playSoundEffect(sampleRate, soundSize, file);
+ playSoundEffect(sampleRate, soundSize, loop, file);
} else if (soundTag == 65535) {
if (waitTillFinished) {
while (isSoundEffectActive()) {
diff --git a/engines/lab/music.h b/engines/lab/music.h
index 42fdf41d67..1a3fd24e72 100644
--- a/engines/lab/music.h
+++ b/engines/lab/music.h
@@ -74,7 +74,7 @@ private:
* Pauses the background music.
*/
void pauseBackMusic();
- void readSound(bool waitTillFinished, Common::File *file);
+ void readSound(bool waitTillFinished, bool loop, Common::File *file);
/**
* Starts up the music initially.
@@ -82,9 +82,6 @@ private:
void startMusic(bool restartFl);
public:
- bool _loopSoundEffect;
-
-public:
Music(LabEngine *vm);
/**
@@ -107,12 +104,12 @@ public:
*/
bool initMusic(const Common::String filename);
bool isSoundEffectActive() const;
- void playSoundEffect(uint16 sampleSpeed, uint32 length, Common::File *dataFile);
+ void playSoundEffect(uint16 sampleSpeed, uint32 length, bool loop, Common::File *dataFile);
/**
* Reads in a music file. Ignores any graphics.
*/
- bool readMusic(const Common::String filename, bool waitTillFinished);
+ bool readMusic(const Common::String filename, bool loop, bool waitTillFinished);
/**
* Changes the background music to the original piece playing.
diff --git a/engines/lab/processroom.cpp b/engines/lab/processroom.cpp
index 4d42f96b50..b955306b7b 100644
--- a/engines/lab/processroom.cpp
+++ b/engines/lab/processroom.cpp
@@ -239,18 +239,15 @@ void LabEngine::doActions(const ActionList &actionList, CloseDataPtr *closePtrLi
switch (action->_actionType) {
case kActionPlaySound:
- _music->_loopSoundEffect = false;
- _music->readMusic(action->_messages[0], true);
+ _music->readMusic(action->_messages[0], false, true);
break;
- case kActionPlaySoundNoWait:
- _music->_loopSoundEffect = false;
- _music->readMusic(action->_messages[0], false);
+ case kActionPlaySoundNoWait: // only used in scene 7 (street, when teleporting to the surreal maze)
+ _music->readMusic(action->_messages[0], false, false);
break;
case kActionPlaySoundLooping:
- _music->_loopSoundEffect = true;
- _music->readMusic(action->_messages[0], false);
+ _music->readMusic(action->_messages[0], true, false);
break;
case kActionShowDiff:
@@ -411,12 +408,7 @@ void LabEngine::doActions(const ActionList &actionList, CloseDataPtr *closePtrLi
break;
case kActionClearSound:
- if (_music->_loopSoundEffect) {
- _music->_loopSoundEffect = false;
- _music->stopSoundEffect();
- } else if (_music->isSoundEffectActive())
- _music->stopSoundEffect();
-
+ _music->stopSoundEffect();
break;
case kActionWinMusic:
@@ -474,16 +466,7 @@ void LabEngine::doActions(const ActionList &actionList, CloseDataPtr *closePtrLi
}
}
- if (_music->_loopSoundEffect) {
- _music->_loopSoundEffect = false;
- _music->stopSoundEffect();
- } else {
- while (_music->isSoundEffectActive()) {
- updateMusicAndEvents();
- _anim->diffNextFrame();
- waitTOF();
- }
- }
+ _music->stopSoundEffect();
}
bool LabEngine::doActionRuleSub(int16 action, int16 roomNum, CloseDataPtr closePtr, CloseDataPtr *setCloseList, bool allowDefaults) {