ft2-clone

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

commit 7eb98bb0d8f983f573e61f43c1d6735181c7d008
parent ebfcc611d346e73f15514d70814efc7c1eef41b1
Author: Olav Sørensen <olav.sorensen@live.no>
Date:   Sun,  4 Sep 2022 15:12:57 +0200

Windowed-sinc interpolator changes

Diffstat:
Msrc/mixer/ft2_mix_macros.h | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/mixer/ft2_windowed_sinc.c | 11++++-------
Msrc/mixer/ft2_windowed_sinc.h | 19++++++++++---------
3 files changed, 83 insertions(+), 16 deletions(-)

diff --git a/src/mixer/ft2_mix_macros.h b/src/mixer/ft2_mix_macros.h @@ -168,6 +168,9 @@ ** */ +#if SINC_TAPS==8 + +#if SINC_FSHIFT>=0 #define WINDOWED_SINC_INTERPOLATION(s, f, scale) \ { \ const float *t = v->fSincLUT + (((uint32_t)(f) >> SINC_FSHIFT) & SINC_FMASK); \ @@ -180,6 +183,72 @@ ( s[3] * t[6]) + \ ( s[4] * t[7])) * (1.0f / scale); \ } +#else +#define WINDOWED_SINC_INTERPOLATION(s, f, scale) \ +{ \ + const float *t = v->fSincLUT + (((uint32_t)(f) << -SINC_FSHIFT) & SINC_FMASK); \ + fSample = ((s[-3] * t[0]) + \ + (s[-2] * t[1]) + \ + (s[-1] * t[2]) + \ + ( s[0] * t[3]) + \ + ( s[1] * t[4]) + \ + ( s[2] * t[5]) + \ + ( s[3] * t[6]) + \ + ( s[4] * t[7])) * (1.0f / scale); \ +} +#endif + +#elif SINC_TAPS==16 + +#if SINC_FSHIFT>=0 +#define WINDOWED_SINC_INTERPOLATION(s, f, scale) \ +{ \ + const float *t = v->fSincLUT + (((uint32_t)(f) >> SINC_FSHIFT) & SINC_FMASK); \ + fSample = ((s[-7] * t[0]) + \ + (s[-6] * t[1]) + \ + (s[-5] * t[2]) + \ + (s[-4] * t[3]) + \ + (s[-3] * t[4]) + \ + (s[-2] * t[5]) + \ + (s[-1] * t[6]) + \ + ( s[0] * t[7]) + \ + ( s[1] * t[8]) + \ + ( s[2] * t[9]) + \ + ( s[3] * t[10]) + \ + ( s[4] * t[11]) + \ + ( s[5] * t[12]) + \ + ( s[6] * t[13]) + \ + ( s[7] * t[14]) + \ + ( s[8] * t[15])) * (1.0f / scale); \ +} +#else +#define WINDOWED_SINC_INTERPOLATION(s, f, scale) \ +{ \ + const float *t = v->fSincLUT + (((uint32_t)(f) << -SINC_FSHIFT) & SINC_FMASK); \ + fSample = ((s[-7] * t[0]) + \ + (s[-6] * t[1]) + \ + (s[-5] * t[2]) + \ + (s[-4] * t[3]) + \ + (s[-3] * t[4]) + \ + (s[-2] * t[5]) + \ + (s[-1] * t[6]) + \ + ( s[0] * t[7]) + \ + ( s[1] * t[8]) + \ + ( s[2] * t[9]) + \ + ( s[3] * t[10]) + \ + ( s[4] * t[11]) + \ + ( s[5] * t[12]) + \ + ( s[6] * t[13]) + \ + ( s[7] * t[14]) + \ + ( s[8] * t[15])) * (1.0f / scale); \ +} +#endif + +#else + +#error mixer/ft2_mix_macros.h: The SINC_TAPS definition is invalid! Valid values: 8 or 16 + +#endif #define RENDER_8BIT_SMP_SINTRP \ WINDOWED_SINC_INTERPOLATION(smpPtr, positionFrac, 128) \ diff --git a/src/mixer/ft2_windowed_sinc.c b/src/mixer/ft2_windowed_sinc.c @@ -1,5 +1,5 @@ -/* Code taken from the OpenMPT project, which has a BSD -** license which is compatible with this project. +/* Code taken from the OpenMPT project, which has a BSD license which is +** compatible with this project. ** ** The code has been slightly modified. */ @@ -10,10 +10,7 @@ #include <math.h> #include "ft2_windowed_sinc.h" -// globalized -float *fKaiserSinc = NULL; -float *fDownSample1 = NULL; -float *fDownSample2 = NULL; +float *fKaiserSinc = NULL, *fDownSample1 = NULL, *fDownSample2 = NULL; // globalized static double Izero(double y) // Compute Bessel function Izero(y) using a series approximation { @@ -71,7 +68,7 @@ bool calcWindowedSincTables(void) getSinc(fKaiserSinc, 9.6377, 0.97); getSinc(fDownSample1, 8.5, 0.5); - getSinc(fDownSample2, 2.7625, 0.425); + getSinc(fDownSample2, 7.3, 0.425); return true; } diff --git a/src/mixer/ft2_windowed_sinc.h b/src/mixer/ft2_windowed_sinc.h @@ -4,14 +4,17 @@ #include <stdbool.h> #include "ft2_mix.h" -// if you change this, also change SINC_PHASES_BITS (>8192 gives very little improvement) -#define SINC_PHASES 8192 -#define SINC_PHASES_BITS 13 /* log2(SINC_PHASES) */ +// 8 or 16. 8 should only be used if the code is too slow for the target system. +#define SINC_TAPS 16 -// don't change these! +// log2(SINC_TAPS) +#define SINC_TAPS_BITS 4 + +#define SINC_PHASES 16384 + +// log2(SINC_PHASES) +#define SINC_PHASES_BITS 14 -#define SINC_TAPS 8 -#define SINC_TAPS_BITS 3 #define SINC_LUT_LEN (SINC_TAPS * SINC_PHASES) #define SINC_FSHIFT (MIXER_FRAC_BITS-(SINC_PHASES_BITS+SINC_TAPS_BITS)) #define SINC_FMASK ((SINC_TAPS*SINC_PHASES)-SINC_TAPS) @@ -23,9 +26,7 @@ // for LUT calculation #define SINC_MID_TAP ((SINC_TAPS/2)*SINC_PHASES) -extern float *fKaiserSinc; -extern float *fDownSample1; -extern float *fDownSample2; +extern float *fKaiserSinc, *fDownSample1, *fDownSample2; bool calcWindowedSincTables(void); void freeWindowedSincTables(void);