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

◆ append_frames()

uint64_t MayaFlux::Kakshya::DynamicSoundStream::append_frames ( std::span< const double >  data,
uint32_t  channel = 0 
)

Write one channel at its write head and advance the head.

Linear mode appends after the last frame written, growing the stream if auto-resize is on. Circular mode wraps at capacity and overwrites the oldest frames; a block larger than the capacity keeps only its newest frames. Each channel has its own head, so writing every channel of a stream once per cycle keeps them aligned.

Parameters
dataSamples for one channel.
channelChannel to write.
Returns
Number of frames written.

Definition at line 221 of file DynamicSoundStream.cpp.

222{
223 if (data.empty() || channel >= get_num_channels()) {
224 return 0;
225 }
226
227 if (m_write_heads.size() < get_num_channels()) {
228 m_write_heads.resize(get_num_channels(), 0);
229 }
230
231 uint64_t& head = m_write_heads[channel];
232
233 if (!m_is_circular) {
234 const uint64_t written = write_frames(data, head, channel);
235 head += written;
236 return written;
237 }
238
239 if (data.size() > m_circular_capacity) {
240 const uint64_t skip = data.size() - m_circular_capacity;
241 head = (head + skip) % m_circular_capacity;
242 data = data.subspan(skip);
243 }
244
245 const uint64_t first = std::min<uint64_t>(data.size(), m_circular_capacity - head);
246 uint64_t written = write_frames(data.subspan(0, first), head, channel);
247
248 if (first < data.size()) {
249 written += write_frames(data.subspan(first), 0, channel);
250 }
251
252 head = (head + data.size()) % m_circular_capacity;
253 return written;
254}
std::vector< uint64_t > m_write_heads
Next append_frames index per channel.
bool m_is_circular
True when operating in circular buffer mode.
uint64_t write_frames(std::span< const double > data, uint64_t start_frame=0, uint32_t channel=0)
Write audio frame data to the container with automatic capacity management.
uint64_t m_circular_capacity
Fixed capacity for circular mode.

References MayaFlux::Kakshya::SoundStreamContainer::get_num_channels(), m_circular_capacity, m_is_circular, m_write_heads, and write_frames().

+ Here is the call graph for this function: