ref: cbfbcc413d629aa99bdf7f1f1b6b7b67a569e095
parent: 65ae4b974e929be2bf6340739a17e9c9dcf70d67
author: Olav Sørensen <olav.sorensen@live.no>
date: Fri Feb 23 12:28:42 EST 2024
Cubic spline code cleanup
--- a/src/mixer/ft2_cubic_spline.c
+++ b/src/mixer/ft2_cubic_spline.c
@@ -18,13 +18,13 @@
float *fPtr = fCubicSplineLUT;
for (int32_t i = 0; i < CUBIC_SPLINE_PHASES; i++)
{
- const double x = i * (1.0 / CUBIC_SPLINE_PHASES); // x = i / CUBIC_SPLINE_PHASES
- const double x2 = x * x; // x^2
- const double x3 = x2 * x; // x^3
+ const double x1 = i * (1.0 / (double)CUBIC_SPLINE_PHASES); // i / CUBIC_SPLINE_PHASES
+ const double x2 = x1 * x1; // x^2
+ const double x3 = x2 * x1; // x^3
- *fPtr++ = (float)(-0.5 * x3 + 1.0 * x2 - 0.5 * x);
+ *fPtr++ = (float)(-0.5 * x3 + 1.0 * x2 - 0.5 * x1);
*fPtr++ = (float)( 1.5 * x3 - 2.5 * x2 + 1.0);
- *fPtr++ = (float)(-1.5 * x3 + 2.0 * x2 + 0.5 * x);
+ *fPtr++ = (float)(-1.5 * x3 + 2.0 * x2 + 0.5 * x1);
*fPtr++ = (float)( 0.5 * x3 - 0.5 * x2);
}
--- a/src/mixer/ft2_cubic_spline.h
+++ b/src/mixer/ft2_cubic_spline.h
@@ -5,7 +5,7 @@
#include "ft2_mix.h" // MIXER_FRAC_BITS
#define CUBIC_SPLINE_TAPS 4
-#define CUBIC_WIDTH_BITS 2
+#define CUBIC_WIDTH_BITS 2 // log2(CUBIC_SPLINE_TAPS)
// 8192 is a good compromise
#define CUBIC_SPLINE_PHASES 8192