LAB: Clean up sound effect looping, starting and stopping code
This commit is contained in:
parent
e231c6753b
commit
d1b5d41005
4 changed files with 19 additions and 39 deletions
|
@ -217,7 +217,9 @@ void Anim::diffNextFrame(bool onlyDiffData) {
|
||||||
_sampleSpeed = _diffFile->readUint16LE();
|
_sampleSpeed = _diffFile->readUint16LE();
|
||||||
_diffFile->skip(2);
|
_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;
|
break;
|
||||||
|
|
||||||
case 65535:
|
case 65535:
|
||||||
|
|
|
@ -56,7 +56,6 @@ Music::Music(LabEngine *vm) : _vm(vm) {
|
||||||
_leftInFile = 0;
|
_leftInFile = 0;
|
||||||
|
|
||||||
_musicOn = false;
|
_musicOn = false;
|
||||||
_loopSoundEffect = false;
|
|
||||||
_queuingAudioStream = nullptr;
|
_queuingAudioStream = nullptr;
|
||||||
_lastMusicRoom = 1;
|
_lastMusicRoom = 1;
|
||||||
_doReset = true;
|
_doReset = true;
|
||||||
|
@ -95,7 +94,7 @@ uint16 Music::getPlayingBufferCount() {
|
||||||
return (_queuingAudioStream) ? _queuingAudioStream->numQueuedStreams() : 0;
|
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();
|
pauseBackMusic();
|
||||||
stopSoundEffect();
|
stopSoundEffect();
|
||||||
|
|
||||||
|
@ -114,7 +113,7 @@ void Music::playSoundEffect(uint16 sampleSpeed, uint32 length, Common::File *dat
|
||||||
dataFile->read(soundData, length);
|
dataFile->read(soundData, length);
|
||||||
|
|
||||||
Audio::SeekableAudioStream *audioStream = Audio::makeRawStream((const byte *)soundData, length, sampleSpeed, soundFlags);
|
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);
|
Audio::LoopingAudioStream *loopingAudioStream = new Audio::LoopingAudioStream(audioStream, loops);
|
||||||
_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_sfxHandle, loopingAudioStream);
|
_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_sfxHandle, loopingAudioStream);
|
||||||
}
|
}
|
||||||
|
@ -274,22 +273,21 @@ void Music::resetMusic() {
|
||||||
_tFile = 0;
|
_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'));
|
Common::File *file = _vm->_resource->openDataFile(filename, MKTAG('D', 'I', 'F', 'F'));
|
||||||
_vm->updateMusicAndEvents();
|
_vm->updateMusicAndEvents();
|
||||||
if (!_loopSoundEffect)
|
stopSoundEffect();
|
||||||
stopSoundEffect();
|
|
||||||
|
|
||||||
if (!file)
|
if (!file)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
_vm->_anim->_doBlack = false;
|
_vm->_anim->_doBlack = false;
|
||||||
readSound(waitTillFinished, file);
|
readSound(waitTillFinished, loop, file);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Music::readSound(bool waitTillFinished, Common::File *file) {
|
void Music::readSound(bool waitTillFinished, bool loop, Common::File *file) {
|
||||||
uint32 magicBytes = file->readUint32LE();
|
uint32 magicBytes = file->readUint32LE();
|
||||||
if (magicBytes != 1219009121) {
|
if (magicBytes != 1219009121) {
|
||||||
warning("readSound: Bad signature, skipping");
|
warning("readSound: Bad signature, skipping");
|
||||||
|
@ -320,7 +318,7 @@ void Music::readSound(bool waitTillFinished, Common::File *file) {
|
||||||
|
|
||||||
uint16 sampleRate = file->readUint16LE();
|
uint16 sampleRate = file->readUint16LE();
|
||||||
file->skip(2);
|
file->skip(2);
|
||||||
playSoundEffect(sampleRate, soundSize, file);
|
playSoundEffect(sampleRate, soundSize, loop, file);
|
||||||
} else if (soundTag == 65535) {
|
} else if (soundTag == 65535) {
|
||||||
if (waitTillFinished) {
|
if (waitTillFinished) {
|
||||||
while (isSoundEffectActive()) {
|
while (isSoundEffectActive()) {
|
||||||
|
|
|
@ -74,16 +74,13 @@ private:
|
||||||
* Pauses the background music.
|
* Pauses the background music.
|
||||||
*/
|
*/
|
||||||
void pauseBackMusic();
|
void pauseBackMusic();
|
||||||
void readSound(bool waitTillFinished, Common::File *file);
|
void readSound(bool waitTillFinished, bool loop, Common::File *file);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts up the music initially.
|
* Starts up the music initially.
|
||||||
*/
|
*/
|
||||||
void startMusic(bool restartFl);
|
void startMusic(bool restartFl);
|
||||||
|
|
||||||
public:
|
|
||||||
bool _loopSoundEffect;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Music(LabEngine *vm);
|
Music(LabEngine *vm);
|
||||||
|
|
||||||
|
@ -107,12 +104,12 @@ public:
|
||||||
*/
|
*/
|
||||||
bool initMusic(const Common::String filename);
|
bool initMusic(const Common::String filename);
|
||||||
bool isSoundEffectActive() const;
|
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.
|
* 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.
|
* Changes the background music to the original piece playing.
|
||||||
|
|
|
@ -239,18 +239,15 @@ void LabEngine::doActions(const ActionList &actionList, CloseDataPtr *closePtrLi
|
||||||
|
|
||||||
switch (action->_actionType) {
|
switch (action->_actionType) {
|
||||||
case kActionPlaySound:
|
case kActionPlaySound:
|
||||||
_music->_loopSoundEffect = false;
|
_music->readMusic(action->_messages[0], false, true);
|
||||||
_music->readMusic(action->_messages[0], true);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kActionPlaySoundNoWait:
|
case kActionPlaySoundNoWait: // only used in scene 7 (street, when teleporting to the surreal maze)
|
||||||
_music->_loopSoundEffect = false;
|
_music->readMusic(action->_messages[0], false, false);
|
||||||
_music->readMusic(action->_messages[0], false);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kActionPlaySoundLooping:
|
case kActionPlaySoundLooping:
|
||||||
_music->_loopSoundEffect = true;
|
_music->readMusic(action->_messages[0], true, false);
|
||||||
_music->readMusic(action->_messages[0], false);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kActionShowDiff:
|
case kActionShowDiff:
|
||||||
|
@ -411,12 +408,7 @@ void LabEngine::doActions(const ActionList &actionList, CloseDataPtr *closePtrLi
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kActionClearSound:
|
case kActionClearSound:
|
||||||
if (_music->_loopSoundEffect) {
|
_music->stopSoundEffect();
|
||||||
_music->_loopSoundEffect = false;
|
|
||||||
_music->stopSoundEffect();
|
|
||||||
} else if (_music->isSoundEffectActive())
|
|
||||||
_music->stopSoundEffect();
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kActionWinMusic:
|
case kActionWinMusic:
|
||||||
|
@ -474,16 +466,7 @@ void LabEngine::doActions(const ActionList &actionList, CloseDataPtr *closePtrLi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_music->_loopSoundEffect) {
|
_music->stopSoundEffect();
|
||||||
_music->_loopSoundEffect = false;
|
|
||||||
_music->stopSoundEffect();
|
|
||||||
} else {
|
|
||||||
while (_music->isSoundEffectActive()) {
|
|
||||||
updateMusicAndEvents();
|
|
||||||
_anim->diffNextFrame();
|
|
||||||
waitTOF();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LabEngine::doActionRuleSub(int16 action, int16 roomNum, CloseDataPtr closePtr, CloseDataPtr *setCloseList, bool allowDefaults) {
|
bool LabEngine::doActionRuleSub(int16 action, int16 roomNum, CloseDataPtr closePtr, CloseDataPtr *setCloseList, bool allowDefaults) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue