MayaFlux 0.3.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 89 of file SoundContainerBuffer.cpp.

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