X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=piecewise_interpolator.h;fp=piecewise_interpolator.h;h=17a9d8b8c41f45c8b1080e0ab0068250f88f3960;hb=9e93fbea58c068d14dd9dad5d0f5226edeef3395;hp=0000000000000000000000000000000000000000;hpb=52c3ac9a9a358ea422810b9376651de9f283bd12;p=nageru diff --git a/piecewise_interpolator.h b/piecewise_interpolator.h new file mode 100644 index 0000000..17a9d8b --- /dev/null +++ b/piecewise_interpolator.h @@ -0,0 +1,27 @@ +#ifndef _PIECEWISE_INTERPOLATOR_H +#define _PIECEWISE_INTERPOLATOR_H + +// A class to do piecewise linear interpolation of one scale to another +// (and back). Typically used to implement nonlinear dB mappings for sliders +// or meters, thus the nomenclature. + +#include + +class PiecewiseInterpolator { +public: + // Both dB and fraction values must go from high to low. + struct ControlPoint { + double db_value; + double fraction; + }; + PiecewiseInterpolator(const std::vector &control_points) + : control_points(control_points) {} + + double fraction_to_db(double db) const; + double db_to_fraction(double x) const; + +private: + const std::vector control_points; +}; + +#endif // !defined(_PIECEWISE_INTERPOLATOR_H)