Drives or reads network batch output into the buffer.
If the network has not been processed this cycle, drives process_batch() with the buffer's sample count. If another context is currently processing, returns immediately without writing data.
28{
31 "NetworkAudioSourceProcessor has null network");
32 return;
33 }
34
35 auto output_mode =
m_network->get_output_mode();
39 "NetworkAudioSourceProcessor: network is not an audio sink (mode={})",
40 static_cast<int>(output_mode));
41 return;
42 }
43
46 "NetworkAudioSourceProcessor: network is disabled");
47 return;
48 }
49
50 auto audio_buffer = std::dynamic_pointer_cast<AudioBuffer>(buffer);
51 if (!audio_buffer) {
52 return;
53 }
54
56 if (auto net_buf = std::dynamic_pointer_cast<NetworkAudioBuffer>(buffer)) {
57 should_clear = net_buf->get_clear_before_process();
58 }
59
60 if (should_clear) {
61 buffer->clear();
62 }
63
64 if (!
m_network->is_processed_this_cycle()) {
66 return;
67 }
68
70 m_network->add_channel_usage(audio_buffer->get_channel_id());
72 m_network->process_batch(audio_buffer->get_num_samples());
75 }
76
77 const auto net_output =
m_network->get_audio_buffer();
78 if (!net_output) {
79 return;
80 }
81
82 auto& buffer_data = audio_buffer->get_data();
83 const auto& network_data = *net_output;
84
85 auto scale =
static_cast<double>(
m_mix);
86
89 uint32_t channel = audio_buffer->get_channel_id();
90 double routing_amount =
m_network->get_routing_state().amount[channel];
91 scale *= routing_amount;
92 }
93 }
94
95 if (scale == 0.0) {
96 return;
97 }
98
99 const size_t copy_size = std::min(buffer_data.size(), network_data.size());
100
101 if (should_clear && scale == 1.0) {
102 std::copy_n(network_data.begin(), copy_size, buffer_data.begin());
103 } else {
104 for (size_t i = 0; i < copy_size; ++i) {
105 buffer_data[i] += network_data[i] * scale;
106 }
107 }
108
111 m_network->request_reset_from_channel(audio_buffer->get_channel_id());
112 }
113}
#define MF_RT_ERROR(comp, ctx,...)
#define MF_RT_DEBUG(comp, ctx,...)
std::shared_ptr< Nodes::Network::NodeNetwork > m_network
bool m_clear_before_process
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
@ AUDIO_COMPUTE
processed each cycle but not sent to output
@ AUDIO_SINK
Aggregated audio samples sent to output.