summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorMai <mathew1800@gmail.com>2022-11-23 04:49:31 +0000
committerGitHub <noreply@github.com>2022-11-23 04:49:31 +0000
commit0ef6d30a0dde197ccb2736dd46191e7f867f3502 (patch)
tree5abb760f8ff88d88171485e8251e6ac7056b6767 /Source/Core
parent1469055244a3c904e9256c71a4e90027a3b4c3c6 (diff)
parent1c633499842646d7069db067f9c26954c3de144a (diff)
Merge pull request #11165 from AdmiralCurtiss/audiocommon-pass-system
AudioCommon: Pass Core::System to AudioCommon functions.
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/AudioCommon/AudioCommon.cpp53
-rw-r--r--Source/Core/AudioCommon/AudioCommon.h27
-rw-r--r--Source/Core/Core/Core.cpp8
-rw-r--r--Source/Core/Core/HW/CPU.cpp3
-rw-r--r--Source/Core/Core/HW/DSP.cpp7
-rw-r--r--Source/Core/DolphinQt/HotkeyScheduler.cpp3
-rw-r--r--Source/Core/DolphinQt/Settings.cpp5
-rw-r--r--Source/Core/DolphinQt/Settings/AudioPane.cpp3
8 files changed, 55 insertions, 54 deletions
diff --git a/Source/Core/AudioCommon/AudioCommon.cpp b/Source/Core/AudioCommon/AudioCommon.cpp
index 8800fddcf5..ba317d2828 100644
--- a/Source/Core/AudioCommon/AudioCommon.cpp
+++ b/Source/Core/AudioCommon/AudioCommon.cpp
@@ -45,7 +45,7 @@ static std::unique_ptr<SoundStream> CreateSoundStreamForBackend(std::string_view
return {};
}
-void InitSoundStream()
+void InitSoundStream(Core::System& system)
{
std::string backend = Config::Get(Config::MAIN_AUDIO_BACKEND);
std::unique_ptr<SoundStream> sound_stream = CreateSoundStreamForBackend(backend);
@@ -65,32 +65,28 @@ void InitSoundStream()
sound_stream->Init();
}
- Core::System::GetInstance().SetSoundStream(std::move(sound_stream));
+ system.SetSoundStream(std::move(sound_stream));
}
-void PostInitSoundStream()
+void PostInitSoundStream(Core::System& system)
{
- auto& system = Core::System::GetInstance();
-
// This needs to be called after AudioInterface::Init and SerialInterface::Init (for GBA devices)
// where input sample rates are set
- UpdateSoundStream();
- SetSoundStreamRunning(true);
+ UpdateSoundStream(system);
+ SetSoundStreamRunning(system, true);
if (Config::Get(Config::MAIN_DUMP_AUDIO) && !system.IsAudioDumpStarted())
- StartAudioDump();
+ StartAudioDump(system);
}
-void ShutdownSoundStream()
+void ShutdownSoundStream(Core::System& system)
{
- auto& system = Core::System::GetInstance();
-
INFO_LOG_FMT(AUDIO, "Shutting down sound stream");
if (Config::Get(Config::MAIN_DUMP_AUDIO) && system.IsAudioDumpStarted())
- StopAudioDump();
+ StopAudioDump(system);
- SetSoundStreamRunning(false);
+ SetSoundStreamRunning(system, false);
system.SetSoundStream(nullptr);
INFO_LOG_FMT(AUDIO, "Done shutting down sound stream");
@@ -161,9 +157,8 @@ bool SupportsVolumeChanges(std::string_view backend)
return backend == BACKEND_CUBEB || backend == BACKEND_OPENAL || backend == BACKEND_WASAPI;
}
-void UpdateSoundStream()
+void UpdateSoundStream(Core::System& system)
{
- auto& system = Core::System::GetInstance();
SoundStream* sound_stream = system.GetSoundStream();
if (sound_stream)
@@ -173,9 +168,8 @@ void UpdateSoundStream()
}
}
-void SetSoundStreamRunning(bool running)
+void SetSoundStreamRunning(Core::System& system, bool running)
{
- auto& system = Core::System::GetInstance();
SoundStream* sound_stream = system.GetSoundStream();
if (!sound_stream)
@@ -193,18 +187,17 @@ void SetSoundStreamRunning(bool running)
ERROR_LOG_FMT(AUDIO, "Error stopping stream.");
}
-void SendAIBuffer(const short* samples, unsigned int num_samples)
+void SendAIBuffer(Core::System& system, const short* samples, unsigned int num_samples)
{
- auto& system = Core::System::GetInstance();
SoundStream* sound_stream = system.GetSoundStream();
if (!sound_stream)
return;
if (Config::Get(Config::MAIN_DUMP_AUDIO) && !system.IsAudioDumpStarted())
- StartAudioDump();
+ StartAudioDump(system);
else if (!Config::Get(Config::MAIN_DUMP_AUDIO) && system.IsAudioDumpStarted())
- StopAudioDump();
+ StopAudioDump(system);
Mixer* mixer = sound_stream->GetMixer();
@@ -214,9 +207,8 @@ void SendAIBuffer(const short* samples, unsigned int num_samples)
}
}
-void StartAudioDump()
+void StartAudioDump(Core::System& system)
{
- auto& system = Core::System::GetInstance();
SoundStream* sound_stream = system.GetSoundStream();
std::time_t start_time = std::time(nullptr);
@@ -235,9 +227,8 @@ void StartAudioDump()
system.SetAudioDumpStarted(true);
}
-void StopAudioDump()
+void StopAudioDump(Core::System& system)
{
- auto& system = Core::System::GetInstance();
SoundStream* sound_stream = system.GetSoundStream();
if (!sound_stream)
@@ -247,7 +238,7 @@ void StopAudioDump()
system.SetAudioDumpStarted(false);
}
-void IncreaseVolume(unsigned short offset)
+void IncreaseVolume(Core::System& system, unsigned short offset)
{
Config::SetBaseOrCurrent(Config::MAIN_AUDIO_MUTED, false);
int currentVolume = Config::Get(Config::MAIN_AUDIO_VOLUME);
@@ -255,10 +246,10 @@ void IncreaseVolume(unsigned short offset)
if (currentVolume > AUDIO_VOLUME_MAX)
currentVolume = AUDIO_VOLUME_MAX;
Config::SetBaseOrCurrent(Config::MAIN_AUDIO_VOLUME, currentVolume);
- UpdateSoundStream();
+ UpdateSoundStream(system);
}
-void DecreaseVolume(unsigned short offset)
+void DecreaseVolume(Core::System& system, unsigned short offset)
{
Config::SetBaseOrCurrent(Config::MAIN_AUDIO_MUTED, false);
int currentVolume = Config::Get(Config::MAIN_AUDIO_VOLUME);
@@ -266,13 +257,13 @@ void DecreaseVolume(unsigned short offset)
if (currentVolume < AUDIO_VOLUME_MIN)
currentVolume = AUDIO_VOLUME_MIN;
Config::SetBaseOrCurrent(Config::MAIN_AUDIO_VOLUME, currentVolume);
- UpdateSoundStream();
+ UpdateSoundStream(system);
}
-void ToggleMuteVolume()
+void ToggleMuteVolume(Core::System& system)
{
bool isMuted = Config::Get(Config::MAIN_AUDIO_MUTED);
Config::SetBaseOrCurrent(Config::MAIN_AUDIO_MUTED, !isMuted);
- UpdateSoundStream();
+ UpdateSoundStream(system);
}
} // namespace AudioCommon
diff --git a/Source/Core/AudioCommon/AudioCommon.h b/Source/Core/AudioCommon/AudioCommon.h
index 84e3cd0a62..f883f32f85 100644
--- a/Source/Core/AudioCommon/AudioCommon.h
+++ b/Source/Core/AudioCommon/AudioCommon.h
@@ -13,23 +13,28 @@
class Mixer;
+namespace Core
+{
+class System;
+}
+
namespace AudioCommon
{
-void InitSoundStream();
-void PostInitSoundStream();
-void ShutdownSoundStream();
+void InitSoundStream(Core::System& system);
+void PostInitSoundStream(Core::System& system);
+void ShutdownSoundStream(Core::System& system);
std::string GetDefaultSoundBackend();
std::vector<std::string> GetSoundBackends();
DPL2Quality GetDefaultDPL2Quality();
bool SupportsDPL2Decoder(std::string_view backend);
bool SupportsLatencyControl(std::string_view backend);
bool SupportsVolumeChanges(std::string_view backend);
-void UpdateSoundStream();
-void SetSoundStreamRunning(bool running);
-void SendAIBuffer(const short* samples, unsigned int num_samples);
-void StartAudioDump();
-void StopAudioDump();
-void IncreaseVolume(unsigned short offset);
-void DecreaseVolume(unsigned short offset);
-void ToggleMuteVolume();
+void UpdateSoundStream(Core::System& system);
+void SetSoundStreamRunning(Core::System& system, bool running);
+void SendAIBuffer(Core::System& system, const short* samples, unsigned int num_samples);
+void StartAudioDump(Core::System& system);
+void StopAudioDump(Core::System& system);
+void IncreaseVolume(Core::System& system, unsigned short offset);
+void DecreaseVolume(Core::System& system, unsigned short offset);
+void ToggleMuteVolume(Core::System& system);
} // namespace AudioCommon
diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp
index 8a02534c57..097432cc94 100644
--- a/Source/Core/Core/Core.cpp
+++ b/Source/Core/Core/Core.cpp
@@ -448,7 +448,7 @@ static void FifoPlayerThread(const std::optional<std::string>& savestate_path,
// See the BootManager.cpp file description for a complete call schedule.
static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi)
{
- const Core::System& system = Core::System::GetInstance();
+ Core::System& system = Core::System::GetInstance();
const SConfig& core_parameter = SConfig::GetInstance();
CallOnStateChangedCallbacks(State::Starting);
Common::ScopeGuard flag_guard{[] {
@@ -505,8 +505,8 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
Movie::Init(*boot);
Common::ScopeGuard movie_guard{&Movie::Shutdown};
- AudioCommon::InitSoundStream();
- Common::ScopeGuard audio_guard{&AudioCommon::ShutdownSoundStream};
+ AudioCommon::InitSoundStream(system);
+ Common::ScopeGuard audio_guard([&system] { AudioCommon::ShutdownSoundStream(system); });
HW::Init(NetPlay::IsNetPlayRunning() ? &(boot_session_data.GetNetplaySettings()->sram) : nullptr);
@@ -558,7 +558,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
// it's now ok to initialize any custom textures
HiresTexture::Update();
- AudioCommon::PostInitSoundStream();
+ AudioCommon::PostInitSoundStream(system);
// The hardware is initialized.
s_hardware_initialized = true;
diff --git a/Source/Core/Core/HW/CPU.cpp b/Source/Core/Core/HW/CPU.cpp
index 1325cce402..4345954eac 100644
--- a/Source/Core/Core/HW/CPU.cpp
+++ b/Source/Core/Core/HW/CPU.cpp
@@ -14,6 +14,7 @@
#include "Core/Host.h"
#include "Core/PowerPC/GDBStub.h"
#include "Core/PowerPC/PowerPC.h"
+#include "Core/System.h"
#include "VideoCommon/Fifo.h"
namespace CPU
@@ -193,7 +194,7 @@ static void RunAdjacentSystems(bool running)
Fifo::EmulatorState(running);
// Core is responsible for shutting down the sound stream.
if (s_state != State::PowerDown)
- AudioCommon::SetSoundStreamRunning(running);
+ AudioCommon::SetSoundStreamRunning(Core::System::GetInstance(), running);
}
void Stop()
diff --git a/Source/Core/Core/HW/DSP.cpp b/Source/Core/Core/HW/DSP.cpp
index f9d6cd7604..a64e7bf88e 100644
--- a/Source/Core/Core/HW/DSP.cpp
+++ b/Source/Core/Core/HW/DSP.cpp
@@ -414,7 +414,8 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base)
mmio->Register(
base | AUDIO_DMA_CONTROL_LEN, MMIO::DirectRead<u16>(&state.audio_dma.AudioDMAControl.Hex),
MMIO::ComplexWrite<u16>([](u32, u16 val) {
- auto& state = Core::System::GetInstance().GetDSPState().GetData();
+ auto& system = Core::System::GetInstance();
+ auto& state = system.GetDSPState().GetData();
bool already_enabled = state.audio_dma.AudioDMAControl.Enable;
state.audio_dma.AudioDMAControl.Hex = val;
@@ -522,7 +523,7 @@ void UpdateAudioDMA()
// external audio fifo in the emulator, to be mixed with the disc
// streaming output.
void* address = Memory::GetPointer(state.audio_dma.current_source_address);
- AudioCommon::SendAIBuffer(reinterpret_cast<short*>(address), 8);
+ AudioCommon::SendAIBuffer(system, reinterpret_cast<short*>(address), 8);
if (state.audio_dma.remaining_blocks_count != 0)
{
@@ -540,7 +541,7 @@ void UpdateAudioDMA()
}
else
{
- AudioCommon::SendAIBuffer(&zero_samples[0], 8);
+ AudioCommon::SendAIBuffer(system, &zero_samples[0], 8);
}
}
diff --git a/Source/Core/DolphinQt/HotkeyScheduler.cpp b/Source/Core/DolphinQt/HotkeyScheduler.cpp
index f00ddd6e19..0b80d746a7 100644
--- a/Source/Core/DolphinQt/HotkeyScheduler.cpp
+++ b/Source/Core/DolphinQt/HotkeyScheduler.cpp
@@ -30,6 +30,7 @@
#include "Core/IOS/USB/Bluetooth/BTBase.h"
#include "Core/IOS/USB/Bluetooth/BTReal.h"
#include "Core/State.h"
+#include "Core/System.h"
#include "Core/WiiUtils.h"
#ifdef HAS_LIBMGBA
@@ -353,7 +354,7 @@ void HotkeyScheduler::Run()
if (IsHotkey(HK_VOLUME_TOGGLE_MUTE))
{
- AudioCommon::ToggleMuteVolume();
+ AudioCommon::ToggleMuteVolume(Core::System::GetInstance());
ShowVolume();
}
diff --git a/Source/Core/DolphinQt/Settings.cpp b/Source/Core/DolphinQt/Settings.cpp
index a6580acbaa..26e108e80a 100644
--- a/Source/Core/DolphinQt/Settings.cpp
+++ b/Source/Core/DolphinQt/Settings.cpp
@@ -36,6 +36,7 @@
#include "Core/IOS/IOS.h"
#include "Core/NetPlayClient.h"
#include "Core/NetPlayServer.h"
+#include "Core/System.h"
#include "DolphinQt/Host.h"
#include "DolphinQt/QtUtils/QueueOnObject.h"
@@ -384,13 +385,13 @@ void Settings::SetVolume(int volume)
void Settings::IncreaseVolume(int volume)
{
- AudioCommon::IncreaseVolume(volume);
+ AudioCommon::IncreaseVolume(Core::System::GetInstance(), volume);
emit VolumeChanged(GetVolume());
}
void Settings::DecreaseVolume(int volume)
{
- AudioCommon::DecreaseVolume(volume);
+ AudioCommon::DecreaseVolume(Core::System::GetInstance(), volume);
emit VolumeChanged(GetVolume());
}
diff --git a/Source/Core/DolphinQt/Settings/AudioPane.cpp b/Source/Core/DolphinQt/Settings/AudioPane.cpp
index 1da51c1da5..c79e7f58bf 100644
--- a/Source/Core/DolphinQt/Settings/AudioPane.cpp
+++ b/Source/Core/DolphinQt/Settings/AudioPane.cpp
@@ -23,6 +23,7 @@
#include "Core/Config/MainSettings.h"
#include "Core/Core.h"
+#include "Core/System.h"
#include "DolphinQt/Config/SettingsWindow.h"
#include "DolphinQt/Settings.h"
@@ -328,7 +329,7 @@ void AudioPane::SaveSettings()
Config::SetBaseOrCurrent(Config::MAIN_WASAPI_DEVICE, device);
#endif
- AudioCommon::UpdateSoundStream();
+ AudioCommon::UpdateSoundStream(Core::System::GetInstance());
}
void AudioPane::OnDspChanged()