Browse code

[NCSF] Fix subtle rare clipping issues in some songs

Clarissa Walker authored on 2024/09/24 20:51:04
Showing 1 changed files
... ...
@@ -220,12 +220,12 @@ inline std::int16_t Cnv_Sust(int sust)
220 220
 
221 221
 inline int Cnv_Sine(int arg)
222 222
 {
223
+	static const int lut_size = 32;
223 224
 	static const std::int8_t lut[] =
224 225
 	{
225 226
 		0, 6, 12, 19, 25, 31, 37, 43, 49, 54, 60, 65, 71, 76, 81, 85, 90, 94,
226 227
 		98, 102, 106, 109, 112, 115, 117, 120, 122, 123, 125, 126, 126, 127, 127
227 228
 	};
228
-	static const int lut_size = sizeof(lut) / sizeof(std::int8_t);
229 229
 
230 230
 	if (arg < lut_size)
231 231
 		return lut[arg];
Browse code

Move muldiv7 to SSEQPlayer's common.h.

(Basically I was using the same function in 2 files and why do that when I could make it a common thing.)

Naram Qashat authored on 2021/04/07 23:52:06
Showing 1 changed files
... ...
@@ -129,6 +129,11 @@ template<std::size_t N> inline bool VerifyHeader(std::int8_t (&arr)[N], const st
129 129
 	return arrHeader == header;
130 130
 }
131 131
 
132
+inline std::int32_t muldiv7(std::int32_t val, std::uint8_t mul)
133
+{
134
+	return mul == 127 ? val : ((val * mul) >> 7);
135
+}
136
+
132 137
 /*
133 138
  * The remaining functions in this file come from the FeOS Sound System source code.
134 139
  */
Browse code

Use range-based for loops where possible.

Naram Qashat authored on 2021/04/05 23:29:44
Showing 1 changed files
... ...
@@ -51,8 +51,8 @@ struct PseudoFile
51 51
 
52 52
 	template<typename T> typename std::enable_if_t<std::is_integral_v<T>> ReadLE(std::vector<T> &arr)
53 53
 	{
54
-		for (std::size_t i = 0, len = arr.size(); i < len; ++i)
55
-			arr[i] = this->ReadLE<T>();
54
+		for (auto &item : arr)
55
+			item = this->ReadLE<T>();
56 56
 	}
57 57
 
58 58
 	void ReadLE(std::vector<std::uint8_t> &arr)
Browse code

Some template cleanup:

* Move the ToIntegral function from NCSF specifically to the framework in general, so it can be used in the base framework's code too.
* Use type traits a bit more.
* Move convertTo into the ConvertFuncs class.

Naram Qashat authored on 2021/04/05 21:47:28
Showing 1 changed files
... ...
@@ -29,7 +29,7 @@ struct PseudoFile
29 29
 	{
30 30
 	}
31 31
 
32
-	template<typename T> T ReadLE()
32
+	template<typename T> typename std::enable_if_t<std::is_integral_v<T>, T> ReadLE()
33 33
 	{
34 34
 		T finalVal = 0;
35 35
 		for (std::size_t i = 0; i < sizeof(T); ++i)
... ...
@@ -37,7 +37,7 @@ struct PseudoFile
37 37
 		return finalVal;
38 38
 	}
39 39
 
40
-	template<typename T, std::size_t N> void ReadLE(T (&arr)[N])
40
+	template<typename T, std::size_t N> typename std::enable_if_t<std::is_integral_v<T>> ReadLE(T (&arr)[N])
41 41
 	{
42 42
 		for (std::size_t i = 0; i < N; ++i)
43 43
 			arr[i] = this->ReadLE<T>();
... ...
@@ -49,7 +49,7 @@ struct PseudoFile
49 49
 		this->pos += N;
50 50
 	}
51 51
 
52
-	template<typename T> void ReadLE(std::vector<T> &arr)
52
+	template<typename T> typename std::enable_if_t<std::is_integral_v<T>> ReadLE(std::vector<T> &arr)
53 53
 	{
54 54
 		for (std::size_t i = 0, len = arr.size(); i < len; ++i)
55 55
 			arr[i] = this->ReadLE<T>();
... ...
@@ -83,7 +83,7 @@ struct PseudoFile
83 83
  * as little-endian formating.
84 84
  */
85 85
 
86
-template<typename T> inline T ReadLE(const std::uint8_t *arr)
86
+template<typename T> inline typename std::enable_if_t<std::is_integral_v<T>, T> ReadLE(const std::uint8_t *arr)
87 87
 {
88 88
 	T finalVal = 0;
89 89
 	for (std::size_t i = 0; i < sizeof(T); ++i)
... ...
@@ -97,7 +97,7 @@ template<typename T> inline T ReadLE(const std::uint8_t *arr)
97 97
  * integers are in the format of 0x00, 16-bit integers are in the format of
98 98
  * 0x0000, and so on.
99 99
  */
100
-template<typename T> inline std::string NumToHexString(const T &num)
100
+template<typename T> inline typename std::enable_if_t<std::is_integral_v<T>, std::string> NumToHexString(const T &num)
101 101
 {
102 102
 	std::string hex;
103 103
 	std::uint8_t len = sizeof(T) * 2;
... ...
@@ -123,12 +123,6 @@ inline constexpr int REC_GROUP = 5;
123 123
 inline constexpr int REC_PLAYER2 = 6;
124 124
 inline constexpr int REC_STRM = 7;
125 125
 
126
-// Comes from https://stackoverflow.com/a/14589519
127
-template<typename T> inline constexpr auto ToIntegral(const T &e)
128
-{
129
-	return static_cast<std::underlying_type_t<T>>(e);
130
-}
131
-
132 126
 template<std::size_t N> inline bool VerifyHeader(std::int8_t (&arr)[N], const std::string &header)
133 127
 {
134 128
 	std::string arrHeader = std::string(&arr[0], &arr[N]);
Browse code

Silence various Visual Studio warnings:

* Fix the ones in my code where I could use a proper type or valid casts.
* Ignore the designer-time and compiler-time warnings in vendor code or in my code where I am unable to suppress them via casting.
(Most of these were ignored already before introducing the CMake scripts, because they were in vendor code or were annoying to deal with.)

Naram Qashat authored on 2021/03/29 00:10:11
Showing 1 changed files
... ...
@@ -138,7 +138,7 @@ template<std::size_t N> inline bool VerifyHeader(std::int8_t (&arr)[N], const st
138 138
 /*
139 139
  * The remaining functions in this file come from the FeOS Sound System source code.
140 140
  */
141
-inline int Cnv_Attack(int attk)
141
+inline std::uint8_t Cnv_Attack(int attk)
142 142
 {
143 143
 	static const std::uint8_t lut[] =
144 144
 	{
... ...
@@ -151,7 +151,7 @@ inline int Cnv_Attack(int attk)
151 151
 	return attk >= 0x6D ? lut[0x7F - attk] : 0xFF - attk;
152 152
 }
153 153
 
154
-inline int Cnv_Fall(int fall)
154
+inline std::uint16_t Cnv_Fall(int fall)
155 155
 {
156 156
 	if (fall & 0x80) // Supposedly invalid value...
157 157
 		fall = 0; // Use apparently correct default
... ...
@@ -165,7 +165,7 @@ inline int Cnv_Fall(int fall)
165 165
 		return (0x1E00 / (0x7E - fall)) & 0xFFFF;
166 166
 }
167 167
 
168
-inline int Cnv_Scale(int scale)
168
+inline std::int16_t Cnv_Scale(int scale)
169 169
 {
170 170
 	static const std::int16_t lut[] =
171 171
 	{
... ...
@@ -192,7 +192,7 @@ inline int Cnv_Scale(int scale)
192 192
 	return lut[scale];
193 193
 }
194 194
 
195
-inline int Cnv_Sust(int sust)
195
+inline std::int16_t Cnv_Sust(int sust)
196 196
 {
197 197
 	static const std::int16_t lut[] =
198 198
 	{
... ...
@@ -238,17 +238,17 @@ inline int Cnv_Sine(int arg)
238 238
 	return -lut[4 * lut_size - arg];
239 239
 }
240 240
 
241
-inline int read8(const std::uint8_t **ppData)
241
+inline std::uint8_t read8(const std::uint8_t **ppData)
242 242
 {
243 243
 	auto pData = *ppData;
244
-	int x = *pData;
244
+	std::uint8_t x = *pData;
245 245
 	*ppData = pData + 1;
246 246
 	return x;
247 247
 }
248 248
 
249
-inline int read16(const std::uint8_t **ppData)
249
+inline std::uint16_t read16(const std::uint8_t **ppData)
250 250
 {
251
-	int x = read8(ppData);
251
+	std::uint16_t x = read8(ppData);
252 252
 	x |= read8(ppData) << 8;
253 253
 	return x;
254 254
 }
Browse code

Turns out that the trailing return type isn't actually needed here.

Naram Qashat authored on 2021/03/21 04:22:59
Showing 1 changed files
... ...
@@ -124,7 +124,7 @@ inline constexpr int REC_PLAYER2 = 6;
124 124
 inline constexpr int REC_STRM = 7;
125 125
 
126 126
 // Comes from https://stackoverflow.com/a/14589519
127
-template<typename T> inline constexpr auto ToIntegral(const T &e) -> typename std::underlying_type_t<T>
127
+template<typename T> inline constexpr auto ToIntegral(const T &e)
128 128
 {
129 129
 	return static_cast<std::underlying_type_t<T>>(e);
130 130
 }
Browse code

Various changes:

* Use enum class instead of enum (except for the enums for the resource IDs, not really necessary there).
* For NCSF specifically, included a function to convert an enum class to its underlying integral type (as this is needed for use with the std::bitset class).
* Cleanup headers so all the ones needed in a file are explicitly included even if they may possibly be included in another header.
* Used forward declarations in a few spots.
* Explicitly namespaced all (u)int*_t uses (this might seem like overkill, but it helps me see when the standard types are being used with a simple search for std::).
* Made sure it all builds with MinGW-w64 as well (both gcc and clang).
* Removed some std::move from DialogBuilder.cpp based on clang's warnings for that.
* Replaced use of std::copy_n on strings in DialogBuilder.cpp with my CopyToString functions that use wcscpy.
* Replaced CHAR_MIN/CHAR_MAX in eqstr.h and ltstr.h with std::numeric_limits<char>::min/max().

Naram Qashat authored on 2021/03/21 03:16:45
Showing 1 changed files
... ...
@@ -9,9 +9,12 @@
9 9
 
10 10
 #pragma once
11 11
 
12
+#include <algorithm>
12 13
 #include <string>
14
+#include <type_traits>
13 15
 #include <vector>
14 16
 #include <cstring>
17
+#include <cstddef>
15 18
 #include <cstdint>
16 19
 
17 20
 /*
... ...
@@ -19,8 +22,8 @@
19 22
  */
20 23
 struct PseudoFile
21 24
 {
22
-	std::vector<uint8_t> *data;
23
-	uint32_t pos;
25
+	std::vector<std::uint8_t> *data;
26
+	std::uint32_t pos;
24 27
 
25 28
 	PseudoFile() : data(nullptr), pos(0)
26 29
 	{
... ...
@@ -29,18 +32,18 @@ struct PseudoFile
29 32
 	template<typename T> T ReadLE()
30 33
 	{
31 34
 		T finalVal = 0;
32
-		for (size_t i = 0; i < sizeof(T); ++i)
35
+		for (std::size_t i = 0; i < sizeof(T); ++i)
33 36
 			finalVal |= (*this->data)[this->pos++] << (i * 8);
34 37
 		return finalVal;
35 38
 	}
36 39
 
37
-	template<typename T, size_t N> void ReadLE(T (&arr)[N])
40
+	template<typename T, std::size_t N> void ReadLE(T (&arr)[N])
38 41
 	{
39
-		for (size_t i = 0; i < N; ++i)
42
+		for (std::size_t i = 0; i < N; ++i)
40 43
 			arr[i] = this->ReadLE<T>();
41 44
 	}
42 45
 
43
-	template<size_t N> void ReadLE(uint8_t arr[N])
46
+	template<std::size_t N> void ReadLE(std::uint8_t arr[N])
44 47
 	{
45 48
 		std::copy_n(&(*this->data)[this->pos], N, &arr[0]);
46 49
 		this->pos += N;
... ...
@@ -48,11 +51,11 @@ struct PseudoFile
48 51
 
49 52
 	template<typename T> void ReadLE(std::vector<T> &arr)
50 53
 	{
51
-		for (size_t i = 0, len = arr.size(); i < len; ++i)
54
+		for (std::size_t i = 0, len = arr.size(); i < len; ++i)
52 55
 			arr[i] = this->ReadLE<T>();
53 56
 	}
54 57
 
55
-	void ReadLE(std::vector<uint8_t> &arr)
58
+	void ReadLE(std::vector<std::uint8_t> &arr)
56 59
 	{
57 60
 		std::copy_n(&(*this->data)[this->pos], arr.size(), &arr[0]);
58 61
 		this->pos += arr.size();
... ...
@@ -64,7 +67,7 @@ struct PseudoFile
64 67
 		std::string str;
65 68
 		do
66 69
 		{
67
-			chr = static_cast<char>(this->ReadLE<uint8_t>());
70
+			chr = static_cast<char>(this->ReadLE<std::uint8_t>());
68 71
 			if (chr)
69 72
 				str += chr;
70 73
 		} while (chr);
... ...
@@ -80,10 +83,10 @@ struct PseudoFile
80 83
  * as little-endian formating.
81 84
  */
82 85
 
83
-template<typename T> inline T ReadLE(const uint8_t *arr)
86
+template<typename T> inline T ReadLE(const std::uint8_t *arr)
84 87
 {
85 88
 	T finalVal = 0;
86
-	for (size_t i = 0; i < sizeof(T); ++i)
89
+	for (std::size_t i = 0; i < sizeof(T); ++i)
87 90
 		finalVal |= arr[i] << (i * 8);
88 91
 	return finalVal;
89 92
 }
... ...
@@ -97,10 +100,10 @@ template<typename T> inline T ReadLE(const uint8_t *arr)
97 100
 template<typename T> inline std::string NumToHexString(const T &num)
98 101
 {
99 102
 	std::string hex;
100
-	uint8_t len = sizeof(T) * 2;
101
-	for (uint8_t i = 0; i < len; ++i)
103
+	std::uint8_t len = sizeof(T) * 2;
104
+	for (std::uint8_t i = 0; i < len; ++i)
102 105
 	{
103
-		uint8_t tmp = (num >> (i * 4)) & 0xF;
106
+		std::uint8_t tmp = (num >> (i * 4)) & 0xF;
104 107
 		hex = static_cast<char>(tmp < 10 ? tmp + '0' : tmp - 10 + 'a') + hex;
105 108
 	}
106 109
 	return "0x" + hex;
... ...
@@ -120,7 +123,13 @@ inline constexpr int REC_GROUP = 5;
120 123
 inline constexpr int REC_PLAYER2 = 6;
121 124
 inline constexpr int REC_STRM = 7;
122 125
 
123
-template<size_t N> inline bool VerifyHeader(int8_t (&arr)[N], const std::string &header)
126
+// Comes from https://stackoverflow.com/a/14589519
127
+template<typename T> inline constexpr auto ToIntegral(const T &e) -> typename std::underlying_type_t<T>
128
+{
129
+	return static_cast<std::underlying_type_t<T>>(e);
130
+}
131
+
132
+template<std::size_t N> inline bool VerifyHeader(std::int8_t (&arr)[N], const std::string &header)
124 133
 {
125 134
 	std::string arrHeader = std::string(&arr[0], &arr[N]);
126 135
 	return arrHeader == header;
... ...
@@ -131,7 +140,7 @@ template<size_t N> inline bool VerifyHeader(int8_t (&arr)[N], const std::string
131 140
  */
132 141
 inline int Cnv_Attack(int attk)
133 142
 {
134
-	static const uint8_t lut[] =
143
+	static const std::uint8_t lut[] =
135 144
 	{
136 145
 		0x00, 0x01, 0x05, 0x0E, 0x1A, 0x26, 0x33, 0x3F, 0x49, 0x54,
137 146
 		0x5C, 0x64, 0x6D, 0x74, 0x7B, 0x7F, 0x84, 0x89, 0x8F
... ...
@@ -158,7 +167,7 @@ inline int Cnv_Fall(int fall)
158 167
 
159 168
 inline int Cnv_Scale(int scale)
160 169
 {
161
-	static const int16_t lut[] =
170
+	static const std::int16_t lut[] =
162 171
 	{
163 172
 		-32768, -421, -361, -325, -300, -281, -265, -252,
164 173
 		-240, -230, -221, -212, -205, -198, -192, -186,
... ...
@@ -185,7 +194,7 @@ inline int Cnv_Scale(int scale)
185 194
 
186 195
 inline int Cnv_Sust(int sust)
187 196
 {
188
-	static const int16_t lut[] =
197
+	static const std::int16_t lut[] =
189 198
 	{
190 199
 		-32768, -722, -721, -651, -601, -562, -530, -503,
191 200
 		-480, -460, -442, -425, -410, -396, -383, -371,
... ...
@@ -212,12 +221,12 @@ inline int Cnv_Sust(int sust)
212 221
 
213 222
 inline int Cnv_Sine(int arg)
214 223
 {
215
-	static const int8_t lut[] =
224
+	static const std::int8_t lut[] =
216 225
 	{
217 226
 		0, 6, 12, 19, 25, 31, 37, 43, 49, 54, 60, 65, 71, 76, 81, 85, 90, 94,
218 227
 		98, 102, 106, 109, 112, 115, 117, 120, 122, 123, 125, 126, 126, 127, 127
219 228
 	};
220
-	static const int lut_size = sizeof(lut) / sizeof(int8_t);
229
+	static const int lut_size = sizeof(lut) / sizeof(std::int8_t);
221 230
 
222 231
 	if (arg < lut_size)
223 232
 		return lut[arg];
... ...
@@ -229,7 +238,7 @@ inline int Cnv_Sine(int arg)
229 238
 	return -lut[4 * lut_size - arg];
230 239
 }
231 240
 
232
-inline int read8(const uint8_t **ppData)
241
+inline int read8(const std::uint8_t **ppData)
233 242
 {
234 243
 	auto pData = *ppData;
235 244
 	int x = *pData;
... ...
@@ -237,14 +246,14 @@ inline int read8(const uint8_t **ppData)
237 246
 	return x;
238 247
 }
239 248
 
240
-inline int read16(const uint8_t **ppData)
249
+inline int read16(const std::uint8_t **ppData)
241 250
 {
242 251
 	int x = read8(ppData);
243 252
 	x |= read8(ppData) << 8;
244 253
 	return x;
245 254
 }
246 255
 
247
-inline int read24(const uint8_t **ppData)
256
+inline int read24(const std::uint8_t **ppData)
248 257
 {
249 258
 	int x = read8(ppData);
250 259
 	x |= read8(ppData) << 8;
... ...
@@ -252,7 +261,7 @@ inline int read24(const uint8_t **ppData)
252 261
 	return x;
253 262
 }
254 263
 
255
-inline int readvl(const uint8_t **ppData)
264
+inline int readvl(const std::uint8_t **ppData)
256 265
 {
257 266
 	int x = 0;
258 267
 	for (;;)
Browse code

Replaced the SDAT record types enum with constants.

Naram Qashat authored on 2021/03/21 00:45:12
Showing 1 changed files
... ...
@@ -111,17 +111,14 @@ template<typename T> inline std::string NumToHexString(const T &num)
111 111
  * List of types taken from the Nitro Composer Specification
112 112
  * http://www.feshrine.net/hacking/doc/nds-sdat.html
113 113
  */
114
-enum RecordName
115
-{
116
-	REC_SEQ,
117
-	REC_SEQARC,
118
-	REC_BANK,
119
-	REC_WAVEARC,
120
-	REC_PLAYER,
121
-	REC_GROUP,
122
-	REC_PLAYER2,
123
-	REC_STRM
124
-};
114
+inline constexpr int REC_SEQ = 0;
115
+inline constexpr int REC_SEQARC = 1;
116
+inline constexpr int REC_BANK = 2;
117
+inline constexpr int REC_WAVEARC = 3;
118
+inline constexpr int REC_PLAYER = 4;
119
+inline constexpr int REC_GROUP = 5;
120
+inline constexpr int REC_PLAYER2 = 6;
121
+inline constexpr int REC_STRM = 7;
125 122
 
126 123
 template<size_t N> inline bool VerifyHeader(int8_t (&arr)[N], const std::string &header)
127 124
 {
Browse code

Cleanup a few comments and strings.

Naram Qashat authored on 2021/03/20 20:25:12
Showing 1 changed files
... ...
@@ -17,7 +17,6 @@
17 17
 /*
18 18
  * Pseudo-file data structure
19 19
  */
20
-
21 20
 struct PseudoFile
22 21
 {
23 22
 	std::vector<uint8_t> *data;
... ...
@@ -90,8 +89,8 @@ template<typename T> inline T ReadLE(const uint8_t *arr)
90 89
 }
91 90
 
92 91
 /*
93
- * The following function is used to convert an integer into a hexidecimal
94
- * string, the length being determined by the size of the integer.  8-bit
92
+ * The following function is used to convert an integer into a hexadecimal
93
+ * string, the length being determined by the size of the integer. 8-bit
95 94
  * integers are in the format of 0x00, 16-bit integers are in the format of
96 95
  * 0x0000, and so on.
97 96
  */
Browse code

Replace memcpy/memset with std::copy_n/std::fill_n.

Naram Qashat authored on 2021/03/19 16:25:21
Showing 1 changed files
... ...
@@ -43,7 +43,7 @@ struct PseudoFile
43 43
 
44 44
 	template<size_t N> void ReadLE(uint8_t arr[N])
45 45
 	{
46
-		memcpy(&arr[0], &(*this->data)[this->pos], N);
46
+		std::copy_n(&(*this->data)[this->pos], N, &arr[0]);
47 47
 		this->pos += N;
48 48
 	}
49 49
 
... ...
@@ -55,7 +55,7 @@ struct PseudoFile
55 55
 
56 56
 	void ReadLE(std::vector<uint8_t> &arr)
57 57
 	{
58
-		memcpy(&arr[0], &(*this->data)[this->pos], arr.size());
58
+		std::copy_n(&(*this->data)[this->pos], arr.size(), &arr[0]);
59 59
 		this->pos += arr.size();
60 60
 	}
61 61
 
Browse code

Remove last modification date from files.

(I never remember to update these and besides, GitHub history can show when they were last modified.)

Naram Qashat authored on 2021/03/19 10:58:12
Showing 1 changed files
... ...
@@ -1,7 +1,6 @@
1 1
 /*
2 2
  * SSEQ Player - Common functions
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-10-18
5 4
  *
6 5
  * Some code from FeOS Sound System
7 6
  * By fincs
Browse code

[NCSF] Super minor cleanups.

Naram Qashat authored on 2020/08/07 23:25:58
Showing 1 changed files
... ...
@@ -42,7 +42,7 @@ struct PseudoFile
42 42
 			arr[i] = this->ReadLE<T>();
43 43
 	}
44 44
 
45
-	template<size_t N> void ReadLE( uint8_t arr[N])
45
+	template<size_t N> void ReadLE(uint8_t arr[N])
46 46
 	{
47 47
 		memcpy(&arr[0], &(*this->data)[this->pos], N);
48 48
 		this->pos += N;
... ...
@@ -217,12 +217,12 @@ inline int Cnv_Sust(int sust)
217 217
 
218 218
 inline int Cnv_Sine(int arg)
219 219
 {
220
-	static const int lut_size = 32;
221 220
 	static const int8_t lut[] =
222 221
 	{
223 222
 		0, 6, 12, 19, 25, 31, 37, 43, 49, 54, 60, 65, 71, 76, 81, 85, 90, 94,
224 223
 		98, 102, 106, 109, 112, 115, 117, 120, 122, 123, 125, 126, 126, 127, 127
225 224
 	};
225
+	static const int lut_size = sizeof(lut) / sizeof(int8_t);
226 226
 
227 227
 	if (arg < lut_size)
228 228
 		return lut[arg];
Browse code

[NCSF] Correctly handle the SSEQ volume from the INFO block.

Naram Qashat authored on 2014/10/18 04:20:53
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * SSEQ Player - Common functions
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-10-05
4
+ * Last modification on 2014-10-18
5 5
  *
6 6
  * Some code from FeOS Sound System
7 7
  * By fincs
... ...
@@ -161,6 +161,33 @@ inline int Cnv_Fall(int fall)
161 161
 		return (0x1E00 / (0x7E - fall)) & 0xFFFF;
162 162
 }
163 163
 
164
+inline int Cnv_Scale(int scale)
165
+{
166
+	static const int16_t lut[] =
167
+	{
168
+		-32768, -421, -361, -325, -300, -281, -265, -252,
169
+		-240, -230, -221, -212, -205, -198, -192, -186,
170
+		-180, -175, -170, -165, -161, -156, -152, -148,
171
+		-145, -141, -138, -134, -131, -128, -125, -122,
172
+		-120, -117, -114, -112, -110, -107, -105, -103,
173
+		-100, -98, -96, -94, -92, -90, -88, -86,
174
+		-85, -83, -81, -79, -78, -76, -74, -73,
175
+		-71, -70, -68, -67, -65, -64, -62, -61,
176
+		-60, -58, -57, -56, -54, -53, -52, -51,
177
+		-49, -48, -47, -46, -45, -43, -42, -41,
178
+		-40, -39, -38, -37, -36, -35, -34, -33,
179
+		-32, -31, -30, -29, -28, -27, -26, -25,
180
+		-24, -23, -23, -22, -21, -20, -19, -18,
181
+		-17, -17, -16, -15, -14, -13, -12, -12,
182
+		-11, -10, -9, -9, -8, -7, -6, -6,
183
+		-5, -4, -3, -3, -2, -1, -1, 0
184
+	};
185
+
186
+	if (scale & 0x80) // Supposedly invalid value...
187
+		scale = 0x7F; // Use apparently correct default
188
+	return lut[scale];
189
+}
190
+
164 191
 inline int Cnv_Sust(int sust)
165 192
 {
166 193
 	static const int16_t lut[] =
Browse code

[NCSF] Removed the Cnv_Scale function as it seemed to cause sounds to be too loud in some cases.

Naram Qashat authored on 2014/10/05 20:17:36
Showing 1 changed files
... ...
@@ -161,33 +161,6 @@ inline int Cnv_Fall(int fall)
161 161
 		return (0x1E00 / (0x7E - fall)) & 0xFFFF;
162 162
 }
163 163
 
164
-// This function actually doesn't come from FSS, I got the lookup table from the Nintendo DS SDK.
165
-inline int Cnv_Scale(int scale)
166
-{
167
-	static const int16_t lut[] =
168
-	{
169
-		-32768, -421, -361, -325, -300, -281, -265, -252,
170
-		-240, -230, -221, -212, -205, -198, -192, -186,
171
-		-180, -175, -170, -165, -161, -156, -152, -148,
172
-		-145, -141, -138, -134, -131, -128, -125, -122,
173
-		-120, -117, -114, -112, -110, -107, -105, -103,
174
-		-100, -98, -96, -94, -92, -90, -88, -86,
175
-		-85, -83, -81, -79, -78, -76, -74, -73,
176
-		-71, -70, -68, -67, -65, -64, -62, -61,
177
-		-60, -58, -57, -56, -54, -53, -52, -51,
178
-		-49, -48, -47, -46, -45, -43, -42, -41,
179
-		-40, -39, -38, -37, -36, -35, -34, -33,
180
-		-32, -31, -30, -29, -28, -27, -26, -25,
181
-		-24, -23, -23, -22, -21, -20, -19, -18,
182
-		-17, -17, -16, -15, -14, -13, -12, -12,
183
-		-11, -10, -9, -9, -8, -7, -6, -6,
184
-		-5, -4, -3, -3, -2, -1, -1, 0
185
-	};
186
-	if (scale & 0x80)
187
-		scale = 0x7F;
188
-	return lut[scale];
189
-}
190
-
191 164
 inline int Cnv_Sust(int sust)
192 165
 {
193 166
 	static const int16_t lut[] =
Browse code

[NCSF] Fix volume issues with a little help from the Nintendo DS SDK.

Also added a clone of DeSmuME's Sound View that is only build during a
debug build, which helped to identify the above issues.

Naram Qashat authored on 2014/10/05 20:00:09
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * SSEQ Player - Common functions
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-08
4
+ * Last modification on 2014-10-05
5 5
  *
6 6
  * Some code from FeOS Sound System
7 7
  * By fincs
... ...
@@ -161,6 +161,33 @@ inline int Cnv_Fall(int fall)
161 161
 		return (0x1E00 / (0x7E - fall)) & 0xFFFF;
162 162
 }
163 163
 
164
+// This function actually doesn't come from FSS, I got the lookup table from the Nintendo DS SDK.
165
+inline int Cnv_Scale(int scale)
166
+{
167
+	static const int16_t lut[] =
168
+	{
169
+		-32768, -421, -361, -325, -300, -281, -265, -252,
170
+		-240, -230, -221, -212, -205, -198, -192, -186,
171
+		-180, -175, -170, -165, -161, -156, -152, -148,
172
+		-145, -141, -138, -134, -131, -128, -125, -122,
173
+		-120, -117, -114, -112, -110, -107, -105, -103,
174
+		-100, -98, -96, -94, -92, -90, -88, -86,
175
+		-85, -83, -81, -79, -78, -76, -74, -73,
176
+		-71, -70, -68, -67, -65, -64, -62, -61,
177
+		-60, -58, -57, -56, -54, -53, -52, -51,
178
+		-49, -48, -47, -46, -45, -43, -42, -41,
179
+		-40, -39, -38, -37, -36, -35, -34, -33,
180
+		-32, -31, -30, -29, -28, -27, -26, -25,
181
+		-24, -23, -23, -22, -21, -20, -19, -18,
182
+		-17, -17, -16, -15, -14, -13, -12, -12,
183
+		-11, -10, -9, -9, -8, -7, -6, -6,
184
+		-5, -4, -3, -3, -2, -1, -1, 0
185
+	};
186
+	if (scale & 0x80)
187
+		scale = 0x7F;
188
+	return lut[scale];
189
+}
190
+
164 191
 inline int Cnv_Sust(int sust)
165 192
 {
166 193
 	static const int16_t lut[] =
... ...
@@ -184,7 +211,7 @@ inline int Cnv_Sust(int sust)
184 211
 	};
185 212
 
186 213
 	if (sust & 0x80) // Supposedly invalid value...
187
-		sust = 0; // Use apparently correct default
214
+		sust = 0x7F; // Use apparently correct default
188 215
 	return lut[sust];
189 216
 }
190 217
 
Browse code

Use #pragma once instead of include guards.

Naram Qashat authored on 2014/09/08 14:47:36
Showing 1 changed files
... ...
@@ -1,15 +1,14 @@
1 1
 /*
2 2
  * SSEQ Player - Common functions
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-05-01
4
+ * Last modification on 2014-09-08
5 5
  *
6 6
  * Some code from FeOS Sound System
7 7
  * By fincs
8 8
  * https://github.com/fincs/FSS
9 9
  */
10 10
 
11
-#ifndef SSEQPLAYER_COMMON_H
12
-#define SSEQPLAYER_COMMON_H
11
+#pragma once
13 12
 
14 13
 #include <string>
15 14
 #include <vector>
... ...
@@ -243,5 +242,3 @@ inline int readvl(const uint8_t **ppData)
243 242
 	}
244 243
 	return x;
245 244
 }
246
-
247
-#endif
Browse code

Update from FSS commits 39e6fa8 and 5204c55, guards ADSR against invalid values, these may not be 100% correct but they currently work as is.

Naram Qashat authored on 2013/05/01 23:08:02
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * SSEQ Player - Common functions
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-04-23
4
+ * Last modification on 2013-05-01
5 5
  *
6 6
  * Some code from FeOS Sound System
7 7
  * By fincs
... ...
@@ -143,11 +143,15 @@ inline int Cnv_Attack(int attk)
143 143
 		0x5C, 0x64, 0x6D, 0x74, 0x7B, 0x7F, 0x84, 0x89, 0x8F
144 144
 	};
145 145
 
146
+	if (attk & 0x80) // Supposedly invalid value...
147
+		attk = 0; // Use apparently correct default
146 148
 	return attk >= 0x6D ? lut[0x7F - attk] : 0xFF - attk;
147 149
 }
148 150
 
149 151
 inline int Cnv_Fall(int fall)
150 152
 {
153
+	if (fall & 0x80) // Supposedly invalid value...
154
+		fall = 0; // Use apparently correct default
151 155
 	if (fall == 0x7F)
152 156
 		return 0xFFFF;
153 157
 	else if (fall == 0x7E)
... ...
@@ -180,6 +184,8 @@ inline int Cnv_Sust(int sust)
180 184
 		-10, -8, -7, -6, -4, -3, -1, 0
181 185
 	};
182 186
 
187
+	if (sust & 0x80) // Supposedly invalid value...
188
+		sust = 0; // Use apparently correct default
183 189
 	return lut[sust];
184 190
 }
185 191
 
Browse code

Added Lanczos interpolation to the NCSF plugin, and cleaned up a bit of the other code, as well as removing pstdint.h since it's no longer needed.

Naram Qashat authored on 2013/04/23 20:29:21
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * SSEQ Player - Common functions
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-03-3
4
+ * Last modification on 2013-04-23
5 5
  *
6 6
  * Some code from FeOS Sound System
7 7
  * By fincs
... ...
@@ -14,7 +14,7 @@
14 14
 #include <string>
15 15
 #include <vector>
16 16
 #include <cstring>
17
-#include "pstdint.h"
17
+#include <cstdint>
18 18
 
19 19
 /*
20 20
  * Pseudo-file data structure
Browse code

Cleanup of some warnings, updating modification dates, using nullptr instead of NULL in some cases.

Naram Qashat authored on 2013/03/30 16:17:42
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * SSEQ Player - Common functions
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-03-25
4
+ * Last modification on 2013-03-3
5 5
  *
6 6
  * Some code from FeOS Sound System
7 7
  * By fincs
... ...
@@ -25,7 +25,7 @@ struct PseudoFile
25 25
 	std::vector<uint8_t> *data;
26 26
 	uint32_t pos;
27 27
 
28
-	PseudoFile() : data(NULL), pos(0)
28
+	PseudoFile() : data(nullptr), pos(0)
29 29
 	{
30 30
 	}
31 31
 
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,241 @@
1
+/*
2
+ * SSEQ Player - Common functions
3
+ * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
+ * Last modification on 2013-03-25
5
+ *
6
+ * Some code from FeOS Sound System
7
+ * By fincs
8
+ * https://github.com/fincs/FSS
9
+ */
10
+
11
+#ifndef SSEQPLAYER_COMMON_H
12
+#define SSEQPLAYER_COMMON_H
13
+
14
+#include <string>
15
+#include <vector>
16
+#include <cstring>
17
+#include "pstdint.h"
18
+
19
+/*
20
+ * Pseudo-file data structure
21
+ */
22
+
23
+struct PseudoFile
24
+{
25
+	std::vector<uint8_t> *data;
26
+	uint32_t pos;
27
+
28
+	PseudoFile() : data(NULL), pos(0)
29
+	{
30
+	}
31
+
32
+	template<typename T> T ReadLE()
33
+	{
34
+		T finalVal = 0;
35
+		for (size_t i = 0; i < sizeof(T); ++i)
36
+			finalVal |= (*this->data)[this->pos++] << (i * 8);
37
+		return finalVal;
38
+	}
39
+
40
+	template<typename T, size_t N> void ReadLE(T (&arr)[N])
41
+	{
42
+		for (size_t i = 0; i < N; ++i)
43
+			arr[i] = this->ReadLE<T>();
44
+	}
45
+
46
+	template<size_t N> void ReadLE( uint8_t arr[N])
47
+	{
48
+		memcpy(&arr[0], &(*this->data)[this->pos], N);
49
+		this->pos += N;
50
+	}
51
+
52
+	template<typename T> void ReadLE(std::vector<T> &arr)
53
+	{
54
+		for (size_t i = 0, len = arr.size(); i < len; ++i)
55
+			arr[i] = this->ReadLE<T>();
56
+	}
57
+
58
+	void ReadLE(std::vector<uint8_t> &arr)
59
+	{
60
+		memcpy(&arr[0], &(*this->data)[this->pos], arr.size());
61
+		this->pos += arr.size();
62
+	}
63
+
64
+	std::string ReadNullTerminatedString()
65
+	{
66
+		char chr;
67
+		std::string str;
68
+		do
69
+		{
70
+			chr = static_cast<char>(this->ReadLE<uint8_t>());
71
+			if (chr)
72
+				str += chr;
73
+		} while (chr);
74
+		return str;
75
+	}
76
+};
77
+
78
+/*
79
+ * Data Reading
80
+ *
81
+ * The following ReadLE functions will either read from a file or from an
82
+ * array (sent in as a pointer), while making sure that the data is read in
83
+ * as little-endian formating.
84
+ */
85
+
86
+template<typename T> inline T ReadLE(const uint8_t *arr)
87
+{
88
+	T finalVal = 0;
89
+	for (size_t i = 0; i < sizeof(T); ++i)
90
+		finalVal |= arr[i] << (i * 8);
91
+	return finalVal;
92
+}
93
+
94
+/*
95
+ * The following function is used to convert an integer into a hexidecimal
96
+ * string, the length being determined by the size of the integer.  8-bit
97
+ * integers are in the format of 0x00, 16-bit integers are in the format of
98
+ * 0x0000, and so on.
99
+ */
100
+template<typename T> inline std::string NumToHexString(const T &num)
101
+{
102
+	std::string hex;
103
+	uint8_t len = sizeof(T) * 2;
104
+	for (uint8_t i = 0; i < len; ++i)
105
+	{
106
+		uint8_t tmp = (num >> (i * 4)) & 0xF;
107
+		hex = static_cast<char>(tmp < 10 ? tmp + '0' : tmp - 10 + 'a') + hex;
108
+	}
109
+	return "0x" + hex;
110
+}
111
+
112
+/*
113
+ * SDAT Record types
114
+ * List of types taken from the Nitro Composer Specification
115
+ * http://www.feshrine.net/hacking/doc/nds-sdat.html
116
+ */
117
+enum RecordName
118
+{
119
+	REC_SEQ,
120
+	REC_SEQARC,
121
+	REC_BANK,
122
+	REC_WAVEARC,
123
+	REC_PLAYER,
124
+	REC_GROUP,
125
+	REC_PLAYER2,
126
+	REC_STRM
127
+};
128
+
129
+template<size_t N> inline bool VerifyHeader(int8_t (&arr)[N], const std::string &header)
130
+{
131
+	std::string arrHeader = std::string(&arr[0], &arr[N]);
132
+	return arrHeader == header;
133
+}
134
+
135
+/*
136
+ * The remaining functions in this file come from the FeOS Sound System source code.
137
+ */
138
+inline int Cnv_Attack(int attk)
139
+{
140
+	static const uint8_t lut[] =
141
+	{
142
+		0x00, 0x01, 0x05, 0x0E, 0x1A, 0x26, 0x33, 0x3F, 0x49, 0x54,
143
+		0x5C, 0x64, 0x6D, 0x74, 0x7B, 0x7F, 0x84, 0x89, 0x8F
144
+	};
145
+
146
+	return attk >= 0x6D ? lut[0x7F - attk] : 0xFF - attk;
147
+}
148
+
149
+inline int Cnv_Fall(int fall)
150
+{
151
+	if (fall == 0x7F)
152
+		return 0xFFFF;
153
+	else if (fall == 0x7E)
154
+		return 0x3C00;
155
+	else if (fall < 0x32)
156
+		return ((fall << 1) + 1) & 0xFFFF;
157
+	else
158
+		return (0x1E00 / (0x7E - fall)) & 0xFFFF;
159
+}
160
+
161
+inline int Cnv_Sust(int sust)
162
+{
163
+	static const int16_t lut[] =
164
+	{
165
+		-32768, -722, -721, -651, -601, -562, -530, -503,
166
+		-480, -460, -442, -425, -410, -396, -383, -371,
167
+		-360, -349, -339, -330, -321, -313, -305, -297,
168
+		-289, -282, -276, -269, -263, -257, -251, -245,
169
+		-239, -234, -229, -224, -219, -214, -210, -205,
170
+		-201, -196, -192, -188, -184, -180, -176, -173,
171
+		-169, -165, -162, -158, -155, -152, -149, -145,
172
+		-142, -139, -136, -133, -130, -127, -125, -122,
173
+		-119, -116, -114, -111, -109, -106, -103, -101,
174
+		-99, -96, -94, -91, -89, -87, -85, -82,
175
+		-80, -78, -76, -74, -72, -70, -68, -66,
176
+		-64, -62, -60, -58, -56, -54, -52, -50,
177
+		-49, -47, -45, -43, -42, -40, -38, -36,
178
+		-35, -33, -31, -30, -28, -27, -25, -23,
179
+		-22, -20, -19, -17, -16, -14, -13, -11,
180
+		-10, -8, -7, -6, -4, -3, -1, 0
181
+	};
182
+
183
+	return lut[sust];
184
+}
185
+
186
+inline int Cnv_Sine(int arg)
187
+{
188
+	static const int lut_size = 32;
189
+	static const int8_t lut[] =
190
+	{
191
+		0, 6, 12, 19, 25, 31, 37, 43, 49, 54, 60, 65, 71, 76, 81, 85, 90, 94,
192
+		98, 102, 106, 109, 112, 115, 117, 120, 122, 123, 125, 126, 126, 127, 127
193
+	};
194
+
195
+	if (arg < lut_size)
196
+		return lut[arg];
197
+	if (arg < 2 * lut_size)
198
+		return lut[2 * lut_size - arg];
199
+	if (arg < 3 * lut_size)
200
+		return -lut[arg - 2 * lut_size];
201
+	/*else*/
202
+	return -lut[4 * lut_size - arg];
203
+}
204
+
205
+inline int read8(const uint8_t **ppData)
206
+{
207
+	auto pData = *ppData;
208
+	int x = *pData;
209
+	*ppData = pData + 1;
210
+	return x;
211
+}
212
+
213
+inline int read16(const uint8_t **ppData)
214
+{
215
+	int x = read8(ppData);
216
+	x |= read8(ppData) << 8;
217
+	return x;
218
+}
219
+
220
+inline int read24(const uint8_t **ppData)
221
+{
222
+	int x = read8(ppData);
223
+	x |= read8(ppData) << 8;
224
+	x |= read8(ppData) << 16;
225
+	return x;
226
+}
227
+
228
+inline int readvl(const uint8_t **ppData)
229
+{
230
+	int x = 0;
231
+	for (;;)
232
+	{
233
+		int data = read8(ppData);
234
+		x = (x << 7) | (data & 0x7F);
235
+		if (!(data & 0x80))
236
+			break;
237
+	}
238
+	return x;
239
+}
240
+
241
+#endif