shithub: ft²

Download patch

ref: f786bba6a02a7ec34901b55858159020385def4d
parent: 88b6638a2639331ca054357ae9f645a04a5d9983
author: Olav Sørensen <olav.sorensen@live.no>
date: Mon Apr 22 09:22:27 EDT 2024

Small code cleanup

--- a/src/mixer/ft2_cubic_spline.c
+++ b/src/mixer/ft2_cubic_spline.c
@@ -18,7 +18,7 @@
 	float *fPtr = fCubicSplineLUT;
 	for (int32_t i = 0; i < CUBIC_SPLINE_PHASES; i++)
 	{
-		const double x1 = i * (1.0 / (double)CUBIC_SPLINE_PHASES); // i / CUBIC_SPLINE_PHASES
+		const double x1 = i * (1.0 / CUBIC_SPLINE_PHASES);
 		const double x2 = x1 * x1; // x^2
 		const double x3 = x2 * x1; // x^3
 
--- a/src/mixer/ft2_cubic_spline.h
+++ b/src/mixer/ft2_cubic_spline.h
@@ -5,14 +5,14 @@
 #include "ft2_mix.h" // MIXER_FRAC_BITS
 
 #define CUBIC_SPLINE_TAPS 4
-#define CUBIC_WIDTH_BITS 2 // log2(CUBIC_SPLINE_TAPS)
+#define CUBIC_SPLINE_WIDTH_BITS 2 // log2(CUBIC_SPLINE_TAPS)
 
 // 8192 is a good compromise
 #define CUBIC_SPLINE_PHASES 8192
-#define CUBIC_SPLINE_PHASES_BITS 13 // log2(CUBIC_PHASES)
+#define CUBIC_SPLINE_PHASES_BITS 13 // log2(CUBIC_SPLINE_PHASES)
 
 // do not change these!
-#define CUBIC_SPLINE_FSHIFT (MIXER_FRAC_BITS-(CUBIC_SPLINE_PHASES_BITS+CUBIC_WIDTH_BITS))
+#define CUBIC_SPLINE_FSHIFT (MIXER_FRAC_BITS-(CUBIC_SPLINE_PHASES_BITS+CUBIC_SPLINE_WIDTH_BITS))
 #define CUBIC_SPLINE_FMASK ((CUBIC_SPLINE_TAPS*CUBIC_SPLINE_PHASES)-CUBIC_SPLINE_TAPS)
 
 extern float *fCubicSplineLUT;
--- a/src/mixer/ft2_windowed_sinc.c
+++ b/src/mixer/ft2_windowed_sinc.c
@@ -22,15 +22,18 @@
 // zeroth-order modified Bessel function of the first kind (series approximation)
 static double besselI0(double z)
 {
+#define EPSILON (1E-15)
+
 	double s = 1.0, ds = 1.0, d = 2.0;
+	const double zz = z * z;
 
 	do
 	{
-		ds *= (z * z) / (d * d);
+		ds *= zz / (d * d);
 		s += ds;
 		d += 2.0;
 	}
-	while (ds > s*1E-15);
+	while (ds > s*EPSILON);
 
 	return s;
 }
@@ -39,12 +42,12 @@
 {
 	const double I0Beta = besselI0(beta);
 	const double kPi = MY_PI * cutoff;
+	const double xMul = 1.0 / ((numTaps / 2) * (numTaps / 2));
 
 	const uint32_t length = numTaps * SINC_PHASES;
-	const uint32_t tapBits = (int32_t)log2(numTaps);
+	const uint32_t tapBits = (uint32_t)log2(numTaps);
 	const uint32_t tapsMinus1 = numTaps - 1;
-	const double xMul = 1.0 / ((numTaps / 2) * (numTaps / 2));
-	const int32_t midTap = (numTaps / 2) * SINC_PHASES;
+	const int32_t midPoint = (numTaps / 2) * SINC_PHASES;
 
 	for (uint32_t i = 0; i < length; i++)
 	{
@@ -51,9 +54,9 @@
 		const int32_t ix = ((tapsMinus1 - (i & tapsMinus1)) << SINC_PHASES_BITS) + (i >> tapBits);
 
 		double dSinc = 1.0;
-		if (ix != midTap)
+		if (ix != midPoint)
 		{
-			const double x = (ix - midTap) * (1.0 / SINC_PHASES);
+			const double x = (ix - midPoint) * (1.0 / SINC_PHASES);
 			const double xPi = x * kPi;
 
 			// sinc with Kaiser window
--