Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
32 changes: 0 additions & 32 deletions pcsx2-qt/QtHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,38 +879,6 @@ void EmuThread::endCapture()
MTGS::RunOnGSThread(&GSEndCapture);
}

void EmuThread::setAudioOutputVolume(int volume, int fast_forward_volume)
{
if (!isOnEmuThread())
{
QMetaObject::invokeMethod(this, "setAudioOutputVolume", Qt::QueuedConnection, Q_ARG(int, volume),
Q_ARG(int, fast_forward_volume));
return;
}

if (!VMManager::HasValidVM())
return;

EmuConfig.SPU2.OutputVolume = static_cast<u32>(volume);
EmuConfig.SPU2.FastForwardVolume = static_cast<u32>(fast_forward_volume);
SPU2::SetOutputVolume(SPU2::GetResetVolume());
}

void EmuThread::setAudioOutputMuted(bool muted)
{
if (!isOnEmuThread())
{
QMetaObject::invokeMethod(this, "setAudioOutputMuted", Qt::QueuedConnection, Q_ARG(bool, muted));
return;
}

if (!VMManager::HasValidVM())
return;

EmuConfig.SPU2.OutputMuted = muted;
SPU2::SetOutputVolume(SPU2::GetResetVolume());
}

std::optional<WindowInfo> EmuThread::acquireRenderWindow(bool recreate_window)
{
// Check if we're wanting to get exclusive fullscreen. This should be safe to read, since we're going to be calling from the GS thread.
Expand Down
2 changes: 0 additions & 2 deletions pcsx2-qt/QtHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ public Q_SLOTS:
void queueSnapshot(quint32 gsdump_frames);
void beginCapture(const QString& path);
void endCapture();
void setAudioOutputVolume(int volume, int fast_forward_volume);
void setAudioOutputMuted(bool muted);

Q_SIGNALS:
bool messageConfirmed(const QString& title, const QString& message);
Expand Down
36 changes: 18 additions & 18 deletions pcsx2-qt/Settings/AudioSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,21 @@ AudioSettingsWidget::AudioSettingsWidget(SettingsWindow* settings_dialog, QWidge
// for per-game, just use the normal path, since it needs to re-read/apply
if (!dialog()->isPerGameSettings())
{
m_ui.volume->setValue(dialog()->getEffectiveIntValue("SPU2/Output", "OutputVolume", 100));
m_ui.standardVolume->setValue(dialog()->getEffectiveIntValue("SPU2/Output", "StandardVolume", 100));
m_ui.fastForwardVolume->setValue(dialog()->getEffectiveIntValue("SPU2/Output", "FastForwardVolume", 100));
m_ui.muted->setChecked(dialog()->getEffectiveBoolValue("SPU2/Output", "OutputMuted", false));
connect(m_ui.volume, &QSlider::valueChanged, this, &AudioSettingsWidget::onOutputVolumeChanged);
connect(m_ui.standardVolume, &QSlider::valueChanged, this, &AudioSettingsWidget::onStandardVolumeChanged);
connect(m_ui.fastForwardVolume, &QSlider::valueChanged, this, &AudioSettingsWidget::onFastForwardVolumeChanged);
connect(m_ui.muted, &QCheckBox::checkStateChanged, this, &AudioSettingsWidget::onOutputMutedChanged);
updateVolumeLabel();
}
else
{
SettingWidgetBinder::BindWidgetAndLabelToIntSetting(sif, m_ui.volume, m_ui.volumeLabel, tr("%"), "SPU2/Output", "OutputVolume", 100);
SettingWidgetBinder::BindWidgetAndLabelToIntSetting(sif, m_ui.standardVolume, m_ui.standardVolumeLabel, tr("%"), "SPU2/Output", "StandardVolume", 100);
SettingWidgetBinder::BindWidgetAndLabelToIntSetting(sif, m_ui.fastForwardVolume, m_ui.fastForwardVolumeLabel, tr("%"), "SPU2/Output", "FastForwardVolume", 100);
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.muted, "SPU2/Output", "OutputMuted", false);
}
connect(m_ui.resetVolume, &QToolButton::clicked, this, [this]() { resetVolume(false); });
connect(m_ui.resetStandardVolume, &QToolButton::clicked, this, [this]() { resetVolume(false); });
connect(m_ui.resetFastForwardVolume, &QToolButton::clicked, this, [this]() { resetVolume(true); });

dialog()->registerWidgetHelp(
Expand All @@ -103,8 +103,8 @@ AudioSettingsWidget::AudioSettingsWidget(SettingsWindow* settings_dialog, QWidge
m_ui.outputLatencyMS, tr("Output Latency"), tr("%1 ms").arg(AudioStreamParameters::DEFAULT_OUTPUT_LATENCY_MS),
tr("Determines the latency from the buffer to the host audio output. This can be set lower than the target latency "
"to reduce audio delay."));
dialog()->registerWidgetHelp(m_ui.volume, tr("Output Volume"), "100%",
tr("Controls the volume of the audio played on the host."));
dialog()->registerWidgetHelp(m_ui.standardVolume, tr("Standard Volume"), "100%",
tr("Controls the volume of the audio played on the host at normal speed."));
dialog()->registerWidgetHelp(m_ui.fastForwardVolume, tr("Fast Forward Volume"), "100%",
tr("Controls the volume of the audio played on the host when fast forwarding."));
dialog()->registerWidgetHelp(m_ui.muted, tr("Mute All Sound"), tr("Unchecked"),
Expand All @@ -118,9 +118,9 @@ AudioSettingsWidget::AudioSettingsWidget(SettingsWindow* settings_dialog, QWidge
tr("When running outside of 100% speed, adjusts the tempo on audio instead of dropping frames. Produces much nicer fast-forward/slowdown audio."));
dialog()->registerWidgetHelp(m_ui.stretchSettings, tr("Stretch Settings"), tr("N/A"),
tr("These settings fine-tune the behavior of the SoundTouch audio time stretcher when running outside of 100% speed."));
dialog()->registerWidgetHelp(m_ui.resetVolume, tr("Reset Volume"), tr("N/A"),
dialog()->isPerGameSettings() ? tr("Resets output volume back to the global/inherited setting.") :
tr("Resets output volume back to the default."));
dialog()->registerWidgetHelp(m_ui.resetStandardVolume, tr("Reset Standard Volume"), tr("N/A"),
dialog()->isPerGameSettings() ? tr("Resets standard volume back to the global/inherited setting.") :
tr("Resets standard volume back to the default."));
dialog()->registerWidgetHelp(m_ui.resetFastForwardVolume, tr("Reset Fast Forward Volume"), tr("N/A"),
dialog()->isPerGameSettings() ? tr("Resets fast forward volume back to the global/inherited setting.") :
tr("Resets fast forward volume back to the default."));
Expand Down Expand Up @@ -292,7 +292,7 @@ void AudioSettingsWidget::updateLatencyLabel()

void AudioSettingsWidget::updateVolumeLabel()
{
m_ui.volumeLabel->setText(tr("%1%").arg(m_ui.volume->value()));
m_ui.standardVolumeLabel->setText(tr("%1%").arg(m_ui.standardVolume->value()));
m_ui.fastForwardVolumeLabel->setText(tr("%1%").arg(m_ui.fastForwardVolume->value()));
}

Expand All @@ -303,18 +303,18 @@ void AudioSettingsWidget::onMinimalOutputLatencyChanged()
updateLatencyLabel();
}

void AudioSettingsWidget::onOutputVolumeChanged(int new_value)
void AudioSettingsWidget::onStandardVolumeChanged(const int new_value)
{
// only called for base settings
pxAssert(!dialog()->isPerGameSettings());
Host::SetBaseIntSettingValue("SPU2/Output", "OutputVolume", new_value);
Host::SetBaseIntSettingValue("SPU2/Output", "StandardVolume", new_value);
Host::CommitBaseSettingChanges();
g_emu_thread->applySettings();

updateVolumeLabel();
}

void AudioSettingsWidget::onFastForwardVolumeChanged(int new_value)
void AudioSettingsWidget::onFastForwardVolumeChanged(const int new_value)
{
// only called for base settings
pxAssert(!dialog()->isPerGameSettings());
Expand All @@ -325,7 +325,7 @@ void AudioSettingsWidget::onFastForwardVolumeChanged(int new_value)
updateVolumeLabel();
}

void AudioSettingsWidget::onOutputMutedChanged(int new_state)
void AudioSettingsWidget::onOutputMutedChanged(const int new_state)
{
// only called for base settings
pxAssert(!dialog()->isPerGameSettings());
Expand Down Expand Up @@ -478,11 +478,11 @@ void AudioSettingsWidget::onStretchSettingsClicked()
dlg.exec();
}

void AudioSettingsWidget::resetVolume(bool fast_forward)
void AudioSettingsWidget::resetVolume(const bool fast_forward)
{
const char* key = fast_forward ? "FastForwardVolume" : "OutputVolume";
QSlider* const slider = fast_forward ? m_ui.fastForwardVolume : m_ui.volume;
QLabel* const label = fast_forward ? m_ui.fastForwardVolumeLabel : m_ui.volumeLabel;
const char* key = fast_forward ? "FastForwardVolume" : "StandardVolume";
QSlider* const slider = fast_forward ? m_ui.fastForwardVolume : m_ui.standardVolume;
QLabel* const label = fast_forward ? m_ui.fastForwardVolumeLabel : m_ui.standardVolumeLabel;

if (dialog()->isPerGameSettings())
{
Expand Down
8 changes: 4 additions & 4 deletions pcsx2-qt/Settings/AudioSettingsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ private Q_SLOTS:
void updateLatencyLabel();
void updateVolumeLabel();
void onMinimalOutputLatencyChanged();
void onOutputVolumeChanged(int new_value);
void onFastForwardVolumeChanged(int new_value);
void onOutputMutedChanged(int new_state);
void onStandardVolumeChanged(const int new_value);
void onFastForwardVolumeChanged(const int new_value);
void onOutputMutedChanged(const int new_state);

void onExpansionSettingsClicked();
void onStretchSettingsClicked();
Expand All @@ -38,7 +38,7 @@ private Q_SLOTS:
AudioBackend getEffectiveBackend() const;
AudioExpansionMode getEffectiveExpansionMode() const;
u32 getEffectiveExpansionBlockSize() const;
void resetVolume(bool fast_forward);
void resetVolume(const bool fast_forward);

Ui::AudioSettingsWidget m_ui;
u32 m_output_device_latency = 0;
Expand Down
10 changes: 5 additions & 5 deletions pcsx2-qt/Settings/AudioSettingsWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Output Volume:</string>
<string>Standard Volume:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QSlider" name="volume">
<widget class="QSlider" name="standardVolume">
<property name="maximum">
<number>200</number>
</property>
Expand All @@ -245,7 +245,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="volumeLabel">
<widget class="QLabel" name="standardVolumeLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
Expand All @@ -261,9 +261,9 @@
</widget>
</item>
<item>
<widget class="QToolButton" name="resetVolume">
<widget class="QToolButton" name="resetStandardVolume">
<property name="toolTip">
<string>Reset Volume</string>
<string>Reset Standard Volume</string>
</property>
<property name="icon">
<iconset theme="restart-line"/>
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ struct Pcsx2Config
VisualDebugEnabled : 1;
BITFIELD_END

u32 OutputVolume = 100;
u32 StandardVolume = 100;
u32 FastForwardVolume = 100;
bool OutputMuted = false;

Expand Down
54 changes: 42 additions & 12 deletions pcsx2/Hotkeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,56 @@ static void HotkeyAdjustTargetSpeed(double delta)
Host::OSD_QUICK_DURATION);
}

static void HotkeyAdjustVolume(s32 fixed, s32 delta)
static void HotkeyAdjustVolume(const s32 delta)
{
if (!VMManager::HasValidVM())
return;

const s32 current_vol = static_cast<s32>(SPU2::GetOutputVolume());
const s32 new_volume =
std::clamp((fixed >= 0) ? fixed : (current_vol + delta), 0, static_cast<s32>(Pcsx2Config::SPU2Options::MAX_VOLUME));
if (current_vol != new_volume)
// Volume-adjusting hotkeys override mute toggle hotkey. EmuConfig.SPU2.OutputMuted overrides hotkeys.
if (!SPU2::SetOutputMuted(false))
{
Host::AddIconOSDMessage("VolumeChanged", ICON_FA_VOLUME_XMARK, TRANSLATE_STR("Hotkeys", "Volume: Muted in Settings"));
return;
}

const s32 current_volume = static_cast<s32>(SPU2::GetOutputVolume());
const s32 maximum_volume = static_cast<s32>(Pcsx2Config::SPU2Options::MAX_VOLUME);
const s32 new_volume = std::clamp(current_volume + delta, 0, maximum_volume);

if (current_volume != new_volume)
SPU2::SetOutputVolume(static_cast<u32>(new_volume));

if (new_volume == 0)
if (new_volume > 0 && new_volume < maximum_volume)
{
Host::AddIconOSDMessage("VolumeChanged", ICON_FA_VOLUME_XMARK, TRANSLATE_STR("Hotkeys", "Volume: Muted"));
Host::AddIconOSDMessage("VolumeChanged", new_volume < 100 ? ICON_FA_VOLUME_LOW : ICON_FA_VOLUME_HIGH,
fmt::format(TRANSLATE_FS("Hotkeys", "Volume: {} to {}%"), delta < 0 ? TRANSLATE_STR("Hotkeys", "Decreased") : TRANSLATE_STR("Hotkeys", "Increased"), new_volume));
}
else
{
Host::AddIconOSDMessage("VolumeChanged", (current_vol < new_volume) ? ICON_FA_VOLUME_HIGH : ICON_FA_VOLUME_LOW,
fmt::format(TRANSLATE_FS("Hotkeys", "Volume: {}%"), new_volume));
Host::AddIconOSDMessage("VolumeChanged", delta < 0 ? ICON_FA_VOLUME_OFF : ICON_FA_VOLUME_HIGH,
fmt::format(TRANSLATE_FS("Hotkeys", "Volume: {} {}% Reached"), delta < 0 ? TRANSLATE_STR("Hotkeys", "Minimum") : TRANSLATE_STR("Hotkeys", "Maximum"), new_volume));
}
}

static void HotkeyToggleMute()
{
if (!VMManager::HasValidVM())
return;

// Attempt to toggle output muting. EmuConfig.SPU2.OutputMuted overrides hotkeys.
if (SPU2::SetOutputMuted(!SPU2::IsOutputMuted()))
{
if (SPU2::IsOutputMuted())
Host::AddIconOSDMessage("VolumeChanged", ICON_FA_VOLUME_XMARK, TRANSLATE_STR("Hotkeys", "Volume: Muted"));
else
{
const u32 current_volume = SPU2::GetOutputVolume();
Host::AddIconOSDMessage("VolumeChanged", current_volume < 100 ? (current_volume == 0 ? ICON_FA_VOLUME_OFF : ICON_FA_VOLUME_LOW) : ICON_FA_VOLUME_HIGH,
fmt::format(TRANSLATE_FS("Hotkeys", "Volume: Unmuted to {}%"), current_volume));
}
}
else
Host::AddIconOSDMessage("VolumeChanged", ICON_FA_VOLUME_XMARK, TRANSLATE_STR("Hotkeys", "Volume: Muted in Settings"));
}

static void HotkeyLoadStateSlot(s32 slot)
Expand Down Expand Up @@ -293,16 +323,16 @@ DEFINE_HOTKEY_LOADSTATE_X(10, TRANSLATE_NOOP("Hotkeys", "Load State From Slot 10
#undef DEFINE_HOTKEY_LOADSTATE_X
DEFINE_HOTKEY("Mute", TRANSLATE_NOOP("Hotkeys", "Audio"), TRANSLATE_NOOP("Hotkeys", "Toggle Mute"), [](s32 pressed) {
if (!pressed && VMManager::HasValidVM())
HotkeyAdjustVolume((SPU2::GetOutputVolume() == 0) ? SPU2::GetResetVolume() : 0, 0);
HotkeyToggleMute();
})
DEFINE_HOTKEY("IncreaseVolume", TRANSLATE_NOOP("Hotkeys", "Audio"), TRANSLATE_NOOP("Hotkeys", "Increase Volume"),
[](s32 pressed) {
if (!pressed && VMManager::HasValidVM())
HotkeyAdjustVolume(-1, 5);
HotkeyAdjustVolume(5);
})
DEFINE_HOTKEY("DecreaseVolume", TRANSLATE_NOOP("Hotkeys", "Audio"), TRANSLATE_NOOP("Hotkeys", "Decrease Volume"),
[](s32 pressed) {
if (!pressed && VMManager::HasValidVM())
HotkeyAdjustVolume(-1, -5);
HotkeyAdjustVolume(-5);
})
END_HOTKEY_LIST()
8 changes: 4 additions & 4 deletions pcsx2/ImGui/FullscreenUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4511,8 +4511,8 @@ void FullscreenUI::DrawAudioSettingsPage()

MenuHeading(FSUI_CSTR("Audio Control"));

DrawIntRangeSetting(bsi, FSUI_ICONSTR(ICON_FA_VOLUME_HIGH, "Output Volume"),
FSUI_CSTR("Controls the volume of the audio played on the host."), "SPU2/Output", "OutputVolume", 100,
DrawIntRangeSetting(bsi, FSUI_ICONSTR(ICON_FA_VOLUME_HIGH, "Standard Volume"),
FSUI_CSTR("Controls the volume of the audio played on the host at normal speed."), "SPU2/Output", "StandardVolume", 100,
0, 100, "%d%%");
DrawIntRangeSetting(bsi, FSUI_ICONSTR(ICON_FA_FORWARD_FAST, "Fast Forward Volume"),
FSUI_CSTR("Controls the volume of the audio played on the host when fast forwarding."), "SPU2/Output",
Expand Down Expand Up @@ -8288,7 +8288,7 @@ TRANSLATE_NOOP("FullscreenUI", "Determines what frame rate NTSC games run at.");
TRANSLATE_NOOP("FullscreenUI", "PAL Frame Rate");
TRANSLATE_NOOP("FullscreenUI", "Determines what frame rate PAL games run at.");
TRANSLATE_NOOP("FullscreenUI", "Audio Control");
TRANSLATE_NOOP("FullscreenUI", "Controls the volume of the audio played on the host.");
TRANSLATE_NOOP("FullscreenUI", "Controls the volume of the audio played on the host at normal speed.");
TRANSLATE_NOOP("FullscreenUI", "Controls the volume of the audio played on the host when fast forwarding.");
TRANSLATE_NOOP("FullscreenUI", "Prevents the emulator from producing any audible sound.");
TRANSLATE_NOOP("FullscreenUI", "Backend Settings");
Expand Down Expand Up @@ -8839,7 +8839,7 @@ TRANSLATE_NOOP("FullscreenUI", "Shade Boost Brightness");
TRANSLATE_NOOP("FullscreenUI", "Shade Boost Contrast");
TRANSLATE_NOOP("FullscreenUI", "Shade Boost Saturation");
TRANSLATE_NOOP("FullscreenUI", "TV Shaders");
TRANSLATE_NOOP("FullscreenUI", "Output Volume");
TRANSLATE_NOOP("FullscreenUI", "Standard Volume");
TRANSLATE_NOOP("FullscreenUI", "Fast Forward Volume");
TRANSLATE_NOOP("FullscreenUI", "Mute All Sound");
TRANSLATE_NOOP("FullscreenUI", "Audio Backend");
Expand Down
4 changes: 2 additions & 2 deletions pcsx2/Pcsx2Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ void Pcsx2Config::SPU2Options::LoadSave(SettingsWrapper& wrap)

{
SettingsWrapSection("SPU2/Output");
SettingsWrapEntry(OutputVolume);
SettingsWrapEntry(StandardVolume);
SettingsWrapEntry(FastForwardVolume);
SettingsWrapEntry(OutputMuted);
SettingsWrapParsedEnum(Backend, "Backend", &AudioStream::ParseBackendName, &AudioStream::GetBackendName);
Expand All @@ -1247,7 +1247,7 @@ bool Pcsx2Config::SPU2Options::operator!=(const SPU2Options& right) const
bool Pcsx2Config::SPU2Options::operator==(const SPU2Options& right) const
{
return OpEqu(bitset) &&
OpEqu(OutputVolume) &&
OpEqu(StandardVolume) &&
OpEqu(FastForwardVolume) &&
OpEqu(OutputMuted) &&
OpEqu(Backend) &&
Expand Down
Loading