20 double t0,
double rate,
double samplesPerPixel) noexcept
21 : mMapper(
LinearMapper { (0.5 + t0 * rate), samplesPerPixel })
23 assert((0.5 + t0 * rate) >= 0.0);
28 auto mapper = std::get_if<LinearMapper>(&mMapper);
30 if (mapper !=
nullptr)
31 mapper->mInitialValue += bias;
38 assert(oldMapper.
mMapper.index() == 0);
42 if (currentMapper ==
nullptr)
46 std::get_if<LinearMapper>(&oldMapper.
mMapper);
48 if (oldLinearMapper ==
nullptr)
52 const double oldWhere0 =
54 const double oldWhereLast =
57 const double denom = oldWhereLast - oldWhere0;
60 const double guessWhere0 =
64 oldWhereLast <= guessWhere0 ||
78 std::floor(0.5 + oldLen * (guessWhere0 - oldWhere0) / denom);
83 const double correction0 = where0 - guessWhere0;
84 const double correction = std::max(
88 assert(correction == correction0);
99 [column](
const auto& mapper) {
return mapper(column); },
mMapper);
107std::pair<sampleCount, sampleCount>
125 return std::get_if<LinearMapper>(&
mMapper) !=
nullptr;
134 return sampleCount(mInitialValue + column * mSamplesPerPixel);
137PixelSampleMapper::LinearMapper::operator bool() const noexcept
139 return mSamplesPerPixel > 0.0;
emulates std::visit for one visitor
Utility class to calculate sample range for a given column.
PixelSampleMapper()=default
std::pair< sampleCount, sampleCount > GetSampleRange(uint32_t column) const
void applyBias(double bias) noexcept
bool IsLinear() const noexcept
double applyCorrection(const PixelSampleMapper &oldMapper, size_t oldLen, size_t newLen)
std::variant< LinearMapper, CustomMapper > mMapper
sampleCount GetLastSample(uint32_t column) const
sampleCount GetFirstSample(uint32_t column) const
void setCustomMapper(CustomMapper mapper)
std::function< sampleCount(uint32_t)> CustomMapper
Positions or offsets within audio files need a wide type.
decltype(auto) Visit(Visitor &&vis, Variant &&var)
Mimic some of std::visit, for the case of one visitor only.
sampleCount operator()(uint32_t column) const noexcept