summaryrefslogtreecommitdiffstats
path: root/src/audio_core
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2016-04-30 09:49:11 +0200
committerbunnei <bunneidev@gmail.com>2016-04-30 09:49:11 +0200
commitc1f0044a4b10bdff45464e5957f7950a6059d0c9 (patch)
treed9b4673f92da936ce763148f70b82bc7401dd968 /src/audio_core
parentMerge pull request #1650 from JamePeng/update-the-ndm-code (diff)
parentAudio: Add sink selection to configuration files (diff)
downloadyuzu-c1f0044a4b10bdff45464e5957f7950a6059d0c9.tar
yuzu-c1f0044a4b10bdff45464e5957f7950a6059d0c9.tar.gz
yuzu-c1f0044a4b10bdff45464e5957f7950a6059d0c9.tar.bz2
yuzu-c1f0044a4b10bdff45464e5957f7950a6059d0c9.tar.lz
yuzu-c1f0044a4b10bdff45464e5957f7950a6059d0c9.tar.xz
yuzu-c1f0044a4b10bdff45464e5957f7950a6059d0c9.tar.zst
yuzu-c1f0044a4b10bdff45464e5957f7950a6059d0c9.zip
Diffstat (limited to 'src/audio_core')
-rw-r--r--src/audio_core/CMakeLists.txt3
-rw-r--r--src/audio_core/audio_core.cpp33
-rw-r--r--src/audio_core/audio_core.h5
-rw-r--r--src/audio_core/hle/dsp.cpp9
-rw-r--r--src/audio_core/hle/dsp.h11
-rw-r--r--src/audio_core/null_sink.h29
-rw-r--r--src/audio_core/sink_details.cpp18
-rw-r--r--src/audio_core/sink_details.h27
8 files changed, 131 insertions, 4 deletions
diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt
index a965af291..5a2747e78 100644
--- a/src/audio_core/CMakeLists.txt
+++ b/src/audio_core/CMakeLists.txt
@@ -5,6 +5,7 @@ set(SRCS
hle/filter.cpp
hle/pipe.cpp
interpolate.cpp
+ sink_details.cpp
)
set(HEADERS
@@ -15,7 +16,9 @@ set(HEADERS
hle/filter.h
hle/pipe.h
interpolate.h
+ null_sink.h
sink.h
+ sink_details.h
)
include_directories(../../externals/soundtouch/include)
diff --git a/src/audio_core/audio_core.cpp b/src/audio_core/audio_core.cpp
index cbe869a04..d42249ebd 100644
--- a/src/audio_core/audio_core.cpp
+++ b/src/audio_core/audio_core.cpp
@@ -2,9 +2,15 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
+#include <memory>
+#include <string>
+
#include "audio_core/audio_core.h"
#include "audio_core/hle/dsp.h"
#include "audio_core/hle/pipe.h"
+#include "audio_core/null_sink.h"
+#include "audio_core/sink.h"
+#include "audio_core/sink_details.h"
#include "core/core_timing.h"
#include "core/hle/kernel/vm_manager.h"
@@ -28,7 +34,6 @@ static void AudioTickCallback(u64 /*userdata*/, int cycles_late) {
CoreTiming::ScheduleEvent(audio_frame_ticks - cycles_late, tick_event);
}
-/// Initialise Audio
void Init() {
DSP::HLE::Init();
@@ -36,7 +41,6 @@ void Init() {
CoreTiming::ScheduleEvent(audio_frame_ticks, tick_event);
}
-/// Add DSP address spaces to Process's address space.
void AddAddressSpace(Kernel::VMManager& address_space) {
auto r0_vma = address_space.MapBackingMemory(DSP::HLE::region0_base, reinterpret_cast<u8*>(&DSP::HLE::g_regions[0]), sizeof(DSP::HLE::SharedMemory), Kernel::MemoryState::IO).MoveFrom();
address_space.Reprotect(r0_vma, Kernel::VMAPermission::ReadWrite);
@@ -45,10 +49,31 @@ void AddAddressSpace(Kernel::VMManager& address_space) {
address_space.Reprotect(r1_vma, Kernel::VMAPermission::ReadWrite);
}
-/// Shutdown Audio
+void SelectSink(std::string sink_id) {
+ if (sink_id == "auto") {
+ // Auto-select.
+ // g_sink_details is ordered in terms of desirability, with the best choice at the front.
+ const auto& sink_detail = g_sink_details.front();
+ DSP::HLE::SetSink(sink_detail.factory());
+ return;
+ }
+
+ auto iter = std::find_if(g_sink_details.begin(), g_sink_details.end(), [sink_id](const auto& sink_detail) {
+ return sink_detail.id == sink_id;
+ });
+
+ if (iter == g_sink_details.end()) {
+ LOG_ERROR(Audio, "AudioCore::SelectSink given invalid sink_id");
+ DSP::HLE::SetSink(std::make_unique<NullSink>());
+ return;
+ }
+
+ DSP::HLE::SetSink(iter->factory());
+}
+
void Shutdown() {
CoreTiming::UnscheduleEvent(tick_event, 0);
DSP::HLE::Shutdown();
}
-} //namespace
+} // namespace AudioCore
diff --git a/src/audio_core/audio_core.h b/src/audio_core/audio_core.h
index b349895ea..f618361f3 100644
--- a/src/audio_core/audio_core.h
+++ b/src/audio_core/audio_core.h
@@ -4,6 +4,8 @@
#pragma once
+#include <string>
+
namespace Kernel {
class VMManager;
}
@@ -18,6 +20,9 @@ void Init();
/// Add DSP address spaces to a Process.
void AddAddressSpace(Kernel::VMManager& vm_manager);
+/// Select the sink to use based on sink id.
+void SelectSink(std::string sink_id);
+
/// Shutdown Audio Core
void Shutdown();
diff --git a/src/audio_core/hle/dsp.cpp b/src/audio_core/hle/dsp.cpp
index 5759a5b9e..4d44bd2d9 100644
--- a/src/audio_core/hle/dsp.cpp
+++ b/src/audio_core/hle/dsp.cpp
@@ -2,8 +2,11 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
+#include <memory>
+
#include "audio_core/hle/dsp.h"
#include "audio_core/hle/pipe.h"
+#include "audio_core/sink.h"
namespace DSP {
namespace HLE {
@@ -35,6 +38,8 @@ static SharedMemory& WriteRegion() {
return g_regions[1 - CurrentRegionIndex()];
}
+static std::unique_ptr<AudioCore::Sink> sink;
+
void Init() {
DSP::HLE::ResetPipes();
}
@@ -46,5 +51,9 @@ bool Tick() {
return true;
}
+void SetSink(std::unique_ptr<AudioCore::Sink> sink_) {
+ sink = std::move(sink_);
+}
+
} // namespace HLE
} // namespace DSP
diff --git a/src/audio_core/hle/dsp.h b/src/audio_core/hle/dsp.h
index f0f125284..4f2410c27 100644
--- a/src/audio_core/hle/dsp.h
+++ b/src/audio_core/hle/dsp.h
@@ -6,6 +6,7 @@
#include <array>
#include <cstddef>
+#include <memory>
#include <type_traits>
#include "audio_core/hle/common.h"
@@ -15,6 +16,10 @@
#include "common/common_types.h"
#include "common/swap.h"
+namespace AudioCore {
+class Sink;
+}
+
namespace DSP {
namespace HLE {
@@ -535,5 +540,11 @@ void Shutdown();
*/
bool Tick();
+/**
+ * Set the output sink. This must be called before calling Tick().
+ * @param sink The sink to which audio will be output to.
+ */
+void SetSink(std::unique_ptr<AudioCore::Sink> sink);
+
} // namespace HLE
} // namespace DSP
diff --git a/src/audio_core/null_sink.h b/src/audio_core/null_sink.h
new file mode 100644
index 000000000..faf0ee4e1
--- /dev/null
+++ b/src/audio_core/null_sink.h
@@ -0,0 +1,29 @@
+// Copyright 2016 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <cstddef>
+
+#include "audio_core/audio_core.h"
+#include "audio_core/sink.h"
+
+namespace AudioCore {
+
+class NullSink final : public Sink {
+public:
+ ~NullSink() override = default;
+
+ unsigned int GetNativeSampleRate() const override {
+ return native_sample_rate;
+ }
+
+ void EnqueueSamples(const std::vector<s16>&) override {}
+
+ size_t SamplesInQueue() const override {
+ return 0;
+ }
+};
+
+} // namespace AudioCore
diff --git a/src/audio_core/sink_details.cpp b/src/audio_core/sink_details.cpp
new file mode 100644
index 000000000..d2cc74103
--- /dev/null
+++ b/src/audio_core/sink_details.cpp
@@ -0,0 +1,18 @@
+// Copyright 2016 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include <memory>
+#include <vector>
+
+#include "audio_core/null_sink.h"
+#include "audio_core/sink_details.h"
+
+namespace AudioCore {
+
+// g_sink_details is ordered in terms of desirability, with the best choice at the top.
+const std::vector<SinkDetails> g_sink_details = {
+ { "null", []() { return std::make_unique<NullSink>(); } },
+};
+
+} // namespace AudioCore
diff --git a/src/audio_core/sink_details.h b/src/audio_core/sink_details.h
new file mode 100644
index 000000000..4b30cf835
--- /dev/null
+++ b/src/audio_core/sink_details.h
@@ -0,0 +1,27 @@
+// Copyright 2016 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <functional>
+#include <memory>
+#include <vector>
+
+namespace AudioCore {
+
+class Sink;
+
+struct SinkDetails {
+ SinkDetails(const char* id_, std::function<std::unique_ptr<Sink>()> factory_)
+ : id(id_), factory(factory_) {}
+
+ /// Name for this sink.
+ const char* id;
+ /// A method to call to construct an instance of this type of sink.
+ std::function<std::unique_ptr<Sink>()> factory;
+};
+
+extern const std::vector<SinkDetails> g_sink_details;
+
+} // namespace AudioCore