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

View File

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