Skip to content

Commit

Permalink
Merge pull request "New mixer mute handling."
Browse files Browse the repository at this point in the history
See #12 for more information.
  • Loading branch information
Johannes Schickel committed Apr 18, 2011
2 parents 12af50f + 1d60b26 commit 7b4a4d9
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 42 deletions.
56 changes: 35 additions & 21 deletions audio/mixer.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -162,16 +162,11 @@ class Channel {




MixerImpl::MixerImpl(OSystem *system, uint sampleRate) 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); assert(sampleRate > 0);


int i; for (int i = 0; i != NUM_CHANNELS; i++)

for (i = 0; i < ARRAYSIZE(_volumeForSoundType); i++)
_volumeForSoundType[i] = kMaxMixerVolume;

for (i = 0; i != NUM_CHANNELS; i++)
_channels[i] = 0; _channels[i] = 0;
} }


Expand Down Expand Up @@ -322,6 +317,21 @@ void MixerImpl::stopHandle(SoundHandle handle) {
_channels[index] = 0; _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) { void MixerImpl::setChannelVolume(SoundHandle handle, byte volume) {
Common::StackLock lock(_mutex); Common::StackLock lock(_mutex);


Expand Down Expand Up @@ -417,7 +427,7 @@ bool MixerImpl::hasActiveChannelOfType(SoundType type) {
} }


void MixerImpl::setVolumeForSoundType(SoundType type, int volume) { void MixerImpl::setVolumeForSoundType(SoundType type, int volume) {
assert(0 <= type && type < ARRAYSIZE(_volumeForSoundType)); assert(0 <= type && type < ARRAYSIZE(_soundTypeSettings));


// Check range // Check range
if (volume > kMaxMixerVolume) if (volume > kMaxMixerVolume)
Expand All @@ -429,7 +439,7 @@ void MixerImpl::setVolumeForSoundType(SoundType type, int volume) {
// scaling? See also Player_V2::setMasterVolume // scaling? See also Player_V2::setMasterVolume


Common::StackLock lock(_mutex); Common::StackLock lock(_mutex);
_volumeForSoundType[type] = volume; _soundTypeSettings[type].volume = volume;


for (int i = 0; i != NUM_CHANNELS; ++i) { for (int i = 0; i != NUM_CHANNELS; ++i) {
if (_channels[i] && _channels[i]->getType() == type) if (_channels[i] && _channels[i]->getType() == type)
Expand All @@ -438,9 +448,9 @@ void MixerImpl::setVolumeForSoundType(SoundType type, int volume) {
} }


int MixerImpl::getVolumeForSoundType(SoundType type) const { 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;
} }




Expand Down Expand Up @@ -486,17 +496,21 @@ void Channel::updateChannelVolumes() {
// volume is in the range 0 - kMaxMixerVolume. // volume is in the range 0 - kMaxMixerVolume.
// Hence, the vol_l/vol_r values will be in that range, too // Hence, the vol_l/vol_r values will be in that range, too


int vol = _mixer->getVolumeForSoundType(_type) * _volume; if (!_mixer->isSoundTypeMuted(_type)) {

int vol = _mixer->getVolumeForSoundType(_type) * _volume;
if (_balance == 0) {
_volL = vol / Mixer::kMaxChannelVolume; if (_balance == 0) {
_volR = vol / Mixer::kMaxChannelVolume; _volL = vol / Mixer::kMaxChannelVolume;
} else if (_balance < 0) { _volR = vol / Mixer::kMaxChannelVolume;
_volL = vol / Mixer::kMaxChannelVolume; } else if (_balance < 0) {
_volR = ((127 + _balance) * vol) / (Mixer::kMaxChannelVolume * 127); _volL = vol / Mixer::kMaxChannelVolume;
_volR = ((127 + _balance) * vol) / (Mixer::kMaxChannelVolume * 127);
} else {
_volL = ((127 - _balance) * vol) / (Mixer::kMaxChannelVolume * 127);
_volR = vol / Mixer::kMaxChannelVolume;
}
} else { } else {
_volL = ((127 - _balance) * vol) / (Mixer::kMaxChannelVolume * 127); _volL = _volR = 0;
_volR = vol / Mixer::kMaxChannelVolume;
} }
} }


Expand Down
14 changes: 14 additions & 0 deletions audio/mixer.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ class Mixer : Common::NonCopyable {
virtual bool isSoundHandleActive(SoundHandle handle) = 0; 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. * Set the channel volume for the given handle.
Expand Down
12 changes: 11 additions & 1 deletion audio/mixer_intern.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ class MixerImpl : public Mixer {
bool _mixerReady; bool _mixerReady;
uint32 _handleSeed; uint32 _handleSeed;


int _volumeForSoundType[4]; struct SoundTypeSettings {
SoundTypeSettings() : mute(false), volume(kMaxMixerVolume) {}

bool mute;
int volume;
};

SoundTypeSettings _soundTypeSettings[4];
Channel *_channels[NUM_CHANNELS]; Channel *_channels[NUM_CHANNELS];




Expand Down Expand Up @@ -97,6 +104,9 @@ class MixerImpl : public Mixer {


virtual bool isSoundHandleActive(SoundHandle handle); 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 setChannelVolume(SoundHandle handle, byte volume);
virtual void setChannelBalance(SoundHandle handle, int8 balance); virtual void setChannelBalance(SoundHandle handle, int8 balance);


Expand Down
9 changes: 5 additions & 4 deletions engines/draci/sound.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -417,15 +417,16 @@ void Sound::setVolume() {
} else { } else {
_muteSound = _muteVoice = true; _muteSound = _muteVoice = true;
} }

if (ConfMan.getBool("mute")) { if (ConfMan.getBool("mute")) {
_muteSound = _muteVoice = true; _muteSound = _muteVoice = true;
} }


const int soundVolume = _muteSound ? 0: ConfMan.getInt("sfx_volume"); _mixer->muteSoundType(Audio::Mixer::kSFXSoundType, _muteSound);
const int speechVolume = _muteVoice ? 0 : ConfMan.getInt("speech_volume"); _mixer->muteSoundType(Audio::Mixer::kSpeechSoundType, _muteVoice);


_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, soundVolume); _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, speechVolume); _mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume"));
} }


} // End of namespace Draci } // End of namespace Draci
12 changes: 8 additions & 4 deletions engines/engine.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -439,10 +439,14 @@ void Engine::syncSoundSettings() {
if (ConfMan.hasKey("mute")) if (ConfMan.hasKey("mute"))
mute = ConfMan.getBool("mute"); mute = ConfMan.getBool("mute");


_mixer->setVolumeForSoundType(Audio::Mixer::kPlainSoundType, (mute ? 0 : Audio::Mixer::kMaxMixerVolume)); _mixer->muteSoundType(Audio::Mixer::kPlainSoundType, mute);
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, (mute ? 0 : soundVolumeMusic)); _mixer->muteSoundType(Audio::Mixer::kMusicSoundType, mute);
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, (mute ? 0 : soundVolumeSFX)); _mixer->muteSoundType(Audio::Mixer::kSFXSoundType, mute);
_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, (mute ? 0 : soundVolumeSpeech)); _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);
_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, soundVolumeSpeech);
} }


void Engine::flipMute() { void Engine::flipMute() {
Expand Down
16 changes: 4 additions & 12 deletions engines/tinsel/sound.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -131,13 +131,9 @@ bool SoundManager::playSample(int id, Audio::Mixer::SoundType type, Audio::Sound
error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage)); error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage));


// FIXME: Should set this in a different place ;) // FIXME: Should set this in a different place ;)
bool mute = false; _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, _vm->_config->_soundVolume);
if (ConfMan.hasKey("mute"))
mute = ConfMan.getBool("mute");

_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, mute ? 0 : _vm->_config->_soundVolume);
//_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, soundVolumeMusic); //_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; Audio::AudioStream *sampleStream = 0;


Expand Down Expand Up @@ -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 ;) // FIXME: Should set this in a different place ;)
bool mute = false; _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, _vm->_config->_soundVolume);
if (ConfMan.hasKey("mute"))
mute = ConfMan.getBool("mute");

_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, mute ? 0 : _vm->_config->_soundVolume);
//_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, soundVolumeMusic); //_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->sampleNum = id;
curChan->subSample = sub; curChan->subSample = sub;
Expand Down

0 comments on commit 7b4a4d9

Please sign in to comment.