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

◆ extract_channel_data()

DataVariant MayaFlux::Kakshya::extract_channel_data ( const std::shared_ptr< SignalSourceContainer > &  container,
uint32_t  channel_index 
)

Extract data from a specific channel.

Parameters
containerThe container to extract from.
channel_indexIndex of the channel to extract.
Returns
DataVariant containing channel data.

Definition at line 105 of file ContainerUtils.cpp.

107{
108 if (!container) {
109 throw std::invalid_argument("Container is null");
110 }
111
112 const auto structure = container->get_structure();
113 auto channel_count = structure.get_channel_count();
114
115 if (channel_index >= channel_count) {
116 throw std::out_of_range("Channel index out of range");
117 }
118
119 auto data = container->get_data();
120
121 if (structure.organization == OrganizationStrategy::PLANAR) {
122 if (channel_index >= data.size()) {
123 throw std::out_of_range("Channel index out of range for planar data");
124 }
125 return data[channel_index];
126 }
127
128 std::vector<double> temp_storage;
129 auto interleaved_span = extract_from_variant<double>(data[0], temp_storage);
130
131 if (interleaved_span.empty()) {
132 throw std::runtime_error("Failed to extract interleaved data");
133 }
134
135 if (interleaved_span.size() % channel_count != 0) {
136 throw std::runtime_error("Interleaved data size is not a multiple of channel count");
137 }
138
139#ifdef MAYAFLUX_PLATFORM_MACOS
140 std::vector<double> channel_data;
141 for (size_t i = channel_index; i < interleaved_span.size(); i += channel_count) {
142 channel_data.push_back(interleaved_span[i]);
143 }
144#else
145 auto channel_view = interleaved_span
146 | std::views::drop(channel_index)
147 | std::views::stride(channel_count);
148
149 std::vector<double> channel_data;
150 std::ranges::copy(channel_view, std::back_inserter(channel_data));
151#endif // MAYAFLUX_PLATFORM_MACOS
152
153 return DataVariant { std::move(channel_data) };
154}
std::variant< std::vector< double >, std::vector< float >, std::vector< uint8_t >, std::vector< uint16_t >, std::vector< uint32_t >, std::vector< std::complex< float > >, std::vector< std::complex< double > >, std::vector< glm::vec2 >, std::vector< glm::vec3 >, std::vector< glm::vec4 >, std::vector< glm::mat4 > > DataVariant
Multi-type data storage for different precision needs.
Definition NDData.hpp:73

References PLANAR.