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

◆ extract_channel_data()

void MayaFlux::Buffers::ContainerToBufferAdapter::extract_channel_data ( std::span< double >  output)
private

Extract channel data from the container into the output buffer.

Parameters
outputOutput span to fill.

Definition at line 88 of file ContainerBuffer.cpp.

89{
90 if (!m_container) {
91 std::ranges::fill(output, 0.0);
92 return;
93 }
94
95 auto sound_container = std::dynamic_pointer_cast<Kakshya::SoundStreamContainer>(m_container);
96 if (!sound_container) {
97 std::ranges::fill(output, 0.0);
98 return;
99 }
100
101 auto& processed_data = sound_container->get_processed_data();
102 if (processed_data.empty()) {
103 std::ranges::fill(output, 0.0);
104 return;
105 }
106
107 auto structure = sound_container->get_structure();
108
109 if (structure.organization == Kakshya::OrganizationStrategy::INTERLEAVED) {
110 thread_local std::vector<double> temp_storage;
111 auto data_span = Kakshya::extract_from_variant<double>(processed_data[0], temp_storage);
112
113 auto num_channels = structure.get_channel_count();
114 auto samples_to_copy = std::min(static_cast<size_t>(output.size()),
115 static_cast<size_t>(data_span.size() / num_channels));
116
117 for (auto i : std::views::iota(0UZ, samples_to_copy)) {
118 auto interleaved_idx = i * num_channels + m_source_channel;
119 output[i] = (interleaved_idx < data_span.size()) ? data_span[interleaved_idx] : 0.0;
120 }
121
122 if (samples_to_copy < output.size()) {
123 std::ranges::fill(output | std::views::drop(samples_to_copy), 0.0);
124 }
125
126 } else {
127 if (m_source_channel >= processed_data.size()) {
128 std::ranges::fill(output, 0.0);
129 return;
130 }
131
132 thread_local std::vector<double> temp_storage;
133 auto channel_data_span = Kakshya::extract_from_variant<double>(processed_data[m_source_channel], temp_storage);
134
135 auto samples_to_copy = std::min(output.size(), channel_data_span.size());
136 std::ranges::copy_n(channel_data_span.begin(), samples_to_copy, output.begin());
137
138 if (samples_to_copy < output.size()) {
139 std::ranges::fill(output | std::views::drop(samples_to_copy), 0.0);
140 }
141 }
142}
std::shared_ptr< Kakshya::StreamContainer > m_container
@ INTERLEAVED
Single DataVariant with interleaved data (LRLRLR for stereo)

References MayaFlux::Kakshya::INTERLEAVED, m_container, and m_source_channel.

Referenced by on_attach(), and processing_function().

+ Here is the caller graph for this function: