From 7b7ae43f7fe30782201fba691beee1bad18db60a Mon Sep 17 00:00:00 2001 From: Marisa-Chan Date: Fri, 17 Jan 2014 11:10:17 +0700 Subject: ZVISION: Implement crossfade. --- engines/zvision/music_node.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'engines/zvision/music_node.cpp') diff --git a/engines/zvision/music_node.cpp b/engines/zvision/music_node.cpp index 081c9dbcca..30271480c1 100644 --- a/engines/zvision/music_node.cpp +++ b/engines/zvision/music_node.cpp @@ -91,12 +91,31 @@ void MusicNode::unsetPanTrack() { setVolume(_volume); } +void MusicNode::setFade(int32 time, uint8 target) { + _crossfade_target = target; + _crossfade_time = time; + _crossfade = true; +} + bool MusicNode::process(uint32 deltaTimeInMillis) { if (! _engine->_mixer->isSoundHandleActive(_handle)) return stop(); else { uint8 _newvol = _volume; + if (_crossfade) { + if (_crossfade_time > 0) { + if ((int32)deltaTimeInMillis > _crossfade_time) + deltaTimeInMillis = _crossfade_time; + _newvol += floor(((float)(_crossfade_target - _newvol) / (float)_crossfade_time)) * (float)deltaTimeInMillis; + _crossfade_time -= deltaTimeInMillis; + } + else { + _crossfade = false; + _newvol = _crossfade_target; + } + } + if (_pantrack || _volume != _newvol) setVolume(_newvol); } -- cgit v1.2.3