Processes output data for audio interface.
Processes node graph and buffer operations, then fills the output buffer with processed audio data in interleaved format for the audio interface. This is the main processing entry point called by audio callbacks.
74{
76
77 if (output_buffer == nullptr) {
79 "No output available");
81 return 1;
82 }
83
85 if (output_buffer) {
87 std::memset(output_buffer, 0, total_samples * sizeof(double));
88 }
90 return 0;
91 }
92
95 "Invalid processing handle");
97 return 1;
98 }
99
100 try {
102 size_t total_samples = static_cast<size_t>(num_frames) * num_channels;
103 std::span<double> output_span(output_buffer, total_samples);
104
107
108 std::vector<std::span<const double>> buffer_data(num_channels);
109 std::vector<std::vector<std::vector<double>>> all_network_outputs(num_channels);
110 bool has_underrun = false;
111
113
114 for (uint32_t channel = 0; channel < num_channels; channel++) {
117
119
120 if (channel_data.size() < num_frames) {
122 "Channel buffer underrun");
123 has_underrun = true;
124
125 buffer_data[channel] = std::span<const double>();
126 } else {
127 buffer_data[channel] = channel_data;
128 }
129 }
130
131 for (size_t i = 0; i < num_frames; ++i) {
132
134
135 for (size_t j = 0; j < num_channels; ++j) {
136 double buffer_sample = 0.0;
137 if (!buffer_data[j].empty() && i < buffer_data[j].size()) {
138 buffer_sample = buffer_data[j][i];
139 }
140
142
143 for (const auto& network_buffer : all_network_outputs[j]) {
144 if (i < network_buffer.size()) {
145 sample += network_buffer[i];
146 }
147 }
148
149 size_t index = i * num_channels + j;
150 output_span[index] = std::clamp(sample, -1., 1.);
151 }
152 }
153
156
159
160 std::memcpy(
m_snapshot_copy.data(), output_buffer, total_samples *
sizeof(
double));
161 m_snapshot_size.store(
static_cast<uint32_t
>(total_samples), std::memory_order_release);
165
167 return has_underrun ? 1 : 0;
168
169 } catch (const std::exception& e) {
171 "Exception during audio output processing: {}", e.what());
172
173 if (output_buffer) {
175 std::memset(output_buffer, 0, total_samples * sizeof(double));
176 }
177
179 return 1;
180 }
181}
#define MF_RT_WARN(comp, ctx,...)
#define MF_RT_ERROR(comp, ctx,...)
std::atomic< uint64_t > m_snapshot_generation
std::atomic< int > m_callback_active
Active callback counter.
std::atomic< bool > m_is_running
Subsystem running state.
GlobalStreamInfo m_stream_info
Audio stream configuration.
SubsystemProcessingHandle * m_handle
Reference to processing handle.
std::atomic< uint32_t > m_snapshot_size
std::atomic< const double * > m_snapshot_ptr
std::vector< double > m_snapshot_copy
Owned copy of the last output cycle; decouples notification-thread reads from the callback write buff...
std::span< const double > read_channel_data(uint32_t channel) const
Get read-only access to channel data.
void process_channel(uint32_t channel, uint32_t processing_units)
Process specific channel.
void update_routing_states()
void cleanup_completed_routing()
void update_routing_states()
void cleanup_completed_routing()
std::vector< std::vector< double > > process_audio_networks(uint32_t num_samples, uint32_t channel=0)
double process_sample(uint32_t channel)
TaskSchedulerHandle tasks
NodeProcessingHandle nodes
Node processing interface.
BufferProcessingHandle buffers
Buffer processing interface.
void process_buffer_cycle()
Process all tasks scheduled for current buffer cycle.
void process(uint64_t processing_units)
Process all tasks in token domain.
@ AudioCallback
Audio callback thread - strictest real-time requirements.
@ Core
Core engine, backend, subsystems.
uint32_t channels
Number of discrete channels in this set.
ChannelConfig output
Configuration for output signal channels.