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,130 +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 HermiteResampler : public Resampler
9
-{
10
-protected:
11
-	double r_step;
12
-	double r_frac;
13
-	int r_left[4], r_right[4];
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 hermite(double mu1, double a, double b, double c, double d)
19
-	{
20
-		static const double tension = 0.0; //-1 = low, 0 = normal, 1 = high
21
-		static const double bias = 0.0; //-1 = left, 0 = even, 1 = right
22
-
23
-		double mu2, mu3, m0, m1, a0, a1, a2, a3;
24
-
25
-		mu2 = mu1 * mu1;
26
-		mu3 = mu2 * mu1;
27
-
28
-		m0  = (b - a) * (1 + bias) * (1 - tension) / 2;
29
-		m0 += (c - b) * (1 - bias) * (1 - tension) / 2;
30
-		m1  = (c - b) * (1 + bias) * (1 - tension) / 2;
31
-		m1 += (d - c) * (1 - bias) * (1 - tension) / 2;
32
-
33
-		a0 = 2 * mu3 - 3 * mu2 + 1;
34
-		a1 = mu3 - 2 * mu2 + mu1;
35
-		a2 = mu3 - mu2;
36
-		a3 = -2 * mu3 + 3 * mu2;
37
-
38
-		return (a0 * b) + (a1 * m0) + (a2 * m1) + (a3 * c);
39
-	}
40
-
41
-public:
42
-	HermiteResampler(int num_samples) : Resampler(num_samples)
43
-	{
44
-		this->clear();
45
-	}
46
-
47
-	void time_ratio(double ratio)
48
-	{
49
-		this->r_step = ratio;
50
-		this->clear();
51
-	}
52
-
53
-	void clear()
54
-	{
55
-		ring_buffer::clear();
56
-		this->r_frac = 1.0;
57
-		this->r_left[0] = this->r_left[1] = this->r_left[2] = this->r_left[3] = 0;
58
-		this->r_right[0] = this->r_right[1] = this->r_right[2] = this->r_right[3] = 0;
59
-	}
60
-
61
-	void read(short *data, int num_samples)
62
-	{
63
-		int i_position = this->start >> 1;
64
-		short *internal_buffer = reinterpret_cast<short *>(&this->buffer[0]);
65
-		int o_position = 0;
66
-		int consumed = 0;
67
-
68
-		while (o_position < num_samples && consumed < this->buffer_size)
69
-		{
70
-			int s_left = internal_buffer[i_position];
71
-			int s_right = internal_buffer[i_position + 1];
72
-			int max_samples = this->buffer_size >> 1;
73
-			static const double margin_of_error = 1.0e-10;
74
-
75
-			if (std::abs(this->r_step - 1.0) < margin_of_error)
76
-			{
77
-				data[o_position] = static_cast<short>(s_left);
78
-				data[o_position + 1] = static_cast<short>(s_right);
79
-
80
-				o_position += 2;
81
-				i_position += 2;
82
-				if (i_position >= max_samples)
83
-					i_position -= max_samples;
84
-				consumed += 2;
85
-
86
-				continue;
87
-			}
88
-
89
-			while (this->r_frac <= 1.0 && o_position < num_samples)
90
-			{
91
-				data[o_position] = SHORT_CLAMP(hermite(this->r_frac, this->r_left[0], this->r_left[1], this->r_left[2], this->r_left[3]));
92
-				data[o_position + 1] = SHORT_CLAMP(hermite(this->r_frac, this->r_right[0], this->r_right[1], this->r_right[2], this->r_right[3]));
93
-
94
-				o_position += 2;
95
-
96
-				this->r_frac += this->r_step;
97
-			}
98
-
99
-			if (this->r_frac > 1.0)
100
-			{
101
-				this->r_left[0] = this->r_left[1];
102
-				this->r_left[1] = this->r_left[2];
103
-				this->r_left[2] = this->r_left[3];
104
-				this->r_left[3] = s_left;
105
-
106
-				this->r_right[0] = this->r_right[1];
107
-				this->r_right[1] = this->r_right[2];
108
-				this->r_right[2] = this->r_right[3];
109
-				this->r_right[3] = s_right;
110
-
111
-				this->r_frac -= 1.0;
112
-
113
-				i_position += 2;
114
-				if (i_position >= max_samples)
115
-					i_position -= max_samples;
116
-				consumed += 2;
117
-			}
118
-		}
119
-
120
-		this->size -= consumed << 1;
121
-		this->start += consumed << 1;
122
-		if (this->start >= this->buffer_size)
123
-			this->start -= this->buffer_size;
124
-	}
125
-
126
-	int avail()
127
-	{
128
-		return static_cast<int>(std::floor(((this->size >> 2) - this->r_frac) / this->r_step) * 2);
129
-	}
130
-};
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
... ...
@@ -61,7 +61,7 @@ public:
61 61
 	void read(short *data, int num_samples)
