For in_snsf, replaced the B-spline interpolation with the 6-point, 5th-order version, and replaced the Optimal interpolation with 6-point, 5th-order 2nd-order Osculating.
--- a/src/in_snsf/XSFConfig_SNSF.cpp
+++ b/src/in_snsf/XSFConfig_SNSF.cpp
@@ -1,7 +1,7 @@
/*
* xSF - SNSF configuration
* By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2013-03-25
+ * Last modification on 2013-04-12
*
* Partially based on the vio*sf framework
*
@@ -97,7 +97,7 @@
SendMessageW(GetDlgItem(hwndDlg, idResampler), CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(L"Linear Resampler"));
SendMessageW(GetDlgItem(hwndDlg, idResampler), CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(L"Hermite Resampler"));
SendMessageW(GetDlgItem(hwndDlg, idResampler), CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(L"Bspline Resampler"));
- SendMessageW(GetDlgItem(hwndDlg, idResampler), CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(L"Optimal Resampler"));
+ SendMessageW(GetDlgItem(hwndDlg, idResampler), CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(L"Osculating Resampler"));
SendMessageW(GetDlgItem(hwndDlg, idResampler), CB_SETCURSEL, this->resampler, 0);
// Mutes
for (int x = 0, numMutes = this->mutes.size(); x < numMutes; ++x)
--- a/src/in_snsf/XSFPlayer_SNSF.cpp
+++ b/src/in_snsf/XSFPlayer_SNSF.cpp
@@ -25,7 +25,7 @@
#include "snes9x/apu/linear_resampler.h"
#include "snes9x/apu/hermite_resampler.h"
#include "snes9x/apu/bspline_resampler.h"
-#include "snes9x/apu/optimal_resampler.h"
+#include "snes9x/apu/osculating_resampler.h"
#include "snes9x/memmap.h"
class XSFPlayer_SNSF : public XSFPlayer
@@ -231,7 +231,7 @@
S9xInitAPU();
XSFConfig_SNSF *xSFConfig_SNSF = dynamic_cast<XSFConfig_SNSF *>(xSFConfig);
if (xSFConfig_SNSF->resampler == 3)
- S9xInitSound<OptimalResampler>(10, 0);
+ S9xInitSound<OsculatingResampler>(10, 0);
if (xSFConfig_SNSF->resampler == 2)
S9xInitSound<BsplineResampler>(10, 0);
else if (xSFConfig_SNSF->resampler == 1)
--- a/src/in_snsf/snes9x/apu/apu.cpp
+++ b/src/in_snsf/snes9x/apu/apu.cpp
@@ -183,7 +183,7 @@
#include "linear_resampler.h"
#include "hermite_resampler.h"
#include "bspline_resampler.h"
-#include "optimal_resampler.h"
+#include "osculating_resampler.h"
#define APU_DEFAULT_INPUT_RATE 32000
#define APU_MINIMUM_SAMPLE_COUNT 512
@@ -478,7 +478,7 @@
template bool S9xInitSound<LinearResampler>(int, int);
template bool S9xInitSound<HermiteResampler>(int, int);
template bool S9xInitSound<BsplineResampler>(int, int);
-template bool S9xInitSound<OptimalResampler>(int, int);
+template bool S9xInitSound<OsculatingResampler>(int, int);
void S9xSetSoundControl (uint8_t voice_switch)
{
--- a/src/in_snsf/snes9x/apu/bspline_resampler.h
+++ b/src/in_snsf/snes9x/apu/bspline_resampler.h
@@ -16,16 +16,20 @@
protected:
double r_step;
double r_frac;
- int r_left[4], r_right[4];
+ int r_left[6], r_right[6];
- double bspline(double x, double a, double b, double c, double d)
+ double bspline(double x, double a, double b, double c, double d, double e, double f)
{
- double ym1py1 = a + c;
- double c0 = 1 / 6.0 * ym1py1 + 2 / 3.0 * b;
- double c1 = 0.5 * (c - a);
- double c2 = 0.5 * ym1py1 - b;
- double c3 = 0.5 * (b - c) + 1 / 6.0 * (d - a);
- return ((c3 * x + c2) * x + c1) * x + c0;
+ float ym2py2 = a + e, ym1py1 = b + d;
+ float y2mym2 = e - a, y1mym1 = d - b;
+ float sixthym1py1 = 1 / 6.0 * ym1py1;
+ float c0 = 1 / 120.0 * ym2py2 + 13 / 60.0 * ym1py1 + 0.55 * c;
+ float c1 = 1 / 24.0 * y2mym2 + 5 / 12.0 * y1mym1;
+ float c2 = 1 / 12.0 * ym2py2 + sixthym1py1 - 0.5 * c;
+ float c3 = 1 / 12.0 * y2mym2 - 1 / 6.0 * y1mym1;
+ float c4 = 1 / 24.0 * ym2py2 - sixthym1py1 + 0.25 * c;
+ float c5 = 1 / 120.0 * (f - a) + 1 / 24.0 * (b - e) + 1 / 12.0 * (d - c);
+ return ((((c5 * x + c4) * x + c3) * x + c2) * x + c1) * x + c0;
}
public:
@@ -44,8 +48,8 @@
{
ring_buffer::clear ();
this->r_frac = 1.0;
- this->r_left[0] = this->r_left[1] = this->r_left[2] = this->r_left[3] = 0;
- this->r_right[0] = this->r_right[1] = this->r_right[2] = this->r_right[3] = 0;
+ this->r_left[0] = this->r_left[1] = this->r_left[2] = this->r_left[3] = this->r_left[4] = this->r_left[5] = 0;
+ this->r_right[0] = this->r_right[1] = this->r_right[2] = this->r_right[3] = this->r_right[4] = this->r_right[5] = 0;
}
void read(short *data, int num_samples)
@@ -78,8 +82,8 @@
while (this->r_frac <= 1.0 && o_position < num_samples)
{
- data[o_position] = SHORT_CLAMP(bspline(this->r_frac, this->r_left[0], this->r_left[1], this->r_left[2], this->r_left[3]));
- data[o_position + 1] = SHORT_CLAMP(bspline(this->r_frac, this->r_right[0], this->r_right[1], this->r_right[2], this->r_right[3]));
+ data[o_position] = SHORT_CLAMP(bspline(this->r_frac, this->r_left[0], this->r_left[1], this->r_left[2], this->r_left[3], this->r_left[4], this->r_left[5]));
+ data[o_position + 1] = SHORT_CLAMP(bspline(this->r_frac, this->r_right[0], this->r_right[1], this->r_right[2], this->r_right[3], this->r_right[4], this->r_right[5]));
o_position += 2;
@@ -91,12 +95,16 @@
this->r_left[0] = this->r_left[1];
this->r_left[1] = this->r_left[2];
this->r_left[2] = this->r_left[3];
- this->r_left[3] = s_left;
+ this->r_left[3] = this->r_left[4];
+ this->r_left[4] = this->r_left[5];
+ this->r_left[5] = s_left;
this->r_right[0] = this->r_right[1];
this->r_right[1] = this->r_right[2];
this->r_right[2] = this->r_right[3];
- this->r_right[3] = s_right;
+ this->r_right[3] = this->r_right[4];
+ this->r_right[4] = this->r_right[5];
+ this->r_right[5] = s_right;
this->r_frac -= 1.0;
--- a/src/in_snsf/snes9x/apu/optimal_resampler.h
+++ /dev/null
@@ -1,126 +1,1 @@
-/* Simple resampler based on bsnes's ruby audio library */
-#ifndef __OPTIMAL_RESAMPLER_H
-#define __OPTIMAL_RESAMPLER_H
-
-#include <cmath>
-#include "resampler.h"
-
-#undef CLAMP
-#undef SHORT_CLAMP
-//template<typename T1, typename T2> static inline T1 CLAMP(T1 x, T2 low, T2 high) { return x > high ? high : (x < low ? low : x); }
-//template<typename T> static inline short SHORT_CLAMP(T n) { return static_cast<short>(CLAMP(n, -32768, 32767)); }
-
-class OptimalResampler : public Resampler
-{
-protected:
- double r_step;
- double r_frac;
- int r_left[4], r_right[4];
-
- double optimal(double x, double a, double b, double c, double d)
- {
- double z = x - 0.5;
- double even1 = c + b, odd1 = c - b;
- double even2 = d + a, odd2 = d - a;
- double c0 = even1 * 0.46822774170144532 + even2 * 0.03177225758005808;
- double c1 = odd1 * 0.55890365706150436 + odd2 * 0.14703258836343669;
- double c2 = even1 * -0.250153411893796031 + even2 * 0.25015343462990891;
- double c3 = odd1 * -0.49800710906733769 + odd2 * 0.16600005174304033;
- double c4 = even1 * 0.00064264050033187 + even2 * -0.00064273459469381;
- return (((c4 * z + c3) * z + c2) * z + c1) * z + c0;
- }
-
-public:
- OptimalResampler(int num_samples) : Resampler(num_samples)
- {
- this->clear();
- }
-
- void time_ratio(double ratio)
- {
- this->r_step = ratio;
- this->clear();
- }
-
- void clear()
- {
- ring_buffer::clear ();
- this->r_frac = 1.0;
- this->r_left[0] = this->r_left[1] = this->r_left[2] = this->r_left[3] = 0;
- this->r_right[0] = this->r_right[1] = this->r_right[2] = this->r_right[3] = 0;
- }
-
- void read(short *data, int num_samples)
- {
- int i_position = this->start >> 1;
- short *internal_buffer = reinterpret_cast<short *>(this->buffer);
- int o_position = 0;
- int consumed = 0;
-
- while (o_position < num_samples && consumed < this->buffer_size)
- {
- int s_left = internal_buffer[i_position];
- int s_right = internal_buffer[i_position + 1];
- int max_samples = this->buffer_size >> 1;
- const double margin_of_error = 1.0e-10;
-
- if (std::abs(this->r_step - 1.0) < margin_of_error)
- {
- data[o_position] = static_cast<short>(s_left);
- data[o_position + 1] = static_cast<short>(s_right);
-
- o_position += 2;
- i_position += 2;
- if (i_position >= max_samples)
- i_position -= max_samples;
- consumed += 2;
-
- continue;
- }
-
- while (this->r_frac <= 1.0 && o_position < num_samples)
- {
- data[o_position] = SHORT_CLAMP(optimal(this->r_frac, this->r_left[0], this->r_left[1], this->r_left[2], this->r_left[3]));
- data[o_position + 1] = SHORT_CLAMP(optimal(this->r_frac, this->r_right[0], this->r_right[1], this->r_right[2], this->r_right[3]));
-
- o_position += 2;
-
- this->r_frac += this->r_step;
- }
-
- if (this->r_frac > 1.0)
- {
- this->r_left[0] = this->r_left[1];
- this->r_left[1] = this->r_left[2];
- this->r_left[2] = this->r_left[3];
- this->r_left[3] = s_left;
-
- this->r_right[0] = this->r_right[1];
- this->r_right[1] = this->r_right[2];
- this->r_right[2] = this->r_right[3];
- this->r_right[3] = s_right;
-
- this->r_frac -= 1.0;
-
- i_position += 2;
- if (i_position >= max_samples)
- i_position -= max_samples;
- consumed += 2;
- }
- }
-
- this->size -= consumed << 1;
- this->start += consumed << 1;
- if (this->start >= this->buffer_size)
- this->start -= this->buffer_size;
- }
-
- inline int avail()
- {
- return static_cast<int>(std::floor(((this->size >> 2) - this->r_frac) / this->r_step) * 2);
- }
-};
-
-#endif /* __OPTIMAL_RESAMPLER_H */
-
--- /dev/null
+++ b/src/in_snsf/snes9x/apu/osculating_resampler.h
@@ -1,1 +1,132 @@
+/* Simple resampler based on bsnes's ruby audio library */
+#ifndef __OSCULATING_RESAMPLER_H
+#define __OSCULATING_RESAMPLER_H
+
+#include <cmath>
+#include "resampler.h"
+
+#undef CLAMP
+#undef SHORT_CLAMP
+//template<typename T1, typename T2> static inline T1 CLAMP(T1 x, T2 low, T2 high) { return x > high ? high : (x < low ? low : x); }
+//template<typename T> static inline short SHORT_CLAMP(T n) { return static_cast<short>(CLAMP(n, -32768, 32767)); }
+
+class OsculatingResampler : public Resampler
+{
+protected:
+ double r_step;
+ double r_frac;
+ int r_left[6], r_right[6];
+
+ double osculating(double x, double a, double b, double c, double d, double e, double f)
+ {
+ double z = x - 0.5;
+ double even1 = a + f, odd1 = a - f;
+ double even2 = b + e, odd2 = b - e;
+ double even3 = c + d, odd3 = c - d;
+ double c0 = 0.01171875 * even1 - 0.09765625 * even2 + 0.5859375 * even3;
+ double c1 = 0.2109375 * odd2 - 281 / 192.0 * odd3 - 13 / 384.0 * odd1;
+ double c2 = 0.40625 * even2 - 17 / 48.0 * even3 - 5 / 96.0 * even1;
+ double c3 = 0.1875 * odd1 - 53 / 48.0 * odd2 + 2.375 * odd3;
+ double c4 = 1 / 48.0*even1 - 0.0625 * even2 + 1 / 24.0 * even3;
+ double c5 = 25 / 24.0 * odd2 - 25 / 12.0 * odd3 - 5 / 24.0 * odd1;
+ return ((((c5 * z + c4) * z + c3) * z + c2) * z + c1) * z + c0;
+ }
+
+public:
+ OsculatingResampler(int num_samples) : Resampler(num_samples)
+ {
+ this->clear();
+ }
+
+ void time_ratio(double ratio)
+ {
+ this->r_step = ratio;
+ this->clear();
+ }
+
+ void clear()
+ {
+ ring_buffer::clear ();
+ this->r_frac = 1.0;
+ this->r_left[0] = this->r_left[1] = this->r_left[2] = this->r_left[3] = this->r_left[4] = this->r_left[5] = 0;
+ this->r_right[0] = this->r_right[1] = this->r_right[2] = this->r_right[3] = this->r_right[4] = this->r_right[5] = 0;
+ }
+
+ void read(short *data, int num_samples)
+ {
+ int i_position = this->start >> 1;
+ short *internal_buffer = reinterpret_cast<short *>(this->buffer);
+ int o_position = 0;
+ int consumed = 0;
+
+ while (o_position < num_samples && consumed < this->buffer_size)
+ {
+ int s_left = internal_buffer[i_position];
+ int s_right = internal_buffer[i_position + 1];
+ int max_samples = this->buffer_size >> 1;
+ const double margin_of_error = 1.0e-10;
+
+ if (std::abs(this->r_step - 1.0) < margin_of_error)
+ {
+ data[o_position] = static_cast<short>(s_left);
+ data[o_position + 1] = static_cast<short>(s_right);
+
+ o_position += 2;
+ i_position += 2;
+ if (i_position >= max_samples)
+ i_position -= max_samples;
+ consumed += 2;
+
+ continue;
+ }
+
+ while (this->r_frac <= 1.0 && o_position < num_samples)
+ {
+ data[o_position] = SHORT_CLAMP(osculating(this->r_frac, this->r_left[0], this->r_left[1], this->r_left[2], this->r_left[3], this->r_left[4], this->r_left[5]));
+ data[o_position + 1] = SHORT_CLAMP(osculating(this->r_frac, this->r_right[0], this->r_right[1], this->r_right[2], this->r_right[3], this->r_right[4], this->r_right[5]));
+
+ o_position += 2;
+
+ this->r_frac += this->r_step;
+ }
+
+ if (this->r_frac > 1.0)
+ {
+ this->r_left[0] = this->r_left[1];
+ this->r_left[1] = this->r_left[2];
+ this->r_left[2] = this->r_left[3];
+ this->r_left[3] = this->r_left[4];
+ this->r_left[4] = this->r_left[5];
+ this->r_left[5] = s_left;
+
+ this->r_right[0] = this->r_right[1];
+ this->r_right[1] = this->r_right[2];
+ this->r_right[2] = this->r_right[3];
+ this->r_right[3] = this->r_right[4];
+ this->r_right[4] = this->r_right[5];
+ this->r_right[5] = s_right;
+
+ this->r_frac -= 1.0;
+
+ i_position += 2;
+ if (i_position >= max_samples)
+ i_position -= max_samples;
+ consumed += 2;
+ }
+ }
+
+ this->size -= consumed << 1;
+ this->start += consumed << 1;
+ if (this->start >= this->buffer_size)
+ this->start -= this->buffer_size;
+ }
+
+ inline int avail()
+ {
+ return static_cast<int>(std::floor(((this->size >> 2) - this->r_frac) / this->r_step) * 2);
+ }
+};
+
+#endif /* __OSCULATING_RESAMPLER_H */
+