From 3d0ef8c6e1f7f21605fae2a510f7f91759851e16 Mon Sep 17 00:00:00 2001 From: Jamie Bainbridge Date: Wed, 16 Apr 2025 01:05:42 +1000 Subject: [PATCH] SDL audio: Add config slider for audio samples As described on Issue #12705 several users have problems with audio popping, crackling, and distorion with different sample values. Previous commit ece6edf reduced default samples from 1024 to 256 but there does not seem to be an ideal value for all platforms. Make the option configurable in Audio Backend Settings. Signed-off-by: Jamie Bainbridge --- Core/Config.cpp | 1 + Core/Config.h | 1 + Core/ConfigValues.h | 2 ++ Qt/QtMain.cpp | 2 +- SDL/SDLMain.cpp | 2 +- UI/GameSettingsScreen.cpp | 2 ++ 6 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index a264fef029..ae0f4af587 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -769,6 +769,7 @@ static const ConfigSetting soundSettings[] = { ConfigSetting("Enable", &g_Config.bEnableSound, true, CfgFlag::PER_GAME), ConfigSetting("AudioBackend", &g_Config.iAudioBackend, 0, CfgFlag::PER_GAME), ConfigSetting("ExtraAudioBuffering", &g_Config.bExtraAudioBuffering, false, CfgFlag::DEFAULT), + ConfigSetting("AudioSamples", &g_Config.iAudioSamples, 256, CfgFlag::DEFAULT), // Legacy volume settings, these get auto upgraded through default handlers on the new settings. NOTE: Must be before the new ones in the order here. // The default settings here are still relevant, they will get propagated into the new ones. diff --git a/Core/Config.h b/Core/Config.h index 27a88251e0..8260540653 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -286,6 +286,7 @@ public: // Sound bool bEnableSound; int iAudioBackend; + int iAudioSamples; // Legacy volume settings, 0-10. These get auto-upgraded and should not be used. int iLegacyGameVolume; diff --git a/Core/ConfigValues.h b/Core/ConfigValues.h index 6f48e61055..fe4e7efc5f 100644 --- a/Core/ConfigValues.h +++ b/Core/ConfigValues.h @@ -32,6 +32,8 @@ constexpr int PSP_DEFAULT_FIRMWARE = 660; constexpr int VOLUME_OFF = 0; constexpr int VOLUME_FULL = 10; constexpr int VOLUMEHI_FULL = 100; // for newer volume params. will convert them all later +constexpr int AUDIOSAMPLES_MIN = 0; +constexpr int AUDIOSAMPLES_MAX = 2048; // This matches exactly the old shift-based curve. float Volume10ToMultiplier(int volume); diff --git a/Qt/QtMain.cpp b/Qt/QtMain.cpp index f572587a7c..102ed01af2 100644 --- a/Qt/QtMain.cpp +++ b/Qt/QtMain.cpp @@ -87,7 +87,7 @@ static void InitSDLAudioDevice() { fmt.freq = 44100; fmt.format = AUDIO_S16; fmt.channels = 2; - fmt.samples = 256; + fmt.samples = g_Config.iAudioSamples; fmt.callback = &mixaudio; fmt.userdata = nullptr; diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index 75fb4fbbde..349db10b9f 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -146,7 +146,7 @@ static void InitSDLAudioDevice(const std::string &name = "") { fmt.freq = g_sampleRate; fmt.format = AUDIO_S16; fmt.channels = 2; - fmt.samples = 256; + fmt.samples = g_Config.iAudioSamples; fmt.callback = &sdl_mixaudio_callback; fmt.userdata = nullptr; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index f96341b339..5c18117679 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -715,6 +715,8 @@ void GameSettingsScreen::CreateAudioSettings(UI::ViewGroup *audioSettings) { PopupMultiChoiceDynamic *MicChoice = audioSettings->Add(new PopupMultiChoiceDynamic(&g_Config.sMicDevice, a->T("Microphone Device"), micList, I18NCat::NONE, screenManager())); MicChoice->OnChoice.Handle(this, &GameSettingsScreen::OnMicDeviceChange); } + + PopupSliderChoice *audioSamples = audioSettings->Add(new PopupSliderChoice(&g_Config.iAudioSamples, AUDIOSAMPLES_MIN, AUDIOSAMPLES_MAX, 256, a->T("Audio Samples"), screenManager())); } void GameSettingsScreen::CreateControlsSettings(UI::ViewGroup *controlsSettings) {