summaryrefslogtreecommitdiff
path: root/src/audio_core/device
diff options
context:
space:
mode:
authorGravatar Liam2024-01-12 09:35:08 -0500
committerGravatar Liam2024-01-12 10:03:16 -0500
commitd940974789b1b8ff473440883d8c506a275b9b3b (patch)
treee859ecfe3e8c0537035972a83bf2344ebf3577b6 /src/audio_core/device
parentMerge pull request #12653 from liamwhite/once-more (diff)
downloadyuzu-d940974789b1b8ff473440883d8c506a275b9b3b.tar.gz
yuzu-d940974789b1b8ff473440883d8c506a275b9b3b.tar.xz
yuzu-d940974789b1b8ff473440883d8c506a275b9b3b.zip
audio: fetch process object from handle table
Diffstat (limited to 'src/audio_core/device')
-rw-r--r--src/audio_core/device/device_session.cpp14
-rw-r--r--src/audio_core/device/device_session.h12
2 files changed, 19 insertions, 7 deletions
diff --git a/src/audio_core/device/device_session.cpp b/src/audio_core/device/device_session.cpp
index ee42ae529..3c214ec00 100644
--- a/src/audio_core/device/device_session.cpp
+++ b/src/audio_core/device/device_session.cpp
@@ -10,6 +10,8 @@
10#include "core/core_timing.h" 10#include "core/core_timing.h"
11#include "core/memory.h" 11#include "core/memory.h"
12 12
13#include "core/hle/kernel/k_process.h"
14
13namespace AudioCore { 15namespace AudioCore {
14 16
15using namespace std::literals; 17using namespace std::literals;
@@ -25,7 +27,7 @@ DeviceSession::~DeviceSession() {
25} 27}
26 28
27Result DeviceSession::Initialize(std::string_view name_, SampleFormat sample_format_, 29Result DeviceSession::Initialize(std::string_view name_, SampleFormat sample_format_,
28 u16 channel_count_, size_t session_id_, u32 handle_, 30 u16 channel_count_, size_t session_id_, Kernel::KProcess* handle_,
29 u64 applet_resource_user_id_, Sink::StreamType type_) { 31 u64 applet_resource_user_id_, Sink::StreamType type_) {
30 if (stream) { 32 if (stream) {
31 Finalize(); 33 Finalize();
@@ -36,6 +38,7 @@ Result DeviceSession::Initialize(std::string_view name_, SampleFormat sample_for
36 channel_count = channel_count_; 38 channel_count = channel_count_;
37 session_id = session_id_; 39 session_id = session_id_;
38 handle = handle_; 40 handle = handle_;
41 handle->Open();
39 applet_resource_user_id = applet_resource_user_id_; 42 applet_resource_user_id = applet_resource_user_id_;
40 43
41 if (type == Sink::StreamType::In) { 44 if (type == Sink::StreamType::In) {
@@ -54,6 +57,11 @@ void DeviceSession::Finalize() {
54 sink->CloseStream(stream); 57 sink->CloseStream(stream);
55 stream = nullptr; 58 stream = nullptr;
56 } 59 }
60
61 if (handle) {
62 handle->Close();
63 handle = nullptr;
64 }
57} 65}
58 66
59void DeviceSession::Start() { 67void DeviceSession::Start() {
@@ -91,7 +99,7 @@ void DeviceSession::AppendBuffers(std::span<const AudioBuffer> buffers) {
91 stream->AppendBuffer(new_buffer, tmp_samples); 99 stream->AppendBuffer(new_buffer, tmp_samples);
92 } else { 100 } else {
93 Core::Memory::CpuGuestMemory<s16, Core::Memory::GuestMemoryFlags::UnsafeRead> samples( 101 Core::Memory::CpuGuestMemory<s16, Core::Memory::GuestMemoryFlags::UnsafeRead> samples(
94 system.ApplicationMemory(), buffer.samples, buffer.size / sizeof(s16)); 102 handle->GetMemory(), buffer.samples, buffer.size / sizeof(s16));
95 stream->AppendBuffer(new_buffer, samples); 103 stream->AppendBuffer(new_buffer, samples);
96 } 104 }
97 } 105 }
@@ -100,7 +108,7 @@ void DeviceSession::AppendBuffers(std::span<const AudioBuffer> buffers) {
100void DeviceSession::ReleaseBuffer(const AudioBuffer& buffer) const { 108void DeviceSession::ReleaseBuffer(const AudioBuffer& buffer) const {
101 if (type == Sink::StreamType::In) { 109 if (type == Sink::StreamType::In) {
102 auto samples{stream->ReleaseBuffer(buffer.size / sizeof(s16))}; 110 auto samples{stream->ReleaseBuffer(buffer.size / sizeof(s16))};
103 system.ApplicationMemory().WriteBlockUnsafe(buffer.samples, samples.data(), buffer.size); 111 handle->GetMemory().WriteBlockUnsafe(buffer.samples, samples.data(), buffer.size);
104 } 112 }
105} 113}
106 114
diff --git a/src/audio_core/device/device_session.h b/src/audio_core/device/device_session.h
index 7d52f362d..f3fae2617 100644
--- a/src/audio_core/device/device_session.h
+++ b/src/audio_core/device/device_session.h
@@ -20,6 +20,10 @@ struct EventType;
20} // namespace Timing 20} // namespace Timing
21} // namespace Core 21} // namespace Core
22 22
23namespace Kernel {
24class KProcess;
25} // namespace Kernel
26
23namespace AudioCore { 27namespace AudioCore {
24 28
25namespace Sink { 29namespace Sink {
@@ -44,13 +48,13 @@ public:
44 * @param sample_format - Sample format for this device's output. 48 * @param sample_format - Sample format for this device's output.
45 * @param channel_count - Number of channels for this device (2 or 6). 49 * @param channel_count - Number of channels for this device (2 or 6).
46 * @param session_id - This session's id. 50 * @param session_id - This session's id.
47 * @param handle - Handle for this device session (unused). 51 * @param handle - Process handle for this device session.
48 * @param applet_resource_user_id - Applet resource user id for this device session (unused). 52 * @param applet_resource_user_id - Applet resource user id for this device session (unused).
49 * @param type - Type of this stream (Render, In, Out). 53 * @param type - Type of this stream (Render, In, Out).
50 * @return Result code for this call. 54 * @return Result code for this call.
51 */ 55 */
52 Result Initialize(std::string_view name, SampleFormat sample_format, u16 channel_count, 56 Result Initialize(std::string_view name, SampleFormat sample_format, u16 channel_count,
53 size_t session_id, u32 handle, u64 applet_resource_user_id, 57 size_t session_id, Kernel::KProcess* handle, u64 applet_resource_user_id,
54 Sink::StreamType type); 58 Sink::StreamType type);
55 59
56 /** 60 /**
@@ -137,8 +141,8 @@ private:
137 u16 channel_count{}; 141 u16 channel_count{};
138 /// Session id of this device session 142 /// Session id of this device session
139 size_t session_id{}; 143 size_t session_id{};
140 /// Handle of this device session 144 /// Process handle of device memory owner
141 u32 handle{}; 145 Kernel::KProcess* handle{};
142 /// Applet resource user id of this device session 146 /// Applet resource user id of this device session
143 u64 applet_resource_user_id{}; 147 u64 applet_resource_user_id{};
144 /// Total number of samples played by this device session 148 /// Total number of samples played by this device session