Skip to content

Commit

Permalink
Some scope and interpolation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
8bitbubsy committed Nov 6, 2024
1 parent ceccaa3 commit 17c5a21
Show file tree
Hide file tree
Showing 12 changed files with 515 additions and 300 deletions.
2 changes: 2 additions & 0 deletions src/ft2_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "ft2_sample_ed.h"
#include "ft2_diskop.h"
#include "scopes/ft2_scopes.h"
#include "scopes/ft2_scopedraw.h"
#include "ft2_about.h"
#include "ft2_pattern_ed.h"
#include "ft2_module_loader.h"
Expand Down Expand Up @@ -367,6 +368,7 @@ static void cleanUpAndExit(void) // never call this inside the main loop!
freeTextBoxes();
freeMouseCursors();
freeBMPs();
freeScopeIntrpLUT();

if (editor.audioDevConfigFileLocationU != NULL)
{
Expand Down
2 changes: 1 addition & 1 deletion src/mixer/ft2_cubic_spline.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include "ft2_cubic_spline.h"
#include "ft2_cubic_spline.h" // CUBIC_SPLINE_TAPS, CUBIC_SPLINE_PHASES
#include "../ft2_video.h" // showErrorMsgBox()

float *fCubicSplineLUT = NULL; // globalized
Expand Down
38 changes: 24 additions & 14 deletions src/mixer/ft2_gaussian.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/*
** Super Nintendo SPC700 interpolation LUT generator.
** This has long believed to have a Gaussian curve, but it doesn't.
** Super Nintendo (SPC700) Gaussian interpolation LUT generator
**
** It was long believed that it uses a Gaussian curve, but it doesn't!
** We still call it Gaussian interpolation in the FT2 clone though, so
** that people recognize it.
**
** Based on code by Mednafen and nocash:
** https://forums.nesdev.org/viewtopic.php?t=10586
Expand All @@ -10,10 +13,17 @@
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include "ft2_gaussian.h"
#include "ft2_gaussian.h" // GAUSSIAN_TAPS, GAUSSIAN_PHASES
#include "../ft2_header.h" // PI
#include "../ft2_video.h" // showErrorMsgBox()

#define MY_PI 3.14159265358979323846264338327950288
/*
** 1.28 = Super Nintendo
** 2.048 = Sony PlayStation (less aliasing on very low pitches)
*/
#define PI_MULTIPLIER 1.28

#define TAP_SUM_SCALE 1.0

float *fGaussianLUT = NULL; // globalized

Expand All @@ -40,18 +50,18 @@ bool calcGaussianTable(void)
const double x4 = (0.5 + i4) * (1.0 / ((GAUSSIAN_PHASES*4)-1));

// Blackman window
const double w1 = (0.42 + (0.50 * cos(2.0 * MY_PI * x1)) + (0.08 * cos(4.0 * MY_PI * x1))) / x1;
const double w2 = (0.42 + (0.50 * cos(2.0 * MY_PI * x2)) + (0.08 * cos(4.0 * MY_PI * x2))) / x2;
const double w3 = (0.42 + (0.50 * cos(2.0 * MY_PI * x3)) + (0.08 * cos(4.0 * MY_PI * x3))) / x3;
const double w4 = (0.42 + (0.50 * cos(2.0 * MY_PI * x4)) + (0.08 * cos(4.0 * MY_PI * x4))) / x4;
const double w1 = (0.42 + (0.50 * cos(2.0 * PI * x1)) + (0.08 * cos(4.0 * PI * x1))) / x1;
const double w2 = (0.42 + (0.50 * cos(2.0 * PI * x2)) + (0.08 * cos(4.0 * PI * x2))) / x2;
const double w3 = (0.42 + (0.50 * cos(2.0 * PI * x3)) + (0.08 * cos(4.0 * PI * x3))) / x3;
const double w4 = (0.42 + (0.50 * cos(2.0 * PI * x4)) + (0.08 * cos(4.0 * PI * x4))) / x4;

const double t1 = sin(1.28 * MY_PI * x1) * w1;
const double t2 = sin(1.28 * MY_PI * x2) * w2;
const double t3 = sin(1.28 * MY_PI * x3) * w3;
const double t4 = sin(1.28 * MY_PI * x4) * w4;
const double t1 = sin(PI_MULTIPLIER * PI * x1) * w1;
const double t2 = sin(PI_MULTIPLIER * PI * x2) * w2;
const double t3 = sin(PI_MULTIPLIER * PI * x3) * w3;
const double t4 = sin(PI_MULTIPLIER * PI * x4) * w4;

// normalization value (assures unity gain when summing taps)
const double dScale = 1.0 / (t1 + t2 + t3 + t4);
// calculate normalization value (also assures unity gain when summing taps)
const double dScale = TAP_SUM_SCALE / (t1 + t2 + t3 + t4);

*fPtr++ = (float)(t1 * dScale);
*fPtr++ = (float)(t2 * dScale);
Expand Down
2 changes: 1 addition & 1 deletion src/mixer/ft2_gaussian.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#define GAUSSIAN_TAPS 4
#define GAUSSIAN_WIDTH_BITS 2 // log2(GAUSSIAN_TAPS)
#define GAUSSIAN_PHASES 8192
#define GAUSSIAN_PHASES 8192 /* originally 256 on SNES/PSX, but more is better! */
#define GAUSSIAN_PHASES_BITS 13 // log2(GAUSSIAN_PHASES)
#define GAUSSIAN_FSHIFT (MIXER_FRAC_BITS-(GAUSSIAN_PHASES_BITS+GAUSSIAN_WIDTH_BITS))
#define GAUSSIAN_FMASK ((GAUSSIAN_TAPS*GAUSSIAN_PHASES)-GAUSSIAN_TAPS)
Expand Down
Loading

0 comments on commit 17c5a21

Please sign in to comment.