diff options
author | Filippos Karapetis | 2009-11-04 10:20:25 +0000 |
---|---|---|
committer | Filippos Karapetis | 2009-11-04 10:20:25 +0000 |
commit | 2dbf6662fce6e1c0b72bf860d1573aa05fadf850 (patch) | |
tree | 3a10cd541a6cd8ee8f0d8a419740369ccb8a0df7 /engines/sci/sfx | |
parent | 611f5dd95f30012a8c98c4285837a1ce32bdc19a (diff) | |
download | scummvm-rg350-2dbf6662fce6e1c0b72bf860d1573aa05fadf850.tar.gz scummvm-rg350-2dbf6662fce6e1c0b72bf860d1573aa05fadf850.tar.bz2 scummvm-rg350-2dbf6662fce6e1c0b72bf860d1573aa05fadf850.zip |
Moved the sound sync code inside the AudioPlayer class
svn-id: r45655
Diffstat (limited to 'engines/sci/sfx')
-rw-r--r-- | engines/sci/sfx/audio.cpp | 43 | ||||
-rw-r--r-- | engines/sci/sfx/audio.h | 8 |
2 files changed, 46 insertions, 5 deletions
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 |