diff options
author | Colin Snover | 2017-09-24 22:20:14 -0500 |
---|---|---|
committer | Colin Snover | 2017-09-27 20:27:33 -0500 |
commit | 7feccaaa98378eb586501c9de8c2d4ca1bb00aa4 (patch) | |
tree | 231e5f12f05dfdf4489532225f548f9ef1348da3 | |
parent | b98d44ca0ba913c11f03fd45c4fdd99261f294fb (diff) | |
download | scummvm-rg350-7feccaaa98378eb586501c9de8c2d4ca1bb00aa4.tar.gz scummvm-rg350-7feccaaa98378eb586501c9de8c2d4ca1bb00aa4.tar.bz2 scummvm-rg350-7feccaaa98378eb586501c9de8c2d4ca1bb00aa4.zip |
SCI32: Implement SCI3-variant volume handling
Trying to find differences in Lighthouse's audio sample playback,
I discovered that SCI3 had its own variant of handling volumes and
sending this volume information back to game scripts. It is not
known if this fixes any sound bug.
-rw-r--r-- | engines/sci/sound/audio32.cpp | 23 | ||||
-rw-r--r-- | engines/sci/sound/soundcmd.cpp | 13 |
2 files changed, 33 insertions, 3 deletions
diff --git a/engines/sci/sound/audio32.cpp b/engines/sci/sound/audio32.cpp index 2f7338ea63..59ebc86bf3 100644 --- a/engines/sci/sound/audio32.cpp +++ b/engines/sci/sound/audio32.cpp @@ -1061,10 +1061,23 @@ void Audio32::setLoop(const int16 channelIndex, const bool loop) { #pragma mark Effects int16 Audio32::getVolume(const int16 channelIndex) const { - if (channelIndex < 0 || channelIndex >= _numActiveChannels) { + bool getGlobalVolume = false; + switch (getSciVersion()) { + case SCI_VERSION_3: + getGlobalVolume = (channelIndex == kAllChannels); + break; + default: + getGlobalVolume = (channelIndex < 0 || channelIndex >= _numActiveChannels); + } + + if (getGlobalVolume) { return (_mixer->getVolumeForSoundType(Audio::Mixer::kSFXSoundType) + 1) * kMaxVolume / Audio::Mixer::kMaxMixerVolume; } + if (channelIndex < 0 || channelIndex >= _numActiveChannels) { + return -1; + } + Common::StackLock lock(_mutex); return getChannel(channelIndex).volume; } @@ -1266,7 +1279,13 @@ reg_t Audio32::kernelVolume(const int argc, const reg_t *const argv) { Common::StackLock lock(_mutex); const int16 volume = argc > 0 ? argv[0].toSint16() : -1; - const int16 channelIndex = findChannelByArgs(argc, argv, 1, argc > 2 ? argv[2] : NULL_REG); + int16 channelIndex; + + if (getSciVersion() == SCI_VERSION_3 && argc < 2) { + channelIndex = kAllChannels; + } else { + channelIndex = findChannelByArgs(argc, argv, 1, argc > 2 ? argv[2] : NULL_REG); + } if (volume != -1) { setVolume(channelIndex, volume); diff --git a/engines/sci/sound/soundcmd.cpp b/engines/sci/sound/soundcmd.cpp index e8fd20d2e5..0bb295d41e 100644 --- a/engines/sci/sound/soundcmd.cpp +++ b/engines/sci/sound/soundcmd.cpp @@ -514,8 +514,19 @@ void SoundCommandParser::processUpdateCues(reg_t obj) { if (musicSlot->isSample) { #ifdef ENABLE_SCI32 if (_soundVersion >= SCI_VERSION_2) { - const int position = g_sci->_audio32->getPosition(ResourceId(kResourceTypeAudio, musicSlot->resourceId), musicSlot->soundObj); + const ResourceId audioId = ResourceId(kResourceTypeAudio, musicSlot->resourceId); + + if (getSciVersion() == SCI_VERSION_3) { + // In SSCI the volume is first set to -1 and then reset later if + // a sample is playing in the audio player, but since our audio + // code returns -1 for not-found samples, the extra check is not + // needed and we can just always set it to the return value of + // the getVolume call + const int16 volume = g_sci->_audio32->getVolume(audioId, musicSlot->soundObj); + writeSelectorValue(_segMan, musicSlot->soundObj, SELECTOR(vol), volume); + } + const int16 position = g_sci->_audio32->getPosition(audioId, musicSlot->soundObj); if (position == -1) { processStopSound(musicSlot->soundObj, true); } |