mirror of
https://github.com/libretro/scummvm.git
synced 2025-05-13 09:36:21 +00:00
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.
This commit is contained in:
parent
41706cb4d9
commit
12a31200f2
@ -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 (!_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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user