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

◆ read_once()

bool MayaFlux::Buffers::AudioBuffer::read_once ( const std::shared_ptr< AudioBuffer > &  buffer,
bool  force = false 
)
virtual

Reads audio data into the buffer from the audio backend.

Parameters
bufferShared pointer to the AudioBuffer to read data into
forceWhether to force reading even if in processing state
Returns
True if data was successfully read, false otherwise

This method attempts to read audio data from the audio backend into the provided AudioBuffer. If force is true, it will attempt to read even if the current buffer or the copy buffer are in processing state

Definition at line 97 of file AudioBuffer.cpp.

98{
99 if (buffer && buffer->get_num_samples() == m_num_samples) {
100 if (m_is_processing.load() || buffer->is_processing()) {
102 "read_once: Attempting to read from an audio buffer while it is being processed.");
103
104 if (!force) {
106 "read_once: Skipping read due to ongoing processing.");
107 return false;
108 }
110 "read_once: Forcing read despite ongoing processing. This may lead to data corruption.");
111 }
112 m_data = buffer->get_data();
113 m_has_data = true;
114 return true;
115 }
116
118 "read_once: Buffer read failed due to size mismatch or null buffer.");
119
120 return false;
121}
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
bool m_has_data
Whether the audio buffer has data to process this cycle.
std::atomic< bool > m_is_processing
uint32_t m_num_samples
Capacity of the buffer in audio samples.
std::vector< double > m_data
Vector storing the actual double-precision audio sample data.
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.

References MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, m_data, m_has_data, m_is_processing, m_num_samples, MF_ERROR, and MF_WARN.