Use settings values for Sound settings

macos_ci_fix
elsid 1 year ago
parent fe5dbb7a25
commit a84e412a37
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -55,6 +55,20 @@ namespace
{
value.set(spinBox.value());
}
int toIndex(Settings::HrtfMode value)
{
switch (value)
{
case Settings::HrtfMode::Auto:
return 0;
case Settings::HrtfMode::Disable:
return 1;
case Settings::HrtfMode::Enable:
return 2;
}
return 0;
}
}
Launcher::SettingsPage::SettingsPage(Config::GameSettings& gameSettings, QWidget* parent)
@ -210,11 +224,7 @@ bool Launcher::SettingsPage::loadSettings()
audioDeviceSelectorComboBox->setCurrentIndex(audioDeviceIndex);
}
}
const int hrtfEnabledIndex = Settings::sound().mHrtfEnable;
if (hrtfEnabledIndex >= -1 && hrtfEnabledIndex <= 1)
{
enableHRTFComboBox->setCurrentIndex(hrtfEnabledIndex + 1);
}
enableHRTFComboBox->setCurrentIndex(toIndex(Settings::sound().mHrtfEnable));
const std::string& selectedHRTFProfile = Settings::sound().mHrtf;
if (selectedHRTFProfile.empty() == false)
{
@ -356,7 +366,12 @@ void Launcher::SettingsPage::saveSettings()
else
Settings::sound().mDevice.set({});
Settings::sound().mHrtfEnable.set(enableHRTFComboBox->currentIndex() - 1);
static constexpr std::array<Settings::HrtfMode, 3> hrtfModes{
Settings::HrtfMode::Auto,
Settings::HrtfMode::Disable,
Settings::HrtfMode::Enable,
};
Settings::sound().mHrtfEnable.set(hrtfModes[enableHRTFComboBox->currentIndex()]);
if (hrtfProfileSelectorComboBox->currentIndex() != 0)
Settings::sound().mHrtf.set(hrtfProfileSelectorComboBox->currentText().toStdString());

@ -69,7 +69,7 @@ add_openmw_dir (mwlua
add_openmw_dir (mwsound
soundmanagerimp openal_output ffmpeg_decoder sound sound_buffer sound_decoder sound_output
loudness movieaudiofactory alext efx efx-presets regionsoundselector watersoundupdater volumesettings
loudness movieaudiofactory alext efx efx-presets regionsoundselector watersoundupdater
)
add_openmw_dir (mwworld

@ -6,7 +6,7 @@
#include <components/debug/debuglog.hpp>
#include <components/esm3/loadsoun.hpp>
#include <components/misc/resourcehelpers.hpp>
#include <components/settings/settings.hpp>
#include <components/settings/values.hpp>
#include <components/vfs/pathutil.hpp>
#include <algorithm>
@ -37,11 +37,9 @@ namespace MWSound
SoundBufferPool::SoundBufferPool(Sound_Output& output)
: mOutput(&output)
, mBufferCacheMax(std::max(Settings::Manager::getInt("buffer cache max", "Sound"), 1) * 1024 * 1024)
, mBufferCacheMax(Settings::sound().mBufferCacheMax * 1024 * 1024)
, mBufferCacheMin(
std::min(static_cast<std::size_t>(std::max(Settings::Manager::getInt("buffer cache min", "Sound"), 1))
* 1024 * 1024,
mBufferCacheMax))
std::min(static_cast<std::size_t>(Settings::sound().mBufferCacheMin) * 1024 * 1024, mBufferCacheMax))
{
}

@ -5,6 +5,8 @@
#include <string>
#include <vector>
#include <components/settings/hrtfmode.hpp>
#include "../mwbase/soundmanager.hpp"
namespace MWSound
@ -19,19 +21,14 @@ namespace MWSound
// An opaque handle for the implementation's sound instances.
typedef void* Sound_Instance;
enum class HrtfMode
{
Disable,
Enable,
Auto
};
enum Environment
{
Env_Normal,
Env_Underwater
};
using HrtfMode = Settings::HrtfMode;
class Sound_Output
{
SoundManager& mManager;

@ -10,6 +10,7 @@
#include <components/debug/debuglog.hpp>
#include <components/misc/resourcehelpers.hpp>
#include <components/misc/rng.hpp>
#include <components/settings/values.hpp>
#include <components/vfs/manager.hpp>
#include <components/vfs/pathutil.hpp>
@ -73,6 +74,33 @@ namespace MWSound
return 1.0;
}
// Gets the combined volume settings for the given sound type
float volumeFromType(Type type)
{
float volume = Settings::sound().mMasterVolume;
switch (type)
{
case Type::Sfx:
volume *= Settings::sound().mSfxVolume;
break;
case Type::Voice:
volume *= Settings::sound().mVoiceVolume;
break;
case Type::Foot:
volume *= Settings::sound().mFootstepsVolume;
break;
case Type::Music:
volume *= Settings::sound().mMusicVolume;
break;
case Type::Movie:
case Type::Mask:
break;
}
return volume;
}
}
// For combining PlayMode and Type flags
@ -103,12 +131,7 @@ namespace MWSound
return;
}
const std::string& hrtfname = Settings::Manager::getString("hrtf", "Sound");
int hrtfstate = Settings::Manager::getInt("hrtf enable", "Sound");
HrtfMode hrtfmode = hrtfstate < 0 ? HrtfMode::Auto : hrtfstate > 0 ? HrtfMode::Enable : HrtfMode::Disable;
const std::string& devname = Settings::Manager::getString("device", "Sound");
if (!mOutput->init(devname, hrtfname, hrtfmode))
if (!mOutput->init(Settings::sound().mDevice, Settings::sound().mHrtf, Settings::sound().mHrtfEnable))
{
Log(Debug::Error) << "Failed to initialize audio output, sound disabled";
return;
@ -219,12 +242,6 @@ namespace MWSound
return sound;
}
// Gets the combined volume settings for the given sound type
float SoundManager::volumeFromType(Type type) const
{
return mVolumeSettings.getVolumeFromType(type);
}
void SoundManager::stopMusic()
{
if (mMusic)
@ -1156,8 +1173,6 @@ namespace MWSound
void SoundManager::processChangedSettings(const Settings::CategorySettingVector& settings)
{
mVolumeSettings.update();
if (!mOutput->isInitialized())
return;
mOutput->startUpdate();

@ -16,7 +16,6 @@
#include "regionsoundselector.hpp"
#include "sound_buffer.hpp"
#include "type.hpp"
#include "volumesettings.hpp"
#include "watersoundupdater.hpp"
namespace VFS
@ -57,8 +56,6 @@ namespace MWSound
std::unordered_map<std::string, std::vector<int>> mMusicToPlay; // A list with music files not yet played
std::string mLastPlayedMusic; // The music file that was last played
VolumeSettings mVolumeSettings;
WaterSoundUpdater mWaterSoundUpdater;
SoundBufferPool mSoundBuffers;
@ -144,8 +141,6 @@ namespace MWSound
void updateWaterSound();
void updateMusic(float duration);
float volumeFromType(Type type) const;
enum class WaterSoundAction
{
DoNothing,

@ -1,56 +0,0 @@
#include "volumesettings.hpp"
#include <components/settings/settings.hpp>
#include <algorithm>
namespace MWSound
{
namespace
{
float clamp(float value)
{
return std::clamp(value, 0.f, 1.f);
}
}
VolumeSettings::VolumeSettings()
: mMasterVolume(clamp(Settings::Manager::getFloat("master volume", "Sound")))
, mSFXVolume(clamp(Settings::Manager::getFloat("sfx volume", "Sound")))
, mMusicVolume(clamp(Settings::Manager::getFloat("music volume", "Sound")))
, mVoiceVolume(clamp(Settings::Manager::getFloat("voice volume", "Sound")))
, mFootstepsVolume(clamp(Settings::Manager::getFloat("footsteps volume", "Sound")))
{
}
float VolumeSettings::getVolumeFromType(Type type) const
{
float volume = mMasterVolume;
switch (type)
{
case Type::Sfx:
volume *= mSFXVolume;
break;
case Type::Voice:
volume *= mVoiceVolume;
break;
case Type::Foot:
volume *= mFootstepsVolume;
break;
case Type::Music:
volume *= mMusicVolume;
break;
case Type::Movie:
case Type::Mask:
break;
}
return volume;
}
void VolumeSettings::update()
{
*this = VolumeSettings();
}
}

@ -1,26 +0,0 @@
#ifndef GAME_SOUND_VOLUMESETTINGS_H
#define GAME_SOUND_VOLUMESETTINGS_H
#include "type.hpp"
namespace MWSound
{
class VolumeSettings
{
public:
VolumeSettings();
float getVolumeFromType(Type type) const;
void update();
private:
float mMasterVolume;
float mSFXVolume;
float mMusicVolume;
float mVoiceVolume;
float mFootstepsVolume;
};
}
#endif

@ -1,16 +1,11 @@
#ifndef OPENMW_COMPONENTS_SETTINGS_CATEGORIES_SOUND_H
#define OPENMW_COMPONENTS_SETTINGS_CATEGORIES_SOUND_H
#include "components/settings/hrtfmode.hpp"
#include "components/settings/sanitizerimpl.hpp"
#include "components/settings/settingvalue.hpp"
#include <osg/Math>
#include <osg/Vec2f>
#include <osg/Vec3f>
#include <cstdint>
#include <string>
#include <string_view>
namespace Settings
{
@ -26,7 +21,7 @@ namespace Settings
SettingValue<float> mVoiceVolume{ mIndex, "Sound", "voice volume", makeClampSanitizerFloat(0, 1) };
SettingValue<int> mBufferCacheMin{ mIndex, "Sound", "buffer cache min", makeMaxSanitizerInt(1) };
SettingValue<int> mBufferCacheMax{ mIndex, "Sound", "buffer cache max", makeMaxSanitizerInt(1) };
SettingValue<int> mHrtfEnable{ mIndex, "Sound", "hrtf enable", makeEnumSanitizerInt({ -1, 0, 1 }) };
SettingValue<HrtfMode> mHrtfEnable{ mIndex, "Sound", "hrtf enable" };
SettingValue<std::string> mHrtf{ mIndex, "Sound", "hrtf" };
};
}

@ -0,0 +1,14 @@
#ifndef OPENMW_COMPONENTS_SETTINGS_HRTFMODE_H
#define OPENMW_COMPONENTS_SETTINGS_HRTFMODE_H
namespace Settings
{
enum class HrtfMode
{
Disable,
Enable,
Auto,
};
}
#endif

@ -103,6 +103,22 @@ namespace Settings
throw std::invalid_argument("Invalid LightingMethod value: " + std::to_string(static_cast<int>(value)));
}
int toInt(HrtfMode value)
{
switch (value)
{
case HrtfMode::Auto:
return -1;
case HrtfMode::Disable:
return 0;
case HrtfMode::Enable:
return 1;
}
Log(Debug::Warning) << "Invalid HRTF mode value: " << static_cast<int>(value) << ", fallback to auto (-1)";
return -1;
}
}
CategorySettingValueMap Manager::mDefaultSettings = CategorySettingValueMap();
@ -480,6 +496,11 @@ namespace Settings
setString(setting, category, toString(value));
}
void Manager::set(std::string_view setting, std::string_view category, HrtfMode value)
{
setInt(setting, category, toInt(value));
}
void Manager::recordInit(std::string_view setting, std::string_view category)
{
sInitialized.emplace(category, setting);

@ -3,6 +3,7 @@
#include "categories.hpp"
#include "gyroscopeaxis.hpp"
#include "hrtfmode.hpp"
#include "navmeshrendermode.hpp"
#include <components/detournavigator/collisionshapetype.hpp>
@ -112,6 +113,7 @@ namespace Settings
static void set(std::string_view setting, std::string_view category, const std::vector<std::string>& value);
static void set(std::string_view setting, std::string_view category, const MyGUI::Colour& value);
static void set(std::string_view setting, std::string_view category, SceneUtil::LightingMethod value);
static void set(std::string_view setting, std::string_view category, HrtfMode value);
private:
static std::set<std::pair<std::string_view, std::string_view>> sInitialized;
@ -226,6 +228,17 @@ namespace Settings
{
return parseLightingMethod(getString(setting, category));
}
template <>
inline HrtfMode Manager::getImpl<HrtfMode>(std::string_view setting, std::string_view category)
{
const int value = getInt(setting, category);
if (value < 0)
return HrtfMode::Auto;
if (value > 0)
return HrtfMode::Enable;
return HrtfMode::Disable;
}
}
#endif // COMPONENTS_SETTINGS_H

@ -41,6 +41,7 @@ namespace Settings
GyroscopeAxis,
NavMeshRenderMode,
LightingMethod,
HrtfMode,
};
template <class T>
@ -154,6 +155,12 @@ namespace Settings
return SettingValueType::LightingMethod;
}
template <>
inline constexpr SettingValueType getSettingValueType<HrtfMode>()
{
return SettingValueType::HrtfMode;
}
inline constexpr std::string_view getSettingValueTypeName(SettingValueType type)
{
switch (type)
@ -194,6 +201,8 @@ namespace Settings
return "navmesh render mode";
case SettingValueType::LightingMethod:
return "lighting method";
case SettingValueType::HrtfMode:
return "hrtf mode";
}
return "unsupported";
}

Loading…
Cancel
Save