Skip to content

Volume control UI changes, part 2 #19971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Upgrade reverb volume to the new format
  • Loading branch information
hrydgard committed Feb 12, 2025
commit 62e01d37a5f907f5351f69de5c8ee0fff102e99d
8 changes: 7 additions & 1 deletion Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
5 changes: 3 additions & 2 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,15 @@ struct Config {
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
Expand Down
2 changes: 1 addition & 1 deletion Core/HW/SasAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 8 additions & 6 deletions Core/HW/SasReverb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class BufferWrapper {
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) {
Expand All @@ -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_];
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions Core/HW/SasReverb.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SasReverb {

// 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 {
Expand All @@ -41,4 +41,4 @@ class SasReverb {
int16_t *workspace_;
int preset_;
int pos_;
};
};
2 changes: 1 addition & 1 deletion UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down