18template <
typename SampleType =
float>
class MapClipT {
20 static_assert(std::floating_point<SampleType>);
21 bool configure(SampleType input_min, SampleType input_max, SampleType output_min,
22 SampleType output_max)
noexcept {
23 if (!std::isfinite(input_min) || !std::isfinite(input_max) || !std::isfinite(output_min) ||
24 !std::isfinite(output_max) || !(input_max > input_min))
26 input_min_ = input_min;
27 input_max_ = input_max;
28 output_min_ = output_min;
29 output_max_ = output_max;
33 SampleType
process(SampleType input)
const noexcept {
34 if (!std::isfinite(input))
36 if (input <= input_min_)
38 if (input >= input_max_)
40 const auto span = input_max_ - input_min_;
42 const auto unit = std::isfinite(span)
43 ? (input - input_min_) / span
44 : (input * SampleType{0.5} - input_min_ * SampleType{0.5}) /
45 (input_max_ * SampleType{0.5} - input_min_ * SampleType{0.5});
46 return std::lerp(output_min_, output_max_, unit);
50 SampleType input_min_ = 0;
51 SampleType input_max_ = 1;
52 SampleType output_min_ = 0;
53 SampleType output_max_ = 1;
65 static_assert(std::floating_point<SampleType>);
66 void set_table(std::span<const SampleType> table)
noexcept {
70 SampleType
process(
double index)
const noexcept {
71 if (table_.empty() || !std::isfinite(index))
74 return table_.front();
75 const auto last = table_.size() - 1;
76 if (index >=
static_cast<double>(last))
78 const auto left =
static_cast<std::size_t
>(index);
79 const auto fraction =
static_cast<SampleType
>(index -
static_cast<double>(
left));
80 return std::lerp(table_[
left], table_[
left + 1], fraction);
84 std::span<const SampleType> table_;
Read an externally indexed control waveform.
Definition indexed_control.hpp:63
void set_table(std::span< const SampleType > table) noexcept
Definition indexed_control.hpp:66
SampleType process(double index) const noexcept
Definition indexed_control.hpp:70
Map a finite control interval to another interval and clip outside it.
Definition indexed_control.hpp:18
bool configure(SampleType input_min, SampleType input_max, SampleType output_min, SampleType output_max) noexcept
Definition indexed_control.hpp:21
SampleType process(SampleType input) const noexcept
Definition indexed_control.hpp:33
Definition additive_bank.hpp:218
MapClipT< double > MapClip64
Definition indexed_control.hpp:57
@ left
Definition multi_channel_meter.hpp:66
IndexedControlT< double > IndexedControl64
Definition indexed_control.hpp:88
IndexedControlT< float > IndexedControl
Definition indexed_control.hpp:87
MapClipT< float > MapClip
Definition indexed_control.hpp:56