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

◆ interpolate_linear()

void MayaFlux::Kinesis::Discrete::interpolate_linear ( std::span< const double >  src,
std::span< double >  dst 
)
noexcept

Linear interpolation from src into dst (caller sizes dst) Branchless inner loop with precomputed step; dst may be larger or smaller than src.

The final index is clamped via std::min rather than a conditional branch, permitting auto-vectorisation.

Parameters
srcSource span (read-only)
dstDestination span (written in-place)

Definition at line 156 of file Transform.cpp.

157{
158 const size_t dst_n = dst.size();
159 const size_t src_n = src.size();
160
161 if (dst_n == 0 || src_n == 0)
162 return;
163
164 if (dst_n == 1 || src_n == 1) {
165 std::ranges::fill(dst, src[0]);
166 return;
167 }
168
169 const double step = static_cast<double>(src_n - 1) / static_cast<double>(dst_n - 1);
170
171 Parallel::for_each(Parallel::par_unseq,
172 std::views::iota(size_t { 0 }, dst_n).begin(),
173 std::views::iota(size_t { 0 }, dst_n).end(),
174 [&src, &dst, step, src_n](size_t i) {
175 const double pos = static_cast<double>(i) * step;
176 const auto idx = static_cast<size_t>(pos);
177 const size_t idx1 = std::min(idx + 1, src_n - 1);
178 const double frac = pos - static_cast<double>(idx);
179 dst[i] = src[idx] + frac * (src[idx1] - src[idx]);
180 });
181}

Referenced by time_stretch().

+ Here is the caller graph for this function: