Use cached offset
All checks were successful
eden-license / license-header (pull_request) Successful in 22s

This commit is contained in:
MaranBr 2025-09-29 16:20:58 -04:00
parent e40cdc3dc1
commit 8e27312fdf

View file

@ -36,14 +36,20 @@ void DeviceSinkCommand::Process(const AudioRenderer::CommandListProcessor& proce
.consumed{false},
};
std::array<s16, TargetSampleCount * MaxChannels> samples{};
static bool initialized = false;
static std::array<s32, MaxChannels> cached_offsets{};
if (!initialized) {
for (u32 channel = 0; channel < input_count; channel++) {
//const auto offset{inputs[channel] * out_buffer.frames};
const auto offset{channel * out_buffer.frames};
cached_offsets[channel] = static_cast<s16>(inputs[channel] * out_buffer.frames);
}
initialized = true;
}
for (u32 index = 0; index < out_buffer.frames; index++) {
samples[index * input_count + channel] =
static_cast<s16>(std::clamp(sample_buffer[offset + index], min, max));
std::array<s16, TargetSampleCount * MaxChannels> 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<s16>(std::clamp(sample_buffer[offset + index], min, max));
}
}