Compare commits

...

5 Commits

Author SHA1 Message Date
16-Bit-Dog
6f0e5df5a2 clang auto format followed
I think... just moved the code to VS to see if it auto formatted
2021-01-27 08:19:38 -05:00
16-Bit-Dog
3097cb2ff8 Update audio_renderer.cpp 2021-01-27 00:54:55 -05:00
16-Bit-Dog
cfd073ab7b had some wrong variable names; heh 2021-01-27 00:53:37 -05:00
16-Bit-Dog
be0c8b5ac5 Update audio_renderer.cpp 2021-01-27 00:51:58 -05:00
16-Bit-Dog
835d8c3169 async addition
a mix of async thread work and keeping dedicated thread time to a non-async process to reduce latency of a task: slight reduction in time to complete audio rendering
2021-01-27 00:46:56 -05:00

View File

@@ -1,7 +1,8 @@
// Copyright 2018 yuzu Emulator Project
// Copyright 2020 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <future>
#include <limits>
#include <vector>
@@ -68,6 +69,11 @@ namespace {
} // namespace
namespace AudioCore {
std::vector<std::future<void>> queueMixedThreadFence;
std::future<void> keepThreadReady1;
std::future<void> keepThreadReady2;
AudioRenderer::AudioRenderer(Core::Timing::CoreTiming& core_timing, Core::Memory::Memory& memory_,
AudioCommon::AudioRendererParameter params,
Stream::ReleaseCallback&& release_callback,
@@ -195,7 +201,9 @@ ResultCode AudioRenderer::UpdateAudioRenderer(const std::vector<u8>& input_param
return AudioCommon::Audren::ERR_INVALID_PARAMETERS;
}
ReleaseAndQueueBuffers();
keepThreadReady1 = std::async(std::launch::async, [&] { ReleaseAndQueueBuffers(); });
keepThreadReady1.get();
return RESULT_SUCCESS;
}
@@ -209,15 +217,19 @@ void AudioRenderer::QueueMixedBuffer(Buffer::Tag tag) {
if (!splitter_context.UsingSplitter()) {
mix_context.SortInfo();
}
// Sort our voices
voice_context.SortInfo();
// Handle samples
command_generator.GenerateVoiceCommands();
command_generator.GenerateSubMixCommands();
command_generator.GenerateFinalMixCommands();
queueMixedThreadFence.push_back(std::async(std::launch::async, [&] {
// Sort our voices
voice_context.SortInfo();
// Handle samples
command_generator.GenerateVoiceCommands();
command_generator.GenerateSubMixCommands();
command_generator.GenerateFinalMixCommands();
command_generator.PostCommand();
}));
command_generator.PostCommand();
// Base sample size
std::size_t BUFFER_SIZE{worker_params.sample_count};
// Samples
@@ -236,6 +248,7 @@ void AudioRenderer::QueueMixedBuffer(Buffer::Tag tag) {
mix_buffers[i] =
command_generator.GetMixBuffer(in_params.buffer_offset + buffer_offsets[i]);
}
queueMixedThreadFence[queueMixedThreadFence.size() - 1].get();
for (std::size_t i = 0; i < BUFFER_SIZE; i++) {
if (channel_count == 1) {
@@ -313,11 +326,16 @@ void AudioRenderer::QueueMixedBuffer(Buffer::Tag tag) {
elapsed_frame_count++;
voice_context.UpdateStateByDspShared();
}
void AudioRenderer::ReleaseAndQueueBuffers() {
const auto released_buffers{audio_out->GetTagsAndReleaseBuffers(stream)};
queueMixedThreadFence.resize(0); // instead of passing a s16 to the queue mixed buffer to
// control, pushing values to a vector seemed about as fast
for (const auto& tag : released_buffers) {
QueueMixedBuffer(tag);
keepThreadReady2 = std::async(std::launch::async, [&] { QueueMixedBuffer(tag); });
keepThreadReady2.get();
}
}