Browse code

Update snes9x code from 1.53 to 1.6.0.

Notable differences from upstream:
* Did not use the same #include setup for the new byuu apu and instead chose to do things more traditionally, as the latter is also much easier to deal with in Visual Studio than just including .cpp files into other .cpp files...
* MSU1 support not included (I see no need for this in a plugin meant to be used for original SNES music).
* The dynamic rate control on the APU not included (I also see no need for it in this plugin).
* The extra resamplers I added in were removed as the original hermite resampler was folded into a single non-inhertiable resampler.
* Bits of cleanup.

Naram Qashat authored on 2021/04/19 21:20:36
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,126 +0,0 @@
1
-/* Simple resampler based on bsnes's ruby audio library */
2
-
3
-#pragma once
4
-
5
-#include <cmath>
6
-#include "resampler.h"
7
-
8
-class OsculatingResampler : public Resampler
9
-{
10
-protected:
11
-	double r_step;
12
-	double r_frac;
13
-	int r_left[6], r_right[6];
14
-
15
-	template<typename T1, typename T2> static T1 CLAMP(T1 x, T2 low, T2 high) { return x > high ? high : (x < low ? low : x); }
16
-	template<typename T> static short SHORT_CLAMP(T n) { return static_cast<short>(CLAMP(n, -32768, 32767)); }
17
-
18
-	double osculating(double x, double a, double b, double c, double d, double e, double f)
19
-	{
20
-		double z = x - 0.5;
21
-		double even1 = a + f, odd1 = a - f;
22
-		double even2 = b + e, odd2 = b - e;
23
-		double even3 = c + d, odd3 = c - d;
24
-		double c0 = 0.01171875 * even1 - 0.09765625 * even2 + 0.5859375 * even3;
25
-		double c1 = 0.2109375 * odd2 - 281 / 192.0 * odd3 - 13 / 384.0 * odd1;
26
-		double c2 = 0.40625 * even2 - 17 / 48.0 * even3 - 5 / 96.0 * even1;
27
-		double c3 = 0.1875 * odd1 - 53 / 48.0 * odd2 + 2.375 * odd3;
28
-		double c4 = 1 / 48.0*even1 - 0.0625 * even2 + 1 / 24.0 * even3;
29
-		double c5 = 25 / 24.0 * odd2 - 25 / 12.0 * odd3 - 5 / 24.0 * odd1;
30
-		return ((((c5 * z + c4) * z + c3) * z + c2) * z + c1) * z + c0;
31
-	}
32
-
33
-public:
34
-	OsculatingResampler(int num_samples) : Resampler(num_samples)
35
-	{
36
-		this->clear();
37
-	}
38
-
39
-	void time_ratio(double ratio)
40
-	{
41
-		this->r_step = ratio;
42
-		this->clear();
43
-	}
44
-
45
-	void clear()
46
-	{
47
-		ring_buffer::clear();
48
-		this->r_frac = 1.0;
49
-		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;
50
-		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;
51
-	}
52
-
53
-	void read(short *data, int num_samples)
54
-	{
55
-		int i_position = this->start >> 1;
56
-		short *internal_buffer = reinterpret_cast<short *>(&this->buffer[0]);
57
-		int o_position = 0;
58
-		int consumed = 0;
59
-
60
-		while (o_position < num_samples && consumed < this->buffer_size)
61
-		{
62
-			int s_left = internal_buffer[i_position];
63
-			int s_right = internal_buffer[i_position + 1];
64
-			int max_samples = this->buffer_size >> 1;
65
-			static const double margin_of_error = 1.0e-10;
66
-
67
-			if (std::abs(this->r_step - 1.0) < margin_of_error)
68
-			{
69
-				data[o_position] = static_cast<short>(s_left);
70
-				data[o_position + 1] = static_cast<short>(s_right);
71
-
72
-				o_position += 2;
73
-				i_position += 2;
74
-				if (i_position >= max_samples)
75
-					i_position -= max_samples;
76
-				consumed += 2;
77
-
78
-				continue;
79
-			}
80
-
81
-			while (this->r_frac <= 1.0 && o_position < num_samples)
82
-			{
83
-				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]));
84
-				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]));
85
-
86
-				o_position += 2;
87
-
88
-				this->r_frac += this->r_step;
89
-			}
90
-
91
-			if (this->r_frac > 1.0)
92
-			{
93
-				this->r_left[0] = this->r_left[1];
94
-				this->r_left[1] = this->r_left[2];
95
-				this->r_left[2] = this->r_left[3];
96
-				this->r_left[3] = this->r_left[4];
97
-				this->r_left[4] = this->r_left[5];
98
-				this->r_left[5] = s_left;
99
-
100
-				this->r_right[0] = this->r_right[1];
101
-				this->r_right[1] = this->r_right[2];
102
-				this->r_right[2] = this->r_right[3];
103
-				this->r_right[3] = this->r_right[4];
104
-				this->r_right[4] = this->r_right[5];
105
-				this->r_right[5] = s_right;
106
-
107
-				this->r_frac -= 1.0;
108
-
109
-				i_position += 2;
110
-				if (i_position >= max_samples)
111
-					i_position -= max_samples;
112
-				consumed += 2;
113
-			}
114
-		}
115
-
116
-		this->size -= consumed << 1;
117
-		this->start += consumed << 1;
118
-		if (this->start >= this->buffer_size)
119
-			this->start -= this->buffer_size;
120
-	}
121
-
122
-	int avail()
123
-	{
124
-		return static_cast<int>(std::floor(((this->size >> 2) - this->r_frac) / this->r_step) * 2);
125
-	}
126
-};
Browse code

* Fixes for gcc and clang (while they can compile the code, the DLLs made aren't functional, but oh well).

* [2SF] Used more up-to-date asmjit, despite the ugly looking code.

Naram Qashat authored on 2014/09/17 19:51:45
Showing 1 changed files
... ...
@@ -53,7 +53,7 @@ public:
53 53
 	void read(short *data, int num_samples)
54 54
 	{
55 55
 		int i_position = this->start >> 1;
56
-		short *internal_buffer = reinterpret_cast<short *>(this->buffer);
56
+		short *internal_buffer = reinterpret_cast<short *>(&this->buffer[0]);
57 57
 		int o_position = 0;
58 58
 		int consumed = 0;
59 59
 
Browse code

A few more cases of using #pragma once instead of include guards.

Naram Qashat authored on 2014/09/08 14:51:19
Showing 1 changed files
... ...
@@ -1,7 +1,6 @@
1 1
 /* Simple resampler based on bsnes's ruby audio library */
2 2
 
3
-#ifndef __OSCULATING_RESAMPLER_H
4
-#define __OSCULATING_RESAMPLER_H
3
+#pragma once
5 4
 
6 5
 #include <cmath>
7 6
 #include "resampler.h"
... ...
@@ -125,5 +124,3 @@ public:
125 124
 		return static_cast<int>(std::floor(((this->size >> 2) - this->r_frac) / this->r_step) * 2);
126 125
 	}
127 126
 };
128
-
129
-#endif /* __OSCULATING_RESAMPLER_H */
Browse code

[SNSF] Massive code cleanup, as well as removing as much unused code/variables as possible.

Naram Qashat authored on 2013/05/23 06:02:16
Showing 1 changed files
... ...
@@ -6,9 +6,6 @@
6 6
 #include <cmath>
7 7
 #include "resampler.h"
8 8
 
9
-#undef CLAMP
10
-#undef SHORT_CLAMP
11
-
12 9
 class OsculatingResampler : public Resampler
