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

◆ advance_position() [2/2]

std::vector< uint64_t > MayaFlux::Kakshya::advance_position ( const std::vector< uint64_t > &  current_positions,
uint64_t  frames_to_advance,
const ContainerDataStructure structure,
bool  looping_enabled,
const Region loop_region 
)

Advance current positions by a number of frames, with optional looping.

Parameters
current_positionsCurrent positions per channel.
frames_to_advanceNumber of frames to advance.
structureContainer data structure (for total frames).
looping_enabledWhether looping is enabled.
loop_regionLoop region for wrapping.
Returns
New advanced positions per channel.

Definition at line 153 of file CoordUtils.cpp.

159{
160 uint64_t num_channels = structure.get_channel_count();
161 uint64_t total_frames = structure.get_samples_count_per_channel();
162
163 if (current_positions.size() != num_channels) {
164 throw std::invalid_argument(
165 "Position vector size " + std::to_string(current_positions.size()) + " must match channel count " + std::to_string(num_channels));
166 }
167
168 std::vector<uint64_t> new_positions;
169 new_positions.reserve(num_channels);
170
171 for (size_t ch = 0; ch < num_channels; ++ch) {
172 uint64_t current_frame = current_positions[ch];
173 uint64_t new_frame = current_frame + frames_to_advance;
174
175 if (new_frame >= total_frames) {
176 if (looping_enabled && !loop_region.start_coordinates.empty()) {
177 uint64_t loop_start = (ch < loop_region.start_coordinates.size())
178 ? loop_region.start_coordinates[ch]
179 : loop_region.start_coordinates[0];
180 uint64_t loop_end = (ch < loop_region.end_coordinates.size())
181 ? loop_region.end_coordinates[ch]
182 : loop_region.end_coordinates[0];
183
184 if (loop_end > loop_start) {
185 uint64_t loop_length = loop_end - loop_start + 1;
186 uint64_t overflow = new_frame - total_frames;
187 new_frame = loop_start + (overflow % loop_length);
188 } else {
189 new_frame = loop_start;
190 }
191 } else {
192 new_frame = total_frames - 1;
193 }
194 }
195
196 new_positions.push_back(new_frame);
197 }
198
199 return new_positions;
200}
static uint64_t get_channel_count(const std::vector< DataDimension > &dimensions)
Extract channel count from dimensions.
static uint64_t get_samples_count_per_channel(const std::vector< DataDimension > &dimensions)
Get samples per channel (time dimension only).
std::vector< uint64_t > end_coordinates
Ending frame index (inclusive)
Definition Region.hpp:72
std::vector< uint64_t > start_coordinates
Starting frame index (inclusive)
Definition Region.hpp:69

References MayaFlux::Kakshya::Region::end_coordinates, MayaFlux::Kakshya::ContainerDataStructure::get_channel_count(), MayaFlux::Kakshya::ContainerDataStructure::get_samples_count_per_channel(), and MayaFlux::Kakshya::Region::start_coordinates.

Referenced by MayaFlux::Kakshya::SoundStreamContainer::advance_read_position(), MayaFlux::Kakshya::RegionProcessorBase::organize_container_data(), and MayaFlux::Kakshya::ContiguousAccessProcessor::process().

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