aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWalter van Niftrik2010-01-12 00:51:37 +0000
committerWalter van Niftrik2010-01-12 00:51:37 +0000
commit1a570df5dc3f1931eb9caadf2dddc1d08987c954 (patch)
tree6e59983f84fed7275402d00450e07f71cb1aee9e
parentdc45c729a99714c27f5ce9d35cdf67e5fbcd8159 (diff)
downloadscummvm-rg350-1a570df5dc3f1931eb9caadf2dddc1d08987c954.tar.gz
scummvm-rg350-1a570df5dc3f1931eb9caadf2dddc1d08987c954.tar.bz2
scummvm-rg350-1a570df5dc3f1931eb9caadf2dddc1d08987c954.zip
SCI: Handle master volume inside music drivers
svn-id: r47261
-rw-r--r--engines/sci/sci.cpp21
-rw-r--r--engines/sci/sci.h1
-rw-r--r--engines/sci/sound/music.cpp21
-rw-r--r--engines/sci/sound/music.h1
-rw-r--r--engines/sci/sound/softseq/adlib.cpp2
-rw-r--r--engines/sci/sound/softseq/amiga.cpp2
-rw-r--r--engines/sci/sound/softseq/pcjr.cpp2
-rw-r--r--engines/sci/sound/soundcmd.cpp16
-rw-r--r--engines/sci/sound/soundcmd.h5
9 files changed, 53 insertions, 18 deletions
diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp
index 17fb5962bb..05a1f5cf8b 100644
--- a/engines/sci/sci.cpp
+++ b/engines/sci/sci.cpp
@@ -178,6 +178,8 @@ Common::Error SciEngine::run() {
}
#endif
+ syncSoundSettings();
+
_gamestate->_gui->init(_gamestate->usesOldGfxFunctions());
debug("Emulating SCI version %s\n", getSciVersionDesc(getSciVersion()).c_str());
@@ -187,6 +189,8 @@ Common::Error SciEngine::run() {
game_exit(_gamestate);
script_free_breakpoints(_gamestate);
+ ConfMan.flushToDisk();
+
delete _gamestate->_soundCmd;
delete _gamestate->_gui;
delete _gamestate->_event;
@@ -281,4 +285,21 @@ void SciEngine::pauseEngineIntern(bool pause) {
_mixer->pauseAll(pause);
}
+void SciEngine::syncSoundSettings() {
+ Engine::syncSoundSettings();
+
+#ifndef USE_OLD_MUSIC_FUNCTIONS
+ bool mute = false;
+ if (ConfMan.hasKey("mute"))
+ mute = ConfMan.getBool("mute");
+
+ int soundVolumeMusic = (mute ? 0 : ConfMan.getInt("music_volume"));
+
+ if (_gamestate && _gamestate->_soundCmd) {
+ int vol = (soundVolumeMusic + 1) * SoundCommandParser::kMaxSciVolume / Audio::Mixer::kMaxMixerVolume;
+ _gamestate->_soundCmd->setMasterVolume(vol);
+ }
+#endif
+}
+
} // End of namespace Sci
diff --git a/engines/sci/sci.h b/engines/sci/sci.h
index fd56d860c3..a12894306b 100644
--- a/engines/sci/sci.h
+++ b/engines/sci/sci.h
@@ -122,6 +122,7 @@ public:
Common::Error saveGameState(int slot, const char *desc);
bool canLoadGameStateCurrently();
bool canSaveGameStateCurrently();
+ void syncSoundSettings();
const char* getGameID() const;
int getResourceVersion() const;
diff --git a/engines/sci/sound/music.cpp b/engines/sci/sound/music.cpp
index fd1e6f1bd9..15d691a8e4 100644
--- a/engines/sci/sound/music.cpp
+++ b/engines/sci/sound/music.cpp
@@ -40,7 +40,7 @@ namespace Sci {
#define DISABLE_VOLUME_FADING
SciMusic::SciMusic(SciVersion soundVersion)
- : _soundVersion(soundVersion), _soundOn(true) {
+ : _soundVersion(soundVersion), _soundOn(true), _masterVolume(0) {
// Reserve some space in the playlist, to avoid expensive insertion
// operations
@@ -57,12 +57,6 @@ SciMusic::~SciMusic() {
void SciMusic::init() {
// system init
_pMixer = g_system->getMixer();
- _pMixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt(
- "sfx_volume"));
- _pMixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType,
- ConfMan.getInt("speech_volume"));
- _pMixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType,
- ConfMan.getInt("music_volume"));
// SCI sound init
_dwTempo = 0;
@@ -469,15 +463,16 @@ void SciMusic::soundResume(MusicEntry *pSnd) {
}
uint16 SciMusic::soundGetMasterVolume() {
- return (_pMixer->getVolumeForSoundType(Audio::Mixer::kMusicSoundType) + 8) * 0xF / Audio::Mixer::kMaxMixerVolume;
+ return _masterVolume;
}
void SciMusic::soundSetMasterVolume(uint16 vol) {
- vol = vol & 0xF; // 0..15
- vol = vol * Audio::Mixer::kMaxMixerVolume / 0xF;
- // "master volume" is music and SFX only, speech (audio resources) are supposed to be unaffected
- _pMixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, vol);
- _pMixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, vol);
+ _masterVolume = vol;
+
+ Common::StackLock lock(_mutex);
+
+ if (_pMidiDrv)
+ _pMidiDrv->setVolume(vol);
}
void SciMusic::printPlayList(Console *con) {
diff --git a/engines/sci/sound/music.h b/engines/sci/sound/music.h
index 049e192c23..adf64727ec 100644
--- a/engines/sci/sound/music.h
+++ b/engines/sci/sound/music.h
@@ -226,6 +226,7 @@ private:
MusicList _playList;
bool _soundOn;
byte _reverb;
+ byte _masterVolume;
};
} // End of namespace Sci
diff --git a/engines/sci/sound/softseq/adlib.cpp b/engines/sci/sound/softseq/adlib.cpp
index c8c12040ec..5d0c9bef66 100644
--- a/engines/sci/sound/softseq/adlib.cpp
+++ b/engines/sci/sound/softseq/adlib.cpp
@@ -229,7 +229,7 @@ int MidiDriver_Adlib::open(bool isSCI0) {
MidiDriver_Emulated::open();
- _mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_mixerSoundHandle, this, -1, _mixer->kMaxChannelVolume, 0, DisposeAfterUse::NO);
+ _mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_mixerSoundHandle, this, -1, _mixer->kMaxChannelVolume, 0, DisposeAfterUse::NO);
return 0;
}
diff --git a/engines/sci/sound/softseq/amiga.cpp b/engines/sci/sound/softseq/amiga.cpp
index 8324fc9dd2..7c57bb6efd 100644
--- a/engines/sci/sound/softseq/amiga.cpp
+++ b/engines/sci/sound/softseq/amiga.cpp
@@ -541,7 +541,7 @@ int MidiDriver_Amiga::open() {
MidiDriver_Emulated::open();
- _mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_mixerSoundHandle, this, -1, _mixer->kMaxChannelVolume, 0, DisposeAfterUse::NO);
+ _mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_mixerSoundHandle, this, -1, _mixer->kMaxChannelVolume, 0, DisposeAfterUse::NO);
return Common::kNoError;
}
diff --git a/engines/sci/sound/softseq/pcjr.cpp b/engines/sci/sound/softseq/pcjr.cpp
index 3dc5af3be5..476526b06e 100644
--- a/engines/sci/sound/softseq/pcjr.cpp
+++ b/engines/sci/sound/softseq/pcjr.cpp
@@ -219,7 +219,7 @@ int MidiDriver_PCJr::open(int channels) {
MidiDriver_Emulated::open();
- _mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_mixerSoundHandle, this, -1, _mixer->kMaxChannelVolume, 0, DisposeAfterUse::NO);
+ _mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_mixerSoundHandle, this, -1, _mixer->kMaxChannelVolume, 0, DisposeAfterUse::NO);
return 0;
}
diff --git a/engines/sci/sound/soundcmd.cpp b/engines/sci/sound/soundcmd.cpp
index feaa2e6906..cc1cc75a6a 100644
--- a/engines/sci/sound/soundcmd.cpp
+++ b/engines/sci/sound/soundcmd.cpp
@@ -29,6 +29,7 @@
#include "sci/sound/iterator/iterator.h" // for SongIteratorStatus
#endif
+#include "common/config-manager.h"
#include "sci/sound/music.h"
#include "sci/sound/soundcmd.h"
@@ -610,8 +611,13 @@ void SoundCommandParser::cmdMasterVolume(reg_t obj, int16 value) {
_acc = make_reg(0, _state->sfx_getVolume());
#else
debugC(2, kDebugLevelSound, "cmdMasterVolume: %d", value);
- if (_argc > 1) // the first parameter is the sound command
- _music->soundSetMasterVolume(obj.toSint16());
+ if (_argc > 1) { // the first parameter is the sound command
+ int vol = CLIP<int16>(obj.toSint16(), 0, kMaxSciVolume);
+ vol = vol * Audio::Mixer::kMaxMixerVolume / kMaxSciVolume;
+ ConfMan.setInt("music_volume", vol);
+ ConfMan.setInt("sfx_volume", vol);
+ g_engine->syncSoundSettings();
+ }
_acc = make_reg(0, _music->soundGetMasterVolume());
#endif
}
@@ -1090,4 +1096,10 @@ void SoundCommandParser::resetDriver() {
#endif
}
+void SoundCommandParser::setMasterVolume(int vol) {
+#ifndef USE_OLD_MUSIC_FUNCTIONS
+ _music->soundSetMasterVolume(vol);
+#endif
+}
+
} // End of namespace Sci
diff --git a/engines/sci/sound/soundcmd.h b/engines/sci/sound/soundcmd.h
index 548dcf3889..94e0698523 100644
--- a/engines/sci/sound/soundcmd.h
+++ b/engines/sci/sound/soundcmd.h
@@ -49,6 +49,10 @@ public:
SoundCommandParser(ResourceManager *resMan, SegManager *segMan, AudioPlayer *audio, SciVersion soundVersion);
~SoundCommandParser();
+ enum {
+ kMaxSciVolume = 15
+ };
+
#ifdef USE_OLD_MUSIC_FUNCTIONS
void updateSfxState(SfxState *newState) { _state = newState; }
#endif
@@ -59,6 +63,7 @@ public:
void reconstructPlayList(int savegame_version);
void printPlayList(Console *con);
void resetDriver();
+ void setMasterVolume(int vol);
#ifndef USE_OLD_MUSIC_FUNCTIONS
/**