62 62
 	{
63 63
 		int i_position = this->start >> 1;
64
-		short *internal_buffer = reinterpret_cast<short *>(this->buffer);
64
+		short *internal_buffer = reinterpret_cast<short *>(&this->buffer[0]);
65 65
 		int o_position = 0;
66 66
 		int consumed = 0;
67 67
 
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 __HERMITE_RESAMPLER_H
4
-#define __HERMITE_RESAMPLER_H
3
+#pragma once
5 4
 
6 5
 #include <cmath>
7 6
 #include "resampler.h"
... ...
@@ -129,5 +128,3 @@ public:
129 128
 		return static_cast<int>(std::floor(((this->size >> 2) - this->r_frac) / this->r_step) * 2);
130 129
 	}
131 130
 };
132
-
133
-#endif /* __HERMITE_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
... ...
@@ -3,142 +3,131 @@
3 3
 #ifndef __HERMITE_RESAMPLER_H
4 4
 #define __HERMITE_RESAMPLER_H
5 5
 
6
+#include <cmath>
6 7
 #include "resampler.h"
7 8
 
8
-#undef CLAMP
9
-#undef SHORT_CLAMP
10
-#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
11
-#define SHORT_CLAMP(n) ((short) CLAMP((n), -32768, 32767))
12
-
13 9
 class HermiteResampler : public Resampler
