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

◆ peek_sequential()

uint64_t MayaFlux::Kakshya::SoundStreamContainer::peek_sequential ( std::span< double >  output,
uint64_t  count,
uint64_t  offset = 0 
) const
overridevirtual

Peek at data without advancing the read position.

Parameters
outputBuffer to write data into
countNumber of elements to peek
offsetOffset from current position in primary dimension
Returns
Actual number of elements read

Enables lookahead, preview, or non-destructive inspection of stream data.

Implements MayaFlux::Kakshya::StreamContainer.

Definition at line 505 of file SoundStreamContainer.cpp.

506{
507 auto interleaved_span = get_data_as_double();
508 if (interleaved_span.empty() || output.empty())
509 return 0;
510
511 uint64_t start_frame = m_read_position.empty() ? 0 : m_read_position[0].load();
512 start_frame += offset;
513 uint64_t elements_to_read = std::min<uint64_t>(count, static_cast<uint64_t>(output.size()));
514
515 if (!m_looping_enabled) {
516 uint64_t linear_start = start_frame * m_num_channels;
517 if (linear_start >= interleaved_span.size()) {
518 std::ranges::fill(output, 0.0);
519 return 0;
520 }
521 auto view = interleaved_span
522 | std::views::drop(linear_start)
523 | std::views::take(elements_to_read);
524
525 auto copied = std::ranges::copy(view, output.begin());
526 std::ranges::fill(output.subspan(copied.out - output.begin()), 0.0);
527 return static_cast<uint64_t>(copied.out - output.begin());
528 }
529
530 if (m_loop_region.start_coordinates.empty()) {
531 std::ranges::fill(output, 0.0);
532 return 0;
533 }
534
535 uint64_t loop_start_frame = m_loop_region.start_coordinates[0];
536 uint64_t loop_end_frame = m_loop_region.end_coordinates[0];
537 uint64_t loop_length_frames = loop_end_frame - loop_start_frame + 1;
538
539 std::ranges::for_each(
540 std::views::iota(0UZ, elements_to_read),
541 [&](uint64_t i) {
542 uint64_t element_pos = start_frame * m_num_channels + i;
543 uint64_t frame_pos = element_pos / m_num_channels;
544 uint64_t channel_offset = element_pos % m_num_channels;
545
546 uint64_t wrapped_frame = ((frame_pos - loop_start_frame) % loop_length_frames) + loop_start_frame;
547 uint64_t wrapped_element = wrapped_frame * m_num_channels + channel_offset;
548
549 output[i] = (wrapped_element < interleaved_span.size()) ? interleaved_span[wrapped_element] : 0.0;
550 });
551
552 if (elements_to_read < output.size()) {
553 std::ranges::fill(output.subspan(elements_to_read), 0.0);
554 }
555 return elements_to_read;
556}
size_t count
std::shared_ptr< Core::VKImage > output
float offset
std::span< const double > get_data_as_double() const
Get the audio data as a specific type.
std::vector< std::atomic< uint64_t > > m_read_position
std::vector< uint64_t > end_coordinates
Ending frame index (inclusive)
Definition Region.hpp:78
std::vector< uint64_t > start_coordinates
Starting frame index (inclusive)
Definition Region.hpp:75

References count, MayaFlux::Kakshya::Region::end_coordinates, get_data_as_double(), m_loop_region, m_looping_enabled, m_num_channels, m_read_position, offset, output, and MayaFlux::Kakshya::Region::start_coordinates.

Referenced by read_sequential().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: