8 : m_stream_info(stream_info)
10 , m_audio_device(m_audiobackend->create_device_manager())
11 , m_subsystem_tokens {
12 .Buffer =
MayaFlux::Buffers::ProcessingToken::AUDIO_BACKEND,
13 .Node =
MayaFlux::Nodes::ProcessingToken::AUDIO_RATE,
14 .Task =
MayaFlux::Vruta::ProcessingToken::SAMPLE_ACCURATE
35 error<std::runtime_error>(
38 std::source_location::current(),
39 "AudioSubsystem not initialized");
43 [
this](
void* output_buffer,
void* input_buffer,
unsigned int num_frames) ->
int {
44 auto input_ptr =
static_cast<double*
>(input_buffer);
45 auto output_ptr =
static_cast<double*
>(output_buffer);
47 if (input_ptr && output_ptr) {
48 return this->
process_audio(input_ptr, output_ptr, num_frames);
66 if (output_buffer ==
nullptr) {
68 "No output available");
76 std::memset(output_buffer, 0, total_samples *
sizeof(
double));
84 "Invalid processing handle");
91 size_t total_samples =
static_cast<size_t>(num_frames) * num_channels;
92 std::span<double> output_span(output_buffer, total_samples);
94 std::vector<std::span<const double>> buffer_data(num_channels);
95 std::vector<std::vector<std::vector<double>>> all_network_outputs(num_channels);
96 bool has_underrun =
false;
100 for (uint32_t channel = 0; channel < num_channels; channel++) {
106 if (channel_data.size() < num_frames) {
108 "Channel buffer underrun");
111 buffer_data[channel] = std::span<const double>();
113 buffer_data[channel] = channel_data;
117 for (
size_t i = 0; i < num_frames; ++i) {
121 for (
size_t j = 0; j < num_channels; ++j) {
122 double buffer_sample = 0.0;
123 if (!buffer_data[j].empty() && i < buffer_data[j].size()) {
124 buffer_sample = buffer_data[j][i];
129 for (
const auto& network_buffer : all_network_outputs[j]) {
130 if (i < network_buffer.size()) {
131 sample += network_buffer[i];
135 size_t index = i * num_channels + j;
136 output_span[index] = std::clamp(sample, -1., 1.);
141 return has_underrun ? 1 : 0;
143 }
catch (
const std::exception& e) {
145 "Exception during audio output processing: {}", e.what());
149 std::memset(output_buffer, 0, total_samples *
sizeof(
double));
162 "Invalid processing handle");
170 std::memset(input_buffer, 0, total_samples *
sizeof(
double));
201 error<std::runtime_error>(
204 std::source_location::current(),
205 "Cannot start AudioSubsystem: not initialized");
220 "Stopping AudioSubsystem...");
234 "AudioSubsystem stopped");
#define MF_INFO(comp, ctx,...)
#define MF_RT_WARN(comp, ctx,...)
#define MF_RT_ERROR(comp, ctx,...)
Factory pattern implementation for audio backend instantiation.
void initialize(SubsystemProcessingHandle &handle) override
Initialize audio processing with provided handle.
bool m_is_ready
Subsystem ready state.
void stop() override
Stop audio processing and streaming.
void shutdown() override
Shutdown and cleanup audio resources.
std::unique_ptr< IAudioBackend > m_audiobackend
Audio backend implementation.
int process_output(double *output_buffer, unsigned int num_frames)
Processes output data for audio interface.
std::atomic< int > m_callback_active
Active callback counter.
int process_audio(double *input_buffer, double *output_buffer, unsigned int num_frames)
Processes both input and output data in full-duplex mode.
AudioSubsystem(GlobalStreamInfo &stream_info, Utils::AudioBackendType backend_type=Utils::AudioBackendType::RTAUDIO)
Constructs AudioSubsystem with stream configuration.
void pause() override
Pause audio processing without stopping the stream.
std::atomic< bool > m_is_running
Subsystem running state.
void start() override
Start audio processing and streaming.
GlobalStreamInfo m_stream_info
Audio stream configuration.
SubsystemProcessingHandle * m_handle
Reference to processing handle.
bool m_is_paused
Subsystem paused state.
int process_input(double *input_buffer, unsigned int num_frames)
Processes input data from audio interface.
void resume() override
Resume audio processing after pause.
std::unique_ptr< AudioDevice > m_audio_device
Audio device manager.
std::unique_ptr< AudioStream > m_audio_stream
Audio stream manager.
void register_callbacks() override
Register audio backend callbacks for real-time processing.
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 process_input(double *input_data, uint32_t num_channels, uint32_t num_frames)
@brienf Process Input from backend into buffer manager
std::vector< std::vector< double > > process_audio_networks(uint32_t num_samples, uint32_t channel=0)
double process_sample(uint32_t channel)
std::map< std::string, ProcessHook > post_process_hooks
TaskSchedulerHandle tasks
NodeProcessingHandle nodes
Node processing interface.
std::map< std::string, ProcessHook > pre_process_hooks
BufferProcessingHandle buffers
Buffer processing interface.
Unified interface combining buffer and node processing for subsystems.
void process_buffer_cycle()
Process all tasks scheduled for current buffer cycle.
void process(uint64_t processing_units)
Process all tasks in token domain.
@ AudioSubsystem
Audio subsystem operations (backend, device, stream management)
@ AudioCallback
Audio callback thread - strictest real-time requirements.
@ Core
Core engine, backend, subsystems.
Main namespace for the Maya Flux audio engine.
uint32_t channels
Number of discrete channels in this set.
ChannelConfig input
Configuration for input signal channels (disabled by default)
ChannelConfig output
Configuration for output signal channels.
Comprehensive configuration for digital audio stream processing.