mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-01 23:12:35 +00:00
[QoL] Audio Volume & Mute Audio
This commit is contained in:
parent
69777e2ffa
commit
d54696b126
@ -71,6 +71,8 @@ static bool isFpsColor = true;
|
|||||||
static bool isSeparateLogFilesEnabled = false;
|
static bool isSeparateLogFilesEnabled = false;
|
||||||
static s16 cursorState = HideCursorState::Idle;
|
static s16 cursorState = HideCursorState::Idle;
|
||||||
static int cursorHideTimeout = 5; // 5 seconds (default)
|
static int cursorHideTimeout = 5; // 5 seconds (default)
|
||||||
|
static bool muteVolume = false;
|
||||||
|
static int audioVolume = 100;
|
||||||
static double trophyNotificationDuration = 6.0;
|
static double trophyNotificationDuration = 6.0;
|
||||||
static bool useUnifiedInputConfig = true;
|
static bool useUnifiedInputConfig = true;
|
||||||
static bool overrideControllerColor = false;
|
static bool overrideControllerColor = false;
|
||||||
@ -211,6 +213,14 @@ int getCursorHideTimeout() {
|
|||||||
return cursorHideTimeout;
|
return cursorHideTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool muteAudio() {
|
||||||
|
return muteVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getAudioVolume() {
|
||||||
|
return audioVolume;
|
||||||
|
}
|
||||||
|
|
||||||
double getTrophyNotificationDuration() {
|
double getTrophyNotificationDuration() {
|
||||||
return trophyNotificationDuration;
|
return trophyNotificationDuration;
|
||||||
}
|
}
|
||||||
@ -790,6 +800,13 @@ void load(const std::filesystem::path& path) {
|
|||||||
useUnifiedInputConfig = toml::find_or<bool>(input, "useUnifiedInputConfig", true);
|
useUnifiedInputConfig = toml::find_or<bool>(input, "useUnifiedInputConfig", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.contains("Audio")) {
|
||||||
|
const toml::value& audio = data.at("Audio");
|
||||||
|
|
||||||
|
muteVolume = toml::find_or<bool>(audio, "muteAudio", false);
|
||||||
|
audioVolume = toml::find_or<int>(audio, "audioVolume", 100);
|
||||||
|
}
|
||||||
|
|
||||||
if (data.contains("GPU")) {
|
if (data.contains("GPU")) {
|
||||||
const toml::value& gpu = data.at("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) {
|
void sortTomlSections(toml::ordered_value& data) {
|
||||||
toml::ordered_value ordered_data;
|
toml::ordered_value ordered_data;
|
||||||
std::vector<std::string> section_order = {"General", "Input", "GPU", "Vulkan",
|
std::vector<std::string> section_order = {"General", "Input", "Audio", "GPU", "Vulkan",
|
||||||
"Debug", "Keys", "GUI", "Settings"};
|
"Debug", "Keys", "GUI", "Settings"};
|
||||||
|
|
||||||
for (const auto& section : section_order) {
|
for (const auto& section : section_order) {
|
||||||
if (data.contains(section)) {
|
if (data.contains(section)) {
|
||||||
@ -976,6 +993,8 @@ void save(const std::filesystem::path& path) {
|
|||||||
data["Input"]["specialPadClass"] = specialPadClass;
|
data["Input"]["specialPadClass"] = specialPadClass;
|
||||||
data["Input"]["isMotionControlsEnabled"] = isMotionControlsEnabled;
|
data["Input"]["isMotionControlsEnabled"] = isMotionControlsEnabled;
|
||||||
data["Input"]["useUnifiedInputConfig"] = useUnifiedInputConfig;
|
data["Input"]["useUnifiedInputConfig"] = useUnifiedInputConfig;
|
||||||
|
data["Audio"]["muteAudio"] = muteVolume;
|
||||||
|
data["Audio"]["audioVolume"] = audioVolume;
|
||||||
data["GPU"]["screenWidth"] = screenWidth;
|
data["GPU"]["screenWidth"] = screenWidth;
|
||||||
data["GPU"]["screenHeight"] = screenHeight;
|
data["GPU"]["screenHeight"] = screenHeight;
|
||||||
data["GPU"]["nullGpu"] = isNullGpu;
|
data["GPU"]["nullGpu"] = isNullGpu;
|
||||||
|
@ -60,6 +60,9 @@ void SetOverrideControllerColor(bool enable);
|
|||||||
int* GetControllerCustomColor();
|
int* GetControllerCustomColor();
|
||||||
void SetControllerCustomColor(int r, int b, int g);
|
void SetControllerCustomColor(int r, int b, int g);
|
||||||
|
|
||||||
|
bool muteAudio();
|
||||||
|
int getAudioVolume();
|
||||||
|
|
||||||
u32 getScreenWidth();
|
u32 getScreenWidth();
|
||||||
u32 getScreenHeight();
|
u32 getScreenHeight();
|
||||||
s32 getGpuId();
|
s32 getGpuId();
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <SDL3/SDL_audio.h>
|
#include <SDL3/SDL_audio.h>
|
||||||
#include <SDL3/SDL_hints.h>
|
#include <SDL3/SDL_hints.h>
|
||||||
|
|
||||||
|
#include "common/config.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "core/libraries/audio/audioout.h"
|
#include "core/libraries/audio/audioout.h"
|
||||||
#include "core/libraries/audio/audioout_backend.h"
|
#include "core/libraries/audio/audioout_backend.h"
|
||||||
@ -76,8 +77,18 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// SDL does not have per-channel volumes, for now just take the maximum of the channels.
|
// 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);
|
// const auto vol = *std::ranges::max_element(ch_volumes);
|
||||||
if (!SDL_SetAudioStreamGain(stream, static_cast<float>(vol) / SCE_AUDIO_OUT_VOLUME_0DB)) {
|
|
||||||
|
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: {}",
|
LOG_WARNING(Lib_AudioOut, "Failed to change SDL audio stream volume: {}",
|
||||||
SDL_GetError());
|
SDL_GetError());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user