diff options
author | Marisa-Chan | 2014-01-17 10:57:29 +0700 |
---|---|---|
committer | Marisa-Chan | 2014-01-17 10:57:29 +0700 |
commit | 41415002b223e5ae0e53fb351ee41d8a99fbc920 (patch) | |
tree | 50185a4f1b19b5677194282fe4c2fbc90c30f210 /engines/zvision/music_node.cpp | |
parent | 61224e7225061551765c07b691e8d8c5da3434df (diff) | |
download | scummvm-rg350-41415002b223e5ae0e53fb351ee41d8a99fbc920.tar.gz scummvm-rg350-41415002b223e5ae0e53fb351ee41d8a99fbc920.tar.bz2 scummvm-rg350-41415002b223e5ae0e53fb351ee41d8a99fbc920.zip |
ZVISION: Implement PanTrack.
Diffstat (limited to 'engines/zvision/music_node.cpp')
-rw-r--r-- | engines/zvision/music_node.cpp | 75 |
1 files changed, 74 insertions, 1 deletions
diff --git a/engines/zvision/music_node.cpp b/engines/zvision/music_node.cpp index 709b554823..081c9dbcca 100644 --- a/engines/zvision/music_node.cpp +++ b/engines/zvision/music_node.cpp @@ -26,6 +26,7 @@ #include "zvision/zvision.h" #include "zvision/script_manager.h" +#include "zvision/render_manager.h" #include "zvision/zork_raw.h" #include "common/stream.h" @@ -40,7 +41,7 @@ MusicNode::MusicNode(ZVision *engine, uint32 key, Common::String &filename, bool _loop = loop; _volume = volume; _crossfade = false; - _crossfade_delta = 0; + _crossfade_target = 0; _crossfade_time = 0; _attenuate = 0; _pantrack = false; @@ -57,6 +58,7 @@ MusicNode::MusicNode(ZVision *engine, uint32 key, Common::String &filename, bool audioStream = makeRawZorkStream(filename, _engine); } + _stereo = audioStream->isStereo(); if (_loop) { Audio::LoopingAudioStream *loopingAudioStream = new Audio::LoopingAudioStream(audioStream, 0, DisposeAfterUse::YES); @@ -76,10 +78,81 @@ MusicNode::~MusicNode() { debug(1, "MusicNode: %d destroyed\n", _key); } +void MusicNode::setPanTrack(int16 pos) { + if (!_stereo) { + _pantrack = true; + _pantrack_X = pos; + setVolume(_volume); + } +} + +void MusicNode::unsetPanTrack() { + _pantrack = false; + setVolume(_volume); +} + bool MusicNode::process(uint32 deltaTimeInMillis) { if (! _engine->_mixer->isSoundHandleActive(_handle)) return stop(); + else { + uint8 _newvol = _volume; + + if (_pantrack || _volume != _newvol) + setVolume(_newvol); + } return false; } +void MusicNode::setVolume(uint8 new_volume) { + if (_pantrack) { + int cur_x = _engine->getScriptManager()->getStateValue(StateKey_ViewPos); + cur_x -= _pantrack_X; + int32 _width = _engine->getRenderManager()->getBkgSize().x; + if (cur_x < (-_width) / 2) + cur_x += _width; + else if (cur_x >= _width / 2) + cur_x -= _width; + + float norm = (float)cur_x / ((float)_width / 2.0); + float lvl = fabs(norm); + if (lvl > 0.5) + lvl = (lvl - 0.5) * 1.7; + else + lvl = 1.0; + + float bal = sin(-norm * 3.1415926) * 127.0; + + if (_engine->_mixer->isSoundHandleActive(_handle)) { + _engine->_mixer->setChannelBalance(_handle, bal); + _engine->_mixer->setChannelVolume(_handle, new_volume * lvl); + } + } else { + if (_engine->_mixer->isSoundHandleActive(_handle)) { + _engine->_mixer->setChannelBalance(_handle, 0); + _engine->_mixer->setChannelVolume(_handle, new_volume); + } + } + + _volume = new_volume; +} + +PanTrackNode::PanTrackNode(ZVision *engine, uint32 key, uint32 slot, int16 pos) + : SideFX(engine, key, SIDEFX_PANTRACK) { + _slot = slot; + + SideFX *fx = _engine->getScriptManager()->getSideFX(slot); + if (fx && fx->getType() == SIDEFX_AUDIO) { + MusicNode *mus = (MusicNode *)fx; + mus->setPanTrack(pos); + } +} + +PanTrackNode::~PanTrackNode() { + SideFX *fx = _engine->getScriptManager()->getSideFX(_slot); + if (fx && fx->getType() == SIDEFX_AUDIO) { + MusicNode *mus = (MusicNode *)fx; + mus->unsetPanTrack(); + } +} + } // End of namespace ZVision |