Merge pull request #14711 from unknownbrackets/reverb-volume

Sas: Add option to control reverb volume
This commit is contained in:
Henrik Rydgård 2021-08-10 13:02:30 +02:00 committed by GitHub
commit d62899efcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 30 additions and 10 deletions

View File

@ -904,7 +904,8 @@ static ConfigSetting soundSettings[] = {
ConfigSetting("Enable", &g_Config.bEnableSound, true, true, true),
ConfigSetting("AudioBackend", &g_Config.iAudioBackend, 0, true, true),
ConfigSetting("ExtraAudioBuffering", &g_Config.bExtraAudioBuffering, false, true, false),
ConfigSetting("GlobalVolume", &g_Config.iGlobalVolume, VOLUME_MAX, true, true),
ConfigSetting("GlobalVolume", &g_Config.iGlobalVolume, VOLUME_FULL, true, true),
ConfigSetting("ReverbVolume", &g_Config.iReverbVolume, VOLUME_FULL, true, true),
ConfigSetting("AltSpeedVolume", &g_Config.iAltSpeedVolume, -1, true, true),
ConfigSetting("AudioDevice", &g_Config.sAudioDevice, "", true, false),
ConfigSetting("AutoAudioDevice", &g_Config.bAutoAudioDevice, true, true, false),

View File

@ -238,6 +238,7 @@ public:
bool bEnableSound;
int iAudioBackend;
int iGlobalVolume;
int iReverbVolume;
int iAltSpeedVolume;
bool bExtraAudioBuffering; // For bluetooth
std::string sAudioDevice;

View File

@ -28,7 +28,7 @@ const int PSP_MODEL_FAT = 0;
const int PSP_MODEL_SLIM = 1;
const int PSP_DEFAULT_FIRMWARE = 660;
static const int8_t VOLUME_OFF = 0;
static const int8_t VOLUME_MAX = 10;
static const int8_t VOLUME_FULL = 10;
enum class CPUCore {
INTERPRETER = 0,

View File

@ -680,7 +680,7 @@ void SasInstance::ApplyWaveformEffect() {
sendBufferDownsampled[i * 2 + 1] = clamp_s16(sendBuffer[i * 4 + 1]);
}
// Volume max is 0x1000, while our factor is up to 0x8000. Shifting right by 3 fixes that.
// 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);
}

View File

@ -18,6 +18,8 @@
#include <cstdint>
#include <cstring>
#include "Common/Math/math_util.h"
#include "Core/Config.h"
#include "Core/HW/SasReverb.h"
#include "Core/Util/AudioFormat.h"
@ -219,6 +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);
// Standard volume is 10, which pairs with a normal shift of 15.
const uint8_t finalShift = 25 - reverbVolume;
if (reverbVolume == 0) {
// Force to zero output, which is not the same as "Off."
memset(output, 0, inputSize * 4);
return;
}
const SasReverbData &d = presets[preset_];
// We put this on the stack instead of in the object to let the compiler optimize better (avoid mem r/w).
@ -255,8 +266,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 >> 15);
output[i * 4 + 1] = clamp_s16(Rout * volRight >> 15);
output[i * 4 + 0] = clamp_s16((Lout * volLeft) >> finalShift);
output[i * 4 + 1] = clamp_s16((Rout * volRight) >> finalShift);
output[i * 4 + 2] = 0;
output[i * 4 + 3] = 0;

View File

@ -149,12 +149,12 @@ inline void ClampBufferToS16WithVolume(s16 *out, const s32 *in, size_t size) {
}
}
if (volume >= VOLUME_MAX) {
if (volume >= VOLUME_FULL) {
ClampBufferToS16<false>(out, in, size, 0);
} else if (volume <= VOLUME_OFF) {
memset(out, 0, size * sizeof(s16));
} else {
ClampBufferToS16<true>(out, in, size, VOLUME_MAX - (s8)volume);
ClampBufferToS16<true>(out, in, size, VOLUME_FULL - (s8)volume);
}
}

View File

@ -609,15 +609,19 @@ void GameSettingsScreen::CreateViews() {
audioSettings->Add(new CheckBox(&g_Config.bEnableSound, a->T("Enable Sound")));
PopupSliderChoice *volume = audioSettings->Add(new PopupSliderChoice(&g_Config.iGlobalVolume, VOLUME_OFF, VOLUME_MAX, a->T("Global volume"), screenManager()));
PopupSliderChoice *volume = audioSettings->Add(new PopupSliderChoice(&g_Config.iGlobalVolume, VOLUME_OFF, VOLUME_FULL, a->T("Global volume"), screenManager()));
volume->SetEnabledPtr(&g_Config.bEnableSound);
volume->SetZeroLabel(a->T("Mute"));
PopupSliderChoice *altVolume = audioSettings->Add(new PopupSliderChoice(&g_Config.iAltSpeedVolume, VOLUME_OFF, VOLUME_MAX, a->T("Alternate speed volume"), screenManager()));
PopupSliderChoice *altVolume = audioSettings->Add(new PopupSliderChoice(&g_Config.iAltSpeedVolume, VOLUME_OFF, VOLUME_FULL, a->T("Alternate speed volume"), screenManager()));
altVolume->SetEnabledPtr(&g_Config.bEnableSound);
altVolume->SetZeroLabel(a->T("Mute"));
altVolume->SetNegativeDisable(a->T("Use global volume"));
PopupSliderChoice *reverbVolume = audioSettings->Add(new PopupSliderChoice(&g_Config.iReverbVolume, VOLUME_OFF, 2 * VOLUME_FULL, a->T("Reverb volume"), screenManager()));
reverbVolume->SetEnabledPtr(&g_Config.bEnableSound);
reverbVolume->SetZeroLabel(a->T("Disabled"));
// Hide the backend selector in UWP builds (we only support XAudio2 there).
#if PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
if (IsVistaOrHigher()) {

View File

@ -405,6 +405,8 @@ int main(int argc, const char* argv[])
g_Config.sMACAddress = "12:34:56:78:9A:BC";
g_Config.iFirmwareVersion = PSP_DEFAULT_FIRMWARE;
g_Config.iPSPModel = PSP_MODEL_SLIM;
g_Config.iGlobalVolume = VOLUME_FULL;
g_Config.iReverbVolume = VOLUME_FULL;
#ifdef _WIN32
g_Config.internalDataDirectory.clear();

View File

@ -420,7 +420,8 @@ void retro_init(void)
// libretro does its own timing, so this should stay CONTINUOUS.
g_Config.iUnthrottleMode = (int)UnthrottleMode::CONTINUOUS;
g_Config.bMemStickInserted = true;
g_Config.iGlobalVolume = VOLUME_MAX - 1;
g_Config.iGlobalVolume = VOLUME_FULL - 1;
g_Config.iReverbVolume = VOLUME_FULL;
g_Config.iAltSpeedVolume = -1;
g_Config.bEnableSound = true;
g_Config.iCwCheatRefreshRate = 60;