Code: Select all
public double readSample(double pointer) {
int ptrLeft = (int) pointer;
double dMinus1 = pointer - ptrLeft;
if (dMinus1 == 0.0) {
return buffer.readAt(ptrLeft);
}
double dMinus2 = dMinus1 - 1;
double dMinus3 = dMinus2 - 1;
double d = dMinus1 + 1;
double halfDTimesDMinus3 = d * dMinus3 * 0.5;
double oneSixthDMinus1TimesDMinus2 = dMinus1 * dMinus2 / 6.0;
double n0 = buffer.readAt(ptrLeft - 1);
double n1 = buffer.readAt(ptrLeft);
double n2 = buffer.readAt(ptrLeft + 1);
double n3 = buffer.readAt(ptrLeft + 2);
double h0 = -oneSixthDMinus1TimesDMinus2 * dMinus3;
double h1 = halfDTimesDMinus3 * dMinus2;
double h2 = -halfDTimesDMinus3 * dMinus1;
double h3 = d * oneSixthDMinus1TimesDMinus2;
return (n0 * h0) + (n1 * h1) + (n2 * h2) + (n3 * h3);
}