diff options
| author | 2016-04-27 13:53:23 +0100 | |
|---|---|---|
| committer | 2016-04-30 07:41:02 +0100 | |
| commit | 4e971f44a27c2e4abc25ddf0720d287a688e0a4d (patch) | |
| tree | c88ce045e20e40dd022a56dbd4a5281024591e61 /src/audio_core | |
| parent | AudioCore: List of sink types (diff) | |
| download | yuzu-4e971f44a27c2e4abc25ddf0720d287a688e0a4d.tar.gz yuzu-4e971f44a27c2e4abc25ddf0720d287a688e0a4d.tar.xz yuzu-4e971f44a27c2e4abc25ddf0720d287a688e0a4d.zip | |
Audio: Add sink selection to configuration files
Diffstat (limited to 'src/audio_core')
| -rw-r--r-- | src/audio_core/audio_core.cpp | 33 | ||||
| -rw-r--r-- | src/audio_core/audio_core.h | 5 | ||||
| -rw-r--r-- | src/audio_core/hle/dsp.cpp | 9 | ||||
| -rw-r--r-- | src/audio_core/hle/dsp.h | 11 | ||||
| -rw-r--r-- | src/audio_core/sink_details.cpp | 1 |
5 files changed, 55 insertions, 4 deletions
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 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <memory> | ||
| 6 | #include <string> | ||
| 7 | |||
| 5 | #include "audio_core/audio_core.h" | 8 | #include "audio_core/audio_core.h" |
| 6 | #include "audio_core/hle/dsp.h" | 9 | #include "audio_core/hle/dsp.h" |
| 7 | #include "audio_core/hle/pipe.h" | 10 | #include "audio_core/hle/pipe.h" |
| 11 | #include "audio_core/null_sink.h" | ||
| 12 | #include "audio_core/sink.h" | ||
| 13 | #include "audio_core/sink_details.h" | ||
| 8 | 14 | ||
| 9 | #include "core/core_timing.h" | 15 | #include "core/core_timing.h" |
| 10 | #include "core/hle/kernel/vm_manager.h" | 16 | #include "core/hle/kernel/vm_manager.h" |
| @@ -28,7 +34,6 @@ static void AudioTickCallback(u64 /*userdata*/, int cycles_late) { | |||
| 28 | CoreTiming::ScheduleEvent(audio_frame_ticks - cycles_late, tick_event); | 34 | CoreTiming::ScheduleEvent(audio_frame_ticks - cycles_late, tick_event); |
| 29 | } | 35 | } |
| 30 | 36 | ||
| 31 | /// Initialise Audio | ||
| 32 | void Init() { | 37 | void Init() { |
| 33 | DSP::HLE::Init(); | 38 | DSP::HLE::Init(); |
| 34 | 39 | ||
| @@ -36,7 +41,6 @@ void Init() { | |||
| 36 | CoreTiming::ScheduleEvent(audio_frame_ticks, tick_event); | 41 | CoreTiming::ScheduleEvent(audio_frame_ticks, tick_event); |
| 37 | } | 42 | } |
| 38 | 43 | ||
| 39 | /// Add DSP address spaces to Process's address space. | ||
| 40 | void AddAddressSpace(Kernel::VMManager& address_space) { | 44 | void AddAddressSpace(Kernel::VMManager& address_space) { |
| 41 | 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(); | 45 | 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(); |
| 42 | address_space.Reprotect(r0_vma, Kernel::VMAPermission::ReadWrite); | 46 | address_space.Reprotect(r0_vma, Kernel::VMAPermission::ReadWrite); |
| @@ -45,10 +49,31 @@ void AddAddressSpace(Kernel::VMManager& address_space) { | |||
| 45 | address_space.Reprotect(r1_vma, Kernel::VMAPermission::ReadWrite); | 49 | address_space.Reprotect(r1_vma, Kernel::VMAPermission::ReadWrite); |
| 46 | } | 50 | } |
| 47 | 51 | ||
| 48 | /// Shutdown Audio | 52 | void SelectSink(std::string sink_id) { |
| 53 | if (sink_id == "auto") { | ||
| 54 | // Auto-select. | ||
| 55 | // g_sink_details is ordered in terms of desirability, with the best choice at the front. | ||
| 56 | const auto& sink_detail = g_sink_details.front(); | ||
| 57 | DSP::HLE::SetSink(sink_detail.factory()); | ||
| 58 | return; | ||
| 59 | } | ||
| 60 | |||
| 61 | auto iter = std::find_if(g_sink_details.begin(), g_sink_details.end(), [sink_id](const auto& sink_detail) { | ||
| 62 | return sink_detail.id == sink_id; | ||
| 63 | }); | ||
| 64 | |||
| 65 | if (iter == g_sink_details.end()) { | ||
| 66 | LOG_ERROR(Audio, "AudioCore::SelectSink given invalid sink_id"); | ||
| 67 | DSP::HLE::SetSink(std::make_unique<NullSink>()); | ||
| 68 | return; | ||
| 69 | } | ||
| 70 | |||
| 71 | DSP::HLE::SetSink(iter->factory()); | ||
| 72 | } | ||
| 73 | |||
| 49 | void Shutdown() { | 74 | void Shutdown() { |
| 50 | CoreTiming::UnscheduleEvent(tick_event, 0); | 75 | CoreTiming::UnscheduleEvent(tick_event, 0); |
| 51 | DSP::HLE::Shutdown(); | 76 | DSP::HLE::Shutdown(); |
| 52 | } | 77 | } |
| 53 | 78 | ||
| 54 | } //namespace | 79 | } // 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 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <string> | ||
| 8 | |||
| 7 | namespace Kernel { | 9 | namespace Kernel { |
| 8 | class VMManager; | 10 | class VMManager; |
| 9 | } | 11 | } |
| @@ -18,6 +20,9 @@ void Init(); | |||
| 18 | /// Add DSP address spaces to a Process. | 20 | /// Add DSP address spaces to a Process. |
| 19 | void AddAddressSpace(Kernel::VMManager& vm_manager); | 21 | void AddAddressSpace(Kernel::VMManager& vm_manager); |
| 20 | 22 | ||
| 23 | /// Select the sink to use based on sink id. | ||
| 24 | void SelectSink(std::string sink_id); | ||
| 25 | |||
| 21 | /// Shutdown Audio Core | 26 | /// Shutdown Audio Core |
| 22 | void Shutdown(); | 27 | void Shutdown(); |
| 23 | 28 | ||
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 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <memory> | ||
| 6 | |||
| 5 | #include "audio_core/hle/dsp.h" | 7 | #include "audio_core/hle/dsp.h" |
| 6 | #include "audio_core/hle/pipe.h" | 8 | #include "audio_core/hle/pipe.h" |
| 9 | #include "audio_core/sink.h" | ||
| 7 | 10 | ||
| 8 | namespace DSP { | 11 | namespace DSP { |
| 9 | namespace HLE { | 12 | namespace HLE { |
| @@ -35,6 +38,8 @@ static SharedMemory& WriteRegion() { | |||
| 35 | return g_regions[1 - CurrentRegionIndex()]; | 38 | return g_regions[1 - CurrentRegionIndex()]; |
| 36 | } | 39 | } |
| 37 | 40 | ||
| 41 | static std::unique_ptr<AudioCore::Sink> sink; | ||
| 42 | |||
| 38 | void Init() { | 43 | void Init() { |
| 39 | DSP::HLE::ResetPipes(); | 44 | DSP::HLE::ResetPipes(); |
| 40 | } | 45 | } |
| @@ -46,5 +51,9 @@ bool Tick() { | |||
| 46 | return true; | 51 | return true; |
| 47 | } | 52 | } |
| 48 | 53 | ||
| 54 | void SetSink(std::unique_ptr<AudioCore::Sink> sink_) { | ||
| 55 | sink = std::move(sink_); | ||
| 56 | } | ||
| 57 | |||
| 49 | } // namespace HLE | 58 | } // namespace HLE |
| 50 | } // namespace DSP | 59 | } // 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 @@ | |||
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <cstddef> | 8 | #include <cstddef> |
| 9 | #include <memory> | ||
| 9 | #include <type_traits> | 10 | #include <type_traits> |
| 10 | 11 | ||
| 11 | #include "audio_core/hle/common.h" | 12 | #include "audio_core/hle/common.h" |
| @@ -15,6 +16,10 @@ | |||
| 15 | #include "common/common_types.h" | 16 | #include "common/common_types.h" |
| 16 | #include "common/swap.h" | 17 | #include "common/swap.h" |
| 17 | 18 | ||
| 19 | namespace AudioCore { | ||
| 20 | class Sink; | ||
| 21 | } | ||
| 22 | |||
| 18 | namespace DSP { | 23 | namespace DSP { |
| 19 | namespace HLE { | 24 | namespace HLE { |
| 20 | 25 | ||
| @@ -535,5 +540,11 @@ void Shutdown(); | |||
| 535 | */ | 540 | */ |
| 536 | bool Tick(); | 541 | bool Tick(); |
| 537 | 542 | ||
| 543 | /** | ||
| 544 | * Set the output sink. This must be called before calling Tick(). | ||
| 545 | * @param sink The sink to which audio will be output to. | ||
| 546 | */ | ||
| 547 | void SetSink(std::unique_ptr<AudioCore::Sink> sink); | ||
| 548 | |||
| 538 | } // namespace HLE | 549 | } // namespace HLE |
| 539 | } // namespace DSP | 550 | } // namespace DSP |
diff --git a/src/audio_core/sink_details.cpp b/src/audio_core/sink_details.cpp index 20412daaf..d2cc74103 100644 --- a/src/audio_core/sink_details.cpp +++ b/src/audio_core/sink_details.cpp | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | namespace AudioCore { | 11 | namespace AudioCore { |
| 12 | 12 | ||
| 13 | // g_sink_details is ordered in terms of desirability, with the best choice at the top. | ||
| 13 | const std::vector<SinkDetails> g_sink_details = { | 14 | const std::vector<SinkDetails> g_sink_details = { |
| 14 | { "null", []() { return std::make_unique<NullSink>(); } }, | 15 | { "null", []() { return std::make_unique<NullSink>(); } }, |
| 15 | }; | 16 | }; |