14 10
 {
15
-    protected:
16
-
17
-        double r_step;
18
-        double r_frac;
19
-        int    r_left[4], r_right[4];
20
-
21
-        double
22
-        hermite (double mu1, double a, double b, double c, double d)
23
-        {
24
-            const double tension = 0.0; //-1 = low, 0 = normal, 1 = high
25
-            const double bias    = 0.0; //-1 = left, 0 = even, 1 = right
26
-
27
-            double mu2, mu3, m0, m1, a0, a1, a2, a3;
28
-
29
-            mu2 = mu1 * mu1;
30
-            mu3 = mu2 * mu1;
31
-
32
-            m0  = (b - a) * (1 + bias) * (1 - tension) / 2;
33
-            m0 += (c - b) * (1 - bias) * (1 - tension) / 2;
34
-            m1  = (c - b) * (1 + bias) * (1 - tension) / 2;
35
-            m1 += (d - c) * (1 - bias) * (1 - tension) / 2;
36
-
37
-            a0 = +2 * mu3 - 3 * mu2 + 1;
38
-            a1 =      mu3 - 2 * mu2 + mu1;
39
-            a2 =      mu3 -     mu2;
40
-            a3 = -2 * mu3 + 3 * mu2;
41
-
42
-            return (a0 * b) + (a1 * m0) + (a2 * m1) + (a3 * c);
43
-        }
44
-
45
-    public:
46
-        HermiteResampler (int num_samples) : Resampler (num_samples)
47
-        {
48
-            clear ();
49
-        }
50
-
51
-        ~HermiteResampler ()
52
-        {
53
-        }
54
-
55
-        void
56
-        time_ratio (double ratio)
57
-        {
58
-            r_step = ratio;
59
-            clear ();
60
-        }
61
-
62
-        void
63
-        clear()
64
-        {
65
-            ring_buffer::clear ();
66
-            r_frac = 1.0;
67
-            r_left [0] = r_left [1] = r_left [2] = r_left [3] = 0;
68
-            r_right[0] = r_right[1] = r_right[2] = r_right[3] = 0;
69
-        }
70
-
71
-        void
72
-        read (short *data, int num_samples)
73
-        {
74
-            int i_position = start >> 1;
75
-            short *internal_buffer = (short *) buffer;
76
-            int o_position = 0;
77
-            int consumed = 0;
78
-
79
-            while (o_position < num_samples && consumed < buffer_size)
80
-            {
81
-                int s_left = internal_buffer[i_position];
82
-                int s_right = internal_buffer[i_position + 1];
83
-                int max_samples = buffer_size >> 1;
84
-                const double margin_of_error = 1.0e-10;
85
-
86
-                if (fabs(r_step - 1.0) < margin_of_error)
87
-                {
88
-                    data[o_position] = (short) s_left;
89
-                    data[o_position + 1] = (short) s_right;
90
-
91
-                    o_position += 2;
92
-                    i_position += 2;
93
-                    if (i_position >= max_samples)
94
-                        i_position -= max_samples;
95
-                    consumed += 2;
96
-
97
-                    continue;
98
-                }
99
-
100
-                while (r_frac <= 1.0 && o_position < num_samples)
101
-                {
102
-                    data[o_position]     = SHORT_CLAMP (hermite (r_frac, r_left [0], r_left [1], r_left [2], r_left [3]));
103
-                    data[o_position + 1] = SHORT_CLAMP (hermite (r_frac, r_right[0], r_right[1], r_right[2], r_right[3]));
104
-
105
-                    o_position += 2;
106
-
107
-                    r_frac += r_step;
108
-                }
109
-
110
-                if (r_frac > 1.0)
111
-                {
112
-                    r_left [0] = r_left [1];
113
-                    r_left [1] = r_left [2];
114
-                    r_left [2] = r_left [3];
115
-                    r_left [3] = s_left;
116
-    
117
-                    r_right[0] = r_right[1];
118
-                    r_right[1] = r_right[2];
119
-                    r_right[2] = r_right[3];
120
-                    r_right[3] = s_right;                    
121
-                    
122
-                    r_frac -= 1.0;
123
-                    
124
-                    i_position += 2;
125
-                    if (i_position >= max_samples)
126
-                        i_position -= max_samples;
127
-                    consumed += 2;
128
-                }
129
-            }
130
-
131
-            size -= consumed << 1;
132
-            start += consumed << 1;
133
-            if (start >= buffer_size)
134
-                start -= buffer_size;
135
-        }
136
-
137
-        inline int
138
-        avail()
139
-        {
140
-            return (int) floor (((size >> 2) - r_frac) / r_step) * 2;
141
-        }
11
+protected:
12
+	double r_step;
13
+	double r_frac;
14
+	int r_left[4], r_right[4];
15
+
16
+	template<typename T1, typename T2> static T1 CLAMP(T1 x, T2 low, T2 high) { return x > high ? high : (x < low ? low : x); }
17
+	template<typename T> static short SHORT_CLAMP(T n) { return static_cast<short>(CLAMP(n, -32768, 32767)); }
18
+
19
+	double hermite(double mu1, double a, double b, double c, double d)
20
+	{
21
+		static const double tension = 0.0; //-1 = low, 0 = normal, 1 = high
22
+		static const double bias = 0.0; //-1 = left, 0 = even, 1 = right
23
+
24
+		double mu2, mu3, m0, m1, a0, a1, a2, a3;
25
+
26
+		mu2 = mu1 * mu1;
27
+		mu3 = mu2 * mu1;
28
+
29
+		m0  = (b - a) * (1 + bias) * (1 - tension) / 2;
30
+		m0 += (c - b) * (1 - bias) * (1 - tension) / 2;
31
+		m1  = (c - b) * (1 + bias) * (1 - tension) / 2;
32
+		m1 += (d - c) * (1 - bias) * (1 - tension) / 2;
33
+
34
+		a0 = 2 * mu3 - 3 * mu2 + 1;
35
+		a1 = mu3 - 2 * mu2 + mu1;
36
+		a2 = mu3 - mu2;
37
+		a3 = -2 * mu3 + 3 * mu2;
38
+
39
+		return (a0 * b) + (a1 * m0) + (a2 * m1) + (a3 * c);
40
+	}
41
+
42
+public:
43
+	HermiteResampler(int num_samples) : Resampler(num_samples)
44
+	{
45
+		this->clear();
46
+	}
47
+
48
+	void time_ratio(double ratio)
49
+	{
50
+		this->r_step = ratio;
51
+		this->clear();
52
+	}
53
+
54
+	void clear()
55
+	{
56
+		ring_buffer::clear();
57
+		this->r_frac = 1.0;
58
+		this->r_left[0] = this->r_left[1] = this->r_left[2] = this->r_left[3] = 0;
59
+		this->r_right[0] = this->r_right[1] = this->r_right[2] = this->r_right[3] = 0;
60
+	}
61
+
62
+	void read(short *data, int num_samples)
63
+	{
64
+		int i_position = this->start >> 1;
65
+		short *internal_buffer = reinterpret_cast<short *>(this->buffer);
66
+		int o_position = 0;
67
+		int consumed = 0;
68
+
69
+		while (o_position < num_samples && consumed < this->buffer_size)
70
+		{
71
+			int s_left = internal_buffer[i_position];
72
+			int s_right = internal_buffer[i_position + 1];
73
+			int max_samples = this->buffer_size >> 1;
74
+			static const double margin_of_error = 1.0e-10;
75
+
76
+			if (std::abs(this->r_step - 1.0) < margin_of_error)
77
+			{
78
+				data[o_position] = static_cast<short>(s_left);
79
+				data[o_position + 1] = static_cast<short>(s_right);
80
+
81
+				o_position += 2;
82
+				i_position += 2;
83
+				if (i_position >= max_samples)
84
+					i_position -= max_samples;
85
+				consumed += 2;
86
+
87
+				continue;
88
+			}
89
+
90
+			while (this->r_frac <= 1.0 && o_position < num_samples)
91
+			{
92
+				data[o_position] = SHORT_CLAMP(hermite(this->r_frac, this->r_left[0], this->r_left[1], this->r_left[2], this->r_left[3]));
93
+				data[o_position + 1] = SHORT_CLAMP(hermite(this->r_frac, this->r_right[0], this->r_right[1], this->r_right[2], this->r_right[3]));
94
+
95
+				o_position += 2;
96
+
97
+				this->r_frac += this->r_step;
98
+			}
99
+
100
+			if (this->r_frac > 1.0)
101
+			{
102
+				this->r_left[0] = this->r_left[1];
103
+				this->r_left[1] = this->r_left[2];
104
+				this->r_left[2] = this->r_left[3];
105
+				this->r_left[3] = s_left;
106
+
107
+				this->r_right[0] = this->r_right[1];
108
+				this->r_right[1] = this->r_right[2];
109
+				this->r_right[2] = this->r_right[3];
110
+				this->r_right[3] = s_right;
111
+
112
+				this->r_frac -= 1.0;
113
+
114
+				i_position += 2;
115
+				if (i_position >= max_samples)
116
+					i_position -= max_samples;
117
+				consumed += 2;
118
+			}
119
+		}
120
+
121
+		this->size -= consumed << 1;
122
+		this->start += consumed << 1;
123
+		if (this->start >= this->buffer_size)
124
+			this->start -= this->buffer_size;
125
+	}
126
+
127
+	int avail()
128
+	{
129
+		return static_cast<int>(std::floor(((this->size >> 2) - this->r_frac) / this->r_step) * 2);
130
+	}
142 131
 };
