Qt: Move audio backend names to core and allow translation

This commit is contained in:
Stenzek 2023-06-26 21:24:46 +10:00 committed by lightningterror
parent 79e1fd1ea4
commit 16e47f1d6b
6 changed files with 50 additions and 27 deletions

View File

@ -39,20 +39,6 @@ static constexpr s32 DEFAULT_SOUNDTOUCH_SEQUENCE_LENGTH = 30;
static constexpr s32 DEFAULT_SOUNDTOUCH_SEEK_WINDOW = 20;
static constexpr s32 DEFAULT_SOUNDTOUCH_OVERLAP = 10;
static const char* s_output_module_entries[] = {QT_TRANSLATE_NOOP("AudioSettingsWidget", "No Sound (Emulate SPU2 only)"),
//: Cubeb is an audio engine name. Leave as-is.
QT_TRANSLATE_NOOP("AudioSettingsWidget", "Cubeb (Cross-platform)"),
#ifdef _WIN32
//: XAudio2 is an audio engine name. Leave as-is.
QT_TRANSLATE_NOOP("AudioSettingsWidget", "XAudio2"),
#endif
nullptr};
static const char* s_output_module_values[] = {"nullout", "cubeb",
#ifdef _WIN32
"xaudio2",
#endif
nullptr};
AudioSettingsWidget::AudioSettingsWidget(SettingsDialog* dialog, QWidget* parent)
: QWidget(parent)
, m_dialog(dialog)
@ -60,6 +46,7 @@ AudioSettingsWidget::AudioSettingsWidget(SettingsDialog* dialog, QWidget* parent
SettingsInterface* sif = dialog->getSettingsInterface();
m_ui.setupUi(this);
populateOutputModules();
SettingWidgetBinder::BindWidgetToIntSetting(sif, m_ui.syncMode, "SPU2/Output", "SynchMode", DEFAULT_SYNCHRONIZATION_MODE);
SettingWidgetBinder::BindWidgetToIntSetting(sif, m_ui.expansionMode, "SPU2/Output", "SpeakerConfiguration", DEFAULT_EXPANSION_MODE);
@ -69,8 +56,7 @@ AudioSettingsWidget::AudioSettingsWidget(SettingsDialog* dialog, QWidget* parent
updateTargetLatencyRange();
expansionModeChanged();
SettingWidgetBinder::BindWidgetToEnumSetting(
sif, m_ui.outputModule, "SPU2/Output", "OutputModule", s_output_module_entries, s_output_module_values, DEFAULT_OUTPUT_MODULE);
SettingWidgetBinder::BindWidgetToStringSetting(sif, m_ui.outputModule, "SPU2/Output", "OutputModule", DEFAULT_OUTPUT_MODULE);
SettingWidgetBinder::BindSliderToIntSetting(
//: Measuring unit that will appear after the number selected in its option. Adapt the space depending on your language's rules.
sif, m_ui.targetLatency, m_ui.targetLatencyLabel, tr(" ms"), "SPU2/Output", "Latency", DEFAULT_TARGET_LATENCY);
@ -156,6 +142,12 @@ void AudioSettingsWidget::expansionModeChanged()
m_ui.dplLevel->setDisabled(!expansion51);
}
void AudioSettingsWidget::populateOutputModules()
{
for (const SndOutModule* mod : GetSndOutModules())
m_ui.outputModule->addItem(qApp->translate("SPU2", mod->GetDisplayName()), QString::fromUtf8(mod->GetIdent()));
}
void AudioSettingsWidget::outputModuleChanged()
{
const std::string module_name(m_dialog->getEffectiveStringValue("SPU2/Output", "OutputModule", DEFAULT_OUTPUT_MODULE));

View File

@ -42,6 +42,7 @@ private Q_SLOTS:
void resetTimestretchDefaults();
private:
void populateOutputModules();
void updateVolumeLabel();
SettingsDialog* m_dialog;

View File

@ -19,6 +19,7 @@
#include "SPU2/spu2.h"
#include "GS/GSCapture.h"
#include "GS/GSVector.h"
#include "Host.h"
#include "common/Assertions.h"
#include "common/Timer.h"
@ -48,6 +49,11 @@ namespace
return "nullout";
}
const char* GetDisplayName() const override
{
return TRANSLATE_NOOP("SPU2", "No Sound (Emulate SPU2 only)");
}
const char* const* GetBackendNames() const override
{
return nullptr;
@ -63,6 +69,13 @@ namespace
static NullOutModule s_NullOut;
static SndOutModule* NullOut = &s_NullOut;
#ifdef _WIN32
extern SndOutModule* XAudio2Out;
#endif
#if defined(SPU2X_CUBEB)
extern SndOutModule* CubebOut;
#endif
static SndOutModule* mods[] =
{
NullOut,
@ -76,6 +89,11 @@ static SndOutModule* mods[] =
static SndOutModule* s_output_module;
gsl::span<SndOutModule*> GetSndOutModules()
{
return mods;
}
static SndOutModule* FindOutputModule(const char* name)
{
for (u32 i = 0; i < std::size(mods); i++)

View File

@ -17,6 +17,8 @@
#include <vector>
#include "gsl/span"
// Number of stereo samples per SndOut block.
// All drivers must work in units of this size when communicating with
// SndOut.
@ -319,13 +321,15 @@ namespace SndBuffer
class SndOutModule
{
public:
// Virtual destructor, because it helps fight C+++ funny-business.
virtual ~SndOutModule() {}
virtual ~SndOutModule() = default;
// Returns a unique identification string for this driver.
// (usually just matches the driver's cpp filename)
virtual const char* GetIdent() const = 0;
// Returns the full name for this driver, and can be translated.
virtual const char* GetDisplayName() const = 0;
// Returns a null-terminated list of backends, or nullptr.
virtual const char* const* GetBackendNames() const = 0;
@ -343,10 +347,4 @@ public:
virtual int GetEmptySampleCount() = 0;
};
#ifdef _WIN32
extern SndOutModule* XAudio2Out;
#endif
#if defined(SPU2X_CUBEB)
extern SndOutModule* CubebOut;
#endif
gsl::span<SndOutModule*> GetSndOutModules();

View File

@ -150,8 +150,7 @@ public:
cubeb_set_log_callback(CUBEB_LOG_NORMAL, LogCallback);
#endif
const std::string backend(Host::GetStringSettingValue("SPU2/Output", "BackendName", ""));
int rv = cubeb_init(&m_context, "PCSX2", backend.empty() ? nullptr : backend.c_str());
int rv = cubeb_init(&m_context, "PCSX2", EmuConfig.SPU2.BackendName.empty() ? nullptr : EmuConfig.SPU2.BackendName.c_str());
if (rv != CUBEB_OK)
{
Host::ReportFormattedErrorAsync("Cubeb Error", "Could not initialize cubeb context: %d", rv);
@ -375,6 +374,12 @@ public:
return "cubeb";
}
const char* GetDisplayName() const override
{
//: Cubeb is an audio engine name. Leave as-is.
return TRANSLATE_NOOP("SPU2", "Cubeb (Cross-platform)");
}
const char* const* GetBackendNames() const override
{
return cubeb_get_backend_names();

View File

@ -14,7 +14,10 @@
*/
#include "PrecompiledHeader.h"
#include "SPU2/Global.h"
#include "Host.h"
#include "common/Console.h"
#include "common/RedtapeWindows.h"
#include "common/RedtapeWilCom.h"
@ -356,6 +359,12 @@ public:
return "xaudio2";
}
const char* GetDisplayName() const override
{
//: XAudio2 is an audio engine name. Leave as-is.
return TRANSLATE_NOOP("SPU2", "XAudio2");
}
const char* const* GetBackendNames() const override
{
return nullptr;