diff options
Diffstat (limited to 'audio/mixer.cpp')
-rw-r--r-- | audio/mixer.cpp | 42 |
1 files changed, 32 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; } } |