MayaFlux 0.4.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 157 of file CoordUtils.cpp.

163{
164 uint64_t num_channels = structure.get_channel_count();
165 uint64_t total_frames = structure.get_samples_count_per_channel();
166
167 if (current_positions.size() != num_channels) {
168 error<std::invalid_argument>(Journal::Component::Kakshya, Journal::Context::Runtime, std::source_location::current(),
169 "Position vector size {} must match channel count {}", current_positions.size(), num_channels);
170 }
171
172 std::vector<uint64_t> new_positions;
173 new_positions.reserve(num_channels);
174
175 for (size_t ch = 0; ch < num_channels; ++ch) {
176 uint64_t current_frame = current_positions[ch];
177 uint64_t new_frame = current_frame + frames_to_advance;
178
179 if (new_frame >= total_frames) {
180 if (looping_enabled && !loop_region.start_coordinates.empty()) {
181 uint64_t loop_start = (ch < loop_region.start_coordinates.size())
182 ? loop_region.start_coordinates[ch]
183 : loop_region.start_coordinates[0];
184 uint64_t loop_end = (ch < loop_region.end_coordinates.size())
185 ? loop_region.end_coordinates[ch]
186 : loop_region.end_coordinates[0];
187
188 if (loop_end > loop_start) {
189 uint64_t loop_length = loop_end - loop_start + 1;
190 uint64_t overflow = new_frame - total_frames;
191 new_frame = loop_start + (overflow % loop_length);
192 } else {
193 new_frame = loop_start;
194 }
195 } else {
196 new_frame = total_frames - 1;
197 }
198 }
199
200 new_positions.push_back(new_frame);
201 }
202
203 return new_positions;
204}
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:78
std::vector< uint64_t > start_coordinates
Starting frame index (inclusive)
Definition Region.hpp:75

References MayaFlux::Kakshya::Region::end_coordinates, MayaFlux::Kakshya::ContainerDataStructure::get_channel_count(), MayaFlux::Kakshya::ContainerDataStructure::get_samples_count_per_channel(), MayaFlux::Journal::Kakshya, MayaFlux::Journal::Runtime, 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: