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

◆ extract_channel_data()

void MayaFlux::Buffers::SoundStreamReader::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 91 of file SoundContainerBuffer.cpp.

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