From 2dbf6662fce6e1c0b72bf860d1573aa05fadf850 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Wed, 4 Nov 2009 10:20:25 +0000 Subject: Moved the sound sync code inside the AudioPlayer class svn-id: r45655 --- engines/sci/engine/ksound.cpp | 40 +++++----------------------------------- engines/sci/sfx/audio.cpp | 43 ++++++++++++++++++++++++++++++++++++++++--- engines/sci/sfx/audio.h | 8 ++++++-- 3 files changed, 51 insertions(+), 40 deletions(-) (limited to 'engines/sci') diff --git a/engines/sci/engine/ksound.cpp b/engines/sci/engine/ksound.cpp index 7db26b0815..42a8088eb5 100644 --- a/engines/sci/engine/ksound.cpp +++ b/engines/sci/engine/ksound.cpp @@ -1189,10 +1189,7 @@ reg_t kDoSync(EngineState *s, int argc, reg_t *argv) { case kSciAudioSyncStart: { ResourceId id; - if (s->_audio->_syncResource) { - s->resMan->unlockResource(s->_audio->_syncResource); - s->_audio->_syncResource = NULL; - } + s->_audio->stopSoundSync(); // Load sound sync resource and lock it if (argc == 3) { @@ -1205,41 +1202,14 @@ reg_t kDoSync(EngineState *s, int argc, reg_t *argv) { return s->r_acc; } - s->_audio->_syncResource = s->resMan->findResource(id, 1); - - if (s->_audio->_syncResource) { - PUT_SEL32V(segMan, argv[1], syncCue, 0); - s->_audio->_syncOffset = 0; - } else { - warning("DoSync: failed to find resource %s", id.toString().c_str()); - // Notify the scripts to stop sound sync - PUT_SEL32V(segMan, argv[1], syncCue, SIGNAL_OFFSET); - } + s->_audio->setSoundSync(id, argv[1], segMan); break; } - case kSciAudioSyncNext: { - Resource *res = s->_audio->_syncResource; - if (res && (s->_audio->_syncOffset < res->size - 1)) { - int16 syncCue = -1; - int16 syncTime = (int16)READ_LE_UINT16(res->data + s->_audio->_syncOffset); - - s->_audio->_syncOffset += 2; - - if ((syncTime != -1) && (s->_audio->_syncOffset < res->size - 1)) { - syncCue = (int16)READ_LE_UINT16(res->data + s->_audio->_syncOffset); - s->_audio->_syncOffset += 2; - } - - PUT_SEL32V(segMan, argv[1], syncTime, syncTime); - PUT_SEL32V(segMan, argv[1], syncCue, syncCue); - } + case kSciAudioSyncNext: + s->_audio->doSoundSync(argv[1], segMan); break; - } case kSciAudioSyncStop: - if (s->_audio->_syncResource) { - s->resMan->unlockResource(s->_audio->_syncResource); - s->_audio->_syncResource = NULL; - } + s->_audio->stopSoundSync(); break; default: warning("DoSync: Unhandled subfunction %d", argv[0].toUint16()); diff --git a/engines/sci/sfx/audio.cpp b/engines/sci/sfx/audio.cpp index 1afda91a45..f68ee37c18 100644 --- a/engines/sci/sfx/audio.cpp +++ b/engines/sci/sfx/audio.cpp @@ -24,6 +24,8 @@ */ #include "sci/resource.h" +#include "sci/engine/kernel.h" +#include "sci/engine/seg_manager.h" #include "sci/sfx/audio.h" #include "common/system.h" @@ -38,10 +40,8 @@ AudioPlayer::AudioPlayer(ResourceManager *resMan) : _resMan(resMan), _audioRate( } AudioPlayer::~AudioPlayer() { + stopSoundSync(); stopAudio(); - - if (_syncResource) - _resMan->unlockResource(_syncResource); } int AudioPlayer::startAudio(uint16 module, uint32 number) { @@ -224,4 +224,41 @@ Audio::AudioStream* AudioPlayer::getAudioStream(uint32 number, uint32 volume, in return NULL; } +void AudioPlayer::setSoundSync(ResourceId id, reg_t syncObjAddr, SegManager *segMan) { + _syncResource = _resMan->findResource(id, 1); + _syncOffset = 0; + + if (_syncResource) { + PUT_SEL32V(segMan, syncObjAddr, syncCue, 0); + } else { + warning("setSoundSync: failed to find resource %s", id.toString().c_str()); + // Notify the scripts to stop sound sync + PUT_SEL32V(segMan, syncObjAddr, syncCue, SIGNAL_OFFSET); + } +} + +void AudioPlayer::doSoundSync(reg_t syncObjAddr, SegManager *segMan) { + if (_syncResource && (_syncOffset < _syncResource->size - 1)) { + int16 syncCue = -1; + int16 syncTime = (int16)READ_LE_UINT16(_syncResource->data + _syncOffset); + + _syncOffset += 2; + + if ((syncTime != -1) && (_syncOffset < _syncResource->size - 1)) { + syncCue = (int16)READ_LE_UINT16(_syncResource->data + _syncOffset); + _syncOffset += 2; + } + + PUT_SEL32V(segMan, syncObjAddr, syncTime, syncTime); + PUT_SEL32V(segMan, syncObjAddr, syncCue, syncCue); + } +} + +void AudioPlayer::stopSoundSync() { + if (_syncResource) { + _resMan->unlockResource(_syncResource); + _syncResource = NULL; + } +} + } // End of namespace Sci diff --git a/engines/sci/sfx/audio.h b/engines/sci/sfx/audio.h index d3b9358ecb..043189a922 100644 --- a/engines/sci/sfx/audio.h +++ b/engines/sci/sfx/audio.h @@ -30,6 +30,7 @@ namespace Sci { class ResourceManager; +class SegManager; class AudioPlayer { public: @@ -44,14 +45,17 @@ public: void pauseAudio() { g_system->getMixer()->pauseHandle(_audioHandle, true); } void resumeAudio() { g_system->getMixer()->pauseHandle(_audioHandle, false); } - Resource *_syncResource; /**< Used by kDoSync for speech syncing in CD talkie games */ - uint _syncOffset; + void setSoundSync(ResourceId id, reg_t syncObjAddr, SegManager *segMan); + void doSoundSync(reg_t syncObjAddr, SegManager *segMan); + void stopSoundSync(); private: ResourceManager *_resMan; uint16 _audioRate; Audio::SoundHandle _audioHandle; Audio::AudioStream* getAudioStream(uint32 number, uint32 volume, int *sampleLen); + Resource *_syncResource; /**< Used by kDoSync for speech syncing in CD talkie games */ + uint _syncOffset; }; } // End of namespace Sci -- cgit v1.2.3