AGOS: Got rid of _masterVolume and replaced with _musicVolume and _sfxVolume so that music and sfx are separately controlled via the Options menu

svn-id: r33065
This commit is contained in:
Christopher Page 2008-07-14 22:10:04 +00:00
parent d2e8d4831e
commit ebd3510b72
5 changed files with 46 additions and 25 deletions

View file

@ -572,7 +572,7 @@ int AGOSEngine::init() {
if (ret) if (ret)
warning("MIDI Player init failed: \"%s\"", _midi.getErrorName (ret)); warning("MIDI Player init failed: \"%s\"", _midi.getErrorName (ret));
_midi.setVolume(ConfMan.getInt("music_volume")); _midi.setVolume(ConfMan.getInt("music_volume"), ConfMan.getInt("sfx_volume"));
_midiEnabled = true; _midiEnabled = true;
@ -1083,7 +1083,8 @@ uint32 AGOSEngine::getTime() const {
void AGOSEngine::syncSoundSettings() { void AGOSEngine::syncSoundSettings() {
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume")); _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume")); _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
_midi.setVolume(ConfMan.getInt("music_volume")); _mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume"));
_midi.setVolume(ConfMan.getInt("music_volume"), ConfMan.getInt("sfx_volume"));
} }
} // End of namespace AGOS } // End of namespace AGOS

View file

@ -563,14 +563,14 @@ bool AGOSEngine::processSpecialKeys() {
case Common::KEYCODE_PLUS: case Common::KEYCODE_PLUS:
case Common::KEYCODE_KP_PLUS: case Common::KEYCODE_KP_PLUS:
if (_midiEnabled) { if (_midiEnabled) {
_midi.setVolume(_midi.getVolume() + 16); _midi.setVolume(_midi.getMusicVolume() + 16, _midi.getSFXVolume() + 16);
} }
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, _mixer->getVolumeForSoundType(Audio::Mixer::kMusicSoundType) + 16); _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, _mixer->getVolumeForSoundType(Audio::Mixer::kMusicSoundType) + 16);
break; break;
case Common::KEYCODE_MINUS: case Common::KEYCODE_MINUS:
case Common::KEYCODE_KP_MINUS: case Common::KEYCODE_KP_MINUS:
if (_midiEnabled) { if (_midiEnabled) {
_midi.setVolume(_midi.getVolume() - 16); _midi.setVolume(_midi.getMusicVolume() - 16, _midi.getSFXVolume() - 16);
} }
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, _mixer->getVolumeForSoundType(Audio::Mixer::kMusicSoundType) - 16); _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, _mixer->getVolumeForSoundType(Audio::Mixer::kMusicSoundType) - 16);
break; break;

View file

