Struct thl::dsp::slicing::SliceMap#

struct SliceMap#

Collaboration diagram for thl::dsp::slicing::SliceMap:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "2" [label="std::array< uint64_t, k_max_slices+1 >" tooltip="std::array< uint64_t, k_max_slices+1 >"] "1" [label="thl::dsp::slicing::SliceMap" tooltip="thl::dsp::slicing::SliceMap" fillcolor="#BFBFBF"] "1" -> "2" [dir=forward tooltip="usage"] }

Slice boundaries of one sample, in frames.

m_bounds[0] == 0, m_bounds[m_count] == m_total_frames, strictly ascending; slice k is [m_bounds[k], m_bounds[k + 1]). Trivially copyable with a fixed capacity, so a host can hand a whole map to the audio thread by value (seqlock, atomic swap of a copy, message queue).

The map belongs to a sample length, not to a sample: alternative sources of the same length (pitch-shifted copies, round-robins) share it, and boundary_frame() rescales for a source of another length.

Public Functions

inline bool valid() const#

Structurally sound: 1..k_max_slices strictly ascending slices that cover the whole sample.

inline size_t boundary_frame(size_t k, size_t total_frames) const#

Boundary k (0..m_count) as a frame of a source total_frames long (exact when the lengths match, rounded otherwise).

inline float normalized_bound(size_t k) const#

Boundary k as a fraction of the sample.

inline std::vector<float> normalized_bounds() const#

All boundaries as fractions of the sample (allocates).

Public Members

uint32_t m_count = {0}#

Number of slices; 0 = no map.

uint64_t m_total_frames = {0}#
std::array<uint64_t, k_max_slices + 1> m_bounds = {}#

Public Static Functions

static inline SliceMap grid(size_t count, size_t total_frames)#

count equal slices of a sample total_frames long.

static inline SliceMap from_normalized(std::span<const float> bounds, size_t total_frames)#

Boundaries given as fractions of the sample.

Each is rounded to the nearest frame. The result is not validated: check valid() (close fractions can collapse onto the same frame).

static inline SliceMap from_frames(std::span<const size_t> bounds, size_t total_frames)#

Boundaries given in frames (count = size - 1, capped). Not validated.