aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2004-12-27 23:43:40 +0000
committerMax Horn2004-12-27 23:43:40 +0000
commitf9b1e4118c5b3350528087f982c2fa9d34a365de (patch)
tree2e923fd483cddb46392874f45bf557052bf1b489
parentbc882a1af4df93feeaff82e69a4609367e373e20 (diff)
downloadscummvm-rg350-f9b1e4118c5b3350528087f982c2fa9d34a365de.tar.gz
scummvm-rg350-f9b1e4118c5b3350528087f982c2fa9d34a365de.tar.bz2
scummvm-rg350-f9b1e4118c5b3350528087f982c2fa9d34a365de.zip
Use the mixer to handle sound volumes
svn-id: r16349
-rw-r--r--sword2/controls.cpp38
-rw-r--r--sword2/driver/d_sound.cpp100
-rw-r--r--sword2/driver/d_sound.h9
-rw-r--r--sword2/sword2.cpp8
4 files changed, 38 insertions, 117 deletions
diff --git a/sword2/controls.cpp b/sword2/controls.cpp
index c3712970b9..63a04de150 100644
--- a/sword2/controls.cpp
+++ b/sword2/controls.cpp
@@ -862,10 +862,14 @@ private:
Widget *_gfxPreview;
Button *_okButton;
Button *_cancelButton;
+
+ SoundMixer *_mixer;
public:
OptionsDialog(Gui *gui) : Dialog(gui) {
_fr = new FontRendererGui(gui, gui->_vm->_controlsFontId);
+
+ _mixer = _gui->_vm->_mixer;
_panel = new Widget(this, 1);
_panel->createSurfaceImages(3405, 0, 40);
@@ -891,9 +895,9 @@ public:
_fxSwitch->linkSurfaceImages(_musicSwitch, 516, 250);
_fxSwitch->reverseStates();
- _musicSlider = new Slider(this, _panel, 255, 309, 161, 170, 27);
- _speechSlider = new Slider(this, _panel, 255, 309, 208, 170, 27, _musicSlider);
- _fxSlider = new Slider(this, _panel, 255, 309, 254, 170, 27, _musicSlider);
+ _musicSlider = new Slider(this, _panel, SoundMixer::kMaxMixerVolume, 309, 161, 170, 27);
+ _speechSlider = new Slider(this, _panel, SoundMixer::kMaxMixerVolume, 309, 208, 170, 27, _musicSlider);
+ _fxSlider = new Slider(this, _panel, SoundMixer::kMaxMixerVolume, 309, 254, 170, 27, _musicSlider);
_gfxSlider = new Slider(this, _panel, 3, 309, 341, 170, 27, _musicSlider);
_gfxPreview = new Widget(this, 4);
@@ -928,9 +932,11 @@ public:
_musicSwitch->setValue(!_gui->_vm->_sound->isMusicMute());
_speechSwitch->setValue(!_gui->_vm->_sound->isSpeechMute());
_fxSwitch->setValue(!_gui->_vm->_sound->isFxMute());
- _musicSlider->setValue(_gui->_vm->_sound->getMusicVolume());
- _speechSlider->setValue(_gui->_vm->_sound->getSpeechVolume());
- _fxSlider->setValue(_gui->_vm->_sound->getFxVolume());
+
+ _musicSlider->setValue(_mixer->getVolumeForSoundType(SoundMixer::kMusicAudioDataType));
+ _speechSlider->setValue(_mixer->getVolumeForSoundType(SoundMixer::kSpeechAudioDataType));
+ _fxSlider->setValue(_mixer->getVolumeForSoundType(SoundMixer::kSFXAudioDataType));
+
_gfxSlider->setValue(_gui->_vm->_graphics->getRenderLevel());
_gfxPreview->setState(_gui->_vm->_graphics->getRenderLevel());
}
@@ -989,7 +995,7 @@ public:
if (widget == _musicSwitch) {
_gui->_vm->_sound->muteMusic(result != 0);
} else if (widget == _musicSlider) {
- _gui->_vm->_sound->setMusicVolume(result);
+ _mixer->setVolumeForSoundType(SoundMixer::kMusicAudioDataType, result);
_gui->_vm->_sound->muteMusic(result == 0);
_musicSwitch->setValue(result != 0);
} else if (widget == _speechSlider) {
@@ -1008,9 +1014,9 @@ public:
_gui->_vm->_sound->muteMusic(!_musicSwitch->getValue());
_gui->_vm->_sound->muteSpeech(!_speechSwitch->getValue());
_gui->_vm->_sound->muteFx(!_fxSwitch->getValue());
- _gui->_vm->_sound->setMusicVolume(_musicSlider->getValue());
- _gui->_vm->_sound->setSpeechVolume(_speechSlider->getValue());
- _gui->_vm->_sound->setFxVolume(_fxSlider->getValue());
+ _mixer->setVolumeForSoundType(SoundMixer::kMusicAudioDataType, _musicSlider->getValue());
+ _mixer->setVolumeForSoundType(SoundMixer::kSpeechAudioDataType, _speechSlider->getValue());
+ _mixer->setVolumeForSoundType(SoundMixer::kSFXAudioDataType, _fxSlider->getValue());
_gui->_vm->_sound->buildPanTable(_gui->_stereoReversed);
_gui->updateGraphicsLevel(_gfxSlider->getValue());
@@ -1491,9 +1497,9 @@ void Gui::readOptionSettings(void) {
updateGraphicsLevel((uint8) ConfMan.getInt("gfx_details"));
- _vm->_sound->setMusicVolume(ConfMan.getInt("music_volume"));
- _vm->_sound->setSpeechVolume(ConfMan.getInt("speech_volume"));
- _vm->_sound->setFxVolume(ConfMan.getInt("sfx_volume"));
+ _vm->_mixer->setVolumeForSoundType(SoundMixer::kMusicAudioDataType, ConfMan.getInt("music_volume"));
+ _vm->_mixer->setVolumeForSoundType(SoundMixer::kSpeechAudioDataType, ConfMan.getInt("speech_volume"));
+ _vm->_mixer->setVolumeForSoundType(SoundMixer::kSFXAudioDataType, ConfMan.getInt("sfx_volume"));
_vm->_sound->muteMusic(ConfMan.getBool("music_mute"));
_vm->_sound->muteSpeech(ConfMan.getBool("speech_mute"));
_vm->_sound->muteFx(ConfMan.getBool("sfx_mute"));
@@ -1501,9 +1507,9 @@ void Gui::readOptionSettings(void) {
}
void Gui::writeOptionSettings(void) {
- ConfMan.set("music_volume", _vm->_sound->getMusicVolume());
- ConfMan.set("speech_volume", _vm->_sound->getSpeechVolume());
- ConfMan.set("sfx_volume", _vm->_sound->getFxVolume());
+ ConfMan.set("music_volume", _vm->_mixer->getVolumeForSoundType(SoundMixer::kMusicAudioDataType));
+ ConfMan.set("speech_volume", _vm->_mixer->getVolumeForSoundType(SoundMixer::kSpeechAudioDataType));
+ ConfMan.set("sfx_volume", _vm->_mixer->getVolumeForSoundType(SoundMixer::kSFXAudioDataType));
ConfMan.set("music_mute", _vm->_sound->isMusicMute());
ConfMan.set("speech_mute", _vm->_sound->isSpeechMute());
ConfMan.set("sfx_mute", _vm->_sound->isFxMute());
diff --git a/sword2/driver/d_sound.cpp b/sword2/driver/d_sound.cpp
index 83b49ad5fb..881a5aa732 100644
--- a/sword2/driver/d_sound.cpp
+++ b/sword2/driver/d_sound.cpp
@@ -469,13 +469,10 @@ Sound::Sound(Sword2Engine *vm) {
_speechPaused = false;
_speechMuted = false;
- _speechVol = 255;
_fxPaused = false;
_fxMuted = false;
- _fxVol = 255;
- _musicVol = 255;
_musicPaused = false;
_musicMuted = false;
@@ -485,7 +482,7 @@ Sound::Sound(Sword2Engine *vm) {
for (int i = 0; i < MAXMUS; i++)
_music[i] = NULL;
- _vm->_mixer->setupPremix(this);
+ _vm->_mixer->setupPremix(this, SoundMixer::kMusicAudioDataType);
}
Sound::~Sound() {
@@ -545,7 +542,7 @@ int Sound::readBuffer(int16 *buffer, const int numSamples) {
if (!_musicMuted) {
for (int j = 0; j < len; j++) {
- clampedAdd(buffer[j], (_musicVol * _mixBuffer[j]) / 255);
+ clampedAdd(buffer[j], _mixBuffer[j]);
}
}
}
@@ -604,26 +601,6 @@ bool Sound::isMusicMute(void) {
}
/**
- * Set the volume of any future as well as playing music.
- * @param volume volume, from 0 (silent) to 16 (max)
- */
-
-void Sound::setMusicVolume(uint volume) {
- if (volume > 255)
- volume = 255;
-
- _musicVol = volume;
-}
-
-/**
- * @return the volume setting for music
- */
-
-uint8 Sound::getMusicVolume(void) {
- return _musicVol;
-}
-
-/**
* Stops the music dead in its tracks. Any music that is currently being
* streamed is paused.
*/
@@ -776,7 +753,7 @@ void Sound::muteSpeech(bool mute) {
_speechMuted = mute;
if (_soundHandleSpeech.isActive()) {
- byte volume = mute ? 0 : _speechVol;
+ uint volume = mute ? 0 : SoundMixer::kMaxChannelVolume;
_vm->_mixer->setChannelVolume(_soundHandleSpeech, volume);
}
@@ -791,30 +768,6 @@ bool Sound::isSpeechMute(void) {
}
/**
- * Set the volume of any future as well as playing speech samples.
- * @param volume volume, from 0 (silent) to 14 (max)
- */
-
-void Sound::setSpeechVolume(uint volume) {
- if (volume > 255)
- volume = 255;
-
- _speechVol = volume;
-
- if (_soundHandleSpeech.isActive() && !_speechMuted && _soundHandleSpeech.isActive()) {
- _vm->_mixer->setChannelVolume(_soundHandleSpeech, _speechVol);
- }
-}
-
-/**
- * @return the volume setting for speech
- */
-
-uint8 Sound::getSpeechVolume(void) {
- return _speechVol;
-}
-
-/**
* Stops the speech dead in its tracks.
*/
@@ -928,11 +881,11 @@ int32 Sound::playCompSpeech(uint32 speechid, uint8 vol, int8 pan) {
// Modify the volume according to the master volume
- byte volume = _speechMuted ? 0 : vol * _speechVol / 16;
+ byte volume = _speechMuted ? 0 : vol * SoundMixer::kMaxChannelVolume / 16;
int8 p = _panTable[pan + 16];
// Start the speech playing
- _vm->_mixer->playInputStream(SoundMixer::kSFXAudioDataType, &_soundHandleSpeech, input, -1, volume, p);
+ _vm->_mixer->playInputStream(SoundMixer::kSpeechAudioDataType, &_soundHandleSpeech, input, -1, volume, p);
return RD_OK;
}
@@ -1014,7 +967,7 @@ void Sound::muteFx(bool mute) {
// Now update the volume of any fxs playing
for (int i = 0; i < MAXFX; i++) {
if (_fx[i]._id) {
- byte volume = mute ? 0 : _fx[i]._volume * _fxVol / 16;
+ byte volume = mute ? 0 : _fx[i]._volume * SoundMixer::kMaxChannelVolume / 16;
_vm->_mixer->setChannelVolume(_fx[i]._handle, volume);
}
@@ -1030,35 +983,6 @@ bool Sound::isFxMute(void) {
}
/**
- * @return the master volume setting for sound effects
- */
-
-uint8 Sound::getFxVolume(void) {
- return _fxVol;
-}
-
-/**
- * Set the master volume of all sound effects. The effects still have their
- * own volume setting as well as the master volume.
- * @param volume volume, from 0 (silent) to 14 (max)
- */
-
-void Sound::setFxVolume(uint volume) {
- if (volume > 255)
- volume = 255;
-
- _fxVol = volume;
-
- if (_fxMuted)
- return;
-
- // Now update the volume of any fxs playing
- for (int i = 0; i < MAXFX; i++)
- if (_fx[i]._id)
- _vm->_mixer->setChannelVolume(_fx[i]._handle, _fx[i]._volume * _fxVol / 16);
-}
-
-/**
* Sets the volume and pan of the sample which is currently playing
* @param id the id of the sample
* @param vol volume
@@ -1077,7 +1001,7 @@ int32 Sound::setFxIdVolumePan(int32 id, uint8 vol, int8 pan) {
_fx[i]._volume = vol;
if (!_fxMuted) {
- _vm->_mixer->setChannelVolume(_fx[i]._handle, _fx[i]._volume * _fxVol / 16);
+ _vm->_mixer->setChannelVolume(_fx[i]._handle, _fx[i]._volume * SoundMixer::kMaxChannelVolume / 16);
_vm->_mixer->setChannelBalance(_fx[i]._handle, _panTable[pan + 16]);
}
@@ -1093,7 +1017,7 @@ int32 Sound::setFxIdVolume(int32 id, uint8 vol) {
_fx[i]._volume = vol;
if (!_fxMuted)
- _vm->_mixer->setChannelVolume(_fx[i]._handle, vol * _fxVol / 16);
+ _vm->_mixer->setChannelVolume(_fx[i]._handle, vol * SoundMixer::kMaxChannelVolume / 16);
return RD_OK;
}
@@ -1190,14 +1114,16 @@ int32 Sound::playFx(int32 id, byte *data, uint8 vol, int8 pan, uint8 type) {
if (!_soundOn)
return RD_OK;
- byte volume = _fxMuted ? 0 : vol * _fxVol / 16;
+ byte volume = _fxMuted ? 0 : vol * SoundMixer::kMaxChannelVolume / 16;
+ SoundMixer::SoundType soundType = SoundMixer::kSFXAudioDataType;
// All lead-ins and lead-outs I've heard are music, so we use
// the music volume setting for them.
if (type == RDSE_FXLEADIN || type == RDSE_FXLEADOUT) {
id = (type == RDSE_FXLEADIN) ? -2 : -1;
- volume = _musicMuted ? 0 : _musicVol;
+ volume = _musicMuted ? 0 : SoundMixer::kMaxChannelVolume;
+ soundType = SoundMixer::kMusicAudioDataType;
}
WavInfo wavInfo;
@@ -1253,7 +1179,7 @@ int32 Sound::playFx(int32 id, byte *data, uint8 vol, int8 pan, uint8 type) {
int8 p = _panTable[pan + 16];
- _vm->_mixer->playRaw(&_fx[fxi]._handle, wavInfo.data, wavInfo.samples, wavInfo.rate, flags, -1, volume, p);
+ _vm->_mixer->playRaw(&_fx[fxi]._handle, wavInfo.data, wavInfo.samples, wavInfo.rate, flags, -1, volume, p, 0, 0, soundType);
return RD_OK;
}
diff --git a/sword2/driver/d_sound.h b/sword2/driver/d_sound.h
index 3a885a89b8..37d7a52111 100644
--- a/sword2/driver/d_sound.h
+++ b/sword2/driver/d_sound.h
@@ -70,17 +70,14 @@ private:
bool _musicPaused;
bool _musicMuted;
- int _musicVol;
PlayingSoundHandle _soundHandleSpeech;
bool _speechPaused;
bool _speechMuted;
- int _speechVol;
FxHandle _fx[MAXFX];
bool _fxPaused;
bool _fxMuted;
- int _fxVol;
int32 getFxIndex(int32 id);
void stopFxHandle(int i);
@@ -104,8 +101,6 @@ public:
void muteMusic(bool mute);
bool isMusicMute(void);
- void setMusicVolume(uint vol);
- uint8 getMusicVolume(void);
void pauseMusic(void);
void unpauseMusic(void);
void stopMusic(void);
@@ -115,8 +110,6 @@ public:
void muteSpeech(bool mute);
bool isSpeechMute(void);
- void setSpeechVolume(uint vol);
- uint8 getSpeechVolume(void);
void pauseSpeech(void);
void unpauseSpeech(void);
int32 stopSpeech(void);
@@ -127,8 +120,6 @@ public:
void muteFx(bool mute);
bool isFxMute(void);
- uint8 getFxVolume(void);
- void setFxVolume(uint vol);
int32 setFxIdVolumePan(int32 id, uint8 vol, int8 pan);
int32 setFxIdVolume(int32 id, uint8 vol);
void pauseFx(void);
diff --git a/sword2/sword2.cpp b/sword2/sword2.cpp
index 303afb357f..e9989db403 100644
--- a/sword2/sword2.cpp
+++ b/sword2/sword2.cpp
@@ -252,11 +252,9 @@ int Sword2Engine::init(GameDetector &detector) {
if (!_mixer->isReady())
warning("Sound initialization failed");
- // We have our own volume settings panel, so don't let ScummVM's mixer
- // soften the sound in any way.
-
- _mixer->setVolumeForSoundType(SoundMixer::kSFXAudioDataType, 256);
- _mixer->setVolumeForSoundType(SoundMixer::kMusicAudioDataType, 256);
+ _mixer->setVolumeForSoundType(SoundMixer::kMusicAudioDataType, ConfMan.getInt("music_volume"));
+ _mixer->setVolumeForSoundType(SoundMixer::kSpeechAudioDataType, ConfMan.getInt("speech_volume"));
+ _mixer->setVolumeForSoundType(SoundMixer::kSFXAudioDataType, ConfMan.getInt("sfx_volume"));
// During normal gameplay, we care neither about mouse button releases
// nor the scroll wheel.