diff --git a/src/common/config.cpp b/src/common/config.cpp index 111c0cfa9..f4b0b5a5f 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -71,6 +71,8 @@ static bool isFpsColor = true; static bool isSeparateLogFilesEnabled = false; static s16 cursorState = HideCursorState::Idle; static int cursorHideTimeout = 5; // 5 seconds (default) +static bool muteVolume = false; +static int audioVolume = 100; static double trophyNotificationDuration = 6.0; static bool useUnifiedInputConfig = true; static bool overrideControllerColor = false; @@ -211,6 +213,14 @@ int getCursorHideTimeout() { return cursorHideTimeout; } +bool muteAudio() { + return muteVolume; +} + +int getAudioVolume() { + return audioVolume; +} + double getTrophyNotificationDuration() { return trophyNotificationDuration; } @@ -790,6 +800,13 @@ void load(const std::filesystem::path& path) { useUnifiedInputConfig = toml::find_or(input, "useUnifiedInputConfig", true); } + if (data.contains("Audio")) { + const toml::value& audio = data.at("Audio"); + + muteVolume = toml::find_or(audio, "muteAudio", false); + audioVolume = toml::find_or(audio, "audioVolume", 100); + } + if (data.contains("GPU")) { const toml::value& gpu = data.at("GPU"); @@ -900,8 +917,8 @@ void load(const std::filesystem::path& path) { void sortTomlSections(toml::ordered_value& data) { toml::ordered_value ordered_data; - std::vector section_order = {"General", "Input", "GPU", "Vulkan", - "Debug", "Keys", "GUI", "Settings"}; + std::vector section_order = {"General", "Input", "Audio", "GPU", "Vulkan", + "Debug", "Keys", "GUI", "Settings"}; for (const auto& section : section_order) { if (data.contains(section)) { @@ -976,6 +993,8 @@ void save(const std::filesystem::path& path) { data["Input"]["specialPadClass"] = specialPadClass; data["Input"]["isMotionControlsEnabled"] = isMotionControlsEnabled; data["Input"]["useUnifiedInputConfig"] = useUnifiedInputConfig; + data["Audio"]["muteAudio"] = muteVolume; + data["Audio"]["audioVolume"] = audioVolume; data["GPU"]["screenWidth"] = screenWidth; data["GPU"]["screenHeight"] = screenHeight; data["GPU"]["nullGpu"] = isNullGpu; diff --git a/src/common/config.h b/src/common/config.h index aba23621c..45c473b4b 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -60,6 +60,9 @@ void SetOverrideControllerColor(bool enable); int* GetControllerCustomColor(); void SetControllerCustomColor(int r, int b, int g); +bool muteAudio(); +int getAudioVolume(); + u32 getScreenWidth(); u32 getScreenHeight(); s32 getGpuId(); diff --git a/src/core/libraries/audio/sdl_audio.cpp b/src/core/libraries/audio/sdl_audio.cpp index 9aee2b447..a64cb31a5 100644 --- a/src/core/libraries/audio/sdl_audio.cpp +++ b/src/core/libraries/audio/sdl_audio.cpp @@ -5,6 +5,7 @@ #include #include +#include "common/config.h" #include "common/logging/log.h" #include "core/libraries/audio/audioout.h" #include "core/libraries/audio/audioout_backend.h" @@ -76,8 +77,18 @@ public: return; } // SDL does not have per-channel volumes, for now just take the maximum of the channels. - const auto vol = *std::ranges::max_element(ch_volumes); - if (!SDL_SetAudioStreamGain(stream, static_cast(vol) / SCE_AUDIO_OUT_VOLUME_0DB)) { + // const auto vol = *std::ranges::max_element(ch_volumes); + + float volume = 0; + if (Config::muteAudio()) { + volume = 0; + } else { + // For the user the volume is from 0 to 100 but for us it is from 0 to 10000. + // So let's multiply by 100. + volume = Config::getAudioVolume() * 100; + } + + if (!SDL_SetAudioStreamGain(stream, volume / SCE_AUDIO_OUT_VOLUME_0DB)) { LOG_WARNING(Lib_AudioOut, "Failed to change SDL audio stream volume: {}", SDL_GetError()); }