mirror of
https://github.com/libretro/scummvm.git
synced 2025-04-12 03:36:42 +00:00
MOHAWK: Myst: Move the sound code to its own class
This commit is contained in:
parent
01480f9a00
commit
a2fc282e1c
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "mohawk/console.h"
|
#include "mohawk/console.h"
|
||||||
#include "mohawk/livingbooks.h"
|
#include "mohawk/livingbooks.h"
|
||||||
|
#include "mohawk/resource.h"
|
||||||
#include "mohawk/sound.h"
|
#include "mohawk/sound.h"
|
||||||
#include "mohawk/video.h"
|
#include "mohawk/video.h"
|
||||||
|
|
||||||
@ -37,6 +38,7 @@
|
|||||||
#include "mohawk/myst_areas.h"
|
#include "mohawk/myst_areas.h"
|
||||||
#include "mohawk/myst_graphics.h"
|
#include "mohawk/myst_graphics.h"
|
||||||
#include "mohawk/myst_scripts.h"
|
#include "mohawk/myst_scripts.h"
|
||||||
|
#include "mohawk/myst_sound.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_RIVEN
|
#ifdef ENABLE_RIVEN
|
||||||
|
@ -34,6 +34,7 @@ MODULE_OBJS += \
|
|||||||
myst_areas.o \
|
myst_areas.o \
|
||||||
myst_graphics.o \
|
myst_graphics.o \
|
||||||
myst_scripts.o \
|
myst_scripts.o \
|
||||||
|
myst_sound.o \
|
||||||
myst_state.o \
|
myst_state.o \
|
||||||
resource_cache.o \
|
resource_cache.o \
|
||||||
myst_stacks/channelwood.o \
|
myst_stacks/channelwood.o \
|
||||||
|
@ -31,11 +31,11 @@
|
|||||||
#include "mohawk/myst_areas.h"
|
#include "mohawk/myst_areas.h"
|
||||||
#include "mohawk/myst_graphics.h"
|
#include "mohawk/myst_graphics.h"
|
||||||
#include "mohawk/myst_scripts.h"
|
#include "mohawk/myst_scripts.h"
|
||||||
|
#include "mohawk/myst_sound.h"
|
||||||
#include "mohawk/myst_state.h"
|
#include "mohawk/myst_state.h"
|
||||||
#include "mohawk/dialogs.h"
|
#include "mohawk/dialogs.h"
|
||||||
#include "mohawk/resource.h"
|
#include "mohawk/resource.h"
|
||||||
#include "mohawk/resource_cache.h"
|
#include "mohawk/resource_cache.h"
|
||||||
#include "mohawk/sound.h"
|
|
||||||
#include "mohawk/video.h"
|
#include "mohawk/video.h"
|
||||||
|
|
||||||
// The stacks
|
// The stacks
|
||||||
@ -290,7 +290,7 @@ Common::Error MohawkEngine_Myst::run() {
|
|||||||
|
|
||||||
_gfx = new MystGraphics(this);
|
_gfx = new MystGraphics(this);
|
||||||
_video = new VideoManager(this);
|
_video = new VideoManager(this);
|
||||||
_sound = new Sound(this);
|
_sound = new MystSound(this);
|
||||||
_console = new MystConsole(this);
|
_console = new MystConsole(this);
|
||||||
_gameState = new MystGameState(this, _saveFileMan);
|
_gameState = new MystGameState(this, _saveFileMan);
|
||||||
_optionsDialog = new MystOptionsDialog(this);
|
_optionsDialog = new MystOptionsDialog(this);
|
||||||
|
@ -43,6 +43,7 @@ class MystScriptParser;
|
|||||||
class MystConsole;
|
class MystConsole;
|
||||||
class MystGameState;
|
class MystGameState;
|
||||||
class MystOptionsDialog;
|
class MystOptionsDialog;
|
||||||
|
class MystSound;
|
||||||
class MystArea;
|
class MystArea;
|
||||||
class MystAreaImageSwitch;
|
class MystAreaImageSwitch;
|
||||||
class MystAreaHover;
|
class MystAreaHover;
|
||||||
@ -206,7 +207,7 @@ public:
|
|||||||
bool _showResourceRects;
|
bool _showResourceRects;
|
||||||
|
|
||||||
VideoManager *_video;
|
VideoManager *_video;
|
||||||
Sound *_sound;
|
MystSound *_sound;
|
||||||
MystGraphics *_gfx;
|
MystGraphics *_gfx;
|
||||||
MystGameState *_gameState;
|
MystGameState *_gameState;
|
||||||
MystScriptParser *_scriptParser;
|
MystScriptParser *_scriptParser;
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include "mohawk/myst_areas.h"
|
#include "mohawk/myst_areas.h"
|
||||||
#include "mohawk/myst_graphics.h"
|
#include "mohawk/myst_graphics.h"
|
||||||
#include "mohawk/myst_scripts.h"
|
#include "mohawk/myst_scripts.h"
|
||||||
#include "mohawk/sound.h"
|
#include "mohawk/myst_sound.h"
|
||||||
#include "mohawk/video.h"
|
#include "mohawk/video.h"
|
||||||
|
|
||||||
#include "common/events.h"
|
#include "common/events.h"
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include "mohawk/myst_areas.h"
|
#include "mohawk/myst_areas.h"
|
||||||
#include "mohawk/myst_graphics.h"
|
#include "mohawk/myst_graphics.h"
|
||||||
#include "mohawk/myst_scripts.h"
|
#include "mohawk/myst_scripts.h"
|
||||||
#include "mohawk/sound.h"
|
#include "mohawk/myst_sound.h"
|
||||||
#include "mohawk/video.h"
|
#include "mohawk/video.h"
|
||||||
|
|
||||||
#include "common/system.h"
|
#include "common/system.h"
|
||||||
|
239
engines/mohawk/myst_sound.cpp
Normal file
239
engines/mohawk/myst_sound.cpp
Normal file
@ -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
|
76
engines/mohawk/myst_sound.h
Normal file
76
engines/mohawk/myst_sound.h
Normal file
@ -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
|
@ -25,7 +25,7 @@
|
|||||||
#include "mohawk/myst_areas.h"
|
#include "mohawk/myst_areas.h"
|
||||||
#include "mohawk/myst_graphics.h"
|
#include "mohawk/myst_graphics.h"
|
||||||
#include "mohawk/myst_state.h"
|
#include "mohawk/myst_state.h"
|
||||||
#include "mohawk/sound.h"
|
#include "mohawk/myst_sound.h"
|
||||||
#include "mohawk/video.h"
|
#include "mohawk/video.h"
|
||||||
#include "mohawk/myst_stacks/channelwood.h"
|
#include "mohawk/myst_stacks/channelwood.h"
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include "mohawk/myst_areas.h"
|
#include "mohawk/myst_areas.h"
|
||||||
#include "mohawk/myst_graphics.h"
|
#include "mohawk/myst_graphics.h"
|
||||||
#include "mohawk/myst_state.h"
|
#include "mohawk/myst_state.h"
|
||||||
#include "mohawk/sound.h"
|
#include "mohawk/myst_sound.h"
|
||||||
#include "mohawk/video.h"
|
#include "mohawk/video.h"
|
||||||
#include "mohawk/myst_stacks/mechanical.h"
|
#include "mohawk/myst_stacks/mechanical.h"
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include "mohawk/myst_areas.h"
|
#include "mohawk/myst_areas.h"
|
||||||
#include "mohawk/myst_graphics.h"
|
#include "mohawk/myst_graphics.h"
|
||||||
#include "mohawk/myst_state.h"
|
#include "mohawk/myst_state.h"
|
||||||
#include "mohawk/sound.h"
|
#include "mohawk/myst_sound.h"
|
||||||
#include "mohawk/video.h"
|
#include "mohawk/video.h"
|
||||||
#include "mohawk/myst_stacks/myst.h"
|
#include "mohawk/myst_stacks/myst.h"
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#include "mohawk/myst.h"
|
#include "mohawk/myst.h"
|
||||||
#include "mohawk/myst_areas.h"
|
#include "mohawk/myst_areas.h"
|
||||||
#include "mohawk/myst_graphics.h"
|
#include "mohawk/myst_graphics.h"
|
||||||
#include "mohawk/sound.h"
|
#include "mohawk/myst_sound.h"
|
||||||
#include "mohawk/video.h"
|
#include "mohawk/video.h"
|
||||||
#include "mohawk/myst_stacks/preview.h"
|
#include "mohawk/myst_stacks/preview.h"
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include "mohawk/graphics.h"
|
#include "mohawk/graphics.h"
|
||||||
#include "mohawk/myst_areas.h"
|
#include "mohawk/myst_areas.h"
|
||||||
#include "mohawk/myst_state.h"
|
#include "mohawk/myst_state.h"
|
||||||
#include "mohawk/sound.h"
|
#include "mohawk/myst_sound.h"
|
||||||
#include "mohawk/video.h"
|
#include "mohawk/video.h"
|
||||||
#include "mohawk/myst_stacks/selenitic.h"
|
#include "mohawk/myst_stacks/selenitic.h"
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include "mohawk/myst_areas.h"
|
#include "mohawk/myst_areas.h"
|
||||||
#include "mohawk/myst_graphics.h"
|
#include "mohawk/myst_graphics.h"
|
||||||
#include "mohawk/myst_state.h"
|
#include "mohawk/myst_state.h"
|
||||||
#include "mohawk/sound.h"
|
#include "mohawk/myst_sound.h"
|
||||||
#include "mohawk/video.h"
|
#include "mohawk/video.h"
|
||||||
#include "mohawk/myst_stacks/stoneship.h"
|
#include "mohawk/myst_stacks/stoneship.h"
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "mohawk/riven_sound.h"
|
#include "mohawk/riven_sound.h"
|
||||||
#include "mohawk/riven.h"
|
#include "mohawk/riven.h"
|
||||||
#include "mohawk/riven_card.h"
|
#include "mohawk/riven_card.h"
|
||||||
|
#include "mohawk/resource.h"
|
||||||
#include "mohawk/sound.h"
|
#include "mohawk/sound.h"
|
||||||
|
|
||||||
namespace Mohawk {
|
namespace Mohawk {
|
||||||
|
@ -21,9 +21,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/events.h"
|
|
||||||
#include "common/system.h"
|
|
||||||
#include "common/textconsole.h"
|
|
||||||
|
|
||||||
#include "audio/mididrv.h"
|
#include "audio/mididrv.h"
|
||||||
#include "audio/midiparser.h"
|
#include "audio/midiparser.h"
|
||||||
@ -33,7 +30,9 @@
|
|||||||
#include "audio/decoders/raw.h"
|
#include "audio/decoders/raw.h"
|
||||||
#include "audio/decoders/wave.h"
|
#include "audio/decoders/wave.h"
|
||||||
|
|
||||||
|
#include "mohawk/mohawk.h"
|
||||||
#include "mohawk/sound.h"
|
#include "mohawk/sound.h"
|
||||||
|
#include "mohawk/resource.h"
|
||||||
|
|
||||||
namespace Mohawk {
|
namespace Mohawk {
|
||||||
|
|
||||||
@ -185,13 +184,11 @@ Sound::Sound(MohawkEngine* vm) : _vm(vm) {
|
|||||||
_midiDriver = NULL;
|
_midiDriver = NULL;
|
||||||
_midiParser = NULL;
|
_midiParser = NULL;
|
||||||
_midiData = NULL;
|
_midiData = NULL;
|
||||||
_mystBackgroundSound.type = kFreeHandle;
|
|
||||||
initMidi();
|
initMidi();
|
||||||
}
|
}
|
||||||
|
|
||||||
Sound::~Sound() {
|
Sound::~Sound() {
|
||||||
stopSound();
|
stopSound();
|
||||||
stopBackgroundMyst();
|
|
||||||
|
|
||||||
if (_midiParser) {
|
if (_midiParser) {
|
||||||
_midiParser->unloadMusic();
|
_midiParser->unloadMusic();
|
||||||
@ -225,12 +222,6 @@ Audio::RewindableAudioStream *Sound::makeAudioStream(uint16 id, CueList *cueList
|
|||||||
Audio::RewindableAudioStream *audStream = NULL;
|
Audio::RewindableAudioStream *audStream = NULL;
|
||||||
|
|
||||||
switch (_vm->getGameType()) {
|
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:
|
case GType_ZOOMBINI:
|
||||||
audStream = makeMohawkWaveStream(_vm->getResource(ID_SND, id));
|
audStream = makeMohawkWaveStream(_vm->getResource(ID_SND, id));
|
||||||
break;
|
break;
|
||||||
@ -273,26 +264,6 @@ Audio::SoundHandle *Sound::playSound(uint16 id, byte volume, bool loop, CueList
|
|||||||
return NULL;
|
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) {
|
void Sound::playMidi(uint16 id) {
|
||||||
uint32 idTag;
|
uint32 idTag;
|
||||||
if (!(_vm->getFeatures() & GF_HASMIDI)) {
|
if (!(_vm->getFeatures() & GF_HASMIDI)) {
|
||||||
@ -430,82 +401,4 @@ uint Sound::getNumSamplesPlayed(uint16 id) {
|
|||||||
return 0;
|
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
|
} // End of namespace Mohawk
|
||||||
|
@ -23,14 +23,13 @@
|
|||||||
#ifndef MOHAWK_SOUND_H
|
#ifndef MOHAWK_SOUND_H
|
||||||
#define MOHAWK_SOUND_H
|
#define MOHAWK_SOUND_H
|
||||||
|
|
||||||
|
#include "common/array.h"
|
||||||
#include "common/scummsys.h"
|
#include "common/scummsys.h"
|
||||||
#include "common/str.h"
|
#include "common/str.h"
|
||||||
|
#include "common/stream.h"
|
||||||
|
|
||||||
#include "audio/mixer.h"
|
#include "audio/mixer.h"
|
||||||
|
|
||||||
#include "mohawk/mohawk.h"
|
|
||||||
#include "mohawk/resource.h"
|
|
||||||
|
|
||||||
class MidiDriver;
|
class MidiDriver;
|
||||||
class MidiParser;
|
class MidiParser;
|
||||||
|
|
||||||
@ -116,14 +115,6 @@ public:
|
|||||||
bool isPlaying();
|
bool isPlaying();
|
||||||
uint getNumSamplesPlayed(uint16 id);
|
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:
|
private:
|
||||||
MohawkEngine *_vm;
|
MohawkEngine *_vm;
|
||||||
MidiDriver *_midiDriver;
|
MidiDriver *_midiDriver;
|
||||||
@ -137,9 +128,6 @@ private:
|
|||||||
SndHandle *getHandle();
|
SndHandle *getHandle();
|
||||||
Audio::RewindableAudioStream *makeAudioStream(uint16 id, CueList *cueList = NULL);
|
Audio::RewindableAudioStream *makeAudioStream(uint16 id, CueList *cueList = NULL);
|
||||||
uint16 convertMystID(uint16 id);
|
uint16 convertMystID(uint16 id);
|
||||||
|
|
||||||
// Myst-specific
|
|
||||||
SndHandle _mystBackgroundSound;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace Mohawk
|
} // End of namespace Mohawk
|
||||||
|
Loading…
x
Reference in New Issue
Block a user