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

◆ get_frames()

void MayaFlux::Kakshya::SoundStreamContainer::get_frames ( std::span< double >  output,
uint64_t  start_frame,
uint64_t  num_frames 
) const
overridevirtual

Get multiple frames efficiently.

Parameters
outputBuffer to write frames into
start_frameFirst frame index
num_framesNumber of frames to retrieve

Implements MayaFlux::Kakshya::NDDataContainer.

Definition at line 209 of file SoundStreamContainer.cpp.

210{
211 if (start_frame >= m_num_frames || output.empty()) {
212 std::ranges::fill(output, 0.0);
213 return;
214 }
215
216 uint64_t frames_to_copy = std::min<size_t>(num_frames, m_num_frames - start_frame);
217 uint64_t elements_to_copy = std::min(
218 frames_to_copy * m_num_channels,
219 static_cast<uint64_t>(output.size()));
220
221 auto interleaved_data = get_data_as_double();
222 uint64_t offset = start_frame * m_num_channels;
223
224 if (offset < interleaved_data.size()) {
225 uint64_t available = std::min<size_t>(elements_to_copy, interleaved_data.size() - offset);
226 std::copy_n(interleaved_data.begin() + offset, available, output.begin());
227
228 if (available < output.size()) {
229 std::fill(output.begin() + available, output.end(), 0.0);
230 }
231 } else {
232 std::ranges::fill(output, 0.0);
233 }
234}
std::span< const double > get_data_as_double() const
Get the audio data as a specific type.

References get_data_as_double(), m_num_channels, and m_num_frames.

+ Here is the call graph for this function: