diff options
-rw-r--r-- | engines/touche/menu.cpp | 6 | ||||
-rw-r--r-- | engines/touche/resource.cpp | 5 | ||||
-rw-r--r-- | engines/touche/touche.cpp | 93 | ||||
-rw-r--r-- | engines/touche/touche.h | 12 |
4 files changed, 105 insertions, 11 deletions
diff --git a/engines/touche/menu.cpp b/engines/touche/menu.cpp index 46429ebbc2..85ca519f05 100644 --- a/engines/touche/menu.cpp +++ b/engines/touche/menu.cpp @@ -260,7 +260,7 @@ void ToucheEngine::redrawMenu(void *menu) { Graphics::drawRect(_offscreenBuffer, kScreenWidth, 106, 118, 340, 164, 0xF9, 0xF7); switch (menuData->mode) { case kMenuSettingsMode: - drawVolumeSlideBar(_offscreenBuffer, kScreenWidth, _midiPlayer->getVolume()); + drawVolumeSlideBar(_offscreenBuffer, kScreenWidth, getMusicVolume()); menuData->buttonsTable[5].data = 0; menuData->buttonsTable[6].data = 0; menuData->buttonsTable[7].data = 0; @@ -307,10 +307,10 @@ void ToucheEngine::handleMenuAction(void *menu, int actionId) { _talkTextMode = kTalkModeVoiceAndText; break; case kActionLowerVolume: - _midiPlayer->adjustVolume(-16); + adjustMusicVolume(-16); break; case kActionUpperVolume: - _midiPlayer->adjustVolume(+16); + adjustMusicVolume(+16); break; case kActionScrollUpSaves: --_saveLoadCurrentPage; diff --git a/engines/touche/resource.cpp b/engines/touche/resource.cpp index 0790d726b7..9625224316 100644 --- a/engines/touche/resource.cpp +++ b/engines/touche/resource.cpp @@ -610,10 +610,7 @@ void ToucheEngine::res_stopSound() { void ToucheEngine::res_loadMusic(int num) { debugC(9, kDebugResource, "ToucheEngine::res_loadMusic() num=%d", num); - uint32 size; - const uint32 offs = res_getDataOffset(kResourceTypeMusic, num, &size); - _fData.seek(offs); - _midiPlayer->play(_fData, size, true); + startMusic(num); } void ToucheEngine::res_loadSpeech(int num) { diff --git a/engines/touche/touche.cpp b/engines/touche/touche.cpp index 4b989963f6..ada12099c3 100644 --- a/engines/touche/touche.cpp +++ b/engines/touche/touche.cpp @@ -32,6 +32,9 @@ #include "common/keyboard.h" #include "common/textconsole.h" +#include "audio/mixer.h" +#include "audio/decoders/vorbis.h" + #include "engines/util.h" #include "graphics/cursorman.h" #include "graphics/palette.h" @@ -58,6 +61,8 @@ ToucheEngine::ToucheEngine(OSystem *system, Common::Language language) _playSoundCounter = 0; + _musicVolume = 0; + _processRandomPaletteCounter = 0; _fastWalkMode = false; @@ -90,6 +95,8 @@ ToucheEngine::~ToucheEngine() { DebugMan.clearAllDebugChannels(); delete _console; + stopMusic(); + _extMusicFile.close(); delete _midiPlayer; } @@ -100,7 +107,7 @@ Common::Error ToucheEngine::run() { setupOpcodes(); - _midiPlayer = new MidiPlayer; + initMusic(); // Setup mixer syncSoundSettings(); @@ -120,7 +127,7 @@ Common::Error ToucheEngine::run() { } void ToucheEngine::restart() { - _midiPlayer->stop(); + stopMusic(); _gameState = kGameStateGameLoop; _displayQuitDialog = false; @@ -216,7 +223,7 @@ void ToucheEngine::readConfigurationSettings() { _talkTextMode = kTalkModeVoiceOnly; } } - _midiPlayer->setVolume(ConfMan.getInt("music_volume")); + setMusicVolume(ConfMan.getInt("music_volume")); } void ToucheEngine::writeConfigurationSettings() { @@ -234,7 +241,7 @@ void ToucheEngine::writeConfigurationSettings() { ConfMan.setBool("subtitles", true); break; } - ConfMan.setInt("music_volume", _midiPlayer->getVolume()); + ConfMan.setInt("music_volume", getMusicVolume()); ConfMan.flushToDisk(); } @@ -3307,4 +3314,82 @@ bool ToucheEngine::canSaveGameStateCurrently() { return _gameState == kGameStateGameLoop && _flagsTable[618] == 0 && !_hideInventoryTexts; } +void ToucheEngine::initMusic() { + // Detect External Music Files + bool extMusic = true; + for (int num = 0; num < 26; num++) { + Common::String extMusicFilename = Common::String::format("track%02d.ogg", num+1); + Common::File extMusicFile; + if (!extMusicFile.open(extMusicFilename)) + extMusic = false; + extMusicFile.close(); + } + + if (!extMusic) { + _midiPlayer = new MidiPlayer; + debug(1, "initMusic(): Using midi music!"); + } else + debug(1, "initMusic(): Using external digital music!"); +} + +void ToucheEngine::startMusic(int num) { + debug(1, "startMusic(%d)", num); + uint32 size; + + stopMusic(); + + if (_midiPlayer) { + const uint32 offs = res_getDataOffset(kResourceTypeMusic, num, &size); + _fData.seek(offs); + _midiPlayer->play(_fData, size, true); + } else { + Common::String extMusicFilename = Common::String::format("track%02d.ogg", num); + if (!_extMusicFile.open(extMusicFilename)) { + error("Unable to open %s for reading", extMusicFilename.c_str()); + } + Audio::SeekableAudioStream *musicStream = Audio::makeVorbisStream(&_extMusicFile, DisposeAfterUse::NO); + Audio::LoopingAudioStream *loopStream = new Audio::LoopingAudioStream(musicStream, 0); + _mixer->playStream(Audio::Mixer::kMusicSoundType, &_musicHandle, loopStream); + _mixer->setChannelVolume(_musicHandle, _musicVolume); + } +} + +void ToucheEngine::stopMusic() { + debug(1, "stopMusic()"); + if (_midiPlayer) + _midiPlayer->stop(); + else { + _mixer->stopHandle(_musicHandle); + _extMusicFile.close(); + } +} + +int ToucheEngine::getMusicVolume() { + if (_midiPlayer) + _musicVolume = _midiPlayer->getVolume(); + return _musicVolume; +} + +void ToucheEngine::setMusicVolume(int volume) { + debug(1, "setMusicVolume(%d)", volume); + _musicVolume = CLIP(volume, 0, 255); + + if (_midiPlayer) + _midiPlayer->setVolume(_musicVolume); + else { + _mixer->setChannelVolume(_musicHandle, _musicVolume); + } +} + +void ToucheEngine::adjustMusicVolume(int diff) { + debug(1, "adjustMusicVolume(%d)", diff); + _musicVolume = CLIP(_musicVolume + diff, 0, 255); + + if (_midiPlayer) + _midiPlayer->adjustVolume(diff); + else { + _mixer->setChannelVolume(_musicHandle, _musicVolume); + } +} + } // namespace Touche diff --git a/engines/touche/touche.h b/engines/touche/touche.h index 949727b665..75d99c21d4 100644 --- a/engines/touche/touche.h +++ b/engines/touche/touche.h @@ -31,6 +31,7 @@ #include "common/util.h" #include "audio/mixer.h" +#include "audio/audiostream.h" #include "engines/engine.h" @@ -646,6 +647,17 @@ protected: MidiPlayer *_midiPlayer; + int _musicVolume; + Audio::SoundHandle _musicHandle; + Common::File _extMusicFile; + + void initMusic(); + void startMusic(int num); + void stopMusic(); + int getMusicVolume(); + void setMusicVolume(int volume); + void adjustMusicVolume(int diff); + Common::Language _language; Common::RandomSource _rnd; |