mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-17 23:27:37 +00:00
Moved the sound sync code inside the AudioPlayer class
svn-id: r45655
This commit is contained in:
parent
611f5dd95f
commit
2dbf6662fc
@ -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());
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user