12 std::vector<DataVariant>
data;
15 size_t access_count = 0;
16 bool is_dirty =
false;
28 std::chrono::duration<double>
age()
const
30 return std::chrono::steady_clock::now() - load_time;
47 bool is_cached =
false;
49 std::vector<uint64_t> current_position { 0 };
50 bool is_active =
false;
62 : source_region(region)
63 , offset_in_region(region.start_coordinates.size(), 0)
64 , segment_size(region.start_coordinates.size())
65 , current_position(region.start_coordinates.size(), 0)
67 for (
size_t i = 0; i < segment_size.size(); ++i) {
68 segment_size[i] = region.
get_span(i);
79 const std::vector<uint64_t>& offset,
80 const std::vector<uint64_t>& size)
81 : source_region(
std::move(region))
82 , offset_in_region(offset)
84 , current_position(size.size(), 0)
94 for (
auto s : segment_size) {
107 if (pos.size() != offset_in_region.size())
110 for (
size_t i = 0; i < pos.size(); ++i) {
111 if (pos[i] < offset_in_region[i] || pos[i] >= offset_in_region[i] + segment_size[i]) {
126 return cache.
age().count();
144 state = RegionState::ACTIVE;
150 state = RegionState::IDLE;
162 cache.
load_time = std::chrono::steady_clock::now();
164 state = RegionState::READY;
174 if (state == RegionState::READY) {
175 state = RegionState::IDLE;
184 std::ranges::fill(current_position, 0);
196 if (current_position.empty() || segment_size.empty() || dimension >= current_position.size()) {
200 current_position[dimension] += steps;
204 for (
size_t dim = dimension; dim < current_position.size(); ++dim) {
205 if (current_position[dim] >= segment_size[dim]) {
206 if (dim == current_position.size() - 1) {
210 uint64_t overflow = current_position[dim] / segment_size[dim];
211 current_position[dim] = current_position[dim] % segment_size[dim];
213 if (dim + 1 < current_position.size()) {
214 current_position[dim + 1] += overflow;
229 if (current_position.empty() || segment_size.empty())
232 return current_position.back() >= segment_size.back();
242 processing_metadata[key] = std::move(value);
251 template <
typename T>
254 auto it = processing_metadata.find(key);
255 if (it != processing_metadata.end()) {
256 return safe_any_cast<T>(it->second);
RegionState
Processing state for regions.
Region source_region
Region this cache corresponds to.
std::vector< DataVariant > data
Cached data.
bool is_dirty
Whether cache is dirty.
std::chrono::duration< double > age() const
std::chrono::steady_clock::time_point load_time
When cache was loaded.
Stores cached data for a region, with metadata for cache management.
bool advance_position(uint64_t steps=1, uint32_t dimension=0)
Advance the current position within the segment.
Region source_region
Associated region.
bool contains_position(const std::vector< uint64_t > &pos) const
Check if a position is within this segment.
uint64_t get_total_elements() const
Get the total number of elements in the segment.
RegionCache cache
Multi-channel cached audio data.
void set_processing_metadata(const std::string &key, std::any value)
Set processing metadata for this segment.
std::vector< uint64_t > offset_in_region
Offset within the source region.
std::unordered_map< std::string, std::any > processing_metadata
Arbitrary processing metadata.
std::optional< T > get_processing_metadata(const std::string &key) const
Get processing metadata for this segment.
RegionSegment(Region region, const std::vector< uint64_t > &offset, const std::vector< uint64_t > &size)
Construct a segment from a region with offset and size.
void mark_cached(const std::vector< DataVariant > &data)
Mark this segment as cached and store the data.
std::vector< uint64_t > segment_size
Size in each dimension.
bool is_at_end() const
Check if the current position is at the end of the segment.
double get_cache_age_seconds() const
Get the age of the cache in seconds.
void reset_position()
Reset the current position within the segment.
void clear_cache()
Clear the cache for this segment.
RegionSegment(const Region ®ion)
Construct a segment from a region (full region).
Represents a discrete segment of audio data with caching capabilities.
uint64_t get_span(uint32_t dimension_index=0) const
Get the span (length) of the region along a dimension.
Represents a point or span in N-dimensional space.