diff options
author | Strangerke | 2014-12-27 15:31:43 +0100 |
---|---|---|
committer | Strangerke | 2014-12-27 15:31:43 +0100 |
commit | 39eab59388c6dc43d1f2c72ee708807ef1bdb198 (patch) | |
tree | 98b48f1c4bee9192a48265a819fd4f5f4e82c2f6 | |
parent | e862172460640188363873b9fa1fb46a3f4c7f78 (diff) | |
download | scummvm-rg350-39eab59388c6dc43d1f2c72ee708807ef1bdb198.tar.gz scummvm-rg350-39eab59388c6dc43d1f2c72ee708807ef1bdb198.tar.bz2 scummvm-rg350-39eab59388c6dc43d1f2c72ee708807ef1bdb198.zip |
ACCESS: Rewrite sound queueing (WIP)
-rw-r--r-- | engines/access/amazon/amazon_logic.cpp | 52 | ||||
-rw-r--r-- | engines/access/events.cpp | 2 | ||||
-rw-r--r-- | engines/access/sound.cpp | 50 | ||||
-rw-r--r-- | engines/access/sound.h | 5 |
4 files changed, 66 insertions, 43 deletions
diff --git a/engines/access/amazon/amazon_logic.cpp b/engines/access/amazon/amazon_logic.cpp index 4a313e8880..c045377f8a 100644 --- a/engines/access/amazon/amazon_logic.cpp +++ b/engines/access/amazon/amazon_logic.cpp @@ -341,15 +341,12 @@ void Opening::doTitle() { _vm->_objectsTable[0] = new SpriteResource(_vm, spriteData); delete spriteData; - _vm->_sound->playSound(1); - _vm->_files->_setPaletteFlag = false; _vm->_files->loadScreen(0, 4); _vm->_sound->playSound(1); _vm->_buffer2.copyFrom(*_vm->_screen); _vm->_buffer1.copyFrom(*_vm->_screen); - _vm->_sound->playSound(1); const int COUNTDOWN[6] = { 2, 0x80, 1, 0x7d, 0, 0x87 }; for (_pCount = 0; _pCount < 3 && !_vm->shouldQuit(); ++_pCount) { @@ -508,40 +505,47 @@ void Opening::doTent() { _vm->_screen->forceFadeIn(); _vm->_video->setVideo(_vm->_screen, Common::Point(126, 73), FileIdent(2, 1), 10); + int previousFrame = -1; while (!_vm->shouldQuit() && !_vm->_video->_videoEnd) { _vm->_video->playVideo(); - if ((_vm->_video->_videoFrame == 32) || (_vm->_video->_videoFrame == 34)) - _vm->_sound->playSound(4); - else if (_vm->_video->_videoFrame == 36) { - if (step != 2) { - _vm->_sound->playSound(2); - step = 2; - } - } else if (_vm->_video->_videoFrame == 18) { - if (step != 1) { - _vm->_midi->newMusic(73, 1); - _vm->_midi->newMusic(11, 0); - step = 1; - _vm->_sound->playSound(1); + if (previousFrame != _vm->_video->_videoFrame) { + previousFrame = _vm->_video->_videoFrame; + + if ((_vm->_video->_videoFrame == 32) || (_vm->_video->_videoFrame == 34)) + _vm->_sound->playSound(4); + else if (_vm->_video->_videoFrame == 36) { + if (step != 2) { + _vm->_sound->playSound(2); + step = 2; + } + } else if (_vm->_video->_videoFrame == 18) { + if (step != 1) { + _vm->_midi->newMusic(73, 1); + _vm->_midi->newMusic(11, 0); + step = 1; + _vm->_sound->playSound(1); + } } } - _vm->_events->pollEventsAndWait(); } _vm->_sound->playSound(5); _vm->_video->setVideo(_vm->_screen, Common::Point(43, 11), FileIdent(2, 2), 10); + previousFrame = -1; while (!_vm->shouldQuit() && !_vm->_video->_videoEnd) { _vm->_video->playVideo(); - if (_vm->_video->_videoFrame == 26) { - _vm->_sound->playSound(5); - } else if (_vm->_video->_videoFrame == 15) { - if (step !=3) { - _vm->_sound->playSound(3); - step = 3; + if (previousFrame != _vm->_video->_videoFrame) { + previousFrame = _vm->_video->_videoFrame; + if (_vm->_video->_videoFrame == 26) { + _vm->_sound->playSound(5); + } else if (_vm->_video->_videoFrame == 15) { + if (step !=3) { + _vm->_sound->playSound(3); + step = 3; + } } } - _vm->_events->pollEventsAndWait(); } diff --git a/engines/access/events.cpp b/engines/access/events.cpp index 0867b09765..6ffe67acfb 100644 --- a/engines/access/events.cpp +++ b/engines/access/events.cpp @@ -140,6 +140,8 @@ void EventsManager::pollEvents(bool skipTimers) { if (checkForNextTimerUpdate() && !skipTimers) nextTimer(); + _vm->_sound->checkSoundQueue(); + _wheelUp = _wheelDown = false; Common::Event event; diff --git a/engines/access/sound.cpp b/engines/access/sound.cpp index a7d96dac9a..82199a8286 100644 --- a/engines/access/sound.cpp +++ b/engines/access/sound.cpp @@ -22,7 +22,6 @@ #include "common/algorithm.h" #include "audio/mixer.h" -#include "audio/audiostream.h" #include "audio/decoders/raw.h" #include "audio/decoders/wave.h" #include "access/access.h" @@ -44,7 +43,19 @@ void SoundManager::clearSounds() { for (uint i = 0; i < _soundTable.size(); ++i) delete _soundTable[i]._res; + _soundTable.clear(); + + if (_mixer->isSoundHandleActive(_effectsHandle)) + _mixer->stopHandle(_effectsHandle); + + if (_queue.size()) + _queue.remove_at(0); + + while (_queue.size()) { + delete _queue[0]; + _queue.remove_at(0); + } } void SoundManager::queueSound(int idx, int fileNum, int subfile) { @@ -77,19 +88,14 @@ void SoundManager::playSound(Resource *res, int priority) { debugC(1, kDebugSound, "playSound"); byte *resourceData = res->data(); - Audio::SoundHandle audioHandle; - Audio::RewindableAudioStream *audioStream = 0; assert(res->_size >= 32); - // HACK: Simulates queueing for the rare sounds played one after the other - while (_mixer->hasActiveChannelOfType(Audio::Mixer::kSFXSoundType)) - ; - if (READ_BE_UINT32(resourceData) == MKTAG('R','I','F','F')) { // CD version uses WAVE-files Common::SeekableReadStream *waveStream = new Common::MemoryReadStream(resourceData, res->_size, DisposeAfterUse::NO); - audioStream = Audio::makeWAVStream(waveStream, DisposeAfterUse::YES); + Audio::RewindableAudioStream *audioStream = Audio::makeWAVStream(waveStream, DisposeAfterUse::YES); + _queue.push_back(audioStream); } else if (READ_BE_UINT32(resourceData) == MKTAG('S', 'T', 'E', 'V')) { // sound files have a fixed header of 32 bytes in total @@ -130,22 +136,30 @@ void SoundManager::playSound(Resource *res, int priority) { return; } - audioStream = Audio::makeRawStream(resourceData + 32, sampleSize, sampleRate, 0); + Audio::RewindableAudioStream *audioStream = Audio::makeRawStream(resourceData + 32, sampleSize, sampleRate, 0); + _queue.push_back(audioStream); } else error("Unknown format"); - audioHandle = Audio::SoundHandle(); - _mixer->playStream(Audio::Mixer::kSFXSoundType, &audioHandle, - audioStream, -1, _mixer->kMaxChannelVolume, 0, + if (!_mixer->isSoundHandleActive(_effectsHandle)) + _mixer->playStream(Audio::Mixer::kSFXSoundType, &_effectsHandle, + _queue[0], -1, _mixer->kMaxChannelVolume, 0, DisposeAfterUse::NO); +} + +void SoundManager::checkSoundQueue() { + debugC(5, kDebugSound, "checkSoundQueue"); + + if (_queue.empty() || _mixer->isSoundHandleActive(_effectsHandle)) + return; + + _queue.remove_at(0); - /* - Audio::QueuingAudioStream *audioStream = Audio::makeQueuingAudioStream(22050, false); - audioStream->queueBuffer(data, size, DisposeAfterUse::YES, 0); - _mixer->playStream(Audio::Mixer::kPlainSoundType, &_soundHandle, audioStream, -1, - Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::YES, false); - */ + if (_queue.size()) + _mixer->playStream(Audio::Mixer::kSFXSoundType, &_effectsHandle, + _queue[0], -1, _mixer->kMaxChannelVolume, 0, + DisposeAfterUse::YES); } void SoundManager::loadSounds(Common::Array<RoomInfo::SoundIdent> &sounds) { diff --git a/engines/access/sound.h b/engines/access/sound.h index d0f4584fac..c276648477 100644 --- a/engines/access/sound.h +++ b/engines/access/sound.h @@ -24,6 +24,7 @@ #define ACCESS_SOUND_H #include "common/scummsys.h" +#include "audio/audiostream.h" #include "audio/mixer.h" #include "access/files.h" #include "audio/midiplayer.h" @@ -47,7 +48,8 @@ class SoundManager { private: AccessEngine *_vm; Audio::Mixer *_mixer; - Audio::SoundHandle _soundHandle; + Audio::SoundHandle _effectsHandle; + Common::Array<Audio::RewindableAudioStream *> _queue; void clearSounds(); @@ -63,6 +65,7 @@ public: void queueSound(int idx, int fileNum, int subfile); void playSound(int soundIndex); + void checkSoundQueue(); Resource *loadSound(int fileNum, int subfile); void loadSounds(Common::Array<RoomInfo::SoundIdent> &sounds); |