diff options
author | Johannes Schickel | 2011-04-18 15:57:04 +0200 |
---|---|---|
committer | Johannes Schickel | 2011-04-18 15:59:34 +0200 |
commit | 7b4a4d9fa65fb843c1fed77197e7cd21ca7f93b8 (patch) | |
tree | 600130f772946fc8a07b5bf6d800434bd0a8e666 /audio | |
parent | 12af50f2ffd7b000ac97a5cea0a596c96fb54924 (diff) | |
parent | 1d60b266879d58663827e7ce0b727c201433394d (diff) | |
download | scummvm-rg350-7b4a4d9fa65fb843c1fed77197e7cd21ca7f93b8.tar.gz scummvm-rg350-7b4a4d9fa65fb843c1fed77197e7cd21ca7f93b8.tar.bz2 scummvm-rg350-7b4a4d9fa65fb843c1fed77197e7cd21ca7f93b8.zip |
Merge pull request "New mixer mute handling."
See https://github.com/scummvm/scummvm/pull/12 for more information.
Diffstat (limited to 'audio')
-rw-r--r-- | audio/mixer.cpp | 56 | ||||
-rw-r--r-- | audio/mixer.h | 14 | ||||
-rw-r--r-- | audio/mixer_intern.h | 12 |
3 files changed, 60 insertions, 22 deletions
diff --git a/audio/mixer.cpp b/audio/mixer.cpp index dc0287e3fb..63f006cbc9 100644 --- a/audio/mixer.cpp +++ b/audio/mixer.cpp @@ -162,16 +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(_volumeForSoundType); i++) - _volumeForSoundType[i] = kMaxMixerVolume; - - for (i = 0; i != NUM_CHANNELS; i++) + for (int i = 0; i != NUM_CHANNELS; i++) _channels[i] = 0; } @@ -322,6 +317,21 @@ void MixerImpl::stopHandle(SoundHandle handle) { _channels[index] = 0; } +void MixerImpl::muteSoundType(SoundType type, bool 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) + _channels[i]->notifyGlobalVolChange(); + } +} + +bool MixerImpl::isSoundTypeMuted(SoundType type) const { + assert(0 <= type && type < ARRAYSIZE(_soundTypeSettings)); + return _soundTypeSettings[type].mute; +} + void MixerImpl::setChannelVolume(SoundHandle handle, byte volume) { Common::StackLock lock(_mutex); @@ -417,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) @@ -429,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) @@ -438,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; } @@ -486,17 +496,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->isSoundTypeMuted(_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..89b50e550f 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 type the sound type + * @param mute Whether to mute (= true) or not (= false). + */ + virtual void muteSoundType(SoundType type, bool mute) = 0; + + /** + * Query the mute state for a given sound type. + * + * @param type the sound type + */ + 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 dd2746e9ea..d7764e50d9 100644 --- a/audio/mixer_intern.h +++ b/audio/mixer_intern.h @@ -64,7 +64,14 @@ private: bool _mixerReady; uint32 _handleSeed; - int _volumeForSoundType[4]; + struct SoundTypeSettings { + SoundTypeSettings() : mute(false), volume(kMaxMixerVolume) {} + + bool mute; + int volume; + }; + + SoundTypeSettings _soundTypeSettings[4]; Channel *_channels[NUM_CHANNELS]; @@ -97,6 +104,9 @@ public: virtual bool isSoundHandleActive(SoundHandle handle); + 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); |