Trying to cleanup the volume control mess inside the SCUMM engine: renamed MusicEngine::setMasterVolume to setMusicVolume; fixed iMuse to use the correct method for setMusicVolume (previously modified the iMuse internal volume control); hooked up the volume control of various other music engines; added ScummEngine::setupVolume method which can be called whenever volume settings change, and which gurantees that those are handled uniformly

svn-id: r15944
This commit is contained in:
Max Horn 2004-11-28 21:24:02 +00:00
parent 6c84bbf2bd
commit 1ae87c0fbb
19 changed files with 65 additions and 67 deletions

View File

@ -462,31 +462,8 @@ void ConfigDialog::close() {
}
GUI_OptionsDialog::close();
// Sync the engine with the config manager
int soundVolumeMaster = ConfMan.getInt("master_volume");
int soundVolumeMusic = ConfMan.getInt("music_volume");
int soundVolumeSfx = ConfMan.getInt("sfx_volume");
int soundVolumeSpeech = ConfMan.getInt("speech_volume");
if (_vm->_imuseDigital) {
_vm->_mixer->setVolume(soundVolumeMaster);
_vm->_imuseDigital->setGroupMusicVolume(soundVolumeMusic / 2);
_vm->_imuseDigital->setGroupSfxVolume(soundVolumeSfx / 2);
_vm->_imuseDigital->setGroupVoiceVolume(soundVolumeSpeech / 2);
return;
}
if (_vm->_imuse) {
_vm->_imuse->set_music_volume(soundVolumeMusic);
}
if (_vm->_musicEngine) {
_vm->_musicEngine->setMasterVolume(soundVolumeMaster);
}
_vm->_mixer->setVolume(soundVolumeSfx * soundVolumeMaster / 255);
_vm->_mixer->setMusicVolume(soundVolumeMusic);
_vm->setupVolumes();
}

View File

@ -566,13 +566,13 @@ int IMuseInternal::query_queue(int param) {
}
}
int IMuseInternal::set_music_volume(uint vol) {
int IMuseInternal::setMusicVolume(uint vol) {
if (vol > 255)
vol = 255;
if (_music_volume == vol)
return 0;
_music_volume = vol;
vol = vol * _master_volume / 255;
vol = _master_volume * _music_volume / 255;
for (uint i = 0; i < ARRAYSIZE(_channel_volume); i++) {
_channel_volume_eff[i] = _channel_volume[i] * vol / 255;
}
@ -581,13 +581,13 @@ int IMuseInternal::set_music_volume(uint vol) {
return 0;
}
int IMuseInternal::setMasterVolume(uint vol) {
int IMuseInternal::setImuseMasterVolume(uint vol) {
if (vol > 255)
vol = 255;
if (_master_volume == vol)
return 0;
_master_volume = vol;
vol = vol * _music_volume / 255;
vol = _master_volume * _music_volume / 255;
for (uint i = 0; i < ARRAYSIZE(_channel_volume); i++) {
_channel_volume_eff[i] = _channel_volume[i] * vol / 255;
}
@ -685,8 +685,8 @@ int32 IMuseInternal::doCommand (int numargs, int a[]) {
if (a[1] > 127)
return -1;
else {
warning ("IMuse doCommand(6) - setMasterVolume (%d)", a[1]);
return setMasterVolume((a[1] << 1) |(a[1] ? 0 : 1)); // Convert from 0-127 to 0-255
warning ("IMuse doCommand(6) - setImuseMasterVolume (%d)", a[1]);
return setImuseMasterVolume((a[1] << 1) |(a[1] ? 0 : 1)); // Convert from 0-127 to 0-255
}
case 7:
warning ("IMuse doCommand(7) - getMasterVolume (%d)", a[1]);
@ -1378,7 +1378,7 @@ int IMuseInternal::save_or_load(Serializer *ser, ScummEngine *scumm) {
// Load all sounds that we need
fix_players_after_load(scumm);
fix_parts_after_load();
setMasterVolume(_master_volume);
setImuseMasterVolume(_master_volume);
if (_midi_native)
reallocateMidiChannels(_midi_native);
@ -1745,8 +1745,7 @@ inline void IMuse::out() const { _system->unlockMutex(_mutex); }
void IMuse::on_timer(MidiDriver *midi) { in(); _target->on_timer(midi); out(); }
void IMuse::pause(bool paused) { in(); _target->pause(paused); out(); }
int IMuse::save_or_load(Serializer *ser, ScummEngine *scumm) { in(); int ret = _target->save_or_load(ser, scumm); out(); return ret; }
int IMuse::set_music_volume(uint vol) { in(); int ret = _target->set_music_volume(vol); out(); return ret; }
void IMuse::setMasterVolume(int vol) { in(); _target->setMasterVolume(vol); out(); }
void IMuse::setMusicVolume(int vol) { in(); _target->setMusicVolume(vol); out(); }
void IMuse::startSound(int sound) { in(); _target->startSound(sound); out(); }
void IMuse::stopSound(int sound) { in(); _target->stopSound(sound); out(); }
void IMuse::stopAllSounds() { in(); _target->stopAllSounds(); out(); }

View File

@ -61,8 +61,7 @@ public:
void on_timer(MidiDriver *midi);
void pause(bool paused);
int save_or_load(Serializer *ser, ScummEngine *scumm);
int set_music_volume(uint vol);
void setMasterVolume(int vol);
void setMusicVolume(int vol);
void startSound(int sound);
void stopSound(int sound);
void stopAllSounds();

View File

@ -154,7 +154,7 @@ public:
void setVolume(int soundId, int volume);
void setPan(int soundId, int pan);
void setFade(int soundId, int destVolume, int delay60HzTicks);
void setMasterVolume(int vol) {}
void setMusicVolume(int vol) {}
void stopSound(int sound);
void stopAllSounds();
void pause(bool pause);

View File

@ -450,8 +450,8 @@ public:
int terminate1();
int terminate2();
int save_or_load(Serializer *ser, ScummEngine *scumm);
int set_music_volume(uint vol);
int setMasterVolume(uint vol);
int setMusicVolume(uint vol);
int setImuseMasterVolume(uint vol);
bool startSound(int sound);
int stopSound(int sound);
int stopAllSounds();

View File

@ -382,15 +382,13 @@ void ScummEngine::processKbd(bool smushMode) {
vol -= 16;
vol = vol & 0xF0;
ConfMan.set("music_volume", vol);
if (_imuse)
_imuse->set_music_volume (vol);
setupVolumes();
} else if (_lastKeyHit == ']') { // ] Music volume up
int vol = ConfMan.getInt("music_volume");
vol = (vol + 16) & 0xFF0;
if (vol > 255) vol = 255;
ConfMan.set("music_volume", vol);
if (_imuse)
_imuse->set_music_volume (vol);
setupVolumes();
} else if (_lastKeyHit == '-') { // - text speed down
if (_defaultTalkDelay < 9)
_defaultTalkDelay++;

View File

@ -45,7 +45,7 @@ public:
* Set the output volume.
* @param vol the new output volume
*/
virtual void setMasterVolume(int vol) = 0;
virtual void setMusicVolume(int vol) = 0;
/**
* Start playing the sound with the given id.

View File

@ -59,7 +59,7 @@ Player_MOD::~Player_MOD() {
}
}
void Player_MOD::setMasterVolume(int vol) {
void Player_MOD::setMusicVolume(int vol) {
_maxvol = vol;
}

View File

@ -38,7 +38,7 @@ class Player_MOD : public AudioStream {
public:
Player_MOD(ScummEngine *scumm);
virtual ~Player_MOD();
virtual void setMasterVolume(int vol);
virtual void setMusicVolume(int vol);
virtual void startChannel(int id, void *data, int size, int rate, uint8 vol, int loopStart = 0, int loopEnd = 0, int8 pan = 0);
virtual void stopChannel(int id);

View File

@ -374,7 +374,7 @@ Player_V2::Player_V2(ScummEngine *scumm, bool pcjr) {
_RNG = NG_PRESET;
set_pcjr(pcjr);
setMasterVolume(255);
setMusicVolume(255);
_mixer->setupPremix(this);
}
@ -416,7 +416,7 @@ void Player_V2::set_pcjr(bool pcjr) {
mutex_down();
}
void Player_V2::setMasterVolume (int vol) {
void Player_V2::setMusicVolume (int vol) {
if (vol > 255)
vol = 255;

View File

@ -78,7 +78,7 @@ public:
Player_V2(ScummEngine *scumm, bool pcjr);
virtual ~Player_V2();
virtual void setMasterVolume(int vol);
virtual void setMusicVolume(int vol);
virtual void startSound(int sound);
virtual void stopSound(int sound);
virtual void stopAllSounds();

View File

@ -1178,8 +1178,8 @@ Player_V2A::~Player_V2A() {
#endif
}
void Player_V2A::setMasterVolume (int vol) {
_mod->setMasterVolume(vol);
void Player_V2A::setMusicVolume (int vol) {
_mod->setMusicVolume(vol);
}
int Player_V2A::getSoundSlot (int id) const {

View File

@ -43,7 +43,7 @@ public:
Player_V2A(ScummEngine *scumm);
virtual ~Player_V2A();
virtual void setMasterVolume(int vol);
virtual void setMusicVolume(int vol);
virtual void startSound(int sound);
virtual void stopSound(int sound);
virtual void stopAllSounds();

View File

@ -75,8 +75,8 @@ Player_V3A::~Player_V3A() {
}
}
void Player_V3A::setMasterVolume (int vol) {
_mod->setMasterVolume(vol);
void Player_V3A::setMusicVolume (int vol) {
_mod->setMusicVolume(vol);
}
int Player_V3A::getMusChan (int id) const {

View File

@ -42,7 +42,7 @@ public:
Player_V3A(ScummEngine *scumm);
virtual ~Player_V3A();
virtual void setMasterVolume(int vol);
virtual void setMusicVolume(int vol);
virtual void startSound(int sound);
virtual void stopSound(int sound);
virtual void stopAllSounds();

View File

@ -870,13 +870,14 @@ void ScummEngine::saveOrLoad(Serializer *s, uint32 savegameVersion) {
if (_imuse && (_saveSound || !_saveTemporaryState)) {
_imuse->save_or_load(s, this);
_imuse->setMasterVolume(ConfMan.getInt("master_volume"));
_imuse->set_music_volume(ConfMan.getInt("music_volume"));
}
if (_imuseDigital) {
_imuseDigital->saveOrLoad(s);
}
if (s->isLoading())
setupVolumes();
}
void ScummEngine::saveLoadResource(Serializer *ser, int type, int idx) {

View File

@ -1159,7 +1159,7 @@ void ScummEngine_v60he::o60_soundOps() {
int arg = pop();
switch (subOp) {
case 0xde:
_imuse->set_music_volume(arg);
_imuse->setMusicVolume(arg);
break;
case 0xdf:
// Used in fbear introduction

View File

@ -1091,8 +1091,7 @@ int ScummEngine::init(GameDetector &detector) {
if (_imuse) {
_imuse->setBase(res.address[rtSound]);
_imuse->setMasterVolume(ConfMan.getInt("master_volume"));
_imuse->set_music_volume(ConfMan.getInt("music_volume"));
_imuse->setMusicVolume(ConfMan.getInt("music_volume"));
}
_sound->setupSound();
@ -1326,16 +1325,10 @@ void ScummEngine::setupMusic(int midi) {
warning("MIDI driver depends on sound mixer, switching to null MIDI driver");
}
}
_mixer->setVolume(ConfMan.getInt("sfx_volume") * ConfMan.getInt("master_volume") / 255);
_mixer->setMusicVolume(ConfMan.getInt("music_volume"));
// Init iMuse
if (_features & GF_DIGI_IMUSE) {
_musicEngine = _imuseDigital = new IMuseDigital(this, 10);
_mixer->setVolume(ConfMan.getInt("master_volume"));
_imuseDigital->setGroupMusicVolume(ConfMan.getInt("music_volume") / 2);
_imuseDigital->setGroupSfxVolume(ConfMan.getInt("sfx_volume") / 2);
_imuseDigital->setGroupVoiceVolume(ConfMan.getInt("speech_volume") / 2);
} else if ((_features & GF_AMIGA) && (_version == 2)) {
_musicEngine = new Player_V2A(this);
} else if ((_features & GF_AMIGA) && (_version == 3)) {
@ -1367,12 +1360,42 @@ void ScummEngine::setupMusic(int midi) {
}
if (midi == MDT_TOWNS)
_imuse->property(IMuse::PROP_DIRECT_PASSTHROUGH, 1);
_imuse->set_music_volume(ConfMan.getInt("music_volume"));
}
}
setupVolumes();
#endif // ph0x-hack
}
void ScummEngine::setupVolumes() {
// Sync the engine with the config manager
int soundVolumeMaster = ConfMan.getInt("master_volume");
int soundVolumeMusic = ConfMan.getInt("music_volume");
int soundVolumeSfx = ConfMan.getInt("sfx_volume");
int soundVolumeSpeech = ConfMan.getInt("speech_volume");
if (_imuse) {
_imuse->setMusicVolume(soundVolumeMusic);
}
if (_musicEngine) {
_musicEngine->setMusicVolume(soundVolumeMusic);
}
_mixer->setVolume(soundVolumeSfx * soundVolumeMaster / 255);
_mixer->setMusicVolume(soundVolumeMusic);
if (_imuseDigital) {
_mixer->setVolume(soundVolumeMaster);
_imuseDigital->setGroupMusicVolume(soundVolumeMusic / 2);
_imuseDigital->setGroupSfxVolume(soundVolumeSfx / 2);
_imuseDigital->setGroupVoiceVolume(soundVolumeSpeech / 2);
}
}
#pragma mark -
#pragma mark --- Main loop ---

View File

@ -393,6 +393,7 @@ public:
void loadCJKFont();
void setupMusic(int midi);
void setupVolumes();
// Scumm main loop
int scummLoop(int delta);