MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ processing_function()

void MayaFlux::Buffers::ChannelProcessor::processing_function ( const std::shared_ptr< Buffer > &  buffer)
overridevirtual

Processes a buffer by combining tributary buffers and node network output.

Parameters
bufferBuffer to process (should be the root buffer)

This method implements a hierarchical data aggregation algorithm:

  1. Processes all tributary buffers to ensure current data
  2. Combines their outputs into the root buffer using a weighted averaging algorithm
  3. Incorporates node network output if present

The combination algorithm can be customized in the implementation.

Implements MayaFlux::Buffers::BufferProcessor.

Definition at line 11 of file RootAudioBuffer.cpp.

12{
13
14 auto root_audio_buffer = std::dynamic_pointer_cast<RootAudioBuffer>(buffer);
15 if (!root_audio_buffer || root_audio_buffer != m_root_buffer) {
16 return;
17 }
18
19 auto& output_data = root_audio_buffer->get_data();
20 const size_t buffer_size = output_data.size();
21 std::ranges::fill(output_data, 0.0);
22
23 if (root_audio_buffer->has_node_output()) {
24 const auto& node_output = root_audio_buffer->get_node_output();
25 const size_t node_size = node_output.size();
26 const size_t add_size = std::min(buffer_size, node_size);
27
28 for (size_t i = 0; i < add_size; ++i) {
29 output_data[i] += node_output[i];
30 }
31 }
32
33 std::vector<std::shared_ptr<AudioBuffer>> buffers_to_remove;
34 for (auto& child : m_root_buffer->get_child_buffers()) {
35 if (child->needs_removal()) {
36 buffers_to_remove.push_back(child);
37 }
38 }
39
40 uint32_t active_buffers = 0;
41 for (auto& child : m_root_buffer->get_child_buffers()) {
42 if (child->has_data_for_cycle() && !child->needs_removal() && !child->is_internal_only()) {
43 active_buffers++;
44 }
45 }
46
47 if (active_buffers > 0) {
48 const double divisor = m_root_buffer->is_mix_normalized() ? active_buffers : 1.0;
49
50 for (auto& child : m_root_buffer->get_child_buffers()) {
51 if (child->has_data_for_cycle() && !child->needs_removal() && !child->is_internal_only()) {
52 double scale = 1.0;
53 if (child->needs_routing()) {
54 const auto& state = child->get_routing_state();
55 if (state.from_channel == m_root_buffer->get_channel_id()) {
56 scale = state.from_amount;
57 }
58 }
59 const auto& child_data = child->get_data();
60 for (size_t i = 0; i < std::min(child_data.size(), output_data.size()); i++) {
61 output_data[i] += (child_data[i] * scale) / divisor;
62 }
63 }
64 }
65 }
66
67 for (auto& child : buffers_to_remove) {
68 m_root_buffer->remove_child_buffer(child);
69 }
70}
std::shared_ptr< NetworkGeometryBuffer > buffer
std::shared_ptr< RootAudioBuffer > m_root_buffer
Shared pointer to the root buffer this processor manages.
Tendency< D, float > scale(const Tendency< D, float > &t, float factor)
Uniform scaling of a scalar-output tendency.
Definition Tendency.hpp:98

References buffer, and m_root_buffer.