summaryrefslogtreecommitdiffstats
path: root/src/audio_core/renderer/mix/mix_context.h
diff options
context:
space:
mode:
authorKelebek1 <eeeedddccc@hotmail.co.uk>2022-07-17 00:48:45 +0200
committerKelebek1 <eeeedddccc@hotmail.co.uk>2022-07-22 02:11:32 +0200
commit458da8a94877677f086f06cdeecf959ec4283a33 (patch)
tree583166d77602ad90a0d552f37de8729ad80fd6c1 /src/audio_core/renderer/mix/mix_context.h
parentMerge pull request #8598 from Link4565/recv-dontwait (diff)
downloadyuzu-458da8a94877677f086f06cdeecf959ec4283a33.tar
yuzu-458da8a94877677f086f06cdeecf959ec4283a33.tar.gz
yuzu-458da8a94877677f086f06cdeecf959ec4283a33.tar.bz2
yuzu-458da8a94877677f086f06cdeecf959ec4283a33.tar.lz
yuzu-458da8a94877677f086f06cdeecf959ec4283a33.tar.xz
yuzu-458da8a94877677f086f06cdeecf959ec4283a33.tar.zst
yuzu-458da8a94877677f086f06cdeecf959ec4283a33.zip
Diffstat (limited to 'src/audio_core/renderer/mix/mix_context.h')
-rw-r--r--src/audio_core/renderer/mix/mix_context.h124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/audio_core/renderer/mix/mix_context.h b/src/audio_core/renderer/mix/mix_context.h
new file mode 100644
index 000000000..da3aa2829
--- /dev/null
+++ b/src/audio_core/renderer/mix/mix_context.h
@@ -0,0 +1,124 @@
+// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include <span>
+
+#include "audio_core/renderer/mix/mix_info.h"
+#include "audio_core/renderer/nodes/edge_matrix.h"
+#include "audio_core/renderer/nodes/node_states.h"
+#include "common/common_types.h"
+
+namespace AudioCore::AudioRenderer {
+class SplitterContext;
+
+/*
+ * Manages mixing states, sorting and building a node graph to describe a mix order.
+ */
+class MixContext {
+public:
+ /**
+ * Initialize the mix context.
+ *
+ * @param sorted_mix_infos - Buffer for the sorted mix infos.
+ * @param mix_infos - Buffer for the mix infos.
+ * @param effect_process_order_buffer - Buffer for the effect process orders.
+ * @param effect_count - Number of effects in the buffer.
+ * @param node_states_workbuffer - Buffer for node states.
+ * @param node_buffer_size - Size of the node states buffer.
+ * @param edge_matrix_workbuffer - Buffer for edge matrix.
+ * @param edge_matrix_size - Size of the edge matrix buffer.
+ */
+ void Initialize(std::span<MixInfo*> sorted_mix_infos, std::span<MixInfo> mix_infos, u32 count_,
+ std::span<s32> effect_process_order_buffer, u32 effect_count,
+ std::span<u8> node_states_workbuffer, u64 node_buffer_size,
+ std::span<u8> edge_matrix_workbuffer, u64 edge_matrix_size);
+
+ /**
+ * Get a sorted mix at the given index.
+ *
+ * @param index - Index of sorted mix.
+ * @return The sorted mix.
+ */
+ MixInfo* GetSortedInfo(s32 index);
+
+ /**
+ * Set the sorted info at the given index.
+ *
+ * @param index - Index of sorted mix.
+ * @param mix_info - The new mix for this index.
+ */
+ void SetSortedInfo(s32 index, MixInfo& mix_info);
+
+ /**
+ * Get a mix at the given index.
+ *
+ * @param index - Index of mix.
+ * @return The mix.
+ */
+ MixInfo* GetInfo(s32 index);
+
+ /**
+ * Get the final mix.
+ *
+ * @return The final mix.
+ */
+ MixInfo* GetFinalMixInfo();
+
+ /**
+ * Get the current number of mixes.
+ *
+ * @return The number of active mixes.
+ */
+ s32 GetCount() const;
+
+ /**
+ * Update all of the mixes' distance from the final mix.
+ * Needs to be called after altering the mix graph.
+ */
+ void UpdateDistancesFromFinalMix();
+
+ /**
+ * Non-splitter sort, sorts the sorted mixes based on their distance from the final mix.
+ */
+ void SortInfo();
+
+ /**
+ * Re-calculate the mix buffer offsets for each mix after altering the mix.
+ */
+ void CalcMixBufferOffset();
+
+ /**
+ * Splitter sort, traverse the splitter node graph and sort the sorted mixes from results.
+ *
+ * @param splitter_context - Splitter context for the sort.
+ * @return True if the sort was successful, othewise false.
+ */
+ bool TSortInfo(const SplitterContext& splitter_context);
+
+ /**
+ * Get the edge matrix used for the mix graph.
+ *
+ * @return The edge matrix used.
+ */
+ EdgeMatrix& GetEdgeMatrix();
+
+private:
+ /// Array of sorted mixes
+ std::span<MixInfo*> sorted_mix_infos{};
+ /// Array of mixes
+ std::span<MixInfo> mix_infos{};
+ /// Number of active mixes
+ s32 count{};
+ /// Array of effect process orderings
+ std::span<s32> effect_process_order_buffer{};
+ /// Number of effects in the process ordering buffer
+ u64 effect_count{};
+ /// Node states used in splitter sort
+ NodeStates node_states{};
+ /// Edge matrix for connected nodes used in splitter sort
+ EdgeMatrix edge_matrix{};
+};
+
+} // namespace AudioCore::AudioRenderer