aboutsummaryrefslogtreecommitdiff
path: root/engines/wintermute/base/sound/base_sound_manager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/wintermute/base/sound/base_sound_manager.cpp')
-rw-r--r--engines/wintermute/base/sound/base_sound_manager.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/engines/wintermute/base/sound/base_sound_manager.cpp b/engines/wintermute/base/sound/base_sound_manager.cpp
index 441793144d..f3e7bfb408 100644
--- a/engines/wintermute/base/sound/base_sound_manager.cpp
+++ b/engines/wintermute/base/sound/base_sound_manager.cpp
@@ -30,7 +30,6 @@
#include "engines/wintermute/base/base_engine.h"
#include "engines/wintermute/utils/path_util.h"
#include "engines/wintermute/utils/string_util.h"
-#include "engines/wintermute/base/base_game.h"
#include "engines/wintermute/base/base_file_manager.h"
#include "engines/wintermute/base/gfx/base_renderer.h"
#include "engines/wintermute/base/sound/base_sound_buffer.h"
@@ -50,6 +49,7 @@ namespace Wintermute {
BaseSoundMgr::BaseSoundMgr(BaseGame *inGame) : BaseClass(inGame) {
_soundAvailable = false;
_volumeMaster = 255;
+ _volumeMasterPercent = 100;
}
@@ -72,7 +72,7 @@ bool BaseSoundMgr::cleanup() {
//////////////////////////////////////////////////////////////////////////
void BaseSoundMgr::saveSettings() {
if (_soundAvailable) {
- ConfMan.setInt("master_volume", _volumeMaster);
+ ConfMan.setInt("master_volume_percent", _volumeMasterPercent);
}
}
@@ -83,7 +83,8 @@ bool BaseSoundMgr::initialize() {
if (!g_system->getMixer()->isReady()) {
return STATUS_FAILED;
}
- _volumeMaster = (ConfMan.hasKey("master_volume") ? ConfMan.getInt("master_volume") : 255);
+ byte volumeMasterPercent = (ConfMan.hasKey("master_volume_percent") ? ConfMan.getInt("master_volume_percent") : 100);
+ setMasterVolumePercent(volumeMasterPercent);
_soundAvailable = true;
return STATUS_OK;
@@ -92,7 +93,7 @@ bool BaseSoundMgr::initialize() {
//////////////////////////////////////////////////////////////////////////
BaseSoundBuffer *BaseSoundMgr::addSound(const Common::String &filename, Audio::Mixer::SoundType type, bool streamed) {
if (!_soundAvailable) {
- return NULL;
+ return nullptr;
}
BaseSoundBuffer *sound;
@@ -112,7 +113,7 @@ BaseSoundBuffer *BaseSoundMgr::addSound(const Common::String &filename, Audio::M
sound = new BaseSoundBuffer(_gameRef);
if (!sound) {
- return NULL;
+ return nullptr;
}
sound->setStreaming(streamed);
@@ -121,9 +122,9 @@ BaseSoundBuffer *BaseSoundMgr::addSound(const Common::String &filename, Audio::M
bool res = sound->loadFromFile(useFilename);
if (DID_FAIL(res)) {
- _gameRef->LOG(res, "Error loading sound '%s'", useFilename.c_str());
+ BaseEngine::LOG(res, "Error loading sound '%s'", useFilename.c_str());
delete sound;
- return NULL;
+ return nullptr;
}
// Make sure the master-volume is applied to the sound.
@@ -134,7 +135,7 @@ BaseSoundBuffer *BaseSoundMgr::addSound(const Common::String &filename, Audio::M
return sound;
- return NULL;
+ return nullptr;
}
//////////////////////////////////////////////////////////////////////////
@@ -217,6 +218,11 @@ byte BaseSoundMgr::getVolumePercent(Audio::Mixer::SoundType type) {
//////////////////////////////////////////////////////////////////////////
bool BaseSoundMgr::setMasterVolume(byte value) {
+ // This function intentionally doesn't touch _volumeMasterPercent,
+ // as that variable keeps track of what the game actually wanted,
+ // and this gives a close approximation, while letting the game
+ // be none the wiser about round-off-errors. This function should thus
+ // ONLY be called by setMasterVolumePercent.
_volumeMaster = value;
for (uint32 i = 0; i < _sounds.size(); i++) {
_sounds[i]->updateVolume();
@@ -226,14 +232,15 @@ bool BaseSoundMgr::setMasterVolume(byte value) {
//////////////////////////////////////////////////////////////////////////
bool BaseSoundMgr::setMasterVolumePercent(byte percent) {
- setMasterVolume(percent * 255 / 100);
+ _volumeMasterPercent = percent;
+ setMasterVolume((int)ceil(percent * 255.0 / 100.0));
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
byte BaseSoundMgr::getMasterVolumePercent() {
- return getMasterVolume() * 100 / 255;
+ return _volumeMasterPercent;
}
//////////////////////////////////////////////////////////////////////////
@@ -272,7 +279,7 @@ bool BaseSoundMgr::resumeAll() {
//////////////////////////////////////////////////////////////////////////
float BaseSoundMgr::posToPan(int x, int y) {
- float relPos = (float)x / ((float)_gameRef->_renderer->_width);
+ float relPos = (float)x / ((float)BaseEngine::getRenderer()->getWidth());
float minPan = -0.7f;
float maxPan = 0.7f;