aboutsummaryrefslogtreecommitdiff
path: root/engines/mohawk/sound.cpp
diff options
context:
space:
mode:
authorBastien Bouclet2017-07-21 12:25:09 +0200
committerBastien Bouclet2017-07-22 20:38:56 +0200
commita2fc282e1c872a725f58b5d87d783191f1fe3987 (patch)
tree1b814d8c69e3d8fe06785b158a76a4c784195602 /engines/mohawk/sound.cpp
parent01480f9a00bdc237477f6867c9b6404ec160c3f5 (diff)
downloadscummvm-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/sound.cpp')
-rw-r--r--engines/mohawk/sound.cpp111
1 files changed, 2 insertions, 109 deletions
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