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

◆ resample_line()

MAYAFLUX_API void MayaFlux::Kinesis::Acoustics::resample_line ( std::span< const double > source,
std::span< double > target,
double offset = 0.0 )
noexcept

Linearly interpolate a line of values onto another of a different size by relative position.

Parameters
sourceValues on the old line
targetReceives the values on the new line, every element is written
offsetWhere the first value sits in units of the spacing: 0 for the N + 1 pressures, which lie on the grid points, and 0.5 for the N velocities, which lie on the half points

The i-th of m values lies at (i + offset) / (m - 1 + 2 offset) of the length. Positions outside the source are clamped to its ends. An empty source leaves the target zero. Allocates nothing.

Definition at line 73 of file StaggeredLine.cpp.

77{
78 if (source.empty()) {
79 std::ranges::fill(target, 0.0);
80 return;
81 }
82
83 const double from_span = static_cast<double>(source.size()) - 1.0 + 2.0 * offset;
84 const double to_span = static_cast<double>(target.size()) - 1.0 + 2.0 * offset;
85 const double last = static_cast<double>(source.size() - 1);
86
87 for (size_t i = 0; i < target.size(); ++i) {
88 const double position = to_span > 0.0 ? (static_cast<double>(i) + offset) / to_span : 0.0;
89 const double index = std::clamp(position * from_span - offset, 0.0, last);
90 const auto below = static_cast<size_t>(index);
91 const size_t above = std::min(below + 1, source.size() - 1);
92 const double fraction = index - static_cast<double>(below);
93 target[i] = source[below] + fraction * (source[above] - source[below]);
94 }
95}