diff options
-rw-r--r-- | engines/illusions/duckman/scriptopcodes_duckman.cpp | 2 | ||||
-rw-r--r-- | engines/illusions/sound.cpp | 31 | ||||
-rw-r--r-- | engines/illusions/sound.h | 15 |
3 files changed, 46 insertions, 2 deletions
diff --git a/engines/illusions/duckman/scriptopcodes_duckman.cpp b/engines/illusions/duckman/scriptopcodes_duckman.cpp index 5e4dab4667..ee4979a11a 100644 --- a/engines/illusions/duckman/scriptopcodes_duckman.cpp +++ b/engines/illusions/duckman/scriptopcodes_duckman.cpp @@ -640,7 +640,7 @@ void ScriptOpcodes_Duckman::opStopMidiMusic(ScriptThread *scriptThread, OpCall & void ScriptOpcodes_Duckman::opFadeMidiMusic(ScriptThread *scriptThread, OpCall &opCall) { ARG_INT16(duration); ARG_INT16(finalVolume); - // TODO _vm->fadeMidiMusic(2, finalVolume, duration, opCall._threadId); + _vm->_soundMan->fadeMidiMusic(finalVolume, duration, opCall._threadId); } void ScriptOpcodes_Duckman::opAddMenuChoice(ScriptThread *scriptThread, OpCall &opCall) { diff --git a/engines/illusions/sound.cpp b/engines/illusions/sound.cpp index d8b03169ea..6a62ee52c6 100644 --- a/engines/illusions/sound.cpp +++ b/engines/illusions/sound.cpp @@ -23,6 +23,7 @@ #include "common/config-manager.h" #include "illusions/illusions.h" #include "illusions/sound.h" +#include "illusions/time.h" #include "audio/mididrv.h" #include "audio/midiparser.h" @@ -384,6 +385,15 @@ void SoundMan::stopMidiMusic() { _midiPlayer->stop(); } +void SoundMan::fadeMidiMusic(int16 finalVolume, int16 duration, uint32 notifyThreadId) { + _midiMusicFader._active = true; + _midiMusicFader._notifyThreadId = notifyThreadId; + _midiMusicFader._startVolume = _midiMusicFader._currVolume; + _midiMusicFader._finalVolume = finalVolume; + _midiMusicFader._startTime = getCurrentTime(); + _midiMusicFader._duration = duration; +} + void SoundMan::clearMidiMusicQueue() { _midiMusicQueue.clear(); } @@ -467,7 +477,26 @@ void SoundMan::updateMidi() { _midiMusicQueue.remove_at(0); _midiPlayer->play(musicId); } - // TODO Update music volume fading + updateMidiMusicFader(); +} + +void SoundMan::updateMidiMusicFader() { + if (_midiMusicFader._active) { + int16 currTime = getCurrentTime(); + if (currTime - _midiMusicFader._startTime > _midiMusicFader._duration) { + _midiMusicFader._active = false; + currTime = _midiMusicFader._startTime + _midiMusicFader._duration; + if (_midiMusicFader._notifyThreadId) { + _vm->notifyThreadId(_midiMusicFader._notifyThreadId); + _midiMusicFader._notifyThreadId = 0; + } + } + const int16 elapsedTime = currTime - _midiMusicFader._startTime; + const int16 volumeDelta = _midiMusicFader._finalVolume - _midiMusicFader._startVolume; + const int masterMusicVolume = _vm->_mixer->getVolumeForSoundType(Audio::Mixer::kMusicSoundType); + _midiMusicFader._currVolume = _midiMusicFader._startVolume + (elapsedTime * volumeDelta / _midiMusicFader._duration); + _midiPlayer->setVolume(_midiMusicFader._currVolume * masterMusicVolume / 255); + } } void SoundMan::setMusicVolume(uint16 volume) { diff --git a/engines/illusions/sound.h b/engines/illusions/sound.h index 2669102b69..027228ef0b 100644 --- a/engines/illusions/sound.h +++ b/engines/illusions/sound.h @@ -112,6 +112,18 @@ protected: bool _looping; }; +struct MidiMusicFader { + bool _active; + uint _flags; + int16 _currVolume; + int16 _startVolume; + int16 _finalVolume; + int16 _startTime; + int16 _duration; + uint32 _notifyThreadId; + MidiMusicFader() : _active(false), _currVolume(255) {} +}; + class SoundMan { public: SoundMan(IllusionsEngine *vm); @@ -123,6 +135,7 @@ public: void playMidiMusic(uint32 musicId); void stopMidiMusic(); + void fadeMidiMusic(int16 finalVolume, int16 duration, uint32 notifyThreadId); void clearMidiMusicQueue(); uint16 getMusicVolume(); @@ -158,8 +171,10 @@ protected: VoicePlayer *_voicePlayer; SoundList _sounds; Common::Array<uint32> _midiMusicQueue; + MidiMusicFader _midiMusicFader; Sound *getSound(uint32 soundEffectId); void updateMidi(); + void updateMidiMusicFader(); uint16 calcAdjustedVolume(const Common::String &volumeConfigKey, uint16 volume); }; |