143 132
 
144 133
 #endif /* __HERMITE_RESAMPLER_H */
Browse code

Import actual code.

Naram Qashat authored on 2013/03/26 02:41:19
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,144 @@
1
+/* Simple resampler based on bsnes's ruby audio library */
2
+
3
+#ifndef __HERMITE_RESAMPLER_H
4
+#define __HERMITE_RESAMPLER_H
5
+
6
+#include "resampler.h"
7
+
8
+#undef CLAMP
9
+#undef SHORT_CLAMP
10
+#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
11
+#define SHORT_CLAMP(n) ((short) CLAMP((n), -32768, 32767))
12
+
13
+class HermiteResampler : public Resampler
14
+{
15
+    protected:
16
+
17
+        double r_step;
18
+        double r_frac;
19
+        int    r_left[4], r_right[4];
20
+
21
+        double
22
+        hermite (double mu1, double a, double b, double c, double d)
23
+        {
24
+            const double tension = 0.0; //-1 = low, 0 = normal, 1 = high
25
+            const double bias    = 0.0; //-1 = left, 0 = even, 1 = right
26
+
27
+            double mu2, mu3, m0, m1, a0, a1, a2, a3;
28
+
29
+            mu2 = mu1 * mu1;
30
+            mu3 = mu2 * mu1;
31
+
32
+            m0  = (b - a) * (1 + bias) * (1 - tension) / 2;
33
+            m0 += (c - b) * (1 - bias) * (1 - tension) / 2;
34
+            m1  = (c - b) * (1 + bias) * (1 - tension) / 2;
35
+            m1 += (d - c) * (1 - bias) * (1 - tension) / 2;
36
+
37
+            a0 = +2 * mu3 - 3 * mu2 + 1;
38
+            a1 =      mu3 - 2 * mu2 + mu1;
39
+            a2 =      mu3 -     mu2;
40
+            a3 = -2 * mu3 + 3 * mu2;
41
+
42
+            return (a0 * b) + (a1 * m0) + (a2 * m1) + (a3 * c);
43
+        }
44
+
45
+    public:
46
+        HermiteResampler (int num_samples) : Resampler (num_samples)
47
+        {
48
+            clear ();
49
+        }
50
+
51
+        ~HermiteResampler ()
52
+        {
53
+        }
54
+
55
+        void
56
+        time_ratio (double ratio)
57
+        {
58
+            r_step = ratio;
59
+            clear ();
60
+        }
61
+
62
+        void
63
+        clear()
64
+        {
65
+            ring_buffer::clear ();
66
+            r_frac = 1.0;
67
+            r_left [0] = r_left [1] = r_left [2] = r_left [3] = 0;
68
+            r_right[0] = r_right[1] = r_right[2] = r_right[3] = 0;
69
+        }
70
+
71
+        void
72
+        read (short *data, int num_samples)
73
+        {
74
+            int i_position = start >> 1;
75
+            short *internal_buffer = (short *) buffer;
76
+            int o_position = 0;
77
+            int consumed = 0;
78
+
79
+            while (o_position < num_samples && consumed < buffer_size)
80
+            {
81
+                int s_left = internal_buffer[i_position];
82
+                int s_right = internal_buffer[i_position + 1];
83
+                int max_samples = buffer_size >> 1;
84
+                const double margin_of_error = 1.0e-10;
85
+
86
+                if (fabs(r_step - 1.0) < margin_of_error)
87
+                {
88
+                    data[o_position] = (short) s_left;
89
+                    data[o_position + 1] = (short) s_right;
90
+
91
+                    o_position += 2;
92
+                    i_position += 2;
93
+                    if (i_position >= max_samples)
94
+                        i_position -= max_samples;
95
+                    consumed += 2;
96
+
97
+                    continue;
98
+                }
99
+
100
+                while (r_frac <= 1.0 && o_position < num_samples)
101
+                {
102
+                    data[o_position]     = SHORT_CLAMP (hermite (r_frac, r_left [0], r_left [1], r_left [2], r_left [3]));
103
+                    data[o_position + 1] = SHORT_CLAMP (hermite (r_frac, r_right[0], r_right[1], r_right[2], r_right[3]));
104
+
105
+                    o_position += 2;
106
+
107
+                    r_frac += r_step;
108
+                }
109
+
110
+                if (r_frac > 1.0)
111
+                {
112
+                    r_left [0] = r_left [1];
113
+                    r_left [1] = r_left [2];
114
+                    r_left [2] = r_left [3];
115
+                    r_left [3] = s_left;
116
+    
117
+                    r_right[0] = r_right[1];
118
+                    r_right[1] = r_right[2];
119
+                    r_right[2] = r_right[3];
120
+                    r_right[3] = s_right;                    
121
+                    
122
+                    r_frac -= 1.0;
123
+                    
124
+                    i_position += 2;
125
+                    if (i_position >= max_samples)
126
+                        i_position -= max_samples;
127
+                    consumed += 2;
128
+                }
129
+            }
130
+
131
+            size -= consumed << 1;
132
+            start += consumed << 1;
133
+            if (start >= buffer_size)
134
+                start -= buffer_size;
135
+        }
136
+
137
+        inline int
138
+        avail()
139
+        {
140
+            return (int) floor (((size >> 2) - r_frac) / r_step) * 2;
141
+        }
142
+};
143
+
144
+#endif /* __HERMITE_RESAMPLER_H */