From 6012c9fe3af1c649e5ac6392dc4b74bd3cfd0c4f Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 20 Feb 2024 20:02:36 -0500 Subject: audio: rewrite IAudioRendererManager --- src/audio_core/renderer/audio_renderer.cpp | 7 +++---- src/audio_core/renderer/audio_renderer.h | 4 ++-- src/audio_core/renderer/behavior/info_updater.cpp | 9 ++++----- src/audio_core/renderer/behavior/info_updater.h | 10 +++++++--- src/audio_core/renderer/memory/pool_mapper.cpp | 22 ++++++++++++---------- src/audio_core/renderer/memory/pool_mapper.h | 14 +++++++++----- src/audio_core/renderer/system.cpp | 10 +++++----- src/audio_core/renderer/system.h | 8 +++----- 8 files changed, 45 insertions(+), 39 deletions(-) (limited to 'src/audio_core/renderer') diff --git a/src/audio_core/renderer/audio_renderer.cpp b/src/audio_core/renderer/audio_renderer.cpp index df03d03aa..7c728cb86 100644 --- a/src/audio_core/renderer/audio_renderer.cpp +++ b/src/audio_core/renderer/audio_renderer.cpp @@ -17,9 +17,8 @@ Renderer::Renderer(Core::System& system_, Manager& manager_, Kernel::KEvent* ren Result Renderer::Initialize(const AudioRendererParameterInternal& params, Kernel::KTransferMemory* transfer_memory, - const u64 transfer_memory_size, const u32 process_handle, - Kernel::KProcess& process, const u64 applet_resource_user_id, - const s32 session_id) { + const u64 transfer_memory_size, Kernel::KProcess* process_handle, + const u64 applet_resource_user_id, const s32 session_id) { if (params.execution_mode == ExecutionMode::Auto) { if (!manager.AddSystem(system)) { LOG_ERROR(Service_Audio, @@ -30,7 +29,7 @@ Result Renderer::Initialize(const AudioRendererParameterInternal& params, } initialized = true; - system.Initialize(params, transfer_memory, transfer_memory_size, process_handle, process, + system.Initialize(params, transfer_memory, transfer_memory_size, process_handle, applet_resource_user_id, session_id); return ResultSuccess; diff --git a/src/audio_core/renderer/audio_renderer.h b/src/audio_core/renderer/audio_renderer.h index 1219f74ca..f16adeda7 100644 --- a/src/audio_core/renderer/audio_renderer.h +++ b/src/audio_core/renderer/audio_renderer.h @@ -38,14 +38,14 @@ public: * @param params - Input parameters to initialize the system with. * @param transfer_memory - Game-supplied memory for all workbuffers. Unused. * @param transfer_memory_size - Size of the transfer memory. Unused. - * @param process_handle - Process handle, also used for memory. Unused. + * @param process_handle - Process handle, also used for memory. * @param applet_resource_user_id - Applet id for this renderer. Unused. * @param session_id - Session id of this renderer. * @return Result code. */ Result Initialize(const AudioRendererParameterInternal& params, Kernel::KTransferMemory* transfer_memory, u64 transfer_memory_size, - u32 process_handle, Kernel::KProcess& process, u64 applet_resource_user_id, + Kernel::KProcess* process_handle, u64 applet_resource_user_id, s32 session_id); /** diff --git a/src/audio_core/renderer/behavior/info_updater.cpp b/src/audio_core/renderer/behavior/info_updater.cpp index 667711e17..163127789 100644 --- a/src/audio_core/renderer/behavior/info_updater.cpp +++ b/src/audio_core/renderer/behavior/info_updater.cpp @@ -18,11 +18,10 @@ namespace AudioCore::Renderer { InfoUpdater::InfoUpdater(std::span input_, std::span output_, - const u32 process_handle_, BehaviorInfo& behaviour_) - : input{input_.data() + sizeof(UpdateDataHeader)}, - input_origin{input_}, output{output_.data() + sizeof(UpdateDataHeader)}, - output_origin{output_}, in_header{reinterpret_cast( - input_origin.data())}, + Kernel::KProcess* process_handle_, BehaviorInfo& behaviour_) + : input{input_.data() + sizeof(UpdateDataHeader)}, input_origin{input_}, + output{output_.data() + sizeof(UpdateDataHeader)}, output_origin{output_}, + in_header{reinterpret_cast(input_origin.data())}, out_header{reinterpret_cast(output_origin.data())}, expected_input_size{input_.size()}, expected_output_size{output_.size()}, process_handle{process_handle_}, behaviour{behaviour_} { diff --git a/src/audio_core/renderer/behavior/info_updater.h b/src/audio_core/renderer/behavior/info_updater.h index fb4b7d25a..4f27a817e 100644 --- a/src/audio_core/renderer/behavior/info_updater.h +++ b/src/audio_core/renderer/behavior/info_updater.h @@ -8,6 +8,10 @@ #include "common/common_types.h" #include "core/hle/service/audio/errors.h" +namespace Kernel { +class KProcess; +} + namespace AudioCore::Renderer { class BehaviorInfo; class VoiceContext; @@ -39,8 +43,8 @@ class InfoUpdater { static_assert(sizeof(UpdateDataHeader) == 0x40, "UpdateDataHeader has the wrong size!"); public: - explicit InfoUpdater(std::span input, std::span output, u32 process_handle, - BehaviorInfo& behaviour); + explicit InfoUpdater(std::span input, std::span output, + Kernel::KProcess* process_handle, BehaviorInfo& behaviour); /** * Update the voice channel resources. @@ -197,7 +201,7 @@ private: /// Expected output size, see CheckConsumedSize u64 expected_output_size; /// Unused - u32 process_handle; + Kernel::KProcess* process_handle; /// Behaviour BehaviorInfo& behaviour; }; diff --git a/src/audio_core/renderer/memory/pool_mapper.cpp b/src/audio_core/renderer/memory/pool_mapper.cpp index 999bb746b..1df786feb 100644 --- a/src/audio_core/renderer/memory/pool_mapper.cpp +++ b/src/audio_core/renderer/memory/pool_mapper.cpp @@ -8,13 +8,13 @@ namespace AudioCore::Renderer { -PoolMapper::PoolMapper(u32 process_handle_, bool force_map_) +PoolMapper::PoolMapper(Kernel::KProcess* process_handle_, bool force_map_) : process_handle{process_handle_}, force_map{force_map_} {} -PoolMapper::PoolMapper(u32 process_handle_, std::span pool_infos_, u32 pool_count_, - bool force_map_) - : process_handle{process_handle_}, pool_infos{pool_infos_.data()}, - pool_count{pool_count_}, force_map{force_map_} {} +PoolMapper::PoolMapper(Kernel::KProcess* process_handle_, std::span pool_infos_, + u32 pool_count_, bool force_map_) + : process_handle{process_handle_}, pool_infos{pool_infos_.data()}, pool_count{pool_count_}, + force_map{force_map_} {} void PoolMapper::ClearUseState(std::span pools, const u32 count) { for (u32 i = 0; i < count; i++) { @@ -106,15 +106,17 @@ bool PoolMapper::IsForceMapEnabled() const { return force_map; } -u32 PoolMapper::GetProcessHandle(const MemoryPoolInfo* pool) const { +Kernel::KProcess* PoolMapper::GetProcessHandle(const MemoryPoolInfo* pool) const { switch (pool->GetLocation()) { case MemoryPoolInfo::Location::CPU: return process_handle; case MemoryPoolInfo::Location::DSP: - return Kernel::Svc::CurrentProcess; + // return Kernel::Svc::CurrentProcess; + return nullptr; } LOG_WARNING(Service_Audio, "Invalid MemoryPoolInfo location!"); - return Kernel::Svc::CurrentProcess; + // return Kernel::Svc::CurrentProcess; + return nullptr; } bool PoolMapper::Map([[maybe_unused]] const u32 handle, [[maybe_unused]] const CpuAddr cpu_addr, @@ -147,14 +149,14 @@ bool PoolMapper::Unmap([[maybe_unused]] const u32 handle, [[maybe_unused]] const } bool PoolMapper::Unmap(MemoryPoolInfo& pool) const { - [[maybe_unused]] u32 handle{0}; + [[maybe_unused]] Kernel::KProcess* handle{}; switch (pool.GetLocation()) { case MemoryPoolInfo::Location::CPU: handle = process_handle; break; case MemoryPoolInfo::Location::DSP: - handle = Kernel::Svc::CurrentProcess; + // handle = Kernel::Svc::CurrentProcess; break; } // nn::audio::dsp::UnmapUserPointer(handle, pool->cpu_address, pool->size); diff --git a/src/audio_core/renderer/memory/pool_mapper.h b/src/audio_core/renderer/memory/pool_mapper.h index 95ae5d8ea..fb5122b73 100644 --- a/src/audio_core/renderer/memory/pool_mapper.h +++ b/src/audio_core/renderer/memory/pool_mapper.h @@ -10,6 +10,10 @@ #include "common/common_types.h" #include "core/hle/service/audio/errors.h" +namespace Kernel { +class KProcess; +} + namespace AudioCore::Renderer { class AddressInfo; @@ -18,9 +22,9 @@ class AddressInfo; */ class PoolMapper { public: - explicit PoolMapper(u32 process_handle, bool force_map); - explicit PoolMapper(u32 process_handle, std::span pool_infos, u32 pool_count, - bool force_map); + explicit PoolMapper(Kernel::KProcess* process_handle, bool force_map); + explicit PoolMapper(Kernel::KProcess* process_handle, std::span pool_infos, + u32 pool_count, bool force_map); /** * Clear the usage state for all given pools. @@ -98,7 +102,7 @@ public: * @return CurrentProcessHandle if location == DSP, * the PoolMapper's process_handle if location == CPU */ - u32 GetProcessHandle(const MemoryPoolInfo* pool) const; + Kernel::KProcess* GetProcessHandle(const MemoryPoolInfo* pool) const; /** * Map the given region with the given handle. This is a no-op. @@ -167,7 +171,7 @@ public: private: /// Process handle for this mapper, used when location == CPU - u32 process_handle; + Kernel::KProcess* process_handle{}; /// List of memory pools assigned to this mapper MemoryPoolInfo* pool_infos{}; /// The number of pools diff --git a/src/audio_core/renderer/system.cpp b/src/audio_core/renderer/system.cpp index ca656edae..c30d68426 100644 --- a/src/audio_core/renderer/system.cpp +++ b/src/audio_core/renderer/system.cpp @@ -102,8 +102,8 @@ System::System(Core::System& core_, Kernel::KEvent* adsp_rendered_event_) Result System::Initialize(const AudioRendererParameterInternal& params, Kernel::KTransferMemory* transfer_memory, u64 transfer_memory_size, - u32 process_handle_, Kernel::KProcess& process_, - u64 applet_resource_user_id_, s32 session_id_) { + Kernel::KProcess* process_handle_, u64 applet_resource_user_id_, + s32 session_id_) { if (!CheckValidRevision(params.revision)) { return Service::Audio::ResultInvalidRevision; } @@ -119,7 +119,6 @@ Result System::Initialize(const AudioRendererParameterInternal& params, behavior.SetUserLibRevision(params.revision); process_handle = process_handle_; - process = &process_; applet_resource_user_id = applet_resource_user_id_; session_id = session_id_; @@ -132,7 +131,8 @@ Result System::Initialize(const AudioRendererParameterInternal& params, render_device = params.rendering_device; execution_mode = params.execution_mode; - process->GetMemory().ZeroBlock(transfer_memory->GetSourceAddress(), transfer_memory_size); + process_handle->GetMemory().ZeroBlock(transfer_memory->GetSourceAddress(), + transfer_memory_size); // Note: We're not actually using the transfer memory because it's a pain to code for. // Allocate the memory normally instead and hope the game doesn't try to read anything back @@ -616,7 +616,7 @@ void System::SendCommandToDsp() { static_cast((time_limit_percent / 100) * 2'880'000.0 * (static_cast(render_time_limit_percent) / 100.0f))}; audio_renderer.SetCommandBuffer(session_id, translated_addr, command_size, time_limit, - applet_resource_user_id, process, + applet_resource_user_id, process_handle, reset_command_buffers); reset_command_buffers = false; command_buffer_size = command_size; diff --git a/src/audio_core/renderer/system.h b/src/audio_core/renderer/system.h index 753a0b796..3533a74ef 100644 --- a/src/audio_core/renderer/system.h +++ b/src/audio_core/renderer/system.h @@ -74,14 +74,14 @@ public: * @param params - Input parameters to initialize the system with. * @param transfer_memory - Game-supplied memory for all workbuffers. Unused. * @param transfer_memory_size - Size of the transfer memory. Unused. - * @param process_handle - Process handle, also used for memory. Unused. + * @param process_handle - Process handle, also used for memory. * @param applet_resource_user_id - Applet id for this renderer. Unused. * @param session_id - Session id of this renderer. * @return Result code. */ Result Initialize(const AudioRendererParameterInternal& params, Kernel::KTransferMemory* transfer_memory, u64 transfer_memory_size, - u32 process_handle, Kernel::KProcess& process, u64 applet_resource_user_id, + Kernel::KProcess* process_handle, u64 applet_resource_user_id, s32 session_id); /** @@ -278,9 +278,7 @@ private: /// Does what locks do std::mutex lock{}; /// Process this audio render is operating within, used for memory reads/writes. - Kernel::KProcess* process{}; - /// Handle for the process for this system, unused - u32 process_handle{}; + Kernel::KProcess* process_handle{}; /// Applet resource id for this system, unused u64 applet_resource_user_id{}; /// Controls performance input and output -- cgit v1.2.3 From c575a85233cfea2e0935a5609e4e13d980a8c28f Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 20 Feb 2024 21:17:59 -0500 Subject: audio: rewrite IAudioDevice --- src/audio_core/renderer/audio_device.cpp | 14 +- src/audio_core/renderer/audio_device.h | 6 +- src/common/string_util.cpp | 4 + src/common/string_util.h | 1 + src/core/hle/service/audio/audio_device.cpp | 180 ++++++++++------------- src/core/hle/service/audio/audio_device.h | 41 ++++-- src/core/hle/service/audio/audio_in_manager.cpp | 3 +- src/core/hle/service/audio/audio_out_manager.cpp | 4 +- 8 files changed, 127 insertions(+), 126 deletions(-) (limited to 'src/audio_core/renderer') diff --git a/src/audio_core/renderer/audio_device.cpp b/src/audio_core/renderer/audio_device.cpp index 2d9bf82bb..5be5594f6 100644 --- a/src/audio_core/renderer/audio_device.cpp +++ b/src/audio_core/renderer/audio_device.cpp @@ -36,8 +36,7 @@ AudioDevice::AudioDevice(Core::System& system, const u64 applet_resource_user_id : output_sink{system.AudioCore().GetOutputSink()}, applet_resource_user_id{applet_resource_user_id_}, user_revision{revision} {} -u32 AudioDevice::ListAudioDeviceName(std::vector& out_buffer, - const size_t max_count) const { +u32 AudioDevice::ListAudioDeviceName(std::span out_buffer) const { std::span names{}; if (CheckFeatureSupported(SupportTags::AudioUsbDeviceOutput, user_revision)) { @@ -46,19 +45,18 @@ u32 AudioDevice::ListAudioDeviceName(std::vector& out_buffer, names = device_names; } - const u32 out_count{static_cast(std::min(max_count, names.size()))}; + const u32 out_count{static_cast(std::min(out_buffer.size(), names.size()))}; for (u32 i = 0; i < out_count; i++) { - out_buffer.push_back(names[i]); + out_buffer[i] = names[i]; } return out_count; } -u32 AudioDevice::ListAudioOutputDeviceName(std::vector& out_buffer, - const size_t max_count) const { - const u32 out_count{static_cast(std::min(max_count, output_device_names.size()))}; +u32 AudioDevice::ListAudioOutputDeviceName(std::span out_buffer) const { + const u32 out_count{static_cast(std::min(out_buffer.size(), output_device_names.size()))}; for (u32 i = 0; i < out_count; i++) { - out_buffer.push_back(output_device_names[i]); + out_buffer[i] = output_device_names[i]; } return out_count; } diff --git a/src/audio_core/renderer/audio_device.h b/src/audio_core/renderer/audio_device.h index ca4040add..4242dad30 100644 --- a/src/audio_core/renderer/audio_device.h +++ b/src/audio_core/renderer/audio_device.h @@ -36,20 +36,18 @@ public: * Get a list of the available output devices. * * @param out_buffer - Output buffer to write the available device names. - * @param max_count - Maximum number of devices to write (count of out_buffer). * @return Number of device names written. */ - u32 ListAudioDeviceName(std::vector& out_buffer, size_t max_count) const; + u32 ListAudioDeviceName(std::span out_buffer) const; /** * Get a list of the available output devices. * Different to above somehow... * * @param out_buffer - Output buffer to write the available device names. - * @param max_count - Maximum number of devices to write (count of out_buffer). * @return Number of device names written. */ - u32 ListAudioOutputDeviceName(std::vector& out_buffer, size_t max_count) const; + u32 ListAudioOutputDeviceName(std::span out_buffer) const; /** * Set the volume of all streams in the backend sink. diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index 72c481798..1909aced5 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -38,6 +38,10 @@ std::string StringFromBuffer(std::span data) { return std::string(data.begin(), std::find(data.begin(), data.end(), '\0')); } +std::string StringFromBuffer(std::span data) { + return std::string(data.begin(), std::find(data.begin(), data.end(), '\0')); +} + // Turns " hej " into "hej". Also handles tabs. std::string StripSpaces(const std::string& str) { const std::size_t s = str.find_first_not_of(" \t\r\n"); diff --git a/src/common/string_util.h b/src/common/string_util.h index 9da1ca4e9..53d0549ca 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -19,6 +19,7 @@ namespace Common { [[nodiscard]] std::string ToUpper(std::string str); [[nodiscard]] std::string StringFromBuffer(std::span data); +[[nodiscard]] std::string StringFromBuffer(std::span data); [[nodiscard]] std::string StripSpaces(const std::string& s); [[nodiscard]] std::string StripQuotes(const std::string& s); diff --git a/src/core/hle/service/audio/audio_device.cpp b/src/core/hle/service/audio/audio_device.cpp index 3608d08c7..438f3cccd 100644 --- a/src/core/hle/service/audio/audio_device.cpp +++ b/src/core/hle/service/audio/audio_device.cpp @@ -4,7 +4,7 @@ #include "audio_core/audio_core.h" #include "common/string_util.h" #include "core/hle/service/audio/audio_device.h" -#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/cmif_serialization.h" namespace Service::Audio { using namespace AudioCore::Renderer; @@ -15,20 +15,20 @@ IAudioDevice::IAudioDevice(Core::System& system_, u64 applet_resource_user_id, u impl{std::make_unique(system_, applet_resource_user_id, revision)}, event{service_context.CreateEvent(fmt::format("IAudioDeviceEvent-{}", device_num))} { static const FunctionInfo functions[] = { - {0, &IAudioDevice::ListAudioDeviceName, "ListAudioDeviceName"}, - {1, &IAudioDevice::SetAudioDeviceOutputVolume, "SetAudioDeviceOutputVolume"}, - {2, &IAudioDevice::GetAudioDeviceOutputVolume, "GetAudioDeviceOutputVolume"}, - {3, &IAudioDevice::GetActiveAudioDeviceName, "GetActiveAudioDeviceName"}, - {4, &IAudioDevice::QueryAudioDeviceSystemEvent, "QueryAudioDeviceSystemEvent"}, - {5, &IAudioDevice::GetActiveChannelCount, "GetActiveChannelCount"}, - {6, &IAudioDevice::ListAudioDeviceName, "ListAudioDeviceNameAuto"}, - {7, &IAudioDevice::SetAudioDeviceOutputVolume, "SetAudioDeviceOutputVolumeAuto"}, - {8, &IAudioDevice::GetAudioDeviceOutputVolume, "GetAudioDeviceOutputVolumeAuto"}, - {10, &IAudioDevice::GetActiveAudioDeviceName, "GetActiveAudioDeviceNameAuto"}, - {11, &IAudioDevice::QueryAudioDeviceInputEvent, "QueryAudioDeviceInputEvent"}, - {12, &IAudioDevice::QueryAudioDeviceOutputEvent, "QueryAudioDeviceOutputEvent"}, - {13, &IAudioDevice::GetActiveAudioDeviceName, "GetActiveAudioOutputDeviceName"}, - {14, &IAudioDevice::ListAudioOutputDeviceName, "ListAudioOutputDeviceName"}, + {0, D<&IAudioDevice::ListAudioDeviceName>, "ListAudioDeviceName"}, + {1, D<&IAudioDevice::SetAudioDeviceOutputVolume>, "SetAudioDeviceOutputVolume"}, + {2, D<&IAudioDevice::GetAudioDeviceOutputVolume>, "GetAudioDeviceOutputVolume"}, + {3, D<&IAudioDevice::GetActiveAudioDeviceName>, "GetActiveAudioDeviceName"}, + {4, D<&IAudioDevice::QueryAudioDeviceSystemEvent>, "QueryAudioDeviceSystemEvent"}, + {5, D<&IAudioDevice::GetActiveChannelCount>, "GetActiveChannelCount"}, + {6, D<&IAudioDevice::ListAudioDeviceNameAuto>, "ListAudioDeviceNameAuto"}, + {7, D<&IAudioDevice::SetAudioDeviceOutputVolumeAuto>, "SetAudioDeviceOutputVolumeAuto"}, + {8, D<&IAudioDevice::GetAudioDeviceOutputVolumeAuto>, "GetAudioDeviceOutputVolumeAuto"}, + {10, D<&IAudioDevice::GetActiveAudioDeviceNameAuto>, "GetActiveAudioDeviceNameAuto"}, + {11, D<&IAudioDevice::QueryAudioDeviceInputEvent>, "QueryAudioDeviceInputEvent"}, + {12, D<&IAudioDevice::QueryAudioDeviceOutputEvent>, "QueryAudioDeviceOutputEvent"}, + {13, D<&IAudioDevice::GetActiveAudioDeviceName>, "GetActiveAudioOutputDeviceName"}, + {14, D<&IAudioDevice::ListAudioOutputDeviceName>, "ListAudioOutputDeviceName"}, }; RegisterHandlers(functions); @@ -39,15 +39,33 @@ IAudioDevice::~IAudioDevice() { service_context.CloseEvent(event); } -void IAudioDevice::ListAudioDeviceName(HLERequestContext& ctx) { - const size_t in_count = ctx.GetWriteBufferNumElements(); +Result IAudioDevice::ListAudioDeviceName( + OutArray out_names, Out out_count) { + R_RETURN(this->ListAudioDeviceNameAuto(out_names, out_count)); +} + +Result IAudioDevice::SetAudioDeviceOutputVolume( + InArray name, f32 volume) { + R_RETURN(this->SetAudioDeviceOutputVolumeAuto(name, volume)); +} + +Result IAudioDevice::GetAudioDeviceOutputVolume( + Out out_volume, InArray name) { + R_RETURN(this->GetAudioDeviceOutputVolumeAuto(out_volume, name)); +} - std::vector out_names{}; +Result IAudioDevice::GetActiveAudioDeviceName( + OutArray out_name) { + R_RETURN(this->GetActiveAudioDeviceNameAuto(out_name)); +} - const u32 out_count = impl->ListAudioDeviceName(out_names, in_count); +Result IAudioDevice::ListAudioDeviceNameAuto( + OutArray out_names, + Out out_count) { + *out_count = impl->ListAudioDeviceName(out_names); std::string out{}; - for (u32 i = 0; i < out_count; i++) { + for (s32 i = 0; i < *out_count; i++) { std::string a{}; u32 j = 0; while (out_names[i].name[j] != '\0') { @@ -58,109 +76,77 @@ void IAudioDevice::ListAudioDeviceName(HLERequestContext& ctx) { } LOG_DEBUG(Service_Audio, "called.\nNames={}", out); - - IPC::ResponseBuilder rb{ctx, 3}; - - ctx.WriteBuffer(out_names); - - rb.Push(ResultSuccess); - rb.Push(out_count); + R_SUCCEED(); } -void IAudioDevice::SetAudioDeviceOutputVolume(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const f32 volume = rp.Pop(); - - const auto device_name_buffer = ctx.ReadBuffer(); - const std::string name = Common::StringFromBuffer(device_name_buffer); +Result IAudioDevice::SetAudioDeviceOutputVolumeAuto( + InArray name, f32 volume) { + R_UNLESS(!name.empty(), Audio::ResultInsufficientBuffer); - LOG_DEBUG(Service_Audio, "called. name={}, volume={}", name, volume); + const std::string device_name = Common::StringFromBuffer(name[0].name); + LOG_DEBUG(Service_Audio, "called. name={}, volume={}", device_name, volume); - if (name == "AudioTvOutput") { + if (device_name == "AudioTvOutput") { impl->SetDeviceVolumes(volume); } - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IAudioDevice::GetAudioDeviceOutputVolume(HLERequestContext& ctx) { - const auto device_name_buffer = ctx.ReadBuffer(); - const std::string name = Common::StringFromBuffer(device_name_buffer); +Result IAudioDevice::GetAudioDeviceOutputVolumeAuto( + Out out_volume, InArray name) { + R_UNLESS(!name.empty(), Audio::ResultInsufficientBuffer); - LOG_DEBUG(Service_Audio, "called. Name={}", name); + const std::string device_name = Common::StringFromBuffer(name[0].name); + LOG_DEBUG(Service_Audio, "called. Name={}", device_name); - f32 volume{1.0f}; - if (name == "AudioTvOutput") { - volume = impl->GetDeviceVolume(name); + *out_volume = 1.0f; + if (device_name == "AudioTvOutput") { + *out_volume = impl->GetDeviceVolume(device_name); } - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.Push(volume); + R_SUCCEED(); } -void IAudioDevice::GetActiveAudioDeviceName(HLERequestContext& ctx) { - const auto write_size = ctx.GetWriteBufferSize(); - std::string out_name{"AudioTvOutput"}; - - LOG_DEBUG(Service_Audio, "(STUBBED) called. Name={}", out_name); - - out_name.resize(write_size); - - ctx.WriteBuffer(out_name); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); +Result IAudioDevice::GetActiveAudioDeviceNameAuto( + OutArray out_name) { + R_UNLESS(!out_name.empty(), Audio::ResultInsufficientBuffer); + out_name[0] = AudioDevice::AudioDeviceName("AudioTvOutput"); + LOG_DEBUG(Service_Audio, "(STUBBED) called"); + R_SUCCEED(); } -void IAudioDevice::QueryAudioDeviceSystemEvent(HLERequestContext& ctx) { +Result IAudioDevice::QueryAudioDeviceSystemEvent(OutCopyHandle out_event) { LOG_DEBUG(Service_Audio, "(STUBBED) called"); - event->Signal(); - - IPC::ResponseBuilder rb{ctx, 2, 1}; - rb.Push(ResultSuccess); - rb.PushCopyObjects(event->GetReadableEvent()); -} - -void IAudioDevice::GetActiveChannelCount(HLERequestContext& ctx) { - const auto& sink{system.AudioCore().GetOutputSink()}; - u32 channel_count{sink.GetSystemChannels()}; - - LOG_DEBUG(Service_Audio, "(STUBBED) called. Channels={}", channel_count); - - IPC::ResponseBuilder rb{ctx, 3}; - - rb.Push(ResultSuccess); - rb.Push(channel_count); + *out_event = &event->GetReadableEvent(); + R_SUCCEED(); } -void IAudioDevice::QueryAudioDeviceInputEvent(HLERequestContext& ctx) { +Result IAudioDevice::QueryAudioDeviceInputEvent(OutCopyHandle out_event) { LOG_DEBUG(Service_Audio, "(STUBBED) called"); - - IPC::ResponseBuilder rb{ctx, 2, 1}; - rb.Push(ResultSuccess); - rb.PushCopyObjects(event->GetReadableEvent()); + *out_event = &event->GetReadableEvent(); + R_SUCCEED(); } -void IAudioDevice::QueryAudioDeviceOutputEvent(HLERequestContext& ctx) { +Result IAudioDevice::QueryAudioDeviceOutputEvent(OutCopyHandle out_event) { LOG_DEBUG(Service_Audio, "called"); - - IPC::ResponseBuilder rb{ctx, 2, 1}; - rb.Push(ResultSuccess); - rb.PushCopyObjects(event->GetReadableEvent()); + *out_event = &event->GetReadableEvent(); + R_SUCCEED(); } -void IAudioDevice::ListAudioOutputDeviceName(HLERequestContext& ctx) { - const size_t in_count = ctx.GetWriteBufferNumElements(); - - std::vector out_names{}; +Result IAudioDevice::GetActiveChannelCount(Out out_active_channel_count) { + *out_active_channel_count = system.AudioCore().GetOutputSink().GetSystemChannels(); + LOG_DEBUG(Service_Audio, "(STUBBED) called. Channels={}", *out_active_channel_count); + R_SUCCEED(); +} - const u32 out_count = impl->ListAudioOutputDeviceName(out_names, in_count); +Result IAudioDevice::ListAudioOutputDeviceName( + OutArray out_names, Out out_count) { + *out_count = impl->ListAudioOutputDeviceName(out_names); std::string out{}; - for (u32 i = 0; i < out_count; i++) { + for (s32 i = 0; i < *out_count; i++) { std::string a{}; u32 j = 0; while (out_names[i].name[j] != '\0') { @@ -171,13 +157,7 @@ void IAudioDevice::ListAudioOutputDeviceName(HLERequestContext& ctx) { } LOG_DEBUG(Service_Audio, "called.\nNames={}", out); - - IPC::ResponseBuilder rb{ctx, 3}; - - ctx.WriteBuffer(out_names); - - rb.Push(ResultSuccess); - rb.Push(out_count); + R_SUCCEED(); } } // namespace Service::Audio diff --git a/src/core/hle/service/audio/audio_device.h b/src/core/hle/service/audio/audio_device.h index 850c60051..752157272 100644 --- a/src/core/hle/service/audio/audio_device.h +++ b/src/core/hle/service/audio/audio_device.h @@ -4,11 +4,18 @@ #pragma once #include "audio_core/renderer/audio_device.h" +#include "core/hle/service/cmif_types.h" #include "core/hle/service/kernel_helpers.h" #include "core/hle/service/service.h" +namespace Kernel { +class KReadableEvent; +} + namespace Service::Audio { +using AudioCore::Renderer::AudioDevice; + class IAudioDevice final : public ServiceFramework { public: @@ -17,15 +24,31 @@ public: ~IAudioDevice() override; private: - void ListAudioDeviceName(HLERequestContext& ctx); - void SetAudioDeviceOutputVolume(HLERequestContext& ctx); - void GetAudioDeviceOutputVolume(HLERequestContext& ctx); - void GetActiveAudioDeviceName(HLERequestContext& ctx); - void QueryAudioDeviceSystemEvent(HLERequestContext& ctx); - void GetActiveChannelCount(HLERequestContext& ctx); - void QueryAudioDeviceInputEvent(HLERequestContext& ctx); - void QueryAudioDeviceOutputEvent(HLERequestContext& ctx); - void ListAudioOutputDeviceName(HLERequestContext& ctx); + Result ListAudioDeviceName( + OutArray out_names, + Out out_count); + Result SetAudioDeviceOutputVolume( + InArray name, f32 volume); + Result GetAudioDeviceOutputVolume( + Out out_volume, InArray name); + Result GetActiveAudioDeviceName( + OutArray out_name); + Result ListAudioDeviceNameAuto( + OutArray out_names, + Out out_count); + Result SetAudioDeviceOutputVolumeAuto( + InArray name, f32 volume); + Result GetAudioDeviceOutputVolumeAuto( + Out out_volume, InArray name); + Result GetActiveAudioDeviceNameAuto( + OutArray out_name); + Result QueryAudioDeviceSystemEvent(OutCopyHandle out_event); + Result QueryAudioDeviceInputEvent(OutCopyHandle out_event); + Result QueryAudioDeviceOutputEvent(OutCopyHandle out_event); + Result GetActiveChannelCount(Out out_active_channel_count); + Result ListAudioOutputDeviceName( + OutArray out_names, + Out out_count); KernelHelpers::ServiceContext service_context; std::unique_ptr impl; diff --git a/src/core/hle/service/audio/audio_in_manager.cpp b/src/core/hle/service/audio/audio_in_manager.cpp index 9b67af367..d55da17c8 100644 --- a/src/core/hle/service/audio/audio_in_manager.cpp +++ b/src/core/hle/service/audio/audio_in_manager.cpp @@ -96,8 +96,7 @@ Result IAudioInManager::OpenAudioInProtocolSpecified( LOG_DEBUG(Service_Audio, "Opening new AudioIn, session_id={}, free sessions={}", new_session_id, impl->num_free_sessions); - const auto name_buffer = std::span(reinterpret_cast(name[0].name.data()), 0x100); - const auto device_name = Common::StringFromBuffer(name_buffer); + const auto device_name = Common::StringFromBuffer(name[0].name); *out_audio_in = std::make_shared(system, *impl, new_session_id, device_name, parameter, process_handle.Get(), aruid.pid); impl->sessions[new_session_id] = (*out_audio_in)->GetImpl(); diff --git a/src/core/hle/service/audio/audio_out_manager.cpp b/src/core/hle/service/audio/audio_out_manager.cpp index 780e1dcda..153445097 100644 --- a/src/core/hle/service/audio/audio_out_manager.cpp +++ b/src/core/hle/service/audio/audio_out_manager.cpp @@ -75,9 +75,7 @@ Result IAudioOutManager::OpenAudioOutAuto( R_TRY(impl->LinkToManager()); R_TRY(impl->AcquireSessionId(new_session_id)); - const auto name_buffer = std::span(reinterpret_cast(name[0].name.data()), 0x100); - const auto device_name = Common::StringFromBuffer(name_buffer); - + const auto device_name = Common::StringFromBuffer(name[0].name); LOG_DEBUG(Service_Audio, "Opening new AudioOut, sessionid={}, free sessions={}", new_session_id, impl->num_free_sessions); -- cgit v1.2.3 From 2e4a6b7f92fbf73eb5173c9bda5c9b5b61f5458c Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 20 Feb 2024 22:18:57 -0500 Subject: audio: format --- src/CMakeLists.txt | 1 + src/audio_core/opus/parameters.h | 4 ++-- src/audio_core/renderer/behavior/info_updater.cpp | 7 ++++--- src/audio_core/renderer/memory/pool_mapper.cpp | 4 ++-- src/core/hle/service/audio/audio_in.cpp | 5 +++-- src/core/hle/service/audio/audio_in_manager.cpp | 4 ++-- src/core/hle/service/audio/audio_renderer.cpp | 4 ++-- 7 files changed, 16 insertions(+), 13 deletions(-) (limited to 'src/audio_core/renderer') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index edca221b1..cf05a3fe3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -121,6 +121,7 @@ else() -Wno-attributes -Wno-invalid-offsetof -Wno-unused-parameter + -Wno-missing-field-initializers ) if (CMAKE_CXX_COMPILER_ID MATCHES Clang) # Clang or AppleClang diff --git a/src/audio_core/opus/parameters.h b/src/audio_core/opus/parameters.h index 4c54b2825..47c418b9f 100644 --- a/src/audio_core/opus/parameters.h +++ b/src/audio_core/opus/parameters.h @@ -20,7 +20,7 @@ struct OpusParametersEx { /* 0x00 */ u32 sample_rate; /* 0x04 */ u32 channel_count; /* 0x08 */ bool use_large_frame_size; - /* 0x09 */ INSERT_PADDING_BYTES(7); + /* 0x09 */ INSERT_PADDING_BYTES_NOINIT(7); }; // size = 0x10 static_assert(sizeof(OpusParametersEx) == 0x10, "OpusParametersEx has the wrong size!"); @@ -40,7 +40,7 @@ struct OpusMultiStreamParametersEx { /* 0x08 */ u32 total_stream_count; /* 0x0C */ u32 stereo_stream_count; /* 0x10 */ bool use_large_frame_size; - /* 0x11 */ INSERT_PADDING_BYTES(7); + /* 0x11 */ INSERT_PADDING_BYTES_NOINIT(7); /* 0x18 */ std::array mappings; }; // size = 0x118 static_assert(sizeof(OpusMultiStreamParametersEx) == 0x118, diff --git a/src/audio_core/renderer/behavior/info_updater.cpp b/src/audio_core/renderer/behavior/info_updater.cpp index 163127789..3dae6069f 100644 --- a/src/audio_core/renderer/behavior/info_updater.cpp +++ b/src/audio_core/renderer/behavior/info_updater.cpp @@ -19,9 +19,10 @@ namespace AudioCore::Renderer { InfoUpdater::InfoUpdater(std::span input_, std::span output_, Kernel::KProcess* process_handle_, BehaviorInfo& behaviour_) - : input{input_.data() + sizeof(UpdateDataHeader)}, input_origin{input_}, - output{output_.data() + sizeof(UpdateDataHeader)}, output_origin{output_}, - in_header{reinterpret_cast(input_origin.data())}, + : input{input_.data() + sizeof(UpdateDataHeader)}, + input_origin{input_}, output{output_.data() + sizeof(UpdateDataHeader)}, + output_origin{output_}, in_header{reinterpret_cast( + input_origin.data())}, out_header{reinterpret_cast(output_origin.data())}, expected_input_size{input_.size()}, expected_output_size{output_.size()}, process_handle{process_handle_}, behaviour{behaviour_} { diff --git a/src/audio_core/renderer/memory/pool_mapper.cpp b/src/audio_core/renderer/memory/pool_mapper.cpp index 1df786feb..e47eb66d5 100644 --- a/src/audio_core/renderer/memory/pool_mapper.cpp +++ b/src/audio_core/renderer/memory/pool_mapper.cpp @@ -13,8 +13,8 @@ PoolMapper::PoolMapper(Kernel::KProcess* process_handle_, bool force_map_) PoolMapper::PoolMapper(Kernel::KProcess* process_handle_, std::span pool_infos_, u32 pool_count_, bool force_map_) - : process_handle{process_handle_}, pool_infos{pool_infos_.data()}, pool_count{pool_count_}, - force_map{force_map_} {} + : process_handle{process_handle_}, pool_infos{pool_infos_.data()}, + pool_count{pool_count_}, force_map{force_map_} {} void PoolMapper::ClearUseState(std::span pools, const u32 count) { for (u32 i = 0; i < count; i++) { diff --git a/src/core/hle/service/audio/audio_in.cpp b/src/core/hle/service/audio/audio_in.cpp index 9240cc336..416803acc 100644 --- a/src/core/hle/service/audio/audio_in.cpp +++ b/src/core/hle/service/audio/audio_in.cpp @@ -12,8 +12,9 @@ IAudioIn::IAudioIn(Core::System& system_, Manager& manager, size_t session_id, const std::string& device_name, const AudioInParameter& in_params, Kernel::KProcess* handle, u64 applet_resource_user_id) : ServiceFramework{system_, "IAudioIn"}, process{handle}, service_context{system_, "IAudioIn"}, - event{service_context.CreateEvent("AudioInEvent")}, - impl{std::make_shared(system_, manager, event, session_id)} { + event{service_context.CreateEvent("AudioInEvent")}, impl{std::make_shared(system_, + manager, event, + session_id)} { // clang-format off static const FunctionInfo functions[] = { {0, D<&IAudioIn::GetAudioInState>, "GetAudioInState"}, diff --git a/src/core/hle/service/audio/audio_in_manager.cpp b/src/core/hle/service/audio/audio_in_manager.cpp index d55da17c8..2675a5773 100644 --- a/src/core/hle/service/audio/audio_in_manager.cpp +++ b/src/core/hle/service/audio/audio_in_manager.cpp @@ -10,8 +10,8 @@ namespace Service::Audio { using namespace AudioCore::AudioIn; IAudioInManager::IAudioInManager(Core::System& system_) - : ServiceFramework{system_, "audin:u"}, - impl{std::make_unique(system_)} { + : ServiceFramework{system_, "audin:u"}, impl{std::make_unique( + system_)} { // clang-format off static const FunctionInfo functions[] = { {0, D<&IAudioInManager::ListAudioIns>, "ListAudioIns"}, diff --git a/src/core/hle/service/audio/audio_renderer.cpp b/src/core/hle/service/audio/audio_renderer.cpp index b78660cea..fc4aad233 100644 --- a/src/core/hle/service/audio/audio_renderer.cpp +++ b/src/core/hle/service/audio/audio_renderer.cpp @@ -14,8 +14,8 @@ IAudioRenderer::IAudioRenderer(Core::System& system_, Manager& manager_, s32 session_id) : ServiceFramework{system_, "IAudioRenderer"}, service_context{system_, "IAudioRenderer"}, rendered_event{service_context.CreateEvent("IAudioRendererEvent")}, manager{manager_}, - impl{std::make_unique(system_, manager, rendered_event)}, - process_handle{process_handle_} { + impl{std::make_unique(system_, manager, rendered_event)}, process_handle{ + process_handle_} { // clang-format off static const FunctionInfo functions[] = { {0, D<&IAudioRenderer::GetSampleRate>, "GetSampleRate"}, -- cgit v1.2.3