Skip to content

Commit

Permalink
SPU2: Use AudioStream for output
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed May 4, 2024
1 parent ca091ee commit 0f5e735
Show file tree
Hide file tree
Showing 48 changed files with 1,854 additions and 3,323 deletions.
2 changes: 2 additions & 0 deletions pcsx2-qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ target_sources(pcsx2-qt PRIVATE
Settings/AdvancedSettingsWidget.cpp
Settings/AdvancedSettingsWidget.h
Settings/AdvancedSettingsWidget.ui
Settings/AudioExpansionSettingsDialog.ui
Settings/AudioSettingsWidget.cpp
Settings/AudioSettingsWidget.h
Settings/AudioSettingsWidget.ui
Settings/AudioStretchSettingsDialog.ui
Settings/BIOSSettingsWidget.cpp
Settings/BIOSSettingsWidget.h
Settings/BIOSSettingsWidget.ui
Expand Down
33 changes: 33 additions & 0 deletions pcsx2-qt/QtHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "pcsx2/Input/InputManager.h"
#include "pcsx2/MTGS.h"
#include "pcsx2/PerformanceMetrics.h"
#include "pcsx2/SPU2/spu2.h"
#include "pcsx2/VMManager.h"

#include "common/Assertions.h"
Expand Down Expand Up @@ -889,6 +890,38 @@ 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: 2 additions & 0 deletions pcsx2-qt/QtHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ 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
13 changes: 12 additions & 1 deletion pcsx2-qt/QtUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
// SPDX-License-Identifier: LGPL-3.0+

#include "QtUtils.h"
Expand All @@ -14,11 +14,13 @@
#include <QtWidgets/QComboBox>
#include <QtWidgets/QDialog>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QLabel>
#include <QtWidgets/QInputDialog>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QScrollBar>
#include <QtWidgets/QStatusBar>
#include <QtWidgets/QSlider>
#include <QtWidgets/QStyle>
#include <QtWidgets/QTableView>
#include <QtWidgets/QTreeView>
Expand Down Expand Up @@ -202,6 +204,15 @@ namespace QtUtils
}
}

void BindLabelToSlider(QSlider* slider, QLabel* label, float range /*= 1.0f*/)
{
auto update_label = [label, range](int new_value) {
label->setText(QString::number(static_cast<int>(new_value) / range));
};
update_label(slider->value());
QObject::connect(slider, &QSlider::valueChanged, label, std::move(update_label));
}

void SetWindowResizeable(QWidget* widget, bool resizeable)
{
if (QMainWindow* window = qobject_cast<QMainWindow*>(widget); window)
Expand Down
7 changes: 6 additions & 1 deletion pcsx2-qt/QtUtils.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
// SPDX-License-Identifier: LGPL-3.0+

#pragma once
Expand All @@ -20,7 +20,9 @@ class QAction;
class QComboBox;
class QFileInfo;
class QFrame;
class QLabel;
class QKeyEvent;
class QSlider;
class QTableView;
class QTreeView;
class QVariant;
Expand Down Expand Up @@ -71,6 +73,9 @@ namespace QtUtils
/// Sets a widget to italics if the setting value is inherited.
void SetWidgetFontForInheritedSetting(QWidget* widget, bool inherited);

/// Binds a label to a slider's value.
void BindLabelToSlider(QSlider* slider, QLabel* label, float range = 1.0f);

/// Changes whether a window is resizable.
void SetWindowResizeable(QWidget* widget, bool resizeable);

Expand Down
Loading

0 comments on commit 0f5e735

Please sign in to comment.