12 return RtAudio::LINUX_ALSA;
14 return RtAudio::LINUX_PULSE;
16 return RtAudio::UNIX_JACK;
18 return RtAudio::MACOSX_CORE;
20 return RtAudio::WINDOWS_WASAPI;
22 return RtAudio::WINDOWS_ASIO;
24 return RtAudio::WINDOWS_DS;
26 return RtAudio::LINUX_OSS;
28 return RtAudio::UNSPECIFIED;
45 return std::make_unique<RtAudioDevice>(
m_context);
49 unsigned int output_device_id,
50 unsigned int input_device_id,
54 return std::make_unique<RtAudioStream>(
64 return RtAudio::getVersion();
79 , m_defaultOutputDevice(0)
80 , m_defaultInputDevice(0)
83 throw std::invalid_argument(
"RtAudioDevice: context must not be null");
87 throw std::runtime_error(
"No audio devices found");
93 for (
unsigned int id :
m_context->getDeviceIds()) {
95 RtAudio::DeviceInfo info =
m_context->getDeviceInfo(
id);
97 if (info.outputChannels > 0) {
102 if (info.inputChannels > 0) {
106 }
catch (RtAudioErrorType& e) {
107 std::cerr <<
"Error probing device: " <<
id <<
": " << e <<
"\n";
134 unsigned int output_device_id,
135 unsigned int input_device_id,
141 , m_userData(userData)
144 , m_stream_info(streamInfo)
147 throw std::invalid_argument(
"RtAudioStream: context must not be null");
174 m_options.flags |= RTAUDIO_SCHEDULE_REALTIME;
182 m_options.flags |= RTAUDIO_NONINTERLEAVED;
194 bool exclusive = std::any_cast<bool>(rtSpecificOpt->second);
197 m_options.flags |= RtAudio::Api::WINDOWS_WASAPI;
200 }
catch (
const std::bad_any_cast&) {
204 std::source_location::current(),
205 "Invalid type for rtaudio.exclusive option; expected bool");
217 RtAudioFormat format = RTAUDIO_FLOAT64;
221 format = RTAUDIO_FLOAT32;
224 format = RTAUDIO_FLOAT64;
227 format = RTAUDIO_SINT16;
230 format = RTAUDIO_SINT24;
233 format = RTAUDIO_SINT32;
237 RtAudio::StreamParameters* inputParamsPtr =
nullptr;
259 }
catch (
const RtAudioErrorType& e) {
266 std::source_location::current(),
267 "Failed to open RtAudio stream: {}",
275 throw std::runtime_error(
"Cannot start stream: stream not open");
285 }
catch (
const RtAudioErrorType& e) {
289 std::source_location::current(),
290 "Failed to start RtAudio stream: {}",
304 }
catch (
const RtAudioErrorType& e) {
308 std::source_location::current(),
309 "Failed to stop RtAudio stream: {}",
330 }
catch (
const RtAudioErrorType& e) {
337 std::source_location::current(),
338 "Failed to close RtAudio stream: {}",
354 std::function<
int(
void*,
void*,
unsigned int)> processCallback)
362 unsigned int num_frames,
364 RtAudioStreamStatus ,
369 if (stream && stream->m_process_callback) {
380 return std::make_unique<RtAudioBackend>();
382 throw std::runtime_error(
"Unsupported audio backend type");
static std::unique_ptr< IAudioBackend > create_backend(Utils::AudioBackendType type)
Creates a specific audio backend implementation.
int get_api_type() const override
Retrieves the RtAudio API type identifier.
std::string get_version_string() const override
Retrieves the RtAudio library version.
std::unique_ptr< AudioStream > create_stream(unsigned int output_device_id, unsigned int input_device_id, const GlobalStreamInfo &stream_info, void *user_data) override
Creates an RtAudio-specific audio stream.
RtAudio * m_context
Pointer to the underlying RtAudio context.
void cleanup() override
Releases all resources held by the backend.
RtAudioBackend()
Initializes the RtAudio backend.
std::unique_ptr< AudioDevice > create_device_manager() override
Creates an RtAudio-specific device manager.
~RtAudioBackend() override
Cleans up the RtAudio backend.
std::vector< DeviceInfo > m_output_devices
Cached list of output devices.
unsigned int m_defaultOutputDevice
System identifier for the default output device.
RtAudioDevice(RtAudio *context)
Initializes the device manager with an RtAudio context.
RtAudio * m_context
Pointer to the underlying RtAudio context.
std::vector< DeviceInfo > get_input_devices() const override
Retrieves information about all available input devices.
std::vector< DeviceInfo > m_input_devices
Cached list of input devices.
std::vector< DeviceInfo > get_output_devices() const override
Retrieves information about all available output devices.
unsigned int get_default_output_device() const override
Gets the system's primary output device identifier.
unsigned int get_default_input_device() const override
Gets the system's primary input device identifier.
unsigned int m_defaultInputDevice
System identifier for the default input device.
static void mark_stream_closed()
Deregisters an active audio stream from the system.
static void mark_stream_open()
Registers an active audio stream in the system.
static void cleanup()
Releases all audio system resources.
Thread-safe global access point for audio system resources.
RtAudio::StreamOptions m_options
RtAudio-specific stream options.
GlobalStreamInfo m_stream_info
Copy of the stream configuration for reference.
void set_process_callback(std::function< int(void *, void *, unsigned int)> processCallback) override
Sets the function to process audio data.
void start() override
Activates the audio stream and begins data transfer.
void stop() override
Deactivates the audio stream and halts data transfer.
void configure_stream_options()
Configures RtAudio stream options based on GlobalStreamInfo.
~RtAudioStream() override
Ensures proper cleanup of stream resources.
bool m_isOpen
Flag indicating if the stream is currently open.
bool is_open() const override
Checks if the stream is initialized and ready for activation.
void open() override
Initializes the audio stream and allocates required resources.
bool m_isRunning
Flag indicating if the stream is currently running.
RtAudio::StreamParameters m_in_parameters
RtAudio-specific stream input configuration parameters.
RtAudio::StreamParameters m_out_parameters
RtAudio-specific stream output configuration parameters.
RtAudioStream(RtAudio *context, unsigned int output_device_id, unsigned int input_device_id, const GlobalStreamInfo &streamInfo, void *userData)
Initializes an audio stream with the specified configuration.
void close() override
Terminates the audio stream and releases all resources.
RtAudio * m_context
Pointer to the underlying RtAudio context.
std::function< int(void *, void *, unsigned int)> m_process_callback
User-provided callback function for audio processing.
static int rtAudioCallback(void *output_buffer, void *input_buffer, unsigned int num_frames, double stream_time, RtAudioStreamStatus status, void *user_data)
Static callback function for the RtAudio API.
bool is_running() const override
Checks if the stream is actively processing audio data.
RtAudio implementation of the audio stream interface.
static DeviceInfo convert_device_info(const RtAudio::DeviceInfo &rtInfo, unsigned int id, unsigned int defaultOutputDevice, unsigned int defaultInputDevice)
Converts RtAudio-specific device information to the engine's device model.
@ AudioBackend
Audio processing backend (RtAudio, JACK, ASIO)
@ Core
Core engine, backend, subsystems.
uint32_t channels
Number of discrete channels in this set.
bool enabled
Whether this channel set is active in the stream.
uint32_t buffer_size
Number of samples per processing block.
ChannelConfig input
Configuration for input signal channels (disabled by default)
AudioApi
Enumeration of supported audio APIs for wrapper backends like RtAudio.
uint32_t sample_rate
Number of samples processed per second (Hz)
@ FLOAT64
64-bit floating point representation (-1.0 to 1.0)
@ INT16
16-bit integer representation (-32768 to 32767)
@ INT32
32-bit integer representation (-2147483648 to 2147483647)
@ INT24
24-bit integer representation (-8388608 to 8388607)
@ FLOAT32
32-bit floating point representation (-1.0 to 1.0)
ChannelConfig output
Configuration for output signal channels.
AudioFormat format
Sample data format for stream processing.
@ REALTIME
Maximum resource priority with timing guarantees.
@ HIGH
Elevated resource priority.
StreamPriority priority
System resource priority for audio processing.
double buffer_count
Number of buffers in the processing queue (0 for system default)
std::unordered_map< std::string, std::any > backend_options
Backend-specific configuration parameters.
bool non_interleaved
Channel organization mode (true: planar, false: interleaved)
Comprehensive configuration for digital audio stream processing.