13 10
 {
14 11
 protected:
... ...
@@ -48,7 +45,7 @@ public:
48 45
 
49 46
 	void clear()
50 47
 	{
51
-		ring_buffer::clear ();
48
+		ring_buffer::clear();
52 49
 		this->r_frac = 1.0;
53 50
 		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;
54 51
 		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;
... ...
@@ -66,7 +63,7 @@ public:
66 63
 			int s_left = internal_buffer[i_position];
67 64
 			int s_right = internal_buffer[i_position + 1];
68 65
 			int max_samples = this->buffer_size >> 1;
69
-			const double margin_of_error = 1.0e-10;
66
+			static const double margin_of_error = 1.0e-10;
70 67
 
71 68
 			if (std::abs(this->r_step - 1.0) < margin_of_error)
72 69
 			{
... ...
@@ -123,7 +120,7 @@ public:
123 120
 			this->start -= this->buffer_size;
124 121
 	}
125 122
 
126
-	inline int avail()
123
+	int avail()
127 124
 	{
128 125
 		return static_cast<int>(std::floor(((this->size >> 2) - this->r_frac) / this->r_step) * 2);
129 126
 	}
Browse code

Added Sinc resampler to SNSF plugin, as well as fixed issue with there being garbage at the start of an SNSF when played after one has finished.

Naram Qashat authored on 2013/05/08 03:42:24
Showing 1 changed files
... ...
@@ -8,8 +8,6 @@
8 8
 
9 9
 #undef CLAMP
10 10
 #undef SHORT_CLAMP
11
-//template<typename T1, typename T2> static inline T1 CLAMP(T1 x, T2 low, T2 high) { return x > high ? high : (x < low ? low : x); }
12
-//template<typename T> static inline short SHORT_CLAMP(T n) { return static_cast<short>(CLAMP(n, -32768, 32767)); }
13 11
 
14 12
 class OsculatingResampler : public Resampler
15 13
 {
... ...
@@ -18,6 +16,9 @@ protected:
18 16
 	double r_frac;
19 17
 	int r_left[6], r_right[6];
20 18
 
19
+	template<typename T1, typename T2> static T1 CLAMP(T1 x, T2 low, T2 high) { return x > high ? high : (x < low ? low : x); }
20
+	template<typename T> static short SHORT_CLAMP(T n) { return static_cast<short>(CLAMP(n, -32768, 32767)); }
21
+
21 22
 	double osculating(double x, double a, double b, double c, double d, double e, double f)
22 23
 	{
23 24
 		double z = x - 0.5;
Browse code

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.

Naram Qashat authored on 2013/04/12 13:36:31
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,131 @@
1
+/* Simple resampler based on bsnes's ruby audio library */
2
+
3
+#ifndef __OSCULATING_RESAMPLER_H
4
+#define __OSCULATING_RESAMPLER_H
5
+
6
+#include <cmath>
7
+#include "resampler.h"
8
+
9
+#undef CLAMP
10
+#undef SHORT_CLAMP
11
+//template<typename T1, typename T2> static inline T1 CLAMP(T1 x, T2 low, T2 high) { return x > high ? high : (x < low ? low : x); }
12
+//template<typename T> static inline short SHORT_CLAMP(T n) { return static_cast<short>(CLAMP(n, -32768, 32767)); }
13
+
14
+class OsculatingResampler : public Resampler
15
+{
16
+protected:
17
+	double r_step;
18
+	double r_frac;
19
+	int r_left[6], r_right[6];
20
+
21
+	double osculating(double x, double a, double b, double c, double d, double e, double f)
22
+	{
23
+		double z = x - 0.5;
24
+		double even1 = a + f, odd1 = a - f;
25
+		double even2 = b + e, odd2 = b - e;
26
+		double even3 = c + d, odd3 = c - d;
27
+		double c0 = 0.01171875 * even1 - 0.09765625 * even2 + 0.5859375 * even3;
28
+		double c1 = 0.2109375 * odd2 - 281 / 192.0 * odd3 - 13 / 384.0 * odd1;
29
+		double c2 = 0.40625 * even2 - 17 / 48.0 * even3 - 5 / 96.0 * even1;
30
+		double c3 = 0.1875 * odd1 - 53 / 48.0 * odd2 + 2.375 * odd3;
31
+		double c4 = 1 / 48.0*even1 - 0.0625 * even2 + 1 / 24.0 * even3;
32
+		double c5 = 25 / 24.0 * odd2 - 25 / 12.0 * odd3 - 5 / 24.0 * odd1;
33
+		return ((((c5 * z + c4) * z + c3) * z + c2) * z + c1) * z + c0;
34
+	}
35
+
36
+public:
37
+	OsculatingResampler(int num_samples) : Resampler(num_samples)
38
+	{
39
+		this->clear();
40
+	}
41
+
42
+	void time_ratio(double ratio)
43
+	{
44
+		this->r_step = ratio;
45
+		this->clear();
46
+	}
47
+
48
+	void clear()
49
+	{
50
+		ring_buffer::clear ();
51
+		this->r_frac = 1.0;
52
+		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;
53
+		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;
54
+	}
55
+
56
+	void read(short *data, int num_samples)
57
+	{
58
+		int i_position = this->start >> 1;
59
+		short *internal_buffer = reinterpret_cast<short *>(this->buffer);
60
+		int o_position = 0;
61
+		int consumed = 0;
62
+
63
+		while (o_position < num_samples && consumed < this->buffer_size)
64
+		{
65
+			int s_left = internal_buffer[i_position];
66
+			int s_right = internal_buffer[i_position + 1];
67
+			int max_samples = this->buffer_size >> 1;
68
+			const double margin_of_error = 1.0e-10;
69
+
70
+			if (std::abs(this->r_step - 1.0) < margin_of_error)
71
+			{
72
+				data[o_position] = static_cast<short>(s_left);
73
+				data[o_position + 1] = static_cast<short>(s_right);
74
+
75
+				o_position += 2;
76
+				i_position += 2;
77
+				if (i_position >= max_samples)
78
+					i_position -= max_samples;
79
+				consumed += 2;
80
+
81
+				continue;
82
+			}
83
+
84
+			while (this->r_frac <= 1.0 && o_position < num_samples)
85
+			{
86
+				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]));
87
+				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]));
88
+
89
+				o_position += 2;
90
+
91
+				this->r_frac += this->r_step;
92
+			}
93
+
94
+			if (this->r_frac > 1.0)
95
+			{
96
+				this->r_left[0] = this->r_left[1];
97
+				this->r_left[1] = this->r_left[2];
98
+				this->r_left[2] = this->r_left[3];
99
+				this->r_left[3] = this->r_left[4];
100
+				this->r_left[4] = this->r_left[5];
101
+				this->r_left[5] = s_left;
102
+
103
+				this->r_right[0] = this->r_right[1];
104
+				this->r_right[1] = this->r_right[2];
105
+				this->r_right[2] = this->r_right[3];
106
+				this->r_right[3] = this->r_right[4];
107
+				this->r_right[4] = this->r_right[5];
108
+				this->r_right[5] = s_right;
109
+
110
+				this->r_frac -= 1.0;
111
+
112
+				i_position += 2;
113
+				if (i_position >= max_samples)
114
+					i_position -= max_samples;
115
+				consumed += 2;
116
+			}
117
+		}
118
+
119
+		this->size -= consumed << 1;
120
+		this->start += consumed << 1;
121
+		if (this->start >= this->buffer_size)
122
+			this->start -= this->buffer_size;
123
+	}
124
+
125
+	inline int avail()
126
+	{
127
+		return static_cast<int>(std::floor(((this->size >> 2) - this->r_frac) / this->r_step) * 2);
128
+	}
129
+};
130
+
131
+#endif /* __OSCULATING_RESAMPLER_H */