mirror of
https://github.com/libretro/scummvm.git
synced 2025-03-04 01:07:22 +00:00
LAB: Clean up sound effect looping, starting and stopping code
This commit is contained in:
parent
e231c6753b
commit
d1b5d41005
@ -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:
|
||||
|
@ -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()) {
|
||||
|
@ -74,16 +74,13 @@ 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.
|
||||
*/
|
||||
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.
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user