Skip to content

Commit 1158ddd

Browse files
authored
Merge pull request #19969 from hrydgard/volume-control-cleanup
Volume control UI changes, part 1
2 parents d58d193 + d200d80 commit 1158ddd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+225
-231
lines changed

Common/System/System.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ void System_AudioClear();
302302
// These samples really have 16 bits of value, but can be a little out of range.
303303
// This is for pushing rate-controlled 44khz audio from emulation.
304304
// If you push a little too fast, we'll pitch up to a limit, for example.
305-
// Volume is a 12-bit multiplier.
306-
void System_AudioPushSamples(const int32_t *audio, int numSamples, int volume);
305+
// Volume is a unit-range multiplier.
306+
void System_AudioPushSamples(const int32_t *audio, int numSamples, float volume);
307307

308308
inline void System_AudioResetStatCounters() {
309309
return System_AudioGetDebugStats(nullptr, 0);

Common/UI/PopupScreens.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void PopupSliderChoiceFloat::SetFormat(std::string_view fmt) {
202202
EventReturn PopupSliderChoice::HandleClick(EventParams &e) {
203203
restoreFocus_ = HasFocus();
204204

205-
SliderPopupScreen *popupScreen = new SliderPopupScreen(value_, minValue_, maxValue_, defaultValue_, ChopTitle(text_), step_, units_);
205+
SliderPopupScreen *popupScreen = new SliderPopupScreen(value_, minValue_, maxValue_, defaultValue_, ChopTitle(text_), step_, units_, liveUpdate_);
206206
if (!negativeLabel_.empty())
207207
popupScreen->SetNegativeDisable(negativeLabel_);
208208
popupScreen->OnChange.Handle(this, &PopupSliderChoice::HandleChange);
@@ -346,6 +346,13 @@ void SliderPopupScreen::UpdateTextBox() {
346346
char temp[128];
347347
snprintf(temp, sizeof(temp), "%d", sliderValue_);
348348
edit_->SetText(temp);
349+
if (liveUpdate_ && *value_ != sliderValue_) {
350+
*value_ = sliderValue_;
351+
EventParams e{};
352+
e.v = nullptr;
353+
e.a = *value_;
354+
OnChange.Trigger(e);
355+
}
349356
}
350357

351358
void SliderPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {

Common/UI/PopupScreens.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ class MessagePopupScreen : public PopupScreen {
8080

8181
class SliderPopupScreen : public PopupScreen {
8282
public:
83-
SliderPopupScreen(int *value, int minValue, int maxValue, int defaultValue, std::string_view title, int step = 1, std::string_view units = "")
84-
: PopupScreen(title, "OK", "Cancel"), units_(units), value_(value), minValue_(minValue), maxValue_(maxValue), defaultValue_(defaultValue), step_(step) {}
83+
SliderPopupScreen(int *value, int minValue, int maxValue, int defaultValue, std::string_view title, int step, std::string_view units, bool liveUpdate)
84+
: PopupScreen(title, "OK", "Cancel"), units_(units), value_(value), minValue_(minValue), maxValue_(maxValue), defaultValue_(defaultValue), step_(step), liveUpdate_(liveUpdate) {}
8585
void CreatePopupContents(ViewGroup *parent) override;
8686

8787
void SetNegativeDisable(const std::string &str) {
@@ -110,6 +110,7 @@ class SliderPopupScreen : public PopupScreen {
110110
int maxValue_;
111111
int defaultValue_;
112112
int step_;
113+
bool liveUpdate_;
113114
bool changing_ = false;
114115
bool disabled_ = false;
115116
};
@@ -303,6 +304,9 @@ class PopupSliderChoice : public AbstractChoiceWithValueDisplay {
303304
void SetZeroLabel(std::string_view str) {
304305
zeroLabel_ = str;
305306
}
307+
void SetLiveUpdate(bool update) {
308+
liveUpdate_ = update;
309+
}
306310
void SetNegativeDisable(std::string_view str) {
307311
negativeLabel_ = str;
308312
}
@@ -327,6 +331,7 @@ class PopupSliderChoice : public AbstractChoiceWithValueDisplay {
327331
std::string units_;
328332
ScreenManager *screenManager_;
329333
bool restoreFocus_ = false;
334+
bool liveUpdate_ = false;
330335
};
331336

332337
class PopupSliderChoiceFloat : public AbstractChoiceWithValueDisplay {

Common/UI/Root.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ static View *focusedView;
1717
static bool focusMovementEnabled;
1818
bool focusForced;
1919

20-
static std::function<void(UISound, float)> soundCallback;
21-
static bool soundEnabled = true;
20+
static std::function<void(UISound)> soundCallback;
2221

2322
struct DispatchQueueItem {
2423
Event *e;
@@ -126,17 +125,13 @@ static void MoveFocus(ViewGroup *root, FocusDirection direction) {
126125
}
127126
}
128127

129-
void SetSoundEnabled(bool enabled) {
130-
soundEnabled = enabled;
131-
}
132-
133-
void SetSoundCallback(std::function<void(UISound, float)> func) {
128+
void SetSoundCallback(std::function<void(UISound)> func) {
134129
soundCallback = func;
135130
}
136131

137-
void PlayUISound(UISound sound, float volume) {
138-
if (soundEnabled && soundCallback) {
139-
soundCallback(sound, volume);
132+
void PlayUISound(UISound sound) {
133+
if (soundCallback) {
134+
soundCallback(sound);
140135
}
141136
}
142137

Common/UI/Root.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ enum class UISound {
4848
COUNT,
4949
};
5050

51-
void SetSoundEnabled(bool enabled);
52-
void SetSoundCallback(std::function<void(UISound, float)> func);
51+
void SetSoundCallback(std::function<void(UISound)> func);
5352

5453
// This is only meant for actual UI navigation sound, not achievements.
5554
// Call directly into the player for other UI effects.
56-
void PlayUISound(UISound sound, float volume = 0.25f);
55+
void PlayUISound(UISound sound);
5756

5857
} // namespace UI

Core/Config.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -749,10 +749,13 @@ static const ConfigSetting soundSettings[] = {
749749
ConfigSetting("Enable", &g_Config.bEnableSound, true, CfgFlag::PER_GAME),
750750
ConfigSetting("AudioBackend", &g_Config.iAudioBackend, 0, CfgFlag::PER_GAME),
751751
ConfigSetting("ExtraAudioBuffering", &g_Config.bExtraAudioBuffering, false, CfgFlag::DEFAULT),
752-
ConfigSetting("GlobalVolume", &g_Config.iGlobalVolume, VOLUME_FULL, CfgFlag::PER_GAME),
752+
753+
ConfigSetting("GlobalVolume", &g_Config.iGameVolume, VOLUME_FULL, CfgFlag::PER_GAME),
753754
ConfigSetting("ReverbVolume", &g_Config.iReverbVolume, VOLUME_FULL, CfgFlag::PER_GAME),
754-
ConfigSetting("AltSpeedVolume", &g_Config.iAltSpeedVolume, -1, CfgFlag::PER_GAME),
755+
ConfigSetting("AltSpeedRelativeVolume", &g_Config.iAltSpeedVolume, VOLUMEHI_FULL, CfgFlag::PER_GAME),
755756
ConfigSetting("AchievementSoundVolume", &g_Config.iAchievementSoundVolume, 6, CfgFlag::PER_GAME),
757+
ConfigSetting("UIVolume", &g_Config.iUIVolume, 70, CfgFlag::DEFAULT),
758+
756759
ConfigSetting("AudioDevice", &g_Config.sAudioDevice, "", CfgFlag::DEFAULT),
757760
ConfigSetting("AutoAudioDevice", &g_Config.bAutoAudioDevice, true, CfgFlag::DEFAULT),
758761
ConfigSetting("AudioMixWithOthers", &g_Config.bAudioMixWithOthers, true, CfgFlag::DEFAULT),
@@ -1293,12 +1296,14 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
12931296
vPostShaderNames.push_back(it.second);
12941297
}
12951298

1296-
// Check for an old dpad setting
1297-
Section *control = iniFile.GetOrCreateSection("Control");
1298-
float f;
1299-
control->Get("DPadRadius", &f, 0.0f);
1300-
if (f > 0.0f) {
1301-
ResetControlLayout();
1299+
// Check for an old dpad setting (very obsolete)
1300+
Section *control = iniFile.GetSection("Control");
1301+
if (control) {
1302+
float f;
1303+
control->Get("DPadRadius", &f, 0.0f);
1304+
if (f > 0.0f) {
1305+
ResetControlLayout();
1306+
}
13021307
}
13031308

13041309
// Force JIT setting to a valid value for the current system configuration.
@@ -1485,7 +1490,7 @@ void Config::PostLoadCleanup(bool gameSpecific) {
14851490

14861491
// Automatically silence secondary instances. Could be an option I guess, but meh.
14871492
if (PPSSPP_ID > 1) {
1488-
g_Config.iGlobalVolume = 0;
1493+
g_Config.iGameVolume = 0;
14891494
}
14901495

14911496
// Automatically switch away from deprecated setting value.

Core/Config.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,16 @@ struct Config {
279279
// Sound
280280
bool bEnableSound;
281281
int iAudioBackend;
282-
int iGlobalVolume;
282+
283+
// Volume settings, 0-10
284+
int iGameVolume;
283285
int iReverbVolume;
284286
int iAltSpeedVolume;
285287
int iAchievementSoundVolume;
288+
289+
// Newer volume settings, 0-100
290+
int iUIVolume;
291+
286292
bool bExtraAudioBuffering; // For bluetooth
287293
std::string sAudioDevice;
288294
bool bAutoAudioDevice;

Core/ConfigValues.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#pragma once
1919

2020
#include <cstdint>
21+
#include <cmath>
2122
#include <string>
2223
#ifndef _MSC_VER
2324
#include <strings.h>
@@ -30,6 +31,22 @@ constexpr int PSP_MODEL_SLIM = 1;
3031
constexpr int PSP_DEFAULT_FIRMWARE = 660;
3132
constexpr int VOLUME_OFF = 0;
3233
constexpr int VOLUME_FULL = 10;
34+
constexpr int VOLUMEHI_FULL = 100; // for newer volume params. will convert them all later
35+
36+
// This matches exactly the old shift-based curve.
37+
inline float Volume10ToMultiplier(int volume) {
38+
// Allow muting entirely.
39+
if (volume <= 0) {
40+
return 0.0f;
41+
}
42+
return powf(2.0f, (float)(volume - 10));
43+
}
44+
45+
// NOTE: This is used for new volume parameters.
46+
// It uses a more intuitive-feeling curve.
47+
inline float Volume100ToMultiplier(int volume) {
48+
return powf(volume * 0.01f, 1.75f);
49+
}
3350

3451
struct ConfigTouchPos {
3552
float x;

Core/HLE/__sceAudio.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -414,23 +414,15 @@ void __AudioUpdate(bool resetRecording) {
414414
}
415415

416416
if (g_Config.bEnableSound) {
417-
int vol = g_Config.iGlobalVolume;
417+
float multiplier = Volume10ToMultiplier(std::clamp(g_Config.iGameVolume, 0, VOLUME_FULL));
418418
if (PSP_CoreParameter().fpsLimit != FPSLimit::NORMAL || PSP_CoreParameter().fastForward) {
419419
if (g_Config.iAltSpeedVolume != -1) {
420-
vol = g_Config.iAltSpeedVolume;
420+
// Multiply in the alt speed volume instead of replacing like before.
421+
multiplier *= Volume100ToMultiplier(g_Config.iAltSpeedVolume);
421422
}
422423
}
423424

424-
vol = std::clamp(vol, 0, VOLUME_FULL);
425-
426-
// 12-bit volume. So far this isn't any better than the shift, but stay tuned.
427-
int volume;
428-
if (vol != 0) {
429-
volume = 4096 >> (VOLUME_FULL - vol);
430-
} else {
431-
volume = 0;
432-
}
433-
System_AudioPushSamples(mixBuffer, hwBlockSize, volume);
425+
System_AudioPushSamples(mixBuffer, hwBlockSize, multiplier);
434426

435427
#ifndef MOBILE_DEVICE
436428
if (g_Config.bSaveLoadResetsAVdumping && resetRecording) {

Core/HW/StereoResampler.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ unsigned int StereoResampler::Mix(short* samples, unsigned int numSamples, bool
248248
}
249249

250250
// Executes on the emulator thread, pushing sound into the buffer.
251-
void StereoResampler::PushSamples(const s32 *samples, unsigned int numSamples, int volume) {
251+
void StereoResampler::PushSamples(const s32 *samples, unsigned int numSamples, float multiplier) {
252252
inputSampleCount_ += numSamples;
253253

254254
UpdateBufferSize();
@@ -274,6 +274,9 @@ void StereoResampler::PushSamples(const s32 *samples, unsigned int numSamples, i
274274
return;
275275
}
276276

277+
// 12-bit volume.
278+
int volume = (int)(multiplier * 4096.0f);
279+
277280
// Check if we need to roll over to the start of the buffer during the copy.
278281
unsigned int indexW_left_samples = m_maxBufsize * 2 - (indexW & INDEX_MASK);
279282
if (numSamples * 2 > indexW_left_samples) {

0 commit comments

Comments
 (0)