From 8e27312fdf0ad74c9457f0ddfd0cf84cc8584f3b Mon Sep 17 00:00:00 2001 From: MaranBr Date: Mon, 29 Sep 2025 16:20:58 -0400 Subject: [PATCH] Use cached offset --- .../renderer/command/sink/device.cpp | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/audio_core/renderer/command/sink/device.cpp b/src/audio_core/renderer/command/sink/device.cpp index 75c4dae217..fd87878949 100644 --- a/src/audio_core/renderer/command/sink/device.cpp +++ b/src/audio_core/renderer/command/sink/device.cpp @@ -36,14 +36,20 @@ void DeviceSinkCommand::Process(const AudioRenderer::CommandListProcessor& proce .consumed{false}, }; - std::array samples{}; - for (u32 channel = 0; channel < input_count; channel++) { - //const auto offset{inputs[channel] * out_buffer.frames}; - const auto offset{channel * out_buffer.frames}; + static bool initialized = false; + static std::array cached_offsets{}; + if (!initialized) { + for (u32 channel = 0; channel < input_count; channel++) { + cached_offsets[channel] = static_cast(inputs[channel] * out_buffer.frames); + } + initialized = true; + } - for (u32 index = 0; index < out_buffer.frames; index++) { - samples[index * input_count + channel] = - static_cast(std::clamp(sample_buffer[offset + index], min, max)); + std::array samples{}; + for (u32 channel = 0; channel < input_count; ++channel) { + const s32 offset = cached_offsets[channel]; + for (u32 index = 0; index < out_buffer.frames; ++index) { + samples[index * input_count + channel] = static_cast(std::clamp(sample_buffer[offset + index], min, max)); } }