MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
AudioSubsystem.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Subsystem.hpp"
4
6
7namespace MayaFlux::Core {
8
9/**
10 * @class AudioSubsystem
11 * @brief Audio processing subsystem managing real-time audio I/O and processing
12 *
13 * Implements the ISubsystem interface to provide audio-specific processing capabilities
14 * within the MayaFlux engine. Manages audio backends, devices, and streams while
15 * coordinating with the token-based processing architecture for buffer, node and scheduling operations.
16 *
17 * Uses AUDIO_BACKEND token for buffer processing and AUDIO_RATE token for node processing,
18 * enabling real-time audio processing with proper thread safety and resource isolation.
19 */
20class MAYAFLUX_API AudioSubsystem : public ISubsystem {
21public:
22 virtual ~AudioSubsystem() = default;
23
24 /** @brief Initialize audio processing with provided handle */
25 void initialize(SubsystemProcessingHandle& handle) override;
26
27 /** @brief Register audio backend callbacks for real-time processing */
28 void register_callbacks() override;
29
30 /** @brief Start audio processing and streaming */
31 void start() override;
32
33 /** @brief Pause audio processing without stopping the stream */
34 void pause() override;
35
36 /** @brief Resume audio processing after pause */
37 void resume() override;
38
39 /** @brief Stop audio processing and streaming */
40 void stop() override;
41
42 /** @brief Shutdown and cleanup audio resources */
43 void shutdown() override;
44
45 /** @brief Get audio subsystem token configuration */
46 inline SubsystemTokens get_tokens() const override { return m_subsystem_tokens; }
47
48 /** @brief Check if audio subsystem is ready for operation */
49 inline bool is_ready() const override { return m_is_ready; }
50
51 /** @brief Check if audio subsystem is currently running */
52 inline bool is_running() const override { return m_is_running; }
53
54 /** @brief Get access to the underlying audio backend */
55 inline IAudioBackend* get_audio_backend() { return m_audiobackend.get(); }
56
57 /** @brief Get read-only access to stream manager */
58 inline const AudioStream* get_stream_manager() const { return m_audio_stream.get(); }
59
60 /** @brief Get read-only access to device manager */
61 inline const AudioDevice* get_device_manager() const { return m_audio_device.get(); }
62
63 /** @brief Get global stream configuration */
64 inline const GlobalStreamInfo& get_stream_info() const { return m_stream_info; }
65
66 /**
67 * @brief Processes input data from audio interface
68 * @param input_buffer Pointer to interleaved input data
69 * @param num_frames Number of frames to process
70 * @return Status code (0 for success)
71 *
72 * Handles incoming audio data from the audio interface, converting from
73 * interleaved format and routing to appropriate buffer channels for processing.
74 */
75 int process_input(double* input_buffer, unsigned int num_frames);
76
77 /**
78 * @brief Processes output data for audio interface
79 * @param output_buffer Pointer to interleaved output buffer
80 * @param num_frames Number of frames to process
81 * @return Status code (0 for success)
82 *
83 * Processes node graph and buffer operations, then fills the output buffer
84 * with processed audio data in interleaved format for the audio interface.
85 * This is the main processing entry point called by audio callbacks.
86 */
87 int process_output(double* output_buffer, unsigned int num_frames);
88
89 /**
90 * @brief Processes both input and output data in full-duplex mode
91 * @param input_buffer Pointer to input data buffer
92 * @param output_buffer Pointer to output data buffer
93 * @param num_frames Number of frames to process
94 * @return Status code (0 for success)
95 *
96 * Handles full-duplex audio processing, processing input and generating
97 * output simultaneously. Used for real-time effects and monitoring scenarios.
98 */
99 int process_audio(double* input_buffer, double* output_buffer, unsigned int num_frames);
100
101 /**
102 * @brief Constructs AudioSubsystem with stream configuration
103 * @param stream_info Global stream configuration
104 * @param backend_type Audio backend type to use (default: RTAUDIO)
105 *
106 * Constructor - AudioSubsystem instances are created by Engine.
107 * Initializes audio backend and configures processing tokens.
108 */
109 explicit AudioSubsystem(GlobalStreamInfo& stream_info, Utils::AudioBackendType backend_type = Utils::AudioBackendType::RTAUDIO);
110
111 inline SubsystemType get_type() const override { return m_type; }
112
114
115private:
116 GlobalStreamInfo m_stream_info; ///< Audio stream configuration
117
118 std::unique_ptr<IAudioBackend> m_audiobackend; ///< Audio backend implementation
119 std::unique_ptr<AudioDevice> m_audio_device; ///< Audio device manager
120 std::unique_ptr<AudioStream> m_audio_stream; ///< Audio stream manager
121
122 SubsystemTokens m_subsystem_tokens; ///< Processing token configuration
123 SubsystemProcessingHandle* m_handle; ///< Reference to processing handle
124
125 bool m_is_ready {}; ///< Subsystem ready state
126 bool m_is_running {}; ///< Subsystem running state
127 bool m_is_paused {}; ///< Subsystem paused state
128
129 static const SubsystemType m_type = SubsystemType::AUDIO;
130};
131
132}
Manages audio endpoint discovery and enumeration.
Manages digital audio data flow between the engine and hardware.
SubsystemProcessingHandle * get_processing_context_handle() override
Get the processing context handle for this subsystem.
SubsystemType get_type() const override
Get the type of this subsystem.
std::unique_ptr< IAudioBackend > m_audiobackend
Audio backend implementation.
bool is_ready() const override
Check if audio subsystem is ready for operation.
bool is_running() const override
Check if audio subsystem is currently running.
const AudioDevice * get_device_manager() const
Get read-only access to device manager.
GlobalStreamInfo m_stream_info
Audio stream configuration.
SubsystemProcessingHandle * m_handle
Reference to processing handle.
const AudioStream * get_stream_manager() const
Get read-only access to stream manager.
IAudioBackend * get_audio_backend()
Get access to the underlying audio backend.
SubsystemTokens get_tokens() const override
Get audio subsystem token configuration.
const GlobalStreamInfo & get_stream_info() const
Get global stream configuration.
SubsystemTokens m_subsystem_tokens
Processing token configuration.
std::unique_ptr< AudioDevice > m_audio_device
Audio device manager.
std::unique_ptr< AudioStream > m_audio_stream
Audio stream manager.
virtual ~AudioSubsystem()=default
Audio processing subsystem managing real-time audio I/O and processing.
Interface for audio system abstraction layer.
Base interface for all subsystems in the MayaFlux processing architecture.
Definition Subsystem.hpp:25
Unified interface combining buffer and node processing for subsystems.
void initialize()
Definition main.cpp:11
Comprehensive configuration for digital audio stream processing.
Processing token configuration for subsystem operation.