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

◆ processing_function()

void MayaFlux::Buffers::ChannelProcessor::processing_function ( 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 for (auto& child : m_root_buffer->get_child_buffers()) {
49 if (child->has_data_for_cycle() && !child->needs_removal() && !child->is_internal_only()) {
50 const auto& child_data = child->get_data();
51 for (size_t i = 0; i < std::min(child_data.size(), output_data.size()); i++) {
52 output_data[i] += child_data[i] / active_buffers;
53 }
54 }
55 }
56 }
57
58 for (auto& child : buffers_to_remove) {
59 m_root_buffer->remove_child_buffer(child);
60 }
61}
std::shared_ptr< RootAudioBuffer > m_root_buffer
Shared pointer to the root buffer this processor manages.

References m_root_buffer.