1 #include "piecewise_interpolator.h"
5 double PiecewiseInterpolator::fraction_to_db(double db) const
7 if (db >= control_points[0].fraction) {
8 return control_points[0].db_value;
10 if (db <= control_points.back().fraction) {
11 return control_points.back().db_value;
13 for (unsigned i = 1; i < control_points.size(); ++i) {
14 const double x0 = control_points[i].fraction;
15 const double x1 = control_points[i - 1].fraction;
16 const double y0 = control_points[i].db_value;
17 const double y1 = control_points[i - 1].db_value;
18 if (db >= x0 && db <= x1) {
19 const double t = (db - x0) / (x1 - x0);
20 return y0 + t * (y1 - y0);
26 double PiecewiseInterpolator::db_to_fraction(double x) const
28 if (x >= control_points[0].db_value) {
29 return control_points[0].fraction;
31 if (x <= control_points.back().db_value) {
32 return control_points.back().fraction;
34 for (unsigned i = 1; i < control_points.size(); ++i) {
35 const double x0 = control_points[i].db_value;
36 const double x1 = control_points[i - 1].db_value;
37 const double y0 = control_points[i].fraction;
38 const double y1 = control_points[i - 1].fraction;
39 if (x >= x0 && x <= x1) {
40 const double t = (x - x0) / (x1 - x0);
41 return y0 + t * (y1 - y0);