Skip to content
Permalink
Browse files
Merge pull request #10144 from malleoz/dsp-onion
Port Main.DSP to MainSettings
  • Loading branch information
leoetlino committed Oct 16, 2021
2 parents 9a6f0bd + 8ea6bef commit 8195d0b
Show file tree
Hide file tree
Showing 26 changed files with 132 additions and 205 deletions.
@@ -17,6 +17,7 @@
#include "Common/Common.h"
#include "Common/FileUtil.h"
#include "Common/Logging/Log.h"
#include "Core/Config/MainSettings.h"
#include "Core/ConfigManager.h"

// This shouldn't be a global, at least not here.
@@ -51,7 +52,7 @@ static std::unique_ptr<SoundStream> CreateSoundStreamForBackend(std::string_view

void InitSoundStream()
{
std::string backend = SConfig::GetInstance().sBackend;
std::string backend = Config::Get(Config::MAIN_AUDIO_BACKEND);
g_sound_stream = CreateSoundStreamForBackend(backend);

if (!g_sound_stream)
@@ -77,15 +78,15 @@ void PostInitSoundStream()
UpdateSoundStream();
SetSoundStreamRunning(true);

if (SConfig::GetInstance().m_DumpAudio && !s_audio_dump_start)
if (Config::Get(Config::MAIN_DUMP_AUDIO) && !s_audio_dump_start)
StartAudioDump();
}

void ShutdownSoundStream()
{
INFO_LOG_FMT(AUDIO, "Shutting down sound stream");

if (SConfig::GetInstance().m_DumpAudio && s_audio_dump_start)
if (Config::Get(Config::MAIN_DUMP_AUDIO) && s_audio_dump_start)
StopAudioDump();

SetSoundStreamRunning(false);
@@ -163,7 +164,7 @@ void UpdateSoundStream()
{
if (g_sound_stream)
{
int volume = SConfig::GetInstance().m_IsMuted ? 0 : SConfig::GetInstance().m_Volume;
int volume = Config::Get(Config::MAIN_AUDIO_MUTED) ? 0 : Config::Get(Config::MAIN_AUDIO_VOLUME);
g_sound_stream->SetVolume(volume);
}
}
@@ -190,9 +191,9 @@ void SendAIBuffer(const short* samples, unsigned int num_samples)
if (!g_sound_stream)
return;

if (SConfig::GetInstance().m_DumpAudio && !s_audio_dump_start)
if (Config::Get(Config::MAIN_DUMP_AUDIO) && !s_audio_dump_start)
StartAudioDump();
else if (!SConfig::GetInstance().m_DumpAudio && s_audio_dump_start)
else if (!Config::Get(Config::MAIN_DUMP_AUDIO) && s_audio_dump_start)
StopAudioDump();

Mixer* pMixer = g_sound_stream->GetMixer();
@@ -232,28 +233,30 @@ void StopAudioDump()

void IncreaseVolume(unsigned short offset)
{
SConfig::GetInstance().m_IsMuted = false;
int& currentVolume = SConfig::GetInstance().m_Volume;
Config::SetBaseOrCurrent(Config::MAIN_AUDIO_MUTED, false);
int currentVolume = Config::Get(Config::MAIN_AUDIO_VOLUME);
currentVolume += offset;
if (currentVolume > AUDIO_VOLUME_MAX)
currentVolume = AUDIO_VOLUME_MAX;
Config::SetBaseOrCurrent(Config::MAIN_AUDIO_VOLUME, currentVolume);
UpdateSoundStream();
}

void DecreaseVolume(unsigned short offset)
{
SConfig::GetInstance().m_IsMuted = false;
int& currentVolume = SConfig::GetInstance().m_Volume;
Config::SetBaseOrCurrent(Config::MAIN_AUDIO_MUTED, false);
int currentVolume = Config::Get(Config::MAIN_AUDIO_VOLUME);
currentVolume -= offset;
if (currentVolume < AUDIO_VOLUME_MIN)
currentVolume = AUDIO_VOLUME_MIN;
Config::SetBaseOrCurrent(Config::MAIN_AUDIO_VOLUME, currentVolume);
UpdateSoundStream();
}

void ToggleMuteVolume()
{
bool& isMuted = SConfig::GetInstance().m_IsMuted;
isMuted = !isMuted;
bool isMuted = Config::Get(Config::MAIN_AUDIO_MUTED);
Config::SetBaseOrCurrent(Config::MAIN_AUDIO_MUTED, !isMuted);
UpdateSoundStream();
}
} // namespace AudioCommon
@@ -7,7 +7,7 @@

#include "AudioCommon/AudioStretcher.h"
#include "Common/Logging/Log.h"
#include "Core/ConfigManager.h"
#include "Core/Config/MainSettings.h"

namespace AudioCommon
{
@@ -31,7 +31,7 @@ void AudioStretcher::ProcessSamples(const short* in, unsigned int num_in, unsign
// We were given actual_samples number of samples, and num_samples were requested from us.
double current_ratio = static_cast<double>(num_in) / static_cast<double>(num_out);

const double max_latency = SConfig::GetInstance().m_audio_stretch_max_latency;
const double max_latency = Config::Get(Config::MAIN_AUDIO_STRETCH_LATENCY);
const double max_backlog = m_sample_rate * max_latency / 1000.0 / m_stretch_ratio;
const double backlog_fullness = m_sound_touch.numSamples() / max_backlog;
if (backlog_fullness > 5.0)
@@ -8,7 +8,7 @@
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/Thread.h"
#include "Core/ConfigManager.h"
#include "Core/Config/MainSettings.h"

// ~10 ms - needs to be at least 240 for surround
constexpr u32 BUFFER_SAMPLES = 512;
@@ -36,7 +36,7 @@ bool CubebStream::Init()
if (!m_ctx)
return false;

m_stereo = !SConfig::GetInstance().ShouldUseDPL2Decoder();
m_stereo = !Config::ShouldUseDPL2Decoder();

cubeb_stream_params params;
params.rate = m_mixer->GetSampleRate();
@@ -154,7 +154,7 @@ unsigned int Mixer::Mix(short* samples, unsigned int num_samples)

memset(samples, 0, num_samples * 2 * sizeof(short));

if (SConfig::GetInstance().m_audio_stretch)
if (Config::Get(Config::MAIN_AUDIO_STRETCH))
{
unsigned int available_samples =
std::min(m_dma_mixer.AvailableSamples(), m_streaming_mixer.AvailableSamples());
@@ -12,7 +12,7 @@
#include "Common/Logging/Log.h"
#include "Common/MsgHandler.h"
#include "Common/Thread.h"
#include "Core/ConfigManager.h"
#include "Core/Config/MainSettings.h"

static HMODULE s_openal_dll = nullptr;

@@ -212,7 +212,7 @@ void OpenALStream::SoundLoop()

bool float32_capable = palIsExtensionPresent("AL_EXT_float32") != 0;
bool surround_capable = palIsExtensionPresent("AL_EXT_MCFORMATS") || IsCreativeXFi();
bool use_surround = SConfig::GetInstance().ShouldUseDPL2Decoder() && surround_capable;
bool use_surround = Config::ShouldUseDPL2Decoder() && surround_capable;

// As there is no extension to check for 32-bit fixed point support
// and we know that only a X-Fi with hardware OpenAL supports it,
@@ -223,9 +223,9 @@ void OpenALStream::SoundLoop()

u32 frames_per_buffer;
// Can't have zero samples per buffer
if (SConfig::GetInstance().iLatency > 0)
if (Config::Get(Config::MAIN_AUDIO_LATENCY) > 0)
{
frames_per_buffer = frequency / 1000 * SConfig::GetInstance().iLatency / OAL_BUFFERS;
frames_per_buffer = frequency / 1000 * Config::Get(Config::MAIN_AUDIO_LATENCY) / OAL_BUFFERS;
}
else
{
@@ -9,7 +9,7 @@
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/Thread.h"
#include "Core/ConfigManager.h"
#include "Core/Config/MainSettings.h"

namespace
{
@@ -20,7 +20,7 @@ PulseAudio::PulseAudio() = default;

bool PulseAudio::Init()
{
m_stereo = !SConfig::GetInstance().ShouldUseDPL2Decoder();
m_stereo = !Config::ShouldUseDPL2Decoder();
m_channels = m_stereo ? 2 : 6; // will tell PA we use a Stereo or 5.0 channel setup

NOTICE_LOG_FMT(AUDIO, "PulseAudio backend using {} channels", m_channels);
@@ -20,7 +20,7 @@
#include "Common/Logging/Log.h"
#include "Common/StringUtil.h"
#include "Common/Thread.h"
#include "Core/ConfigManager.h"
#include "Core/Config/MainSettings.h"
#include "VideoCommon/OnScreenDisplay.h"

using Microsoft::WRL::ComPtr;
@@ -176,19 +176,19 @@ bool WASAPIStream::SetRunning(bool running)

HRESULT result;

if (SConfig::GetInstance().sWASAPIDevice == "default")
if (Config::Get(Config::MAIN_WASAPI_DEVICE) == "default")
{
result = m_enumerator->GetDefaultAudioEndpoint(eRender, eConsole, device.GetAddressOf());
}
else
{
result = S_OK;
device = GetDeviceByName(SConfig::GetInstance().sWASAPIDevice);
device = GetDeviceByName(Config::Get(Config::MAIN_WASAPI_DEVICE));

if (!device)
{
ERROR_LOG_FMT(AUDIO, "Can't find device '{}', falling back to default",
SConfig::GetInstance().sWASAPIDevice);
Config::Get(Config::MAIN_WASAPI_DEVICE));
result = m_enumerator->GetDefaultAudioEndpoint(eRender, eConsole, device.GetAddressOf());
}
}
@@ -222,7 +222,7 @@ bool WASAPIStream::SetRunning(bool running)

result = audio_client->GetDevicePeriod(nullptr, &device_period);

device_period += SConfig::GetInstance().iLatency * (10000 / m_format.Format.nChannels);
device_period += Config::Get(Config::MAIN_AUDIO_LATENCY) * (10000 / m_format.Format.nChannels);
INFO_LOG_FMT(AUDIO, "Audio period set to {}", device_period);

if (!HandleWinAPI("Failed to obtain device period", result))
@@ -258,7 +258,7 @@ bool WASAPIStream::SetRunning(bool running)
device_period =
static_cast<REFERENCE_TIME>(
10000.0 * 1000 * m_frames_in_buffer / m_format.Format.nSamplesPerSec + 0.5) +
SConfig::GetInstance().iLatency * 10000;
Config::Get(Config::MAIN_AUDIO_LATENCY) * 10000;

result = audio_client->Initialize(
AUDCLNT_SHAREMODE_EXCLUSIVE,
@@ -333,13 +333,13 @@ void WASAPIStream::SoundLoop()
s16* audio_data = reinterpret_cast<s16*>(data);
GetMixer()->Mix(audio_data, m_frames_in_buffer);

const SConfig& config = SConfig::GetInstance();
const bool is_muted = config.m_IsMuted || config.m_Volume == 0;
const bool need_volume_adjustment = config.m_Volume != 100 && !is_muted;
const bool is_muted =
Config::Get(Config::MAIN_AUDIO_MUTED) || Config::Get(Config::MAIN_AUDIO_VOLUME) == 0;
const bool need_volume_adjustment = Config::Get(Config::MAIN_AUDIO_VOLUME) != 100 && !is_muted;

if (need_volume_adjustment)
{
const float volume = config.m_Volume / 100.0f;
const float volume = Config::Get(Config::MAIN_AUDIO_VOLUME) / 100.0f;

for (u32 i = 0; i < m_frames_in_buffer * 2; i++)
*audio_data++ *= volume;
@@ -12,6 +12,7 @@
#include "Common/MsgHandler.h"
#include "Common/StringUtil.h"
#include "Common/Swap.h"
#include "Core/Config/MainSettings.h"
#include "Core/ConfigManager.h"

constexpr size_t WaveFileWriter::BUFFER_SIZE;
@@ -30,7 +31,7 @@ bool WaveFileWriter::Start(const std::string& filename, unsigned int HLESampleRa
// Ask to delete file
if (File::Exists(filename))
{
if (SConfig::GetInstance().m_DumpAudioSilent ||
if (Config::Get(Config::MAIN_DUMP_AUDIO_SILENT) ||
AskYesNoFmtT("Delete the existing file '{0}'?", filename))
{
File::Delete(filename);
@@ -82,22 +82,18 @@ struct ConfigCache
bool bMMU = false;
bool bLowDCBZHack = false;
bool bDisableICache = false;
bool m_EnableJIT = false;
bool bSyncGPU = false;
int iSyncGpuMaxDistance = 0;
int iSyncGpuMinDistance = 0;
float fSyncGpuOverclock = 0;
bool bFastDiscSpeed = false;
bool bDSPHLE = false;
bool bHLE_BS2 = false;
int iSelectedLanguage = 0;
PowerPC::CPUCore cpu_core = PowerPC::CPUCore::Interpreter;
int Volume = 0;
float m_EmulationSpeed = 0;
float m_OCFactor = 0;
bool m_OCEnable = false;
bool m_bt_passthrough_enabled = false;
std::string sBackend;
std::string m_strGPUDeterminismMode;
std::array<WiimoteSource, MAX_BBMOTES> iWiimoteSource{};
std::array<SerialInterface::SIDevices, SerialInterface::MAX_SI_CHANNELS> Pads{};
@@ -117,19 +113,15 @@ void ConfigCache::SaveConfig(const SConfig& config)
bAccurateNaNs = config.bAccurateNaNs;
bDisableICache = config.bDisableICache;
bMMU = config.bMMU;
m_EnableJIT = config.m_DSPEnableJIT;
bSyncGPU = config.bSyncGPU;
iSyncGpuMaxDistance = config.iSyncGpuMaxDistance;
iSyncGpuMinDistance = config.iSyncGpuMinDistance;
fSyncGpuOverclock = config.fSyncGpuOverclock;
bFastDiscSpeed = config.bFastDiscSpeed;
bDSPHLE = config.bDSPHLE;
bHLE_BS2 = config.bHLE_BS2;
iSelectedLanguage = config.SelectedLanguage;
cpu_core = config.cpu_core;
Volume = config.m_Volume;
m_EmulationSpeed = config.m_EmulationSpeed;
sBackend = config.sBackend;
m_strGPUDeterminismMode = config.m_strGPUDeterminismMode;
m_OCFactor = config.m_OCFactor;
m_OCEnable = config.m_OCEnable;
@@ -165,22 +157,17 @@ void ConfigCache::RestoreConfig(SConfig* config)
config->bDisableICache = bDisableICache;
config->bMMU = bMMU;
config->bLowDCBZHack = bLowDCBZHack;
config->m_DSPEnableJIT = m_EnableJIT;
config->bSyncGPU = bSyncGPU;
config->iSyncGpuMaxDistance = iSyncGpuMaxDistance;
config->iSyncGpuMinDistance = iSyncGpuMinDistance;
config->fSyncGpuOverclock = fSyncGpuOverclock;
config->bFastDiscSpeed = bFastDiscSpeed;
config->bDSPHLE = bDSPHLE;
config->bHLE_BS2 = bHLE_BS2;
config->SelectedLanguage = iSelectedLanguage;
config->cpu_core = cpu_core;

// Only change these back if they were actually set by game ini, since they can be changed while a
// game is running.
if (bSetVolume)
config->m_Volume = Volume;

if (config->bWii)
{
for (unsigned int i = 0; i < MAX_BBMOTES; ++i)
@@ -205,7 +192,6 @@ void ConfigCache::RestoreConfig(SConfig* config)
config->m_EXIDevice[i] = m_EXIDevice[i];
}

config->sBackend = sBackend;
config->m_strGPUDeterminismMode = m_strGPUDeterminismMode;
config->m_OCFactor = m_OCFactor;
config->m_OCEnable = m_OCEnable;
@@ -255,7 +241,6 @@ bool BootCore(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi)

// General settings
IniFile::Section* core_section = game_ini.GetOrCreateSection("Core");
IniFile::Section* dsp_section = game_ini.GetOrCreateSection("DSP");
IniFile::Section* controls_section = game_ini.GetOrCreateSection("Controls");

core_section->Get("CPUThread", &StartUp.bCPUThread, StartUp.bCPUThread);
@@ -272,17 +257,12 @@ bool BootCore(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi)
core_section->Get("LowDCBZHack", &StartUp.bLowDCBZHack, StartUp.bLowDCBZHack);
core_section->Get("SyncGPU", &StartUp.bSyncGPU, StartUp.bSyncGPU);
core_section->Get("FastDiscSpeed", &StartUp.bFastDiscSpeed, StartUp.bFastDiscSpeed);
core_section->Get("DSPHLE", &StartUp.bDSPHLE, StartUp.bDSPHLE);
core_section->Get("CPUCore", &StartUp.cpu_core, StartUp.cpu_core);
core_section->Get("HLE_BS2", &StartUp.bHLE_BS2, StartUp.bHLE_BS2);
core_section->Get("GameCubeLanguage", &StartUp.SelectedLanguage, StartUp.SelectedLanguage);
if (core_section->Get("EmulationSpeed", &StartUp.m_EmulationSpeed, StartUp.m_EmulationSpeed))
config_cache.bSetEmulationSpeed = true;

if (dsp_section->Get("Volume", &StartUp.m_Volume, StartUp.m_Volume))
config_cache.bSetVolume = true;
dsp_section->Get("EnableJIT", &StartUp.m_DSPEnableJIT, StartUp.m_DSPEnableJIT);
dsp_section->Get("Backend", &StartUp.sBackend, StartUp.sBackend);
core_section->Get("GPUDeterminismMode", &StartUp.m_strGPUDeterminismMode,
StartUp.m_strGPUDeterminismMode);
core_section->Get("Overclock", &StartUp.m_OCFactor, StartUp.m_OCFactor);
@@ -334,7 +314,6 @@ bool BootCore(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi)
// TODO: remove this once ConfigManager starts using OnionConfig.
StartUp.bCPUThread = Config::Get(Config::MAIN_CPU_THREAD);
StartUp.bJITFollowBranch = Config::Get(Config::MAIN_JIT_FOLLOW_BRANCH);
StartUp.bDSPHLE = Config::Get(Config::MAIN_DSP_HLE);
StartUp.bFastDiscSpeed = Config::Get(Config::MAIN_FAST_DISC_SPEED);
StartUp.cpu_core = Config::Get(Config::MAIN_CPU_CORE);
StartUp.bSyncGPU = Config::Get(Config::MAIN_SYNC_GPU);
@@ -361,12 +340,10 @@ bool BootCore(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi)
const NetPlay::NetSettings& netplay_settings = NetPlay::GetNetSettings();
Config::AddLayer(ConfigLoaders::GenerateNetPlayConfigLoader(netplay_settings));
StartUp.bCPUThread = netplay_settings.m_CPUthread;
StartUp.bDSPHLE = netplay_settings.m_DSPHLE;
StartUp.bCopyWiiSaveNetplay = netplay_settings.m_CopyWiiSave;
StartUp.cpu_core = netplay_settings.m_CPUcore;
StartUp.SelectedLanguage = netplay_settings.m_SelectedLanguage;
StartUp.bOverrideRegionSettings = netplay_settings.m_OverrideRegionSettings;
StartUp.m_DSPEnableJIT = netplay_settings.m_DSPEnableJIT;
StartUp.m_OCEnable = netplay_settings.m_OCEnable;
StartUp.m_OCFactor = netplay_settings.m_OCFactor;
StartUp.m_EXIDevice[0] = netplay_settings.m_EXIDevice[0];

0 comments on commit 8195d0b

Please sign in to comment.