From 6f7cb69c94bef0795f054d881e061745f69d1eda Mon Sep 17 00:00:00 2001 From: Kelebek1 Date: Mon, 29 May 2023 00:35:51 +0100 Subject: Use spans over guest memory where possible instead of copying data. --- .../renderer/command/data_source/decode.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/audio_core/renderer/command/data_source') diff --git a/src/audio_core/renderer/command/data_source/decode.cpp b/src/audio_core/renderer/command/data_source/decode.cpp index f45933203..257aa866e 100644 --- a/src/audio_core/renderer/command/data_source/decode.cpp +++ b/src/audio_core/renderer/command/data_source/decode.cpp @@ -28,7 +28,6 @@ constexpr std::array PitchBySrcQuality = {4, 8, 4}; template static u32 DecodePcm(Core::Memory::Memory& memory, std::span out_buffer, const DecodeArg& req) { - std::array tmp_samples{}; constexpr s32 min{std::numeric_limits::min()}; constexpr s32 max{std::numeric_limits::max()}; @@ -49,19 +48,18 @@ static u32 DecodePcm(Core::Memory::Memory& memory, std::span out_buffer, const VAddr source{req.buffer + (((req.start_offset + req.offset) * channel_count) * sizeof(T))}; const u64 size{channel_count * samples_to_decode}; - const u64 size_bytes{size * sizeof(T)}; - - memory.ReadBlockUnsafe(source, tmp_samples.data(), size_bytes); + Core::Memory::CpuGuestMemory samples( + memory, source, size); if constexpr (std::is_floating_point_v) { for (u32 i = 0; i < samples_to_decode; i++) { - auto sample{static_cast(tmp_samples[i * channel_count + req.target_channel] * + auto sample{static_cast(samples[i * channel_count + req.target_channel] * std::numeric_limits::max())}; out_buffer[i] = static_cast(std::clamp(sample, min, max)); } } else { for (u32 i = 0; i < samples_to_decode; i++) { - out_buffer[i] = tmp_samples[i * channel_count + req.target_channel]; + out_buffer[i] = samples[i * channel_count + req.target_channel]; } } } break; @@ -74,16 +72,17 @@ static u32 DecodePcm(Core::Memory::Memory& memory, std::span out_buffer, } const VAddr source{req.buffer + ((req.start_offset + req.offset) * sizeof(T))}; - memory.ReadBlockUnsafe(source, tmp_samples.data(), samples_to_decode * sizeof(T)); + Core::Memory::CpuGuestMemory samples( + memory, source, samples_to_decode); if constexpr (std::is_floating_point_v) { for (u32 i = 0; i < samples_to_decode; i++) { - auto sample{static_cast(tmp_samples[i * channel_count + req.target_channel] * + auto sample{static_cast(samples[i * channel_count + req.target_channel] * std::numeric_limits::max())}; out_buffer[i] = static_cast(std::clamp(sample, min, max)); } } else { - std::memcpy(out_buffer.data(), tmp_samples.data(), samples_to_decode * sizeof(s16)); + std::memcpy(out_buffer.data(), samples.data(), samples_to_decode * sizeof(s16)); } break; } @@ -101,7 +100,6 @@ static u32 DecodePcm(Core::Memory::Memory& memory, std::span out_buffer, */ static u32 DecodeAdpcm(Core::Memory::Memory& memory, std::span out_buffer, const DecodeArg& req) { - std::array wavebuffer{}; constexpr u32 SamplesPerFrame{14}; constexpr u32 NibblesPerFrame{16}; @@ -139,7 +137,8 @@ static u32 DecodeAdpcm(Core::Memory::Memory& memory, std::span out_buffer, } const auto size{std::max((samples_to_process / 8U) * SamplesPerFrame, 8U)}; - memory.ReadBlockUnsafe(req.buffer + position_in_frame / 2, wavebuffer.data(), size); + Core::Memory::CpuGuestMemory wavebuffer( + memory, req.buffer + position_in_frame / 2, size); auto context{req.adpcm_context}; auto header{context->header}; -- cgit v1.2.3