Merge pull request #10144 from malleoz/dsp-onion

Port Main.DSP to MainSettings
This commit is contained in:
Léo Lam
2021-10-16 11:32:38 +02:00
committed by GitHub
26 changed files with 132 additions and 205 deletions

View File

@ -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,7 +78,7 @@ 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();
}
@ -85,7 +86,7 @@ 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

View File

@ -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)

View File

@ -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();

View File

@ -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());

View File

@ -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
{

View File

@ -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);

View File

@ -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;

View File

@ -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);