From 69629944e5c4f55d1a68cb9bca26cc547b6bc360 Mon Sep 17 00:00:00 2001 From: Coen Rampen Date: Wed, 22 Sep 2021 20:32:07 +0200 Subject: [PATCH] MADE: Use SFX sound type for sampled audio The engine used the plain sound type for sampled sound effects and movie audio and applied the SFX user volume control to the plain sound type. This caused emulators like the AdLib emulator and Munt to be affected by the SFX user volume control, because they use the plain sound type. This commit fixes this by using the SFX sound type instead of the plain sound type. User volume is applied by Engine::syncSoundSettings. This commit also fixes the setSoundVolume script function. Volume was previously applied to the SFX and speech sound types, which were not used. Also, by directly using Mixer::setVolumeForSoundType, it would override the user volume setting. This is fixed by storing the game sound volume in a field and applying this to the current and future audio streams. This fixes bug #6444. --- engines/made/made.cpp | 2 -- engines/made/pmvplayer.cpp | 2 +- engines/made/scriptfuncs.cpp | 15 ++++++++------- engines/made/scriptfuncs.h | 2 ++ 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/engines/made/made.cpp b/engines/made/made.cpp index cdcc3cd8dce..441eb4179f0 100644 --- a/engines/made/made.cpp +++ b/engines/made/made.cpp @@ -114,8 +114,6 @@ void MadeEngine::syncSoundSettings() { mute = ConfMan.getBool("mute"); _music->setVolume(mute ? 0 : ConfMan.getInt("music_volume")); - _mixer->setVolumeForSoundType(Audio::Mixer::kPlainSoundType, - mute ? 0 : ConfMan.getInt("sfx_volume")); } int16 MadeEngine::getTicks() { diff --git a/engines/made/pmvplayer.cpp b/engines/made/pmvplayer.cpp index 8676800c184..6ec5943601f 100644 --- a/engines/made/pmvplayer.cpp +++ b/engines/made/pmvplayer.cpp @@ -189,7 +189,7 @@ bool PmvPlayer::play(const char *filename) { decompressMovieImage(imageData, *_surface, cmdOffs, pixelOffs, maskOffs, lineSize); if (firstTime) { - _mixer->playStream(Audio::Mixer::kPlainSoundType, &_audioStreamHandle, _audioStream); + _mixer->playStream(Audio::Mixer::kSFXSoundType, &_audioStreamHandle, _audioStream); soundStartTime = g_system->getMillis(); skipFrames = 0; firstTime = false; diff --git a/engines/made/scriptfuncs.cpp b/engines/made/scriptfuncs.cpp index bcc08e0dcc5..9035ec0c6bc 100644 --- a/engines/made/scriptfuncs.cpp +++ b/engines/made/scriptfuncs.cpp @@ -36,7 +36,7 @@ namespace Made { -ScriptFunctions::ScriptFunctions(MadeEngine *vm) : _vm(vm), _soundStarted(false) { +ScriptFunctions::ScriptFunctions(MadeEngine *vm) : _vm(vm), _soundStarted(false), _gameAudioVolume(Audio::Mixer::kMaxChannelVolume) { // Initialize the two tone generators _pcSpeaker1 = new Audio::PCSpeaker(); _pcSpeaker2 = new Audio::PCSpeaker(); @@ -252,8 +252,8 @@ int16 ScriptFunctions::sfPlaySound(int16 argc, int16 *argv) { } if (soundNum > 0) { SoundResource *soundRes = _vm->_res->getSound(soundNum); - _vm->_mixer->playStream(Audio::Mixer::kPlainSoundType, &_audioStreamHandle, - soundRes->getAudioStream(_vm->_soundRate, false)); + _vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_audioStreamHandle, + soundRes->getAudioStream(_vm->_soundRate, false), -1, _gameAudioVolume); _vm->_soundEnergyArray = soundRes->getSoundEnergyArray(); _vm->_soundEnergyIndex = 0; _soundStarted = true; @@ -641,8 +641,8 @@ int16 ScriptFunctions::sfPlayVoice(int16 argc, int16 *argv) { stopSound(); if (soundNum > 0) { _soundResource = _vm->_res->getSound(soundNum); - _vm->_mixer->playStream(Audio::Mixer::kPlainSoundType, &_audioStreamHandle, - _soundResource->getAudioStream(_vm->_soundRate, false)); + _vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_audioStreamHandle, + _soundResource->getAudioStream(_vm->_soundRate, false), -1, _gameAudioVolume); _vm->_autoStopSound = true; _soundStarted = true; } @@ -1013,8 +1013,9 @@ int16 ScriptFunctions::sfPlaceMenu(int16 argc, int16 *argv) { } int16 ScriptFunctions::sfSetSoundVolume(int16 argc, int16 *argv) { - _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, argv[0] * 25); - _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, argv[0] * 25); + _gameAudioVolume = argv[0] * 25; + if (_vm->_mixer->isSoundHandleActive(_audioStreamHandle)) + _vm->_mixer->setChannelVolume(_audioStreamHandle, _gameAudioVolume); return 0; } diff --git a/engines/made/scriptfuncs.h b/engines/made/scriptfuncs.h index 9db5586adf4..b47e67dfdee 100644 --- a/engines/made/scriptfuncs.h +++ b/engines/made/scriptfuncs.h @@ -63,6 +63,8 @@ protected: Audio::SoundHandle _voiceStreamHandle; SoundResource* _soundResource; bool _soundStarted; + // The audio volume set by the game scripts. + uint8 _gameAudioVolume; // PlayNote/StopNote and PlayTele/StopTele wave generators Audio::SoundHandle _pcSpeakerHandle1, _pcSpeakerHandle2;