MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ open()

void MayaFlux::Core::RtAudioStream::open ( )
overridevirtual

Initializes the audio stream and allocates required resources.

Opens the RtAudio stream with the configured parameters, making it ready for data transfer. Does not start the actual data flow.

Implements MayaFlux::Core::AudioStream.

Definition at line 210 of file RtAudioBackend.cpp.

211{
212 if (is_open()) {
213 return;
214 }
215
216 try {
217 RtAudioFormat format = RTAUDIO_FLOAT64;
218
219 switch (m_stream_info.format) {
221 format = RTAUDIO_FLOAT32;
222 break;
224 format = RTAUDIO_FLOAT64;
225 break;
227 format = RTAUDIO_SINT16;
228 break;
230 format = RTAUDIO_SINT24;
231 break;
233 format = RTAUDIO_SINT32;
234 break;
235 }
236
237 RtAudio::StreamParameters* inputParamsPtr = nullptr;
238
241 inputParamsPtr = &m_in_parameters;
242 }
243
244 unsigned int requested_buffer = m_stream_info.buffer_size;
245
246#ifdef MAYAFLUX_PLATFORM_LINUX
247 if (m_context->getCurrentApi() == RtAudio::UNIX_JACK) {
248 setenv("PIPEWIRE_QUANTUM",
249 std::to_string(m_stream_info.buffer_size).c_str(), 0);
250 setenv("PIPEWIRE_LATENCY",
252 }
253#endif // MAYAFLUX_PLATFORM_LINUX
254
256
257 m_context->openStream(
259 inputParamsPtr,
260 format,
264 this,
265 &m_options);
266
267 if (m_stream_info.buffer_size != requested_buffer) {
270 "Audio backend changed buffer size from {} to {}. "
271 "Set GlobalStreamInfo.buffer_size = {} before initialization to avoid mismatch.",
273 }
274
275 m_isOpen = true;
276 } catch (const RtAudioErrorType& e) {
278 m_isOpen = false;
279
283 std::source_location::current(),
284 "Failed to open RtAudio stream: {}",
285 m_context->getErrorText());
286 }
287}
#define MF_WARN(comp, ctx,...)
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.
RtAudio::StreamOptions m_options
RtAudio-specific stream options.
bool m_isOpen
Flag indicating if the stream is currently open.
GlobalStreamInfo & m_stream_info
Copy of the stream configuration for reference.
bool is_open() const override
Checks if the stream is initialized and ready for activation.
RtAudio::StreamParameters m_in_parameters
RtAudio-specific stream input configuration parameters.
RtAudio::StreamParameters m_out_parameters
RtAudio-specific stream output configuration parameters.
RtAudio * m_context
Pointer to the underlying RtAudio context.
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.
@ AudioBackend
Audio processing backend (RtAudio, JACK, ASIO)
void error_rethrow(Component component, Context context, std::source_location location=std::source_location::current(), std::string_view additional_context="")
Catch and log an exception, then rethrow it.
std::string format_runtime(std::string_view fmt_str, Args &&... args)
Definition Format.hpp:36
std::string format(format_string< std::remove_cvref_t< Args >... > fmt_str, Args &&... args)
Definition Format.hpp:30
@ 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)
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)
AudioFormat format
Sample data format for stream processing.

References MayaFlux::Journal::AudioBackend, MayaFlux::Core::GlobalStreamInfo::buffer_size, MayaFlux::Core::GlobalStreamInfo::ChannelConfig::channels, MayaFlux::Journal::Core, MayaFlux::Core::GlobalStreamInfo::ChannelConfig::enabled, MayaFlux::Core::GlobalStreamInfo::FLOAT32, MayaFlux::Core::GlobalStreamInfo::FLOAT64, MayaFlux::Core::GlobalStreamInfo::format, MayaFlux::Journal::format_runtime(), MayaFlux::Core::GlobalStreamInfo::input, MayaFlux::Core::GlobalStreamInfo::INT16, MayaFlux::Core::GlobalStreamInfo::INT24, MayaFlux::Core::GlobalStreamInfo::INT32, is_open(), m_context, m_in_parameters, m_isOpen, m_options, m_out_parameters, m_stream_info, MayaFlux::Core::RtAudioSingleton::mark_stream_closed(), MayaFlux::Core::RtAudioSingleton::mark_stream_open(), MF_WARN, rtAudioCallback(), and MayaFlux::Core::GlobalStreamInfo::sample_rate.

+ Here is the call graph for this function: