MOHAWK: Use a separate SndHandle for Myst's background sound

svn-id: r55330
This commit is contained in:
Matthew Hoops 2011-01-19 16:52:47 +00:00
parent 6b123c0d11
commit 918a21cd7b
2 changed files with 25 additions and 29 deletions

View File

@ -45,6 +45,7 @@ Sound::Sound(MohawkEngine* vm) : _vm(vm) {
Sound::~Sound() { Sound::~Sound() {
stopSound(); stopSound();
stopAllSLST(); stopAllSLST();
stopBackgroundMyst();
if (_midiParser) { if (_midiParser) {
_midiParser->unloadMusic(); _midiParser->unloadMusic();
@ -581,18 +582,16 @@ uint16 Sound::convertMystID(uint16 id) {
} }
Audio::SoundHandle *Sound::replaceBackgroundMyst(uint16 id, uint16 volume) { Audio::SoundHandle *Sound::replaceBackgroundMyst(uint16 id, uint16 volume) {
debug (0, "Replacing background %d", id); debug(0, "Replacing background sound with %d", id);
// TODO: The original engine does fading // TODO: The original engine does fading
Common::String name = _vm->getResourceName(ID_MSND, convertMystID(id)); Common::String name = _vm->getResourceName(ID_MSND, convertMystID(id));
// Check if sound is already playing // Check if sound is already playing
for (uint32 i = 0; i < _handles.size(); i++) if (_mystBackgroundSound.type == kUsedHandle && _vm->_mixer->isSoundHandleActive(_mystBackgroundSound.handle)
if (_handles[i].type == kBackgroundHandle && name.equals(_vm->getResourceName(ID_MSND, convertMystID(_mystBackgroundSound.id))))
&& _vm->_mixer->isSoundHandleActive(_handles[i].handle) return &_mystBackgroundSound.handle;
&& name.equals(_vm->getResourceName(ID_MSND, convertMystID(_handles[i].id))))
return &_handles[i].handle;
// Stop old background sound // Stop old background sound
stopBackgroundMyst(); stopBackgroundMyst();
@ -601,46 +600,41 @@ Audio::SoundHandle *Sound::replaceBackgroundMyst(uint16 id, uint16 volume) {
Audio::AudioStream *audStream = makeAudioStream(id); Audio::AudioStream *audStream = makeAudioStream(id);
if (audStream) { if (audStream) {
SndHandle *handle = getHandle(); _mystBackgroundSound.type = kUsedHandle;
handle->type = kBackgroundHandle; _mystBackgroundSound.id = id;
handle->id = id; _mystBackgroundSound.samplesPerSecond = audStream->getRate();
handle->samplesPerSecond = audStream->getRate();
// Set the stream to loop // Set the stream to loop
audStream = Audio::makeLoopingAudioStream((Audio::RewindableAudioStream *)audStream, 0); audStream = Audio::makeLoopingAudioStream((Audio::RewindableAudioStream *)audStream, 0);
_vm->_mixer->playStream(Audio::Mixer::kPlainSoundType, &handle->handle, audStream, -1, volume >> 8); _vm->_mixer->playStream(Audio::Mixer::kPlainSoundType, &_mystBackgroundSound.handle, audStream, -1, volume >> 8);
return &handle->handle; return &_mystBackgroundSound.handle;
} }
return NULL; return NULL;
} }
void Sound::stopBackgroundMyst() { void Sound::stopBackgroundMyst() {
for (uint32 i = 0; i < _handles.size(); i++) if (_mystBackgroundSound.type == kUsedHandle) {
if (_handles[i].type == kBackgroundHandle) { _vm->_mixer->stopHandle(_mystBackgroundSound.handle);
_vm->_mixer->stopHandle(_handles[i].handle); _mystBackgroundSound.type = kFreeHandle;
_handles[i].type = kFreeHandle; _mystBackgroundSound.id = 0;
_handles[i].id = 0; }
}
} }
void Sound::pauseBackgroundMyst() { void Sound::pauseBackgroundMyst() {
for (uint32 i = 0; i < _handles.size(); i++) if (_mystBackgroundSound.type == kUsedHandle)
if (_handles[i].type == kBackgroundHandle) _vm->_mixer->pauseHandle(_mystBackgroundSound.handle, true);
_vm->_mixer->pauseHandle(_handles[i].handle, true);
} }
void Sound::resumeBackgroundMyst() { void Sound::resumeBackgroundMyst() {
for (uint32 i = 0; i < _handles.size(); i++) if (_mystBackgroundSound.type == kUsedHandle)
if (_handles[i].type == kBackgroundHandle) _vm->_mixer->pauseHandle(_mystBackgroundSound.handle, false);
_vm->_mixer->pauseHandle(_handles[i].handle, false);
} }
void Sound::changeBackgroundVolumeMyst(uint16 vol) { void Sound::changeBackgroundVolumeMyst(uint16 vol) {
for (uint32 i = 0; i < _handles.size(); i++) if (_mystBackgroundSound.type == kUsedHandle)
if (_handles[i].type == kBackgroundHandle) _vm->_mixer->setChannelVolume(_mystBackgroundSound.handle, vol >> 8);
_vm->_mixer->setChannelVolume(_handles[i].handle, vol >> 8);
} }
} // End of namespace Mohawk } // End of namespace Mohawk

View File

@ -59,8 +59,7 @@ struct SLSTRecord {
enum SndHandleType { enum SndHandleType {
kFreeHandle, kFreeHandle,
kUsedHandle, kUsedHandle
kBackgroundHandle
}; };
struct SndHandle { struct SndHandle {
@ -163,6 +162,9 @@ private:
Audio::AudioStream *makeAudioStream(uint16 id, CueList *cueList = NULL); Audio::AudioStream *makeAudioStream(uint16 id, CueList *cueList = NULL);
uint16 convertMystID(uint16 id); uint16 convertMystID(uint16 id);
// Myst-specific
SndHandle _mystBackgroundSound;
// Riven-specific // Riven-specific
void playSLSTSound(uint16 index, bool fade, bool loop, uint16 volume, int16 balance); void playSLSTSound(uint16 index, bool fade, bool loop, uint16 volume, int16 balance);
void stopSLSTSound(uint16 id, bool fade); void stopSLSTSound(uint16 id, bool fade);