diff options
author | Bastien Bouclet | 2017-07-21 12:25:09 +0200 |
---|---|---|
committer | Bastien Bouclet | 2017-07-22 20:38:56 +0200 |
commit | a2fc282e1c872a725f58b5d87d783191f1fe3987 (patch) | |
tree | 1b814d8c69e3d8fe06785b158a76a4c784195602 /engines/mohawk | |
parent | 01480f9a00bdc237477f6867c9b6404ec160c3f5 (diff) | |
download | scummvm-rg350-a2fc282e1c872a725f58b5d87d783191f1fe3987.tar.gz scummvm-rg350-a2fc282e1c872a725f58b5d87d783191f1fe3987.tar.bz2 scummvm-rg350-a2fc282e1c872a725f58b5d87d783191f1fe3987.zip |
MOHAWK: Myst: Move the sound code to its own class
Diffstat (limited to 'engines/mohawk')
-rw-r--r-- | engines/mohawk/console.cpp | 2 | ||||
-rw-r--r-- | engines/mohawk/module.mk | 1 | ||||
-rw-r--r-- | engines/mohawk/myst.cpp | 4 | ||||
-rw-r--r-- | engines/mohawk/myst.h | 3 | ||||
-rw-r--r-- | engines/mohawk/myst_areas.cpp | 2 | ||||
-rw-r--r-- | engines/mohawk/myst_scripts.cpp | 2 | ||||
-rw-r--r-- | engines/mohawk/myst_sound.cpp | 239 | ||||
-rw-r--r-- | engines/mohawk/myst_sound.h | 76 | ||||
-rw-r--r-- | engines/mohawk/myst_stacks/channelwood.cpp | 2 | ||||
-rw-r--r-- | engines/mohawk/myst_stacks/mechanical.cpp | 2 | ||||
-rw-r--r-- | engines/mohawk/myst_stacks/myst.cpp | 2 | ||||
-rw-r--r-- | engines/mohawk/myst_stacks/preview.cpp | 2 | ||||
-rw-r--r-- | engines/mohawk/myst_stacks/selenitic.cpp | 2 | ||||
-rw-r--r-- | engines/mohawk/myst_stacks/stoneship.cpp | 2 | ||||
-rw-r--r-- | engines/mohawk/riven_sound.cpp | 1 | ||||
-rw-r--r-- | engines/mohawk/sound.cpp | 111 | ||||
-rw-r--r-- | engines/mohawk/sound.h | 16 |
17 files changed, 335 insertions, 134 deletions
diff --git a/engines/mohawk/console.cpp b/engines/mohawk/console.cpp index 5b810c5cc3..a25023cf39 100644 --- a/engines/mohawk/console.cpp +++ b/engines/mohawk/console.cpp @@ -22,6 +22,7 @@ #include "mohawk/console.h" #include "mohawk/livingbooks.h" +#include "mohawk/resource.h" #include "mohawk/sound.h" #include "mohawk/video.h" @@ -37,6 +38,7 @@ #include "mohawk/myst_areas.h" #include "mohawk/myst_graphics.h" #include "mohawk/myst_scripts.h" +#include "mohawk/myst_sound.h" #endif #ifdef ENABLE_RIVEN diff --git a/engines/mohawk/module.mk b/engines/mohawk/module.mk index de0f205219..e20638f881 100644 --- a/engines/mohawk/module.mk +++ b/engines/mohawk/module.mk @@ -34,6 +34,7 @@ MODULE_OBJS += \ myst_areas.o \ myst_graphics.o \ myst_scripts.o \ + myst_sound.o \ myst_state.o \ resource_cache.o \ myst_stacks/channelwood.o \ diff --git a/engines/mohawk/myst.cpp b/engines/mohawk/myst.cpp index 24778fe5ae..8d96780617 100644 --- a/engines/mohawk/myst.cpp +++ b/engines/mohawk/myst.cpp @@ -31,11 +31,11 @@ #include "mohawk/myst_areas.h" #include "mohawk/myst_graphics.h" #include "mohawk/myst_scripts.h" +#include "mohawk/myst_sound.h" #include "mohawk/myst_state.h" #include "mohawk/dialogs.h" #include "mohawk/resource.h" #include "mohawk/resource_cache.h" -#include "mohawk/sound.h" #include "mohawk/video.h" // The stacks @@ -290,7 +290,7 @@ Common::Error MohawkEngine_Myst::run() { _gfx = new MystGraphics(this); _video = new VideoManager(this); - _sound = new Sound(this); + _sound = new MystSound(this); _console = new MystConsole(this); _gameState = new MystGameState(this, _saveFileMan); _optionsDialog = new MystOptionsDialog(this); diff --git a/engines/mohawk/myst.h b/engines/mohawk/myst.h index a411b64347..39d96bb320 100644 --- a/engines/mohawk/myst.h +++ b/engines/mohawk/myst.h @@ -43,6 +43,7 @@ class MystScriptParser; class MystConsole; class MystGameState; class MystOptionsDialog; +class MystSound; class MystArea; class MystAreaImageSwitch; class MystAreaHover; @@ -206,7 +207,7 @@ public: bool _showResourceRects; VideoManager *_video; - Sound *_sound; + MystSound *_sound; MystGraphics *_gfx; MystGameState *_gameState; MystScriptParser *_scriptParser; diff --git a/engines/mohawk/myst_areas.cpp b/engines/mohawk/myst_areas.cpp index 5e6b39df15..3bb6eb8653 100644 --- a/engines/mohawk/myst_areas.cpp +++ b/engines/mohawk/myst_areas.cpp @@ -23,7 +23,7 @@ #include "mohawk/myst_areas.h" #include "mohawk/myst_graphics.h" #include "mohawk/myst_scripts.h" -#include "mohawk/sound.h" +#include "mohawk/myst_sound.h" #include "mohawk/video.h" #include "common/events.h" diff --git a/engines/mohawk/myst_scripts.cpp b/engines/mohawk/myst_scripts.cpp index f3e44bc154..9141f9f988 100644 --- a/engines/mohawk/myst_scripts.cpp +++ b/engines/mohawk/myst_scripts.cpp @@ -25,7 +25,7 @@ #include "mohawk/myst_areas.h" #include "mohawk/myst_graphics.h" #include "mohawk/myst_scripts.h" -#include "mohawk/sound.h" +#include "mohawk/myst_sound.h" #include "mohawk/video.h" #include "common/system.h" diff --git a/engines/mohawk/myst_sound.cpp b/engines/mohawk/myst_sound.cpp new file mode 100644 index 0000000000..f8cdc04e24 --- /dev/null +++ b/engines/mohawk/myst_sound.cpp @@ -0,0 +1,239 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "mohawk/myst_sound.h" + +#include "mohawk/myst.h" +#include "mohawk/resource.h" + +#include "common/debug.h" + +#include "audio/audiostream.h" +#include "audio/decoders/wave.h" + +namespace Mohawk { + +MystSound::MystSound(MohawkEngine_Myst *vm) : + _vm(vm) { + _mystBackgroundSound.type = kFreeHandle; +} + +MystSound::~MystSound() { + stopSound(); + stopBackgroundMyst(); +} + +Audio::RewindableAudioStream *MystSound::makeAudioStream(uint16 id, CueList *cueList) { + if (_vm->getFeatures() & GF_ME) + return Audio::makeWAVStream(_vm->getResource(ID_MSND, convertMystID(id)), DisposeAfterUse::YES); + else + return makeMohawkWaveStream(_vm->getResource(ID_MSND, id), cueList); +} + +Audio::SoundHandle *MystSound::playSound(uint16 id, byte volume, bool loop, CueList *cueList) { + debug (0, "Playing sound %d", id); + + Audio::RewindableAudioStream *rewindStream = makeAudioStream(id, cueList); + + if (rewindStream) { + SndHandle *handle = getHandle(); + handle->type = kUsedHandle; + handle->id = id; + handle->samplesPerSecond = rewindStream->getRate(); + + // Set the stream to loop here if it's requested + Audio::AudioStream *audStream = rewindStream; + if (loop) + audStream = Audio::makeLoopingAudioStream(rewindStream, 0); + + _vm->_mixer->playStream(Audio::Mixer::kPlainSoundType, &handle->handle, audStream, -1, volume); + return &handle->handle; + } + + return nullptr; +} + +Audio::SoundHandle *MystSound::replaceSoundMyst(uint16 id, byte volume, bool loop) { + debug (0, "Replacing sound %d", id); + + // The original engine also forces looping for those sounds + switch (id) { + case 2205: + case 2207: + case 5378: + case 7220: + case 9119: // Elevator engine sound in mechanical age is looping. + case 9120: + case 9327: + loop = true; + break; + } + + stopSound(); + return playSound(id, volume, loop); +} + +SndHandle *MystSound::getHandle() { + for (uint32 i = 0; i < _handles.size(); i++) { + if (_handles[i].type == kFreeHandle) + return &_handles[i]; + + if (!_vm->_mixer->isSoundHandleActive(_handles[i].handle)) { + _handles[i].type = kFreeHandle; + _handles[i].id = 0; + return &_handles[i]; + } + } + + // Let's add a new sound handle! + SndHandle handle; + handle.handle = Audio::SoundHandle(); + handle.type = kFreeHandle; + handle.id = 0; + _handles.push_back(handle); + + return &_handles[_handles.size() - 1]; +} + +void MystSound::stopSound() { + for (uint32 i = 0; i < _handles.size(); i++) + if (_handles[i].type == kUsedHandle) { + _vm->_mixer->stopHandle(_handles[i].handle); + _handles[i].type = kFreeHandle; + _handles[i].id = 0; + } +} + +void MystSound::stopSound(uint16 id) { + for (uint32 i = 0; i < _handles.size(); i++) + if (_handles[i].type == kUsedHandle && _handles[i].id == id) { + _vm->_mixer->stopHandle(_handles[i].handle); + _handles[i].type = kFreeHandle; + _handles[i].id = 0; + } +} + +bool MystSound::isPlaying(uint16 id) { + for (uint32 i = 0; i < _handles.size(); i++) + if (_handles[i].type == kUsedHandle && _handles[i].id == id) + return _vm->_mixer->isSoundHandleActive(_handles[i].handle); + + return false; +} + +bool MystSound::isPlaying() { + for (uint32 i = 0; i < _handles.size(); i++) + if (_handles[i].type == kUsedHandle) + if (_vm->_mixer->isSoundHandleActive(_handles[i].handle)) + return true; + + return false; +} + +uint MystSound::getNumSamplesPlayed(uint16 id) { + for (uint32 i = 0; i < _handles.size(); i++) + if (_handles[i].type == kUsedHandle && _handles[i].id == id) { + return (_vm->_mixer->getSoundElapsedTime(_handles[i].handle) * _handles[i].samplesPerSecond) / 1000; + } + + return 0; +} + +uint16 MystSound::convertMystID(uint16 id) { + // Myst ME is a bit more efficient with sound storage than Myst + // Myst has lots of sounds repeated. To overcome this, Myst ME + // has MJMP resources which provide a link to the actual MSND + // resource we're looking for. This saves a lot of space from + // repeated data. + if (_vm->hasResource(ID_MJMP, id)) { + Common::SeekableReadStream *mjmpStream = _vm->getResource(ID_MJMP, id); + id = mjmpStream->readUint16LE(); + delete mjmpStream; + } + + return id; +} + +void MystSound::replaceBackgroundMyst(uint16 id, uint16 volume) { + debug(0, "Replacing background sound with %d", id); + + // TODO: The original engine does fading + + Common::String name = _vm->getResourceName(ID_MSND, convertMystID(id)); + + // Only the first eight characters need to be the same to have a match + Common::String prefix; + if (name.size() >= 8) + prefix = Common::String(name.c_str(), name.c_str() + 8); + else + prefix = name; + + // Check if sound is already playing + if (_mystBackgroundSound.type == kUsedHandle && _vm->_mixer->isSoundHandleActive(_mystBackgroundSound.handle) + && _vm->getResourceName(ID_MSND, convertMystID(_mystBackgroundSound.id)).hasPrefix(prefix)) { + // The sound is already playing, just change the volume + changeBackgroundVolumeMyst(volume); + return; + } + + // Stop old background sound + stopBackgroundMyst(); + + // Play new sound + Audio::RewindableAudioStream *rewindStream = makeAudioStream(id); + + if (rewindStream) { + _mystBackgroundSound.type = kUsedHandle; + _mystBackgroundSound.id = id; + _mystBackgroundSound.samplesPerSecond = rewindStream->getRate(); + + // Set the stream to loop + Audio::AudioStream *audStream = Audio::makeLoopingAudioStream(rewindStream, 0); + + _vm->_mixer->playStream(Audio::Mixer::kPlainSoundType, &_mystBackgroundSound.handle, audStream, -1, volume >> 8); + } +} + +void MystSound::stopBackgroundMyst() { + if (_mystBackgroundSound.type == kUsedHandle) { + _vm->_mixer->stopHandle(_mystBackgroundSound.handle); + _mystBackgroundSound.type = kFreeHandle; + _mystBackgroundSound.id = 0; + } +} + +void MystSound::pauseBackgroundMyst() { + if (_mystBackgroundSound.type == kUsedHandle) + _vm->_mixer->pauseHandle(_mystBackgroundSound.handle, true); +} + +void MystSound::resumeBackgroundMyst() { + if (_mystBackgroundSound.type == kUsedHandle) + _vm->_mixer->pauseHandle(_mystBackgroundSound.handle, false); +} + +void MystSound::changeBackgroundVolumeMyst(uint16 vol) { + if (_mystBackgroundSound.type == kUsedHandle) + _vm->_mixer->setChannelVolume(_mystBackgroundSound.handle, vol >> 8); +} + +} // End of namespace Mohawk diff --git a/engines/mohawk/myst_sound.h b/engines/mohawk/myst_sound.h new file mode 100644 index 0000000000..d5cd5413d1 --- /dev/null +++ b/engines/mohawk/myst_sound.h @@ -0,0 +1,76 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef MOHAWK_MYST_SOUND_H +#define MOHAWK_MYST_SOUND_H + +#include "common/scummsys.h" +#include "common/str.h" + +#include "audio/mixer.h" + +#include "mohawk/sound.h" + +namespace Audio { +class RewindableAudioStream; +} + +namespace Mohawk { + +class MohawkEngine_Myst; + +class MystSound { +public: + MystSound(MohawkEngine_Myst *vm); + ~MystSound(); + + // Generic sound functions + Audio::SoundHandle *playSound(uint16 id, byte volume = Audio::Mixer::kMaxChannelVolume, bool loop = false, CueList *cueList = NULL); + void stopSound(); + void stopSound(uint16 id); + bool isPlaying(uint16 id); + bool isPlaying(); + uint getNumSamplesPlayed(uint16 id); + + // Myst-specific sound functions + Audio::SoundHandle *replaceSoundMyst(uint16 id, byte volume = Audio::Mixer::kMaxChannelVolume, bool loop = false); + void replaceBackgroundMyst(uint16 id, uint16 volume = 0xFFFF); + void pauseBackgroundMyst(); + void resumeBackgroundMyst(); + void stopBackgroundMyst(); + void changeBackgroundVolumeMyst(uint16 vol); + +private: + MohawkEngine_Myst *_vm; + + Common::Array<SndHandle> _handles; + SndHandle *getHandle(); + Audio::RewindableAudioStream *makeAudioStream(uint16 id, CueList *cueList = NULL); + uint16 convertMystID(uint16 id); + + // Myst-specific + SndHandle _mystBackgroundSound; +}; + +} // End of namespace Mohawk + +#endif diff --git a/engines/mohawk/myst_stacks/channelwood.cpp b/engines/mohawk/myst_stacks/channelwood.cpp index b8cdb599be..fbe6b60e9e 100644 --- a/engines/mohawk/myst_stacks/channelwood.cpp +++ b/engines/mohawk/myst_stacks/channelwood.cpp @@ -25,7 +25,7 @@ #include "mohawk/myst_areas.h" #include "mohawk/myst_graphics.h" #include "mohawk/myst_state.h" -#include "mohawk/sound.h" +#include "mohawk/myst_sound.h" #include "mohawk/video.h" #include "mohawk/myst_stacks/channelwood.h" diff --git a/engines/mohawk/myst_stacks/mechanical.cpp b/engines/mohawk/myst_stacks/mechanical.cpp index 5f49e694d1..09a876e107 100644 --- a/engines/mohawk/myst_stacks/mechanical.cpp +++ b/engines/mohawk/myst_stacks/mechanical.cpp @@ -25,7 +25,7 @@ #include "mohawk/myst_areas.h" #include "mohawk/myst_graphics.h" #include "mohawk/myst_state.h" -#include "mohawk/sound.h" +#include "mohawk/myst_sound.h" #include "mohawk/video.h" #include "mohawk/myst_stacks/mechanical.h" diff --git a/engines/mohawk/myst_stacks/myst.cpp b/engines/mohawk/myst_stacks/myst.cpp index d5e3fe25c2..f98fee07d4 100644 --- a/engines/mohawk/myst_stacks/myst.cpp +++ b/engines/mohawk/myst_stacks/myst.cpp @@ -25,7 +25,7 @@ #include "mohawk/myst_areas.h" #include "mohawk/myst_graphics.h" #include "mohawk/myst_state.h" -#include "mohawk/sound.h" +#include "mohawk/myst_sound.h" #include "mohawk/video.h" #include "mohawk/myst_stacks/myst.h" diff --git a/engines/mohawk/myst_stacks/preview.cpp b/engines/mohawk/myst_stacks/preview.cpp index 42458758f5..aa36ef7743 100644 --- a/engines/mohawk/myst_stacks/preview.cpp +++ b/engines/mohawk/myst_stacks/preview.cpp @@ -24,7 +24,7 @@ #include "mohawk/myst.h" #include "mohawk/myst_areas.h" #include "mohawk/myst_graphics.h" -#include "mohawk/sound.h" +#include "mohawk/myst_sound.h" #include "mohawk/video.h" #include "mohawk/myst_stacks/preview.h" diff --git a/engines/mohawk/myst_stacks/selenitic.cpp b/engines/mohawk/myst_stacks/selenitic.cpp index 22cb8567f8..47e7a56d27 100644 --- a/engines/mohawk/myst_stacks/selenitic.cpp +++ b/engines/mohawk/myst_stacks/selenitic.cpp @@ -25,7 +25,7 @@ #include "mohawk/graphics.h" #include "mohawk/myst_areas.h" #include "mohawk/myst_state.h" -#include "mohawk/sound.h" +#include "mohawk/myst_sound.h" #include "mohawk/video.h" #include "mohawk/myst_stacks/selenitic.h" diff --git a/engines/mohawk/myst_stacks/stoneship.cpp b/engines/mohawk/myst_stacks/stoneship.cpp index 26c38f2a4f..2062bb99ac 100644 --- a/engines/mohawk/myst_stacks/stoneship.cpp +++ b/engines/mohawk/myst_stacks/stoneship.cpp @@ -25,7 +25,7 @@ #include "mohawk/myst_areas.h" #include "mohawk/myst_graphics.h" #include "mohawk/myst_state.h" -#include "mohawk/sound.h" +#include "mohawk/myst_sound.h" #include "mohawk/video.h" #include "mohawk/myst_stacks/stoneship.h" diff --git a/engines/mohawk/riven_sound.cpp b/engines/mohawk/riven_sound.cpp index efbcdfb33c..2305494bf2 100644 --- a/engines/mohawk/riven_sound.cpp +++ b/engines/mohawk/riven_sound.cpp @@ -28,6 +28,7 @@ #include "mohawk/riven_sound.h" #include "mohawk/riven.h" #include "mohawk/riven_card.h" +#include "mohawk/resource.h" #include "mohawk/sound.h" namespace Mohawk { diff --git a/engines/mohawk/sound.cpp b/engines/mohawk/sound.cpp index 5907c5b002..81d83fc7b9 100644 --- a/engines/mohawk/sound.cpp +++ b/engines/mohawk/sound.cpp @@ -21,9 +21,6 @@ */ #include "common/debug.h" -#include "common/events.h" -#include "common/system.h" -#include "common/textconsole.h" #include "audio/mididrv.h" #include "audio/midiparser.h" @@ -33,7 +30,9 @@ #include "audio/decoders/raw.h" #include "audio/decoders/wave.h" +#include "mohawk/mohawk.h" #include "mohawk/sound.h" +#include "mohawk/resource.h" namespace Mohawk { @@ -185,13 +184,11 @@ Sound::Sound(MohawkEngine* vm) : _vm(vm) { _midiDriver = NULL; _midiParser = NULL; _midiData = NULL; - _mystBackgroundSound.type = kFreeHandle; initMidi(); } Sound::~Sound() { stopSound(); - stopBackgroundMyst(); if (_midiParser) { _midiParser->unloadMusic(); @@ -225,12 +222,6 @@ Audio::RewindableAudioStream *Sound::makeAudioStream(uint16 id, CueList *cueList Audio::RewindableAudioStream *audStream = NULL; switch (_vm->getGameType()) { - case GType_MYST: - if (_vm->getFeatures() & GF_ME) - audStream = Audio::makeWAVStream(_vm->getResource(ID_MSND, convertMystID(id)), DisposeAfterUse::YES); - else - audStream = makeMohawkWaveStream(_vm->getResource(ID_MSND, id), cueList); - break; case GType_ZOOMBINI: audStream = makeMohawkWaveStream(_vm->getResource(ID_SND, id)); break; @@ -273,26 +264,6 @@ Audio::SoundHandle *Sound::playSound(uint16 id, byte volume, bool loop, CueList return NULL; } -Audio::SoundHandle *Sound::replaceSoundMyst(uint16 id, byte volume, bool loop) { - debug (0, "Replacing sound %d", id); - - // The original engine also forces looping for those sounds - switch (id) { - case 2205: - case 2207: - case 5378: - case 7220: - case 9119: // Elevator engine sound in mechanical age is looping. - case 9120: - case 9327: - loop = true; - break; - } - - stopSound(); - return playSound(id, volume, loop); -} - void Sound::playMidi(uint16 id) { uint32 idTag; if (!(_vm->getFeatures() & GF_HASMIDI)) { @@ -430,82 +401,4 @@ uint Sound::getNumSamplesPlayed(uint16 id) { return 0; } -uint16 Sound::convertMystID(uint16 id) { - // Myst ME is a bit more efficient with sound storage than Myst - // Myst has lots of sounds repeated. To overcome this, Myst ME - // has MJMP resources which provide a link to the actual MSND - // resource we're looking for. This saves a lot of space from - // repeated data. - if (_vm->hasResource(ID_MJMP, id)) { - Common::SeekableReadStream *mjmpStream = _vm->getResource(ID_MJMP, id); - id = mjmpStream->readUint16LE(); - delete mjmpStream; - } - - return id; -} - -void Sound::replaceBackgroundMyst(uint16 id, uint16 volume) { - debug(0, "Replacing background sound with %d", id); - - // TODO: The original engine does fading - - Common::String name = _vm->getResourceName(ID_MSND, convertMystID(id)); - - // Only the first eight characters need to be the same to have a match - Common::String prefix; - if (name.size() >= 8) - prefix = Common::String(name.c_str(), name.c_str() + 8); - else - prefix = name; - - // Check if sound is already playing - if (_mystBackgroundSound.type == kUsedHandle && _vm->_mixer->isSoundHandleActive(_mystBackgroundSound.handle) - && _vm->getResourceName(ID_MSND, convertMystID(_mystBackgroundSound.id)).hasPrefix(prefix)) { - // The sound is already playing, just change the volume - changeBackgroundVolumeMyst(volume); - return; - } - - // Stop old background sound - stopBackgroundMyst(); - - // Play new sound - Audio::RewindableAudioStream *rewindStream = makeAudioStream(id); - - if (rewindStream) { - _mystBackgroundSound.type = kUsedHandle; - _mystBackgroundSound.id = id; - _mystBackgroundSound.samplesPerSecond = rewindStream->getRate(); - - // Set the stream to loop - Audio::AudioStream *audStream = Audio::makeLoopingAudioStream(rewindStream, 0); - - _vm->_mixer->playStream(Audio::Mixer::kPlainSoundType, &_mystBackgroundSound.handle, audStream, -1, volume >> 8); - } -} - -void Sound::stopBackgroundMyst() { - if (_mystBackgroundSound.type == kUsedHandle) { - _vm->_mixer->stopHandle(_mystBackgroundSound.handle); - _mystBackgroundSound.type = kFreeHandle; - _mystBackgroundSound.id = 0; - } -} - -void Sound::pauseBackgroundMyst() { - if (_mystBackgroundSound.type == kUsedHandle) - _vm->_mixer->pauseHandle(_mystBackgroundSound.handle, true); -} - -void Sound::resumeBackgroundMyst() { - if (_mystBackgroundSound.type == kUsedHandle) - _vm->_mixer->pauseHandle(_mystBackgroundSound.handle, false); -} - -void Sound::changeBackgroundVolumeMyst(uint16 vol) { - if (_mystBackgroundSound.type == kUsedHandle) - _vm->_mixer->setChannelVolume(_mystBackgroundSound.handle, vol >> 8); -} - } // End of namespace Mohawk diff --git a/engines/mohawk/sound.h b/engines/mohawk/sound.h index 7dcc125668..11fd004513 100644 --- a/engines/mohawk/sound.h +++ b/engines/mohawk/sound.h @@ -23,14 +23,13 @@ #ifndef MOHAWK_SOUND_H #define MOHAWK_SOUND_H +#include "common/array.h" #include "common/scummsys.h" #include "common/str.h" +#include "common/stream.h" #include "audio/mixer.h" -#include "mohawk/mohawk.h" -#include "mohawk/resource.h" - class MidiDriver; class MidiParser; @@ -116,14 +115,6 @@ public: bool isPlaying(); uint getNumSamplesPlayed(uint16 id); - // Myst-specific sound functions - Audio::SoundHandle *replaceSoundMyst(uint16 id, byte volume = Audio::Mixer::kMaxChannelVolume, bool loop = false); - void replaceBackgroundMyst(uint16 id, uint16 volume = 0xFFFF); - void pauseBackgroundMyst(); - void resumeBackgroundMyst(); - void stopBackgroundMyst(); - void changeBackgroundVolumeMyst(uint16 vol); - private: MohawkEngine *_vm; MidiDriver *_midiDriver; @@ -137,9 +128,6 @@ private: SndHandle *getHandle(); Audio::RewindableAudioStream *makeAudioStream(uint16 id, CueList *cueList = NULL); uint16 convertMystID(uint16 id); - - // Myst-specific - SndHandle _mystBackgroundSound; }; } // End of namespace Mohawk |