@ -49,7 +49,9 @@ MidiPlayer::MidiPlayer() {
_enable_sfx = true; _enable_sfx = true;
_current = 0; _current = 0;
_masterVolume = 255; _musicVolume = 255;
_sfxVolume = 255;
resetVolumeTable(); resetVolumeTable();
_paused = false; _paused = false;
@ -104,10 +106,13 @@ void MidiPlayer::send(uint32 b) {
byte channel = (byte)(b & 0x0F); byte channel = (byte)(b & 0x0F);
if ((b & 0xFFF0) == 0x07B0) { if ((b & 0xFFF0) == 0x07B0) {
// Adjust volume changes by master volume. // Adjust volume changes by master music and master sfx volume.
byte volume = (byte)((b >> 16) & 0x7F); byte volume = (byte)((b >> 16) & 0x7F);
_current->volume[channel] = volume; _current->volume[channel] = volume;
volume = volume * _masterVolume / 255; if (_current == &_sfx)
volume = volume * _sfxVolume / 255;
else if (_current == &_music)
volume = volume * _musicVolume / 255;
b = (b & 0xFF00FFFF) | (volume << 16); b = (b & 0xFF00FFFF) | (volume << 16);
} else if ((b & 0xF0) == 0xC0 && _map_mt32_to_gm) { } else if ((b & 0xF0) == 0xC0 && _map_mt32_to_gm) {
b = (b & 0xFFFF00FF) | (MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8); b = (b & 0xFFFF00FF) | (MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8);
@ -133,8 +138,12 @@ void MidiPlayer::send(uint32 b) {
if (!_current->channel[channel]) if (!_current->channel[channel])
_current->channel[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel(); _current->channel[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
if (_current->channel[channel]) { if (_current->channel[channel]) {
if (channel == 9) if (channel == 9) {
_current->channel[9]->volume(_current->volume[9] * _masterVolume / 255); if (_current == &_sfx)
_current->channel[9]->volume(_current->volume[9] * _sfxVolume / 255);
else if (_current == &_music)
_current->channel[9]->volume(_current->volume[9] * _musicVolume / 255);
}
_current->channel[channel]->send(b); _current->channel[channel]->send(b);
if ((b & 0xFFF0) == 0x79B0) { if ((b & 0xFFF0) == 0x79B0) {
// We have received a "Reset All Controllers" message // We have received a "Reset All Controllers" message
@ -143,7 +152,10 @@ void MidiPlayer::send(uint32 b) {
// consistent behaviour, explicitly set the volume to // consistent behaviour, explicitly set the volume to
// what we think it should be. // what we think it should be.
_current->channel[channel]->volume(_current->volume[channel] * _masterVolume / 255); if (_current == &_sfx)
_current->channel[channel]->volume(_current->volume[channel] * _sfxVolume / 255);
else if (_current == &_music)
_current->channel[channel]->volume(_current->volume[channel] * _musicVolume / 255);
} }
} }
} }
@ -255,30 +267,36 @@ void MidiPlayer::pause(bool b) {
Common::StackLock lock(_mutex); Common::StackLock lock(_mutex);
for (int i = 0; i < 16; ++i) { for (int i = 0; i < 16; ++i) {
if (_music.channel[i]) if (_music.channel[i])
_music.channel[i]->volume(_paused ? 0 : (_music.volume[i] * _masterVolume / 255)); _music.channel[i]->volume(_paused ? 0 : (_music.volume[i] * _musicVolume / 255));
if (_sfx.channel[i]) if (_sfx.channel[i])
_sfx.channel[i]->volume(_paused ? 0 : (_sfx.volume[i] * _masterVolume / 255)); _sfx.channel[i]->volume(_paused ? 0 : (_sfx.volume[i] * _sfxVolume / 255));
} }
} }
void MidiPlayer::setVolume(int volume) { void MidiPlayer::setVolume(int musicVol, int sfxVol) {
if (volume < 0) if (musicVol < 0)
volume = 0; musicVol = 0;
else if (volume > 255) else if (musicVol > 255)
volume = 255; musicVol = 255;
if (sfxVol < 0)
sfxVol = 0;
else if (sfxVol > 255)
sfxVol = 255;
if (_masterVolume == volume) if (_musicVolume == musicVol && _sfxVolume == sfxVol)
return; return;
_masterVolume = volume;
_musicVolume = musicVol;
_sfxVolume = sfxVol;
// Now tell all the channels this. // Now tell all the channels this.
Common::StackLock lock(_mutex); Common::StackLock lock(_mutex);
if (_driver && !_paused) { if (_driver && !_paused) {
for (int i = 0; i < 16; ++i) { for (int i = 0; i < 16; ++i) {
if (_music.channel[i]) if (_music.channel[i])
_music.channel[i]->volume(_music.volume[i] * _masterVolume / 255); _music.channel[i]->volume(_music.volume[i] * _musicVolume / 255);
if (_sfx.channel[i]) if (_sfx.channel[i])
_sfx.channel[i]->volume(_sfx.volume[i] * _masterVolume / 255); _sfx.channel[i]->volume(_sfx.volume[i] * _sfxVolume / 255);
} }
} }
} }
@ -354,7 +372,7 @@ void MidiPlayer::resetVolumeTable() {
for (i = 0; i < 16; ++i) { for (i = 0; i < 16; ++i) {
_music.volume[i] = _sfx.volume[i] = 127; _music.volume[i] = _sfx.volume[i] = 127;
if (_driver) if (_driver)
_driver->send(((_masterVolume >> 1) << 16) | 0x7B0 | i); _driver->send(((_musicVolume >> 1) << 16) | 0x7B0 | i);
} }
} }

View file

@ -68,6 +68,8 @@ protected:
// These are maintained for both music and SFX // These are maintained for both music and SFX
byte _masterVolume; // 0-255 byte _masterVolume; // 0-255
byte _musicVolume;
byte _sfxVolume;
bool _paused; bool _paused;
// These are only used for music. // These are only used for music.
@ -103,8 +105,9 @@ public:
void stop(); void stop();
void pause(bool b); void pause(bool b);
int getVolume() { return _masterVolume; } int getMusicVolume() { return _musicVolume; }
void setVolume(int volume); int getSFXVolume() { return _sfxVolume; }
void setVolume(int musicVol, int sfxVol);
void setDriver(MidiDriver *md); void setDriver(MidiDriver *md);
public: public:

View file

@ -1673,7 +1673,6 @@ void ScummEngine::syncSoundSettings() {
_musicEngine->setMusicVolume(soundVolumeMusic); _musicEngine->setMusicVolume(soundVolumeMusic);
} }
_mixer->setVolumeForSoundType(Audio::Mixer::kPlainSoundType, soundVolumeMusic);
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, soundVolumeSfx); _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, soundVolumeSfx);
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, soundVolumeMusic); _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, soundVolumeMusic);
_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, soundVolumeSpeech); _mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, soundVolumeSpeech);