ft2-clone

Fasttracker 2 clone
Log | Files | Refs | README | LICENSE

commit f786bba6a02a7ec34901b55858159020385def4d
parent 88b6638a2639331ca054357ae9f645a04a5d9983
Author: Olav Sørensen <olav.sorensen@live.no>
Date:   Mon, 22 Apr 2024 13:22:00 +0200

Small code cleanup

Diffstat:
Msrc/mixer/ft2_cubic_spline.c | 2+-
Msrc/mixer/ft2_cubic_spline.h | 6+++---
Msrc/mixer/ft2_windowed_sinc.c | 17++++++++++-------
3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/src/mixer/ft2_cubic_spline.c b/src/mixer/ft2_cubic_spline.c @@ -18,7 +18,7 @@ bool calcCubicSplineTable(void) 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 diff --git 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; diff --git a/src/mixer/ft2_windowed_sinc.c b/src/mixer/ft2_windowed_sinc.c @@ -22,15 +22,18 @@ float *fKaiserSinc = NULL, *fDownSample1 = NULL, *fDownSample2 = NULL; // 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,21 +42,21 @@ static void getSinc(uint32_t numTaps, float *fLUTPtr, const double beta, const d { 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++) { 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