]> git.sesse.net Git - nageru/blob - piecewise_interpolator.h
Fix an issue where the mixer lagging too much behind CEF would cause us to display...
[nageru] / piecewise_interpolator.h
1 #ifndef _PIECEWISE_INTERPOLATOR_H
2 #define _PIECEWISE_INTERPOLATOR_H
3
4 // A class to do piecewise linear interpolation of one scale to another
5 // (and back). Typically used to implement nonlinear dB mappings for sliders
6 // or meters, thus the nomenclature.
7
8 #include <vector>
9
10 class PiecewiseInterpolator {
11 public:
12         // Both dB and fraction values must go from high to low.
13         struct ControlPoint {
14                 double db_value;
15                 double fraction;
16         };
17         PiecewiseInterpolator(const std::vector<ControlPoint> &control_points)
18                 : control_points(control_points) {}
19
20         double fraction_to_db(double db) const;
21         double db_to_fraction(double x) const;
22
23 private:
24         const std::vector<ControlPoint> control_points;
25 };
26
27 #endif  // !defined(_PIECEWISE_INTERPOLATOR_H)