From 12a31200f29cfd36e93aa407fc56de28db31028d Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 20 Mar 2011 23:44:46 +0100 Subject: AUDIO: Add per sound type mute flag setting to Mixer(Impl). This also adapts our default implementation MixerImpl to handle the newly added flags properly. Now we do not need to set the sound volume for all types to 0, in case we want to mute them, but instead just set the mute flag for all types to true. This allows engines to be a bit more agonstic about mute support, when it comes to volume options etc. since they can just setup any volume they like, but are still muted (and thus will not break muting anymore). MIDI sound is of course not affected by this. --- audio/mixer.cpp | 42 ++++++++++++++++++++++++++++++++---------- audio/mixer.h | 14 ++++++++++++++ audio/mixer_intern.h | 4 ++++ 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/audio/mixer.cpp b/audio/mixer.cpp index dc0287e3fb..547d2d5f55 100644 --- a/audio/mixer.cpp +++ b/audio/mixer.cpp @@ -168,6 +168,9 @@ MixerImpl::MixerImpl(OSystem *system, uint sampleRate) int i; + for (i = 0; i < ARRAYSIZE(_mute); ++i) + _mute[i] = false; + for (i = 0; i < ARRAYSIZE(_volumeForSoundType); i++) _volumeForSoundType[i] = kMaxMixerVolume; @@ -322,6 +325,21 @@ void MixerImpl::stopHandle(SoundHandle handle) { _channels[index] = 0; } +void MixerImpl::setMuteForSoundType(SoundType type, bool mute) { + assert(0 <= type && type < ARRAYSIZE(_mute)); + _mute[type] = mute; + + for (int i = 0; i != NUM_CHANNELS; ++i) { + if (_channels[i] && _channels[i]->getType() == type) + _channels[i]->notifyGlobalVolChange(); + } +} + +bool MixerImpl::getMuteForSoundType(SoundType type) const { + assert(0 <= type && type < ARRAYSIZE(_mute)); + return _mute[type]; +} + void MixerImpl::setChannelVolume(SoundHandle handle, byte volume) { Common::StackLock lock(_mutex); @@ -486,17 +504,21 @@ void Channel::updateChannelVolumes() { // volume is in the range 0 - kMaxMixerVolume. // Hence, the vol_l/vol_r values will be in that range, too - int vol = _mixer->getVolumeForSoundType(_type) * _volume; - - if (_balance == 0) { - _volL = vol / Mixer::kMaxChannelVolume; - _volR = vol / Mixer::kMaxChannelVolume; - } else if (_balance < 0) { - _volL = vol / Mixer::kMaxChannelVolume; - _volR = ((127 + _balance) * vol) / (Mixer::kMaxChannelVolume * 127); + if (!_mixer->getMuteForSoundType(_type)) { + int vol = _mixer->getVolumeForSoundType(_type) * _volume; + + if (_balance == 0) { + _volL = vol / Mixer::kMaxChannelVolume; + _volR = vol / Mixer::kMaxChannelVolume; + } else if (_balance < 0) { + _volL = vol / Mixer::kMaxChannelVolume; + _volR = ((127 + _balance) * vol) / (Mixer::kMaxChannelVolume * 127); + } else { + _volL = ((127 - _balance) * vol) / (Mixer::kMaxChannelVolume * 127); + _volR = vol / Mixer::kMaxChannelVolume; + } } else { - _volL = ((127 - _balance) * vol) / (Mixer::kMaxChannelVolume * 127); - _volR = vol / Mixer::kMaxChannelVolume; + _volL = _volR = 0; } } diff --git a/audio/mixer.h b/audio/mixer.h index a048124ca3..fe24b85613 100644 --- a/audio/mixer.h +++ b/audio/mixer.h @@ -197,6 +197,20 @@ public: virtual bool isSoundHandleActive(SoundHandle handle) = 0; + /** + * Set the mute state for a given sound type. + * + * @param mute Whether to mute (= true) or not (= false). + * @param type the sound type + */ + virtual void setMuteForSoundType(SoundType type, bool mute) = 0; + + /** + * Query the mute state for a given sound type. + * + * @param type the sound type + */ + virtual bool getMuteForSoundType(SoundType type) const = 0; /** * Set the channel volume for the given handle. diff --git a/audio/mixer_intern.h b/audio/mixer_intern.h index dd2746e9ea..c42436b9a4 100644 --- a/audio/mixer_intern.h +++ b/audio/mixer_intern.h @@ -64,6 +64,7 @@ private: bool _mixerReady; uint32 _handleSeed; + bool _mute[4]; int _volumeForSoundType[4]; Channel *_channels[NUM_CHANNELS]; @@ -97,6 +98,9 @@ public: virtual bool isSoundHandleActive(SoundHandle handle); + virtual void setMuteForSoundType(SoundType type, bool mute); + virtual bool getMuteForSoundType(SoundType type) const; + virtual void setChannelVolume(SoundHandle handle, byte volume); virtual void setChannelBalance(SoundHandle handle, int8 balance); -- cgit v1.2.3 From f9a459d70e0a0de620ac931716481a938a725733 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 20 Mar 2011 23:45:52 +0100 Subject: ENGINES: Make Engine::syncSoundSettings use the Mixer's mute flag directly. This fixes an annoying behavior in the Sword2 option's dialog, which set all sound type volumes to 0, in case it was opened when the user used the global mute setting. --- engines/engine.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/engines/engine.cpp b/engines/engine.cpp index 0e5e58bc72..8145a550ab 100644 --- a/engines/engine.cpp +++ b/engines/engine.cpp @@ -439,10 +439,14 @@ void Engine::syncSoundSettings() { if (ConfMan.hasKey("mute")) mute = ConfMan.getBool("mute"); - _mixer->setVolumeForSoundType(Audio::Mixer::kPlainSoundType, (mute ? 0 : Audio::Mixer::kMaxMixerVolume)); - _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, (mute ? 0 : soundVolumeMusic)); - _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, (mute ? 0 : soundVolumeSFX)); - _mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, (mute ? 0 : soundVolumeSpeech)); + _mixer->setMuteForSoundType(Audio::Mixer::kPlainSoundType, mute); + _mixer->setMuteForSoundType(Audio::Mixer::kMusicSoundType, mute); + _mixer->setMuteForSoundType(Audio::Mixer::kSFXSoundType, mute); + _mixer->setMuteForSoundType(Audio::Mixer::kSpeechSoundType, mute); + _mixer->setVolumeForSoundType(Audio::Mixer::kPlainSoundType, Audio::Mixer::kMaxMixerVolume); + _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, soundVolumeMusic); + _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, soundVolumeSFX); + _mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, soundVolumeSpeech); } void Engine::flipMute() { -- cgit v1.2.3 From 507dd88f9c43a8a038da519bdfe2e9b62456e7fe Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 20 Mar 2011 23:58:08 +0100 Subject: TINSEL: Clean up code a bit, since we now handle digital audio muting differently. --- engines/tinsel/sound.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/engines/tinsel/sound.cpp b/engines/tinsel/sound.cpp index 1fcdb4dcf9..3fef59edef 100644 --- a/engines/tinsel/sound.cpp +++ b/engines/tinsel/sound.cpp @@ -131,13 +131,9 @@ bool SoundManager::playSample(int id, Audio::Mixer::SoundType type, Audio::Sound error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage)); // FIXME: Should set this in a different place ;) - bool mute = false; - if (ConfMan.hasKey("mute")) - mute = ConfMan.getBool("mute"); - - _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, mute ? 0 : _vm->_config->_soundVolume); + _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, _vm->_config->_soundVolume); //_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, soundVolumeMusic); - _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, mute ? 0 : _vm->_config->_voiceVolume); + _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, _vm->_config->_voiceVolume); Audio::AudioStream *sampleStream = 0; @@ -325,13 +321,9 @@ bool SoundManager::playSample(int id, int sub, bool bLooped, int x, int y, int p } // FIXME: Should set this in a different place ;) - bool mute = false; - if (ConfMan.hasKey("mute")) - mute = ConfMan.getBool("mute"); - - _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, mute ? 0 : _vm->_config->_soundVolume); + _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, _vm->_config->_soundVolume); //_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, soundVolumeMusic); - _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, mute ? 0 : _vm->_config->_voiceVolume); + _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, _vm->_config->_voiceVolume); curChan->sampleNum = id; curChan->subSample = sub; -- cgit v1.2.3 From f61eff4404751ad4bf53e8295ea4d5b77847bbed Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 21 Mar 2011 00:30:22 +0100 Subject: DRACI: Adapt to new muting style. --- engines/draci/sound.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/engines/draci/sound.cpp b/engines/draci/sound.cpp index c8646fff67..c1ec235246 100644 --- a/engines/draci/sound.cpp +++ b/engines/draci/sound.cpp @@ -417,15 +417,16 @@ void Sound::setVolume() { } else { _muteSound = _muteVoice = true; } + if (ConfMan.getBool("mute")) { _muteSound = _muteVoice = true; } - const int soundVolume = _muteSound ? 0: ConfMan.getInt("sfx_volume"); - const int speechVolume = _muteVoice ? 0 : ConfMan.getInt("speech_volume"); + _mixer->setMuteForSoundType(Audio::Mixer::kSFXSoundType, _muteSound); + _mixer->setMuteForSoundType(Audio::Mixer::kSpeechSoundType, _muteVoice); - _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, soundVolume); - _mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, speechVolume); + _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume")); + _mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume")); } } // End of namespace Draci -- cgit v1.2.3 From 6b0ccbb095917d5f98722b26bef07d4a0816bb3b Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 16 Apr 2011 18:20:37 +0200 Subject: AUDIO: Renamed mute related functions in Mixer. This renames setMuteForSoundType to muteSoundType and getMuteForSoundType to isSoundTypeMuted. --- audio/mixer.cpp | 6 +++--- audio/mixer.h | 6 +++--- audio/mixer_intern.h | 4 ++-- engines/draci/sound.cpp | 4 ++-- engines/engine.cpp | 8 ++++---- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/audio/mixer.cpp b/audio/mixer.cpp index 547d2d5f55..a2b50ddbc4 100644 --- a/audio/mixer.cpp +++ b/audio/mixer.cpp @@ -325,7 +325,7 @@ void MixerImpl::stopHandle(SoundHandle handle) { _channels[index] = 0; } -void MixerImpl::setMuteForSoundType(SoundType type, bool mute) { +void MixerImpl::muteSoundType(SoundType type, bool mute) { assert(0 <= type && type < ARRAYSIZE(_mute)); _mute[type] = mute; @@ -335,7 +335,7 @@ void MixerImpl::setMuteForSoundType(SoundType type, bool mute) { } } -bool MixerImpl::getMuteForSoundType(SoundType type) const { +bool MixerImpl::isSoundTypeMuted(SoundType type) const { assert(0 <= type && type < ARRAYSIZE(_mute)); return _mute[type]; } @@ -504,7 +504,7 @@ void Channel::updateChannelVolumes() { // volume is in the range 0 - kMaxMixerVolume. // Hence, the vol_l/vol_r values will be in that range, too - if (!_mixer->getMuteForSoundType(_type)) { + if (!_mixer->isSoundTypeMuted(_type)) { int vol = _mixer->getVolumeForSoundType(_type) * _volume; if (_balance == 0) { diff --git a/audio/mixer.h b/audio/mixer.h index fe24b85613..89b50e550f 100644 --- a/audio/mixer.h +++ b/audio/mixer.h @@ -200,17 +200,17 @@ public: /** * Set the mute state for a given sound type. * - * @param mute Whether to mute (= true) or not (= false). * @param type the sound type + * @param mute Whether to mute (= true) or not (= false). */ - virtual void setMuteForSoundType(SoundType type, bool mute) = 0; + virtual void muteSoundType(SoundType type, bool mute) = 0; /** * Query the mute state for a given sound type. * * @param type the sound type */ - virtual bool getMuteForSoundType(SoundType type) const = 0; + virtual bool isSoundTypeMuted(SoundType type) const = 0; /** * Set the channel volume for the given handle. diff --git a/audio/mixer_intern.h b/audio/mixer_intern.h index c42436b9a4..14dff5d53b 100644 --- a/audio/mixer_intern.h +++ b/audio/mixer_intern.h @@ -98,8 +98,8 @@ public: virtual bool isSoundHandleActive(SoundHandle handle); - virtual void setMuteForSoundType(SoundType type, bool mute); - virtual bool getMuteForSoundType(SoundType type) const; + virtual void muteSoundType(SoundType type, bool mute); + virtual bool isSoundTypeMuted(SoundType type) const; virtual void setChannelVolume(SoundHandle handle, byte volume); virtual void setChannelBalance(SoundHandle handle, int8 balance); diff --git a/engines/draci/sound.cpp b/engines/draci/sound.cpp index c1ec235246..0df19794f7 100644 --- a/engines/draci/sound.cpp +++ b/engines/draci/sound.cpp @@ -422,8 +422,8 @@ void Sound::setVolume() { _muteSound = _muteVoice = true; } - _mixer->setMuteForSoundType(Audio::Mixer::kSFXSoundType, _muteSound); - _mixer->setMuteForSoundType(Audio::Mixer::kSpeechSoundType, _muteVoice); + _mixer->muteSoundType(Audio::Mixer::kSFXSoundType, _muteSound); + _mixer->muteSoundType(Audio::Mixer::kSpeechSoundType, _muteVoice); _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume")); _mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume")); diff --git a/engines/engine.cpp b/engines/engine.cpp index 8145a550ab..71f9b68f44 100644 --- a/engines/engine.cpp +++ b/engines/engine.cpp @@ -439,10 +439,10 @@ void Engine::syncSoundSettings() { if (ConfMan.hasKey("mute")) mute = ConfMan.getBool("mute"); - _mixer->setMuteForSoundType(Audio::Mixer::kPlainSoundType, mute); - _mixer->setMuteForSoundType(Audio::Mixer::kMusicSoundType, mute); - _mixer->setMuteForSoundType(Audio::Mixer::kSFXSoundType, mute); - _mixer->setMuteForSoundType(Audio::Mixer::kSpeechSoundType, mute); + _mixer->muteSoundType(Audio::Mixer::kPlainSoundType, mute); + _mixer->muteSoundType(Audio::Mixer::kMusicSoundType, mute); + _mixer->muteSoundType(Audio::Mixer::kSFXSoundType, mute); + _mixer->muteSoundType(Audio::Mixer::kSpeechSoundType, mute); _mixer->setVolumeForSoundType(Audio::Mixer::kPlainSoundType, Audio::Mixer::kMaxMixerVolume); _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, soundVolumeMusic); _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, soundVolumeSFX); -- cgit v1.2.3 From 1d60b266879d58663827e7ce0b727c201433394d Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 16 Apr 2011 18:32:14 +0200 Subject: AUDIO: Cleanup sound type settings handling in MixerImpl. --- audio/mixer.cpp | 28 ++++++++++------------------ audio/mixer_intern.h | 10 ++++++++-- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/audio/mixer.cpp b/audio/mixer.cpp index a2b50ddbc4..63f006cbc9 100644 --- a/audio/mixer.cpp +++ b/audio/mixer.cpp @@ -162,19 +162,11 @@ private: MixerImpl::MixerImpl(OSystem *system, uint sampleRate) - : _syst(system), _sampleRate(sampleRate), _mixerReady(false), _handleSeed(0) { + : _syst(system), _mutex(), _sampleRate(sampleRate), _mixerReady(false), _handleSeed(0), _soundTypeSettings() { assert(sampleRate > 0); - int i; - - for (i = 0; i < ARRAYSIZE(_mute); ++i) - _mute[i] = false; - - for (i = 0; i < ARRAYSIZE(_volumeForSoundType); i++) - _volumeForSoundType[i] = kMaxMixerVolume; - - for (i = 0; i != NUM_CHANNELS; i++) + for (int i = 0; i != NUM_CHANNELS; i++) _channels[i] = 0; } @@ -326,8 +318,8 @@ void MixerImpl::stopHandle(SoundHandle handle) { } void MixerImpl::muteSoundType(SoundType type, bool mute) { - assert(0 <= type && type < ARRAYSIZE(_mute)); - _mute[type] = mute; + assert(0 <= type && type < ARRAYSIZE(_soundTypeSettings)); + _soundTypeSettings[type].mute = mute; for (int i = 0; i != NUM_CHANNELS; ++i) { if (_channels[i] && _channels[i]->getType() == type) @@ -336,8 +328,8 @@ void MixerImpl::muteSoundType(SoundType type, bool mute) { } bool MixerImpl::isSoundTypeMuted(SoundType type) const { - assert(0 <= type && type < ARRAYSIZE(_mute)); - return _mute[type]; + assert(0 <= type && type < ARRAYSIZE(_soundTypeSettings)); + return _soundTypeSettings[type].mute; } void MixerImpl::setChannelVolume(SoundHandle handle, byte volume) { @@ -435,7 +427,7 @@ bool MixerImpl::hasActiveChannelOfType(SoundType type) { } void MixerImpl::setVolumeForSoundType(SoundType type, int volume) { - assert(0 <= type && type < ARRAYSIZE(_volumeForSoundType)); + assert(0 <= type && type < ARRAYSIZE(_soundTypeSettings)); // Check range if (volume > kMaxMixerVolume) @@ -447,7 +439,7 @@ void MixerImpl::setVolumeForSoundType(SoundType type, int volume) { // scaling? See also Player_V2::setMasterVolume Common::StackLock lock(_mutex); - _volumeForSoundType[type] = volume; + _soundTypeSettings[type].volume = volume; for (int i = 0; i != NUM_CHANNELS; ++i) { if (_channels[i] && _channels[i]->getType() == type) @@ -456,9 +448,9 @@ void MixerImpl::setVolumeForSoundType(SoundType type, int volume) { } int MixerImpl::getVolumeForSoundType(SoundType type) const { - assert(0 <= type && type < ARRAYSIZE(_volumeForSoundType)); + assert(0 <= type && type < ARRAYSIZE(_soundTypeSettings)); - return _volumeForSoundType[type]; + return _soundTypeSettings[type].volume; } diff --git a/audio/mixer_intern.h b/audio/mixer_intern.h index 14dff5d53b..d7764e50d9 100644 --- a/audio/mixer_intern.h +++ b/audio/mixer_intern.h @@ -64,8 +64,14 @@ private: bool _mixerReady; uint32 _handleSeed; - bool _mute[4]; - int _volumeForSoundType[4]; + struct SoundTypeSettings { + SoundTypeSettings() : mute(false), volume(kMaxMixerVolume) {} + + bool mute; + int volume; + }; + + SoundTypeSettings _soundTypeSettings[4]; Channel *_channels[NUM_CHANNELS]; -- cgit v1.2.3