From 62e01d37a5f907f5351f69de5c8ee0fff102e99d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 12 Feb 2025 10:09:37 -0600 Subject: [PATCH] Upgrade reverb volume to the new format --- Core/Config.cpp | 8 +++++++- Core/Config.h | 5 +++-- Core/HW/SasAudio.cpp | 2 +- Core/HW/SasReverb.cpp | 14 ++++++++------ Core/HW/SasReverb.h | 4 ++-- UI/GameSettingsScreen.cpp | 2 +- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 38fe0bd669..bc605badc5 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -754,16 +754,22 @@ static int DefaultGameVolume() { return LegacyVolumeToNewVolume(g_Config.iLegacyGameVolume, 100); } +static int DefaultReverbVolume() { + return LegacyVolumeToNewVolume(g_Config.iLegacyReverbVolume, 200); +} + 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), // 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. ConfigSetting("GlobalVolume", &g_Config.iLegacyGameVolume, VOLUME_FULL, CfgFlag::PER_GAME | CfgFlag::DONT_SAVE), + ConfigSetting("ReverbVolume", &g_Config.iLegacyReverbVolume, VOLUME_FULL, CfgFlag::PER_GAME | CfgFlag::DONT_SAVE), ConfigSetting("GameVolume", &g_Config.iGameVolume, &DefaultGameVolume, CfgFlag::PER_GAME), - ConfigSetting("ReverbVolume", &g_Config.iReverbVolume, VOLUME_FULL, CfgFlag::PER_GAME), + ConfigSetting("ReverbRelativeVolume", &g_Config.iReverbVolume, &DefaultReverbVolume, CfgFlag::PER_GAME), ConfigSetting("AltSpeedRelativeVolume", &g_Config.iAltSpeedVolume, VOLUMEHI_FULL, CfgFlag::PER_GAME), ConfigSetting("AchievementSoundVolume", &g_Config.iAchievementSoundVolume, 6, CfgFlag::PER_GAME), ConfigSetting("UIVolume", &g_Config.iUIVolume, 70, CfgFlag::DEFAULT), diff --git a/Core/Config.h b/Core/Config.h index a82c6f8e48..2f9465511f 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -280,14 +280,15 @@ public: bool bEnableSound; int iAudioBackend; - // Volume settings, 0-10 + // Legacy volume settings, 0-10. These get auto-upgraded and should not be used. int iLegacyGameVolume; - int iReverbVolume; + int iLegacyReverbVolume; int iAltSpeedVolume; int iAchievementSoundVolume; // Newer volume settings, 0-100 int iGameVolume; + int iReverbVolume; int iUIVolume; bool bExtraAudioBuffering; // For bluetooth diff --git a/Core/HW/SasAudio.cpp b/Core/HW/SasAudio.cpp index 81b9132b8f..081469c1ef 100644 --- a/Core/HW/SasAudio.cpp +++ b/Core/HW/SasAudio.cpp @@ -729,7 +729,7 @@ void SasInstance::ApplyWaveformEffect() { } // Volume max is 0x1000, while our factor is up to 0x8000. Shifting left by 3 fixes that. - reverb_.ProcessReverb(sendBufferProcessed, sendBufferDownsampled, grainSize / 2, waveformEffect.leftVol << 3, waveformEffect.rightVol << 3); + reverb_.ProcessReverb(sendBufferProcessed, sendBufferDownsampled, grainSize / 2, (uint16_t)(waveformEffect.leftVol << 3), (uint16_t)(waveformEffect.rightVol << 3)); } void SasInstance::DoState(PointerWrap &p) { diff --git a/Core/HW/SasReverb.cpp b/Core/HW/SasReverb.cpp index c67de0abdd..090cb5667b 100644 --- a/Core/HW/SasReverb.cpp +++ b/Core/HW/SasReverb.cpp @@ -207,7 +207,7 @@ private: int size_; }; -void SasReverb::ProcessReverb(int16_t *output, const int16_t *input, size_t inputSize, uint16_t volLeft, uint16_t volRight) { +void SasReverb::ProcessReverb(int16_t *output, const int16_t *input, size_t inputSize, int volLeft, int volRight) { // This means replicate the input signal in the processed buffer. // Can also be used to verify that the error is in here... if (preset_ == -1) { @@ -221,13 +221,15 @@ void SasReverb::ProcessReverb(int16_t *output, const int16_t *input, size_t inpu return; } - const uint8_t reverbVolume = Clamp(g_Config.iReverbVolume, 0, 25); + const float reverbVolumeMultiplier = Volume100ToMultiplier(g_Config.iReverbVolume); // Standard volume is 10, which pairs with a normal shift of 15. - const uint8_t finalShift = 25 - reverbVolume; - if (reverbVolume == 0) { + if (reverbVolumeMultiplier <= 0.0f) { // Force to zero output, which is not the same as "Off." memset(output, 0, inputSize * 4); return; + } else { + volLeft *= reverbVolumeMultiplier; + volRight *= reverbVolumeMultiplier; } const SasReverbData &d = presets[preset_]; @@ -266,8 +268,8 @@ void SasReverb::ProcessReverb(int16_t *output, const int16_t *input, size_t inpu b[d.mRAPF2] = clamp_s16(Rout - (d.vAPF2*b[(d.mRAPF2 - d.dAPF2)] >> 15)); Rout = b[(d.mRAPF2 - d.dAPF2)] + (b[d.mRAPF2] * d.vAPF2 >> 15); // ___Output to Mixer(Output volume multiplied with input from APF2)___________ - output[i * 4 + 0] = clamp_s16((Lout * volLeft) >> finalShift); - output[i * 4 + 1] = clamp_s16((Rout * volRight) >> finalShift); + output[i * 4 + 0] = clamp_s16((Lout * volLeft) >> 15); + output[i * 4 + 1] = clamp_s16((Rout * volRight) >> 15); output[i * 4 + 2] = 0; output[i * 4 + 3] = 0; diff --git a/Core/HW/SasReverb.h b/Core/HW/SasReverb.h index da0fd5f7f9..f34074940b 100644 --- a/Core/HW/SasReverb.h +++ b/Core/HW/SasReverb.h @@ -31,7 +31,7 @@ public: // Input should be a mixdown of all the channels that have reverb enabled, at 22khz. // Output is written back at 44khz. - void ProcessReverb(int16_t *output, const int16_t *input, size_t inputSize, uint16_t volLeft, uint16_t volRight); + void ProcessReverb(int16_t *output, const int16_t *input, size_t inputSize, int volLeft, int volRight); private: enum { @@ -41,4 +41,4 @@ private: int16_t *workspace_; int preset_; int pos_; -}; \ No newline at end of file +}; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 8f941b11af..0999ba8630 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -660,7 +660,7 @@ void GameSettingsScreen::CreateAudioSettings(UI::ViewGroup *audioSettings) { volume->SetEnabledPtr(&g_Config.bEnableSound); volume->SetZeroLabel(a->T("Mute")); - PopupSliderChoice *reverbVolume = audioSettings->Add(new PopupSliderChoice(&g_Config.iReverbVolume, VOLUME_OFF, 2 * VOLUME_FULL, VOLUME_FULL, a->T("Reverb volume"), screenManager())); + PopupSliderChoice *reverbVolume = audioSettings->Add(new PopupSliderChoice(&g_Config.iReverbVolume, VOLUME_OFF, 2 * VOLUMEHI_FULL, VOLUMEHI_FULL, a->T("Reverb volume"), screenManager())); reverbVolume->SetEnabledPtr(&g_Config.bEnableSound); reverbVolume->SetZeroLabel(a->T("Disabled"));