Browse code

Port: Add override keyword.

Clarissa Walker authored on 2024/09/16 22:14:51
Showing 1 changed files
... ...
@@ -38,10 +38,10 @@ class XSFPlayer_SNSF : public XSFPlayer
38 38
 {
39 39
 public:
40 40
 	XSFPlayer_SNSF(const std::filesystem::path &path);
41
-	~XSFPlayer_SNSF() { this->Terminate(); }
42
-	bool Load();
43
-	void GenerateSamples(std::vector<std::uint8_t> &buf, unsigned offset, unsigned samples);
44
-	void Terminate();
41
+	~XSFPlayer_SNSF() override { this->Terminate(); }
42
+	bool Load() override;
43
+	void GenerateSamples(std::vector<std::uint8_t> &buf, unsigned offset, unsigned samples) override;
44
+	void Terminate() override;
45 45
 };
46 46
 
47 47
 const char *XSFPlayer::WinampDescription = "SNSF Decoder";
Browse code

Port: Use std::filesystem::path for reading/writing files. - before override

Clarissa Walker authored on 2024/08/22 20:57:20
Showing 1 changed files
... ...
@@ -37,10 +37,7 @@
37 37
 class XSFPlayer_SNSF : public XSFPlayer
38 38
 {
39 39
 public:
40
-	XSFPlayer_SNSF(const std::string &filename);
41
-#ifdef _WIN32
42
-	XSFPlayer_SNSF(const std::wstring &filename);
43
-#endif
40
+	XSFPlayer_SNSF(const std::filesystem::path &path);
44 41
 	~XSFPlayer_SNSF() { this->Terminate(); }
45 42
 	bool Load();
46 43
 	void GenerateSamples(std::vector<std::uint8_t> &buf, unsigned offset, unsigned samples);
... ...
@@ -52,18 +49,11 @@ const char *XSFPlayer::WinampExts = "snsf;minisnsf\0SNES Sound Format files (*.s
52 49
 
53 50
 extern XSFConfig *xSFConfig;
54 51
 
55
-XSFPlayer *XSFPlayer::Create(const std::string &fn)
52
+XSFPlayer *XSFPlayer::Create(const std::filesystem::path &path)
56 53
 {
57
-	return new XSFPlayer_SNSF(fn);
54
+	return new XSFPlayer_SNSF(path);
58 55
 }
59 56
 
60
-#ifdef _WIN32
61
-XSFPlayer *XSFPlayer::Create(const std::wstring &fn)
62
-{
63
-	return new XSFPlayer_SNSF(fn);
64
-}
65
-#endif
66
-
67 57
 static struct
68 58
 {
69 59
 	std::vector<std::uint8_t> rom, sram;
... ...
@@ -172,11 +162,7 @@ static bool RecursiveLoadSNSF(XSFFile *xSF, int level)
172 162
 {
173 163
 	if (level <= 10 && xSF->GetTagExists("_lib"))
174 164
 	{
175
-#ifdef _WIN32
176
-		auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSF->GetFilename()).parent_path() / xSF->GetTagValue("_lib")).wstring(), 4, 8);
177
-#else
178
-		auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSF->GetFilename()).parent_path() / xSF->GetTagValue("_lib")).string(), 4, 8);
179
-#endif
165
+		auto libxSF = std::make_unique<XSFFile>(xSF->GetFilepath().parent_path() / xSF->GetTagValue("_lib"), 4, 8);
180 166
 		if (!RecursiveLoadSNSF(libxSF.get(), level + 1))
181 167
 			return false;
182 168
 	}
... ...
@@ -193,11 +179,7 @@ static bool RecursiveLoadSNSF(XSFFile *xSF, int level)
193 179
 		if (xSF->GetTagExists(libTag))
194 180
 		{
195 181
 			found = true;
196
-#ifdef _WIN32
197
-			auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSF->GetFilename()).parent_path() / xSF->GetTagValue(libTag)).wstring(), 4, 8);
198
-#else
199
-			auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSF->GetFilename()).parent_path() / xSF->GetTagValue(libTag)).string(), 4, 8);
200
-#endif
182
+			auto libxSF = std::make_unique<XSFFile>(xSF->GetFilepath().parent_path() / xSF->GetTagValue(libTag), 4, 8);
201 183
 			if (!RecursiveLoadSNSF(libxSF.get(), level + 1))
202 184
 				return false;
203 185
 		}
... ...
@@ -216,17 +198,10 @@ static bool LoadSNSF(XSFFile *xSF)
216 198
 	return RecursiveLoadSNSF(xSF, 1);
217 199
 }
218 200
 
219
-XSFPlayer_SNSF::XSFPlayer_SNSF(const std::string &filename) : XSFPlayer()
220
-{
221
-	this->xSF.reset(new XSFFile(filename, 4, 8));
222
-}
223
-
224
-#ifdef _WIN32
225
-XSFPlayer_SNSF::XSFPlayer_SNSF(const std::wstring &filename) : XSFPlayer()
201
+XSFPlayer_SNSF::XSFPlayer_SNSF(const std::filesystem::path &path) : XSFPlayer()
226 202
 {
227
-	this->xSF.reset(new XSFFile(filename, 4, 8));
203
+	this->xSF.reset(new XSFFile(path, 4, 8));
228 204
 }
229
-#endif
230 205
 
231 206
 bool XSFPlayer_SNSF::Load()
232 207
 {
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
... ...
@@ -11,12 +11,17 @@
11 11
  * http://www.snes9x.com/
12 12
  */
13 13
 
14
+#include <algorithm>
14 15
 #include <filesystem>
16
+#include <memory>
17
+#include <string>
18
+#include <vector>
19
+#include <cstddef>
20
+#include <cstdint>
15 21
 #include <zlib.h>
16
-#include "convert.h"
17
-#include "XSFPlayer.h"
18
-#include "XSFConfig_SNSF.h"
19 22
 #include "XSFCommon.h"
23
+#include "XSFConfig_SNSF.h"
24
+#include "XSFPlayer.h"
20 25
 
21 26
 #undef min
22 27
 #undef max
... ...
@@ -38,7 +43,7 @@ public:
38 43
 #endif
39 44
 	~XSFPlayer_SNSF() { this->Terminate(); }
40 45
 	bool Load();
41
-	void GenerateSamples(std::vector<uint8_t> &buf, unsigned offset, unsigned samples);
46
+	void GenerateSamples(std::vector<std::uint8_t> &buf, unsigned offset, unsigned samples);
42 47
 	void Terminate();
43 48
 };
44 49
 
... ...
@@ -61,15 +66,15 @@ XSFPlayer *XSFPlayer::Create(const std::wstring &fn)
61 66
 
62 67
 static struct
63 68
 {
64
-	std::vector<uint8_t> rom, sram;
69
+	std::vector<std::uint8_t> rom, sram;
65 70
 	bool first;
66 71
 	unsigned base;
67
-} loaderwork = { std::vector<uint8_t>(), std::vector<uint8_t>(), false, 0 };
72
+} loaderwork = { std::vector<std::uint8_t>(), std::vector<std::uint8_t>(), false, 0 };
68 73
 
69 74
 class BUFFER
70 75
 {
71 76
 public:
72
-	std::vector<uint8_t> buf;
77
+	std::vector<std::uint8_t> buf;
73 78
 	unsigned fil, cur, len;
74 79
 	BUFFER() : buf(), fil(0), cur(0), len(0) { }
75 80
 	bool Init()
... ...
@@ -107,11 +112,11 @@ bool S9xOpenSoundDevice()
107 112
 	return true;
108 113
 }
109 114
 
110
-static void MapSNSFSection(const std::vector<uint8_t> &section)
115
+static void MapSNSFSection(const std::vector<std::uint8_t> &section)
111 116
 {
112 117
 	auto &data = loaderwork.rom;
113 118
 
114
-	uint32_t offset = Get32BitsLE(&section[0]), size = Get32BitsLE(&section[4]), finalSize = size + offset;
119
+	std::uint32_t offset = Get32BitsLE(&section[0]), size = Get32BitsLE(&section[4]), finalSize = size + offset;
115 120
 	if (!loaderwork.first)
116 121
 	{
117 122
 		loaderwork.first = true;
... ...
@@ -136,17 +141,17 @@ static bool MapSNSF(XSFFile *xSF)
136 141
 
137 142
 	if (!reservedSection.empty())
138 143
 	{
139
-		size_t reservedPosition = 0, reservedSize = reservedSection.size();
144
+		std::size_t reservedPosition = 0, reservedSize = reservedSection.size();
140 145
 		while (reservedPosition + 8 < reservedSize)
141 146
 		{
142
-			uint32_t type = Get32BitsLE(&reservedSection[reservedPosition]), size = Get32BitsLE(&reservedSection[reservedPosition + 4]);
147
+			std::uint32_t type = Get32BitsLE(&reservedSection[reservedPosition]), size = Get32BitsLE(&reservedSection[reservedPosition + 4]);
143 148
 			if (!type)
144 149
 			{
145 150
 				if (loaderwork.sram.empty())
146 151
 					loaderwork.sram.resize(0x20000, 0xFF);
147 152
 				if (reservedPosition + 8 + size > reservedSize)
148 153
 					return false;
149
-				uint32_t offset = Get32BitsLE(&reservedSection[reservedPosition + 8]);
154
+				std::uint32_t offset = Get32BitsLE(&reservedSection[reservedPosition + 8]);
150 155
 				if (size > 4 && loaderwork.sram.size() > offset)
151 156
 				{
152 157
 					auto len = std::min(size - 4, loaderwork.sram.size() - offset);
... ...
@@ -264,7 +269,7 @@ bool XSFPlayer_SNSF::Load()
264 269
 	return XSFPlayer::Load();
265 270
 }
266 271
 
267
-void XSFPlayer_SNSF::GenerateSamples(std::vector<uint8_t> &buf, unsigned offset, unsigned samples)
272
+void XSFPlayer_SNSF::GenerateSamples(std::vector<std::uint8_t> &buf, unsigned offset, unsigned samples)
268 273
 {
269 274
 	unsigned bytes = samples << 2;
270 275
 	while (bytes)
Browse code

Correct a few warnings Visual Studio was complaining about.

Naram Qashat authored on 2021/03/20 20:40:21
Showing 1 changed files
... ...
@@ -64,7 +64,7 @@ static struct
64 64
 	std::vector<uint8_t> rom, sram;
65 65
 	bool first;
66 66
 	unsigned base;
67
-} loaderwork;
67
+} loaderwork = { std::vector<uint8_t>(), std::vector<uint8_t>(), false, 0 };
68 68
 
69 69
 class BUFFER
70 70
 {
Browse code

Use C++17 std::filesystem functions instead of my own.

Naram Qashat authored on 2021/03/20 20:05:50
Showing 1 changed files
... ...
@@ -11,6 +11,7 @@
11 11
  * http://www.snes9x.com/
12 12
  */
13 13
 
14
+#include <filesystem>
14 15
 #include <zlib.h>
15 16
 #include "convert.h"
16 17
 #include "XSFPlayer.h"
... ...
@@ -167,9 +168,9 @@ static bool RecursiveLoadSNSF(XSFFile *xSF, int level)
167 168
 	if (level <= 10 && xSF->GetTagExists("_lib"))
168 169
 	{
169 170
 #ifdef _WIN32
170
-		auto libxSF = std::make_unique<XSFFile>(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue("_lib")), 4, 8);
171
+		auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSF->GetFilename()).parent_path() / xSF->GetTagValue("_lib")).wstring(), 4, 8);
171 172
 #else
172
-		auto libxSF = std::make_unique<XSFFile>(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue("_lib"), 4, 8);
173
+		auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSF->GetFilename()).parent_path() / xSF->GetTagValue("_lib")).string(), 4, 8);
173 174
 #endif
174 175
 		if (!RecursiveLoadSNSF(libxSF.get(), level + 1))
175 176
 			return false;
... ...
@@ -188,9 +189,9 @@ static bool RecursiveLoadSNSF(XSFFile *xSF, int level)
188 189
 		{
189 190
 			found = true;
190 191
 #ifdef _WIN32
191
-			auto libxSF = std::make_unique<XSFFile>(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue(libTag)), 4, 8);
192
+			auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSF->GetFilename()).parent_path() / xSF->GetTagValue(libTag)).wstring(), 4, 8);
192 193
 #else
193
-			auto libxSF = std::make_unique<XSFFile>(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue(libTag), 4, 8);
194
+			auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSF->GetFilename()).parent_path() / xSF->GetTagValue(libTag)).string(), 4, 8);
194 195
 #endif
195 196
 			if (!RecursiveLoadSNSF(libxSF.get(), level + 1))
196 197
 				return false;
Browse code

Use std::make_unique where possible.

Naram Qashat authored on 2021/03/20 04:37:08
Showing 1 changed files
... ...
@@ -167,9 +167,9 @@ static bool RecursiveLoadSNSF(XSFFile *xSF, int level)
167 167
 	if (level <= 10 && xSF->GetTagExists("_lib"))
168 168
 	{
169 169
 #ifdef _WIN32
170
-		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue("_lib")), 4, 8));
170
+		auto libxSF = std::make_unique<XSFFile>(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue("_lib")), 4, 8);
171 171
 #else
172
-		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue("_lib"), 4, 8));
172
+		auto libxSF = std::make_unique<XSFFile>(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue("_lib"), 4, 8);
173 173
 #endif
174 174
 		if (!RecursiveLoadSNSF(libxSF.get(), level + 1))
175 175
 			return false;
... ...
@@ -188,9 +188,9 @@ static bool RecursiveLoadSNSF(XSFFile *xSF, int level)
188 188
 		{
189 189
 			found = true;
190 190
 #ifdef _WIN32
191
-			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue(libTag)), 4, 8));
191
+			auto libxSF = std::make_unique<XSFFile>(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue(libTag)), 4, 8);
192 192
 #else
193
-			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue(libTag), 4, 8));
193
+			auto libxSF = std::make_unique<XSFFile>(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue(libTag), 4, 8);
194 194
 #endif
195 195
 			if (!RecursiveLoadSNSF(libxSF.get(), level + 1))
196 196
 				return false;
Browse code

Correct typos in the function names in the loads of GSF and SNSF.

(This probably came about from copying the code from the 2SF player and not fixing the names.)

Naram Qashat authored on 2021/03/19 15:58:49
Showing 1 changed files
... ...
@@ -106,7 +106,7 @@ bool S9xOpenSoundDevice()
106 106
 	return true;
107 107
 }
108 108
 
109
-static void Map2SFSection(const std::vector<uint8_t> &section)
109
+static void MapSNSFSection(const std::vector<uint8_t> &section)
110 110
 {
111 111
 	auto &data = loaderwork.rom;
112 112
 
... ...
@@ -126,7 +126,7 @@ static void Map2SFSection(const std::vector<uint8_t> &section)
126 126
 	std::copy_n(&section[8], size, &data[offset]);
127 127
 }
128 128
 
129
-static bool Map2SF(XSFFile *xSF)
129
+static bool MapSNSF(XSFFile *xSF)
130 130
 {
131 131
 	if (!xSF->IsValidType(0x23))
132 132
 		return false;
... ...
@@ -157,12 +157,12 @@ static bool Map2SF(XSFFile *xSF)
157 157
 	}
158 158
 
159 159
 	if (!programSection.empty())
160
-		Map2SFSection(programSection);
160
+		MapSNSFSection(programSection);
161 161
 
162 162
 	return true;
163 163
 }
164 164
 
165
-static bool RecursiveLoad2SF(XSFFile *xSF, int level)
165
+static bool RecursiveLoadSNSF(XSFFile *xSF, int level)
166 166
 {
167 167
 	if (level <= 10 && xSF->GetTagExists("_lib"))
168 168
 	{
... ...
@@ -171,11 +171,11 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
171 171
 #else
172 172
 		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue("_lib"), 4, 8));
173 173
 #endif
174
-		if (!RecursiveLoad2SF(libxSF.get(), level + 1))
174
+		if (!RecursiveLoadSNSF(libxSF.get(), level + 1))
175 175
 			return false;
176 176
 	}
177 177
 
178
-	if (!Map2SF(xSF))
178
+	if (!MapSNSF(xSF))
179 179
 		return false;
180 180
 
181 181
 	unsigned n = 2;
... ...
@@ -192,7 +192,7 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
192 192
 #else
193 193
 			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue(libTag), 4, 8));
194 194
 #endif
195
-			if (!RecursiveLoad2SF(libxSF.get(), level + 1))
195
+			if (!RecursiveLoadSNSF(libxSF.get(), level + 1))
196 196
 				return false;
197 197
 		}
198 198
 	} while (found);
... ...
@@ -200,14 +200,14 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
200 200
 	return true;
201 201
 }
202 202
 
203
-static bool Load2SF(XSFFile *xSF)
203
+static bool LoadSNSF(XSFFile *xSF)
204 204
 {
205 205
 	loaderwork.rom.clear();
206 206
 	loaderwork.sram.clear();
207 207
 	loaderwork.first = false;
208 208
 	loaderwork.base = 0;
209 209
 
210
-	return RecursiveLoad2SF(xSF, 1);
210
+	return RecursiveLoadSNSF(xSF, 1);
211 211
 }
212 212
 
213 213
 XSFPlayer_SNSF::XSFPlayer_SNSF(const std::string &filename) : XSFPlayer()
... ...
@@ -224,7 +224,7 @@ XSFPlayer_SNSF::XSFPlayer_SNSF(const std::wstring &filename) : XSFPlayer()
224 224
 
225 225
 bool XSFPlayer_SNSF::Load()
226 226
 {
227
-	if (!Load2SF(this->xSF.get()))
227
+	if (!LoadSNSF(this->xSF.get()))
228 228
 		return false;
229 229
 
230 230
 	Settings.SoundSync = true;
Browse code

Some conversion replacements:

* Replace the (w)stringify functions with the standard std::to_(w)string functions.
* Replace convertTo with versions that use type_traits to determine which standard string conversion function to call, as well as handle enums specically.

Naram Qashat authored on 2021/03/19 11:57:21
Showing 1 changed files
... ...
@@ -183,7 +183,7 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
183 183
 	do
184 184
 	{
185 185
 		found = false;
186
-		std::string libTag = "_lib" + stringify(n++);
186
+		std::string libTag = "_lib" + std::to_string(n++);
187 187
 		if (xSF->GetTagExists(libTag))
188 188
 		{
189 189
 			found = true;
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
  * xSF - SNSF Player
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-25
5 4
  *
6 5
  * Based on a modified in_snsf by Caitsith2
7 6
  * http://snsf.caitsith2.net/
Browse code

* Small Makefile changes.

* Removed a couple files that were not being used.
* Cleanups found with clang's -Weverything (and shutting it up about a
lot of things that were ridiculous, as well as ignoring some of the
warnings still coming up).

Naram Qashat authored on 2014/09/25 12:28:21
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - SNSF Player
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-24
4
+ * Last modification on 2014-09-25
5 5
  *
6 6
  * Based on a modified in_snsf by Caitsith2
7 7
  * http://snsf.caitsith2.net/
... ...
@@ -59,8 +59,6 @@ XSFPlayer *XSFPlayer::Create(const std::wstring &fn)
59 59
 }
60 60
 #endif
61 61
 
62
-volatile bool execute = false;
63
-
64 62
 static struct
65 63
 {
66 64
 	std::vector<uint8_t> rom, sram;
Browse code

Lots of changes in regards to strings, as follows:

* Removed my custom String class, as well as removed the really old
Unicode ConvertUTF, the UTF Converter, and the UTF Encode/Decode
functions.
* Replaced the above with using standard C++ std::wstring_convert and
std::codecvt_utf8.
* Added headers adapted from llvm's libc++ project for allowing the
above C++ classes to exist with GCC and Clang when libc++ isn't being
used.
* Used std::string over std::wstring whenever possible.
* Added header adapted from llvm's libc++ project to create special
versions of the ifstream and ofstream classes that would utilize _wfopen
on non-MSVC Windows compilers, so those compilers could access files on
Windows that use characters outside the current codepage.
* Removed the -static-libgcc and -static-libstdc++ flags from the
Makefile for non-MSVC builds. The generated DLLs will require extra DLLs
from either Cygwin or MinGW (whichever is used to compile), I've only
tested with MinGW and for some reason they crash Winamp on exit, I have
no idea why.

Naram Qashat authored on 2014/09/24 13:58:55
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - SNSF Player
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-17
4
+ * Last modification on 2014-09-24
5 5
  *
6 6
  * Based on a modified in_snsf by Caitsith2
7 7
  * http://snsf.caitsith2.net/
... ...
@@ -33,7 +33,7 @@ class XSFPlayer_SNSF : public XSFPlayer
33 33
 {
34 34
 public:
35 35
 	XSFPlayer_SNSF(const std::string &filename);
36
-#ifdef _MSC_VER
36
+#ifdef _WIN32
37 37
 	XSFPlayer_SNSF(const std::wstring &filename);
38 38
 #endif
39 39
 	~XSFPlayer_SNSF() { this->Terminate(); }
... ...
@@ -52,7 +52,7 @@ XSFPlayer *XSFPlayer::Create(const std::string &fn)
52 52
 	return new XSFPlayer_SNSF(fn);
53 53
 }
54 54
 
55
-#ifdef _MSC_VER
55
+#ifdef _WIN32
56 56
 XSFPlayer *XSFPlayer::Create(const std::wstring &fn)
57 57
 {
58 58
 	return new XSFPlayer_SNSF(fn);
... ...
@@ -169,10 +169,10 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
169 169
 {
170 170
 	if (level <= 10 && xSF->GetTagExists("_lib"))
171 171
 	{
172
-#ifdef _MSC_VER
173
-		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue("_lib").GetWStr(), 4, 8));
172
+#ifdef _WIN32
173
+		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue("_lib")), 4, 8));
174 174
 #else
175
-		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue("_lib").GetAnsi(), 4, 8));
175
+		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue("_lib"), 4, 8));
176 176
 #endif
177 177
 		if (!RecursiveLoad2SF(libxSF.get(), level + 1))
178 178
 			return false;
... ...
@@ -190,10 +190,10 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
190 190
 		if (xSF->GetTagExists(libTag))
191 191
 		{
192 192
 			found = true;
193
-#ifdef _MSC_VER
194
-			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue(libTag).GetWStr(), 4, 8));
193
+#ifdef _WIN32
194
+			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue(libTag)), 4, 8));
195 195
 #else
196
-			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue(libTag).GetAnsi(), 4, 8));
196
+			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue(libTag), 4, 8));
197 197
 #endif
198 198
 			if (!RecursiveLoad2SF(libxSF.get(), level + 1))
199 199
 				return false;
... ...
@@ -218,7 +218,7 @@ XSFPlayer_SNSF::XSFPlayer_SNSF(const std::string &filename) : XSFPlayer()
218 218
 	this->xSF.reset(new XSFFile(filename, 4, 8));
219 219
 }
220 220
 
221
-#ifdef _MSC_VER
221
+#ifdef _WIN32
222 222
 XSFPlayer_SNSF::XSFPlayer_SNSF(const std::wstring &filename) : XSFPlayer()
223 223
 {
224 224
 	this->xSF.reset(new XSFFile(filename, 4, 8));
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
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - SNSF Player
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-05-08
4
+ * Last modification on 2014-09-17
5 5
  *
6 6
  * Based on a modified in_snsf by Caitsith2
7 7
  * http://snsf.caitsith2.net/
... ...
@@ -33,7 +33,9 @@ class XSFPlayer_SNSF : public XSFPlayer
33 33
 {
34 34
 public:
35 35
 	XSFPlayer_SNSF(const std::string &filename);
36
+#ifdef _MSC_VER
36 37
 	XSFPlayer_SNSF(const std::wstring &filename);
38
+#endif
37 39
 	~XSFPlayer_SNSF() { this->Terminate(); }
38 40
 	bool Load();
39 41
 	void GenerateSamples(std::vector<uint8_t> &buf, unsigned offset, unsigned samples);
... ...
@@ -50,10 +52,12 @@ XSFPlayer *XSFPlayer::Create(const std::string &fn)
50 52
 	return new XSFPlayer_SNSF(fn);
51 53
 }
52 54
 
55
+#ifdef _MSC_VER
53 56
 XSFPlayer *XSFPlayer::Create(const std::wstring &fn)
54 57
 {
55 58
 	return new XSFPlayer_SNSF(fn);
56 59
 }
60
+#endif
57 61
 
58 62
 volatile bool execute = false;
59 63
 
... ...
@@ -105,7 +109,7 @@ bool S9xOpenSoundDevice()
105 109
 	return true;
106 110
 }
107 111
 
108
-static void Map2SFSection(const std::vector<uint8_t> &section, int level)
112
+static void Map2SFSection(const std::vector<uint8_t> &section)
109 113
 {
110 114
 	auto &data = loaderwork.rom;
111 115
 
... ...
@@ -125,7 +129,7 @@ static void Map2SFSection(const std::vector<uint8_t> &section, int level)
125 129
 	std::copy_n(&section[8], size, &data[offset]);
126 130
 }
127 131
 
128
-static bool Map2SF(XSFFile *xSF, int level)
132
+static bool Map2SF(XSFFile *xSF)
129 133
 {
130 134
 	if (!xSF->IsValidType(0x23))
131 135
 		return false;
... ...
@@ -156,7 +160,7 @@ static bool Map2SF(XSFFile *xSF, int level)
156 160
 	}
157 161
 
158 162
 	if (!programSection.empty())
159
-		Map2SFSection(programSection, level);
163
+		Map2SFSection(programSection);
160 164
 
161 165
 	return true;
162 166
 }
... ...
@@ -165,7 +169,7 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
165 169
 {
166 170
 	if (level <= 10 && xSF->GetTagExists("_lib"))
167 171
 	{
168
-#ifdef _WIN32
172
+#ifdef _MSC_VER
169 173
 		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue("_lib").GetWStr(), 4, 8));
170 174
 #else
171 175
 		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue("_lib").GetAnsi(), 4, 8));
... ...
@@ -174,7 +178,7 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
174 178
 			return false;
175 179
 	}
176 180
 
177
-	if (!Map2SF(xSF, level))
181
+	if (!Map2SF(xSF))
178 182
 		return false;
179 183
 
180 184
 	unsigned n = 2;
... ...
@@ -186,7 +190,7 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
186 190
 		if (xSF->GetTagExists(libTag))
187 191
 		{
188 192
 			found = true;
189
-#ifdef _WIN32
193
+#ifdef _MSC_VER
190 194
 			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue(libTag).GetWStr(), 4, 8));
191 195
 #else
192 196
 			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue(libTag).GetAnsi(), 4, 8));
... ...
@@ -214,10 +218,12 @@ XSFPlayer_SNSF::XSFPlayer_SNSF(const std::string &filename) : XSFPlayer()
214 218
 	this->xSF.reset(new XSFFile(filename, 4, 8));
215 219
 }
216 220
 
221
+#ifdef _MSC_VER
217 222
 XSFPlayer_SNSF::XSFPlayer_SNSF(const std::wstring &filename) : XSFPlayer()
218 223
 {
219 224
 	this->xSF.reset(new XSFFile(filename, 4, 8));
220 225
 }
226
+#endif
221 227
 
222 228
 bool XSFPlayer_SNSF::Load()
223 229
 {
Browse code

[SNSF] Replaced most uses of fill/copy with fill_n/copy_n, and a few other minor code cleanups.

Naram Qashat authored on 2013/05/27 22:34:22
Showing 1 changed files
... ...
@@ -93,7 +93,7 @@ public:
93 93
 			return;
94 94
 		if (bytes > bleft)
95 95
 			bytes = bleft;
96
-		std::fill(&this->buf[this->fil], &this->buf[this->fil + bytes], 0);
96
+		std::fill_n(&this->buf[this->fil], bytes, 0);
97 97
 		S9xMixSamples(&this->buf[this->fil], bytes >> 1);
98 98
 		this->fil += bytes;
99 99
 	}
... ...
@@ -122,7 +122,7 @@ static void Map2SFSection(const std::vector<uint8_t> &section, int level)
122 122
 		data.resize(finalSize, 0);
123 123
 	else if (data.size() < size + offset)
124 124
 		data.resize(offset + finalSize);
125
-	std::copy(&section[8], &section[8 + size], &data[offset]);
125
+	std::copy_n(&section[8], size, &data[offset]);
126 126
 }
127 127
 
128 128
 static bool Map2SF(XSFFile *xSF, int level)
... ...
@@ -148,7 +148,7 @@ static bool Map2SF(XSFFile *xSF, int level)
148 148
 				if (size > 4 && loaderwork.sram.size() > offset)
149 149
 				{
150 150
 					auto len = std::min(size - 4, loaderwork.sram.size() - offset);
151
-					std::copy(&reservedSection[reservedPosition + 12], &reservedSection[reservedPosition + 12 + len], &loaderwork.sram[offset]);
151
+					std::copy_n(&reservedSection[reservedPosition + 12], len, &loaderwork.sram[offset]);
152 152
 				}
153 153
 			}
154 154
 			reservedPosition += size + 8;
... ...
@@ -276,7 +276,7 @@ void XSFPlayer_SNSF::GenerateSamples(std::vector<uint8_t> &buf, unsigned offset,
276 276
 		unsigned len = remain;
277 277
 		if (len > bytes)
278 278
 			len = bytes;
279
-		std::copy(&buffer.buf[buffer.cur], &buffer.buf[buffer.cur + len], &buf[offset]);
279
+		std::copy_n(&buffer.buf[buffer.cur], len, &buf[offset]);
280 280
 		bytes -= len;
281 281
 		offset += len;
282 282
 		buffer.cur += len;
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
... ...
@@ -93,7 +93,7 @@ public:
93 93
 			return;
94 94
 		if (bytes > bleft)
95 95
 			bytes = bleft;
96
-		memset(&this->buf[this->fil], 0, bytes);
96
+		std::fill(&this->buf[this->fil], &this->buf[this->fil + bytes], 0);
97 97
 		S9xMixSamples(&this->buf[this->fil], bytes >> 1);
98 98
 		this->fil += bytes;
99 99
 	}
... ...
@@ -122,7 +122,7 @@ static void Map2SFSection(const std::vector<uint8_t> &section, int level)
122 122
 		data.resize(finalSize, 0);
123 123
 	else if (data.size() < size + offset)
124 124
 		data.resize(offset + finalSize);
125
-	memcpy(&data[offset], &section[8], size);
125
+	std::copy(&section[8], &section[8 + size], &data[offset]);
126 126
 }
127 127
 
128 128
 static bool Map2SF(XSFFile *xSF, int level)
... ...
@@ -148,7 +148,7 @@ static bool Map2SF(XSFFile *xSF, int level)
148 148
 				if (size > 4 && loaderwork.sram.size() > offset)
149 149
 				{
150 150
 					auto len = std::min(size - 4, loaderwork.sram.size() - offset);
151
-					memcpy(&loaderwork.sram[offset], &reservedSection[reservedPosition + 12], len);
151
+					std::copy(&reservedSection[reservedPosition + 12], &reservedSection[reservedPosition + 12 + len], &loaderwork.sram[offset]);
152 152
 				}
153 153
 			}
154 154
 			reservedPosition += size + 8;
... ...
@@ -276,7 +276,7 @@ void XSFPlayer_SNSF::GenerateSamples(std::vector<uint8_t> &buf, unsigned offset,
276 276
 		unsigned len = remain;
277 277
 		if (len > bytes)
278 278
 			len = bytes;
279
-		memcpy(&buf[offset], &buffer.buf[buffer.cur], len);
279
+		std::copy(&buffer.buf[buffer.cur], &buffer.buf[buffer.cur + len], &buf[offset]);
280 280
 		bytes -= len;
281 281
 		offset += len;
282 282
 		buffer.cur += len;
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
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * xSF - SNSF Player
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-04-23
4
+ * Last modification on 2013-05-08
5 5
  *
6 6
  * Based on a modified in_snsf by Caitsith2
7 7
  * http://snsf.caitsith2.net/
... ...
@@ -26,6 +26,7 @@
26 26
 #include "snes9x/apu/hermite_resampler.h"
27 27
 #include "snes9x/apu/bspline_resampler.h"
28 28
 #include "snes9x/apu/osculating_resampler.h"
29
+#include "snes9x/apu/sinc_resampler.h"
29 30
 #include "snes9x/memmap.h"
30 31
 
31 32
 class XSFPlayer_SNSF : public XSFPlayer
... ...
@@ -71,8 +72,11 @@ public:
71 72
 	BUFFER() : buf(), fil(0), cur(0), len(0) { }
72 73
 	bool Init()
73 74
 	{
75
+		if (!this->buf.empty())
76
+			this->buf.clear();
74 77
 		this->len = 2 * 2 * 48000 / 5;
75
-		buf.resize(len);
78
+		this->buf.resize(len, 0);
79
+		this->fil = this->cur = 0;
76 80
 		return true;
77 81
 	}
78 82
 	void Fill()
... ...
@@ -230,9 +234,11 @@ bool XSFPlayer_SNSF::Load()
230 234
 
231 235
 	S9xInitAPU();
232 236
 	XSFConfig_SNSF *xSFConfig_SNSF = dynamic_cast<XSFConfig_SNSF *>(xSFConfig);
233
-	if (xSFConfig_SNSF->resampler == 3)
237
+	if (xSFConfig_SNSF->resampler == 4)
238
+		S9xInitSound<SincResampler>(10, 0);
239
+	else if (xSFConfig_SNSF->resampler == 3)
234 240
 		S9xInitSound<OsculatingResampler>(10, 0);
235
-	if (xSFConfig_SNSF->resampler == 2)
241
+	else if (xSFConfig_SNSF->resampler == 2)
236 242
 		S9xInitSound<BsplineResampler>(10, 0);
237 243
 	else if (xSFConfig_SNSF->resampler == 1)
238 244
 		S9xInitSound<HermiteResampler>(10, 0);
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
  * xSF - SNSF Player
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-03-30
4
+ * Last modification on 2013-04-23
5 5
  *
6 6
  * Based on a modified in_snsf by Caitsith2
7 7
  * http://snsf.caitsith2.net/
... ...
@@ -207,17 +207,17 @@ static bool Load2SF(XSFFile *xSF)
207 207
 
208 208
 XSFPlayer_SNSF::XSFPlayer_SNSF(const std::string &filename) : XSFPlayer()
209 209
 {
210
-	this->xSF = new XSFFile(filename, 4, 8);
210
+	this->xSF.reset(new XSFFile(filename, 4, 8));
211 211
 }
212 212
 
213 213
 XSFPlayer_SNSF::XSFPlayer_SNSF(const std::wstring &filename) : XSFPlayer()
214 214
 {
215
-	this->xSF = new XSFFile(filename, 4, 8);
215
+	this->xSF.reset(new XSFFile(filename, 4, 8));
216 216
 }
217 217
 
218 218
 bool XSFPlayer_SNSF::Load()
219 219
 {
220
-	if (!Load2SF(this->xSF))
220
+	if (!Load2SF(this->xSF.get()))
221 221
 		return false;
222 222
 
223 223
 	Settings.SoundSync = true;
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
... ...
@@ -25,7 +25,7 @@
25 25
 #include "snes9x/apu/linear_resampler.h"
26 26
 #include "snes9x/apu/hermite_resampler.h"
27 27
 #include "snes9x/apu/bspline_resampler.h"
28
-#include "snes9x/apu/optimal_resampler.h"
28
+#include "snes9x/apu/osculating_resampler.h"
29 29
 #include "snes9x/memmap.h"
30 30
 
31 31
 class XSFPlayer_SNSF : public XSFPlayer
... ...
@@ -231,7 +231,7 @@ bool XSFPlayer_SNSF::Load()
231 231
 	S9xInitAPU();
232 232
 	XSFConfig_SNSF *xSFConfig_SNSF = dynamic_cast<XSFConfig_SNSF *>(xSFConfig);
233 233
 	if (xSFConfig_SNSF->resampler == 3)
234
-		S9xInitSound<OptimalResampler>(10, 0);
234
+		S9xInitSound<OsculatingResampler>(10, 0);
235 235
 	if (xSFConfig_SNSF->resampler == 2)
236 236
 		S9xInitSound<BsplineResampler>(10, 0);
237 237
 	else if (xSFConfig_SNSF->resampler == 1)
Browse code

Added B-spline and Optimal interpolations to in_snsf, but I'll probably be changing this later.

Naram Qashat authored on 2013/04/12 10:24:45
Showing 1 changed files
... ...
@@ -24,6 +24,8 @@
24 24
 #include "snes9x/apu/apu.h"
25 25
 #include "snes9x/apu/linear_resampler.h"
26 26
 #include "snes9x/apu/hermite_resampler.h"
27
+#include "snes9x/apu/bspline_resampler.h"
28
+#include "snes9x/apu/optimal_resampler.h"
27 29
 #include "snes9x/memmap.h"
28 30
 
29 31
 class XSFPlayer_SNSF : public XSFPlayer
... ...
@@ -228,7 +230,11 @@ bool XSFPlayer_SNSF::Load()
228 230
 
229 231
 	S9xInitAPU();
230 232
 	XSFConfig_SNSF *xSFConfig_SNSF = dynamic_cast<XSFConfig_SNSF *>(xSFConfig);
231
-	if (xSFConfig_SNSF->resampler)
233
+	if (xSFConfig_SNSF->resampler == 3)
234
+		S9xInitSound<OptimalResampler>(10, 0);
235
+	if (xSFConfig_SNSF->resampler == 2)
236
+		S9xInitSound<BsplineResampler>(10, 0);
237
+	else if (xSFConfig_SNSF->resampler == 1)
232 238
 		S9xInitSound<HermiteResampler>(10, 0);
233 239
 	else
234 240
 		S9xInitSound<LinearResampler>(10, 0);
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
  * xSF - SNSF Player
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-03-25
4
+ * Last modification on 2013-03-30
5 5
  *
6 6
  * Based on a modified in_snsf by Caitsith2
7 7
  * http://snsf.caitsith2.net/
Browse code

Utilized more C++11 constructs. Also attempted to fix issue with the Info Box not wanting to come up anymore if the file doesn't exist.

Naram Qashat authored on 2013/03/30 07:36:38
Showing 1 changed files
... ...
@@ -160,9 +160,9 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
160 160
 	if (level <= 10 && xSF->GetTagExists("_lib"))
161 161
 	{
162 162
 #ifdef _WIN32
163
-		auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue("_lib").GetWStr(), 4, 8));
163
+		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue("_lib").GetWStr(), 4, 8));
164 164
 #else
165
-		auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue("_lib").GetAnsi(), 4, 8));
165
+		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue("_lib").GetAnsi(), 4, 8));
166 166
 #endif
167 167
 		if (!RecursiveLoad2SF(libxSF.get(), level + 1))
168 168
 			return false;
... ...
@@ -181,9 +181,9 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
181 181
 		{
182 182
 			found = true;
183 183
 #ifdef _WIN32
184
-			auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue(libTag).GetWStr(), 4, 8));
184
+			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue(libTag).GetWStr(), 4, 8));
185 185
 #else
186
-			auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue(libTag).GetAnsi(), 4, 8));
186
+			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue(libTag).GetAnsi(), 4, 8));
187 187
 #endif
188 188
 			if (!RecursiveLoad2SF(libxSF.get(), level + 1))
189 189
 				return false;
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,284 @@
1
+/*
2
+ * xSF - SNSF Player
3
+ * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
+ * Last modification on 2013-03-25
5
+ *
6
+ * Based on a modified in_snsf by Caitsith2
7
+ * http://snsf.caitsith2.net/
8
+ *
9
+ * Partially based on the vio*sf framework
10
+ *
11
+ * Utilizes a modified snes9x v1.53 for playback
12
+ * http://www.snes9x.com/
13
+ */
14
+
15
+#include <zlib.h>
16
+#include "convert.h"
17
+#include "XSFPlayer.h"
18
+#include "XSFConfig_SNSF.h"
19
+#include "XSFCommon.h"
20
+
21
+#undef min
22
+#undef max
23
+
24
+#include "snes9x/apu/apu.h"
25
+#include "snes9x/apu/linear_resampler.h"
26
+#include "snes9x/apu/hermite_resampler.h"
27
+#include "snes9x/memmap.h"
28
+
29
+class XSFPlayer_SNSF : public XSFPlayer
30
+{
31
+public:
32
+	XSFPlayer_SNSF(const std::string &filename);
33
+	XSFPlayer_SNSF(const std::wstring &filename);
34
+	~XSFPlayer_SNSF() { this->Terminate(); }
35
+	bool Load();
36
+	void GenerateSamples(std::vector<uint8_t> &buf, unsigned offset, unsigned samples);
37
+	void Terminate();
38
+};
39
+
40
+const char *XSFPlayer::WinampDescription = "SNSF Decoder";
41
+const char *XSFPlayer::WinampExts = "snsf;minisnsf\0SNES Sound Format files (*.snsf;*.minisnsf)\0";
42
+
43
+extern XSFConfig *xSFConfig;
44
+
45
+XSFPlayer *XSFPlayer::Create(const std::string &fn)
46
+{
47
+	return new XSFPlayer_SNSF(fn);
48
+}
49
+
50
+XSFPlayer *XSFPlayer::Create(const std::wstring &fn)
51
+{
52
+	return new XSFPlayer_SNSF(fn);
53
+}
54
+
55
+volatile bool execute = false;
56
+
57
+static struct
58
+{
59
+	std::vector<uint8_t> rom, sram;
60
+	bool first;
61
+	unsigned base;
62
+} loaderwork;
63
+
64
+class BUFFER
65
+{
66
+public:
67
+	std::vector<uint8_t> buf;
68
+	unsigned fil, cur, len;
69
+	BUFFER() : buf(), fil(0), cur(0), len(0) { }
70
+	bool Init()
71
+	{
72
+		this->len = 2 * 2 * 48000 / 5;
73
+		buf.resize(len);
74
+		return true;
75
+	}
76
+	void Fill()
77
+	{
78
+		S9xSyncSound();
79
+		S9xMainLoop();
80
+		this->Mix();
81
+	}
82
+	void Mix()
83
+	{
84
+		unsigned bytes = (S9xGetSampleCount() << 1) & ~3;
85
+		unsigned bleft = (this->len - this->fil) & ~3;
86
+		if (!bytes)
87
+			return;
88
+		if (bytes > bleft)
89
+			bytes = bleft;
90
+		memset(&this->buf[this->fil], 0, bytes);
91
+		S9xMixSamples(&this->buf[this->fil], bytes >> 1);
92
+		this->fil += bytes;
93
+	}
94
+};
95
+static BUFFER buffer;
96
+
97
+bool S9xOpenSoundDevice()
98
+{
99
+	return true;
100
+}
101
+
102
+static void Map2SFSection(const std::vector<uint8_t> &section, int level)
103
+{
104
+	auto &data = loaderwork.rom;
105
+
106
+	uint32_t offset = Get32BitsLE(&section[0]), size = Get32BitsLE(&section[4]), finalSize = size + offset;
107
+	if (!loaderwork.first)
108
+	{
109
+		loaderwork.first = true;
110
+		loaderwork.base = offset;
111
+	}
112
+	else
113
+		offset += loaderwork.base;
114
+	offset &= 0x1FFFFFFF;
115
+	if (data.empty())
116
+		data.resize(finalSize, 0);
117
+	else if (data.size() < size + offset)
118
+		data.resize(offset + finalSize);
119
+	memcpy(&data[offset], &section[8], size);
120
+}
121
+
122
+static bool Map2SF(XSFFile *xSF, int level)
123
+{
124
+	if (!xSF->IsValidType(0x23))
125
+		return false;
126
+
127
+	auto &reservedSection = xSF->GetReservedSection(), &programSection = xSF->GetProgramSection();
128
+
129
+	if (!reservedSection.empty())
130
+	{
131
+		size_t reservedPosition = 0, reservedSize = reservedSection.size();
132
+		while (reservedPosition + 8 < reservedSize)
133
+		{
134
+			uint32_t type = Get32BitsLE(&reservedSection[reservedPosition]), size = Get32BitsLE(&reservedSection[reservedPosition + 4]);
135
+			if (!type)
136
+			{
137
+				if (loaderwork.sram.empty())
138
+					loaderwork.sram.resize(0x20000, 0xFF);
139
+				if (reservedPosition + 8 + size > reservedSize)
140
+					return false;
141
+				uint32_t offset = Get32BitsLE(&reservedSection[reservedPosition + 8]);
142
+				if (size > 4 && loaderwork.sram.size() > offset)
143
+				{
144
+					auto len = std::min(size - 4, loaderwork.sram.size() - offset);
145
+					memcpy(&loaderwork.sram[offset], &reservedSection[reservedPosition + 12], len);
146
+				}
147
+			}
148
+			reservedPosition += size + 8;
149
+		}
150
+	}
151
+
152
+	if (!programSection.empty())
153
+		Map2SFSection(programSection, level);
154
+
155
+	return true;
156
+}
157
+
158
+static bool RecursiveLoad2SF(XSFFile *xSF, int level)
159
+{
160
+	if (level <= 10 && xSF->GetTagExists("_lib"))
161
+	{
162
+#ifdef _WIN32
163
+		auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue("_lib").GetWStr(), 4, 8));
164
+#else
165
+		auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue("_lib").GetAnsi(), 4, 8));
166
+#endif
167
+		if (!RecursiveLoad2SF(libxSF.get(), level + 1))
168
+			return false;
169
+	}
170
+
171
+	if (!Map2SF(xSF, level))
172
+		return false;
173
+
174
+	unsigned n = 2;
175
+	bool found;
176
+	do
177
+	{
178
+		found = false;
179
+		std::string libTag = "_lib" + stringify(n++);
180
+		if (xSF->GetTagExists(libTag))
181
+		{
182
+			found = true;
183
+#ifdef _WIN32
184
+			auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue(libTag).GetWStr(), 4, 8));
185
+#else
186
+			auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue(libTag).GetAnsi(), 4, 8));
187
+#endif
188
+			if (!RecursiveLoad2SF(libxSF.get(), level + 1))
189
+				return false;
190
+		}
191
+	} while (found);
192
+
193
+	return true;
194
+}
195
+
196
+static bool Load2SF(XSFFile *xSF)
197
+{
198
+	loaderwork.rom.clear();
199
+	loaderwork.sram.clear();
200
+	loaderwork.first = false;
201
+	loaderwork.base = 0;
202
+
203
+	return RecursiveLoad2SF(xSF, 1);
204
+}
205
+
206
+XSFPlayer_SNSF::XSFPlayer_SNSF(const std::string &filename) : XSFPlayer()
207
+{
208
+	this->xSF = new XSFFile(filename, 4, 8);
209
+}
210
+
211
+XSFPlayer_SNSF::XSFPlayer_SNSF(const std::wstring &filename) : XSFPlayer()
212
+{
213
+	this->xSF = new XSFFile(filename, 4, 8);
214
+}
215
+
216
+bool XSFPlayer_SNSF::Load()
217
+{
218
+	if (!Load2SF(this->xSF))
219
+		return false;
220
+
221
+	Settings.SoundSync = true;
222
+	Settings.Mute = false;
223
+	Settings.SoundPlaybackRate = this->sampleRate;
224
+	Settings.SixteenBitSound = true;
225
+	Settings.Stereo = true;
226
+
227
+	Memory.Init();
228
+
229
+	S9xInitAPU();
230
+	XSFConfig_SNSF *xSFConfig_SNSF = dynamic_cast<XSFConfig_SNSF *>(xSFConfig);
231
+	if (xSFConfig_SNSF->resampler)
232
+		S9xInitSound<HermiteResampler>(10, 0);
233
+	else
234
+		S9xInitSound<LinearResampler>(10, 0);
235
+
236
+	if (!buffer.Init())
237
+		return false;
238
+
239
+	if (!Memory.LoadROMSNSF(&loaderwork.rom[0], loaderwork.rom.size(), &loaderwork.sram[0], loaderwork.sram.size()))
240
+		return false;
241
+
242
+	//S9xSetPlaybackRate(Settings.SoundPlaybackRate);
243
+	S9xSetSoundMute(false);
244
+
245
+	// bad hack for gradius3snsf.rar
246
+	//Settings.TurboMode = true;
247
+
248
+	return XSFPlayer::Load();
249
+}
250
+
251
+void XSFPlayer_SNSF::GenerateSamples(std::vector<uint8_t> &buf, unsigned offset, unsigned samples)
252
+{
253
+	unsigned bytes = samples << 2;
254
+	while (bytes)
255
+	{
256
+		unsigned remain = buffer.fil - buffer.cur;
257
+		while (!remain)
258
+		{
259
+			buffer.cur = buffer.fil = 0;
260
+			buffer.Fill();
261
+
262
+			remain = buffer.fil - buffer.cur;
263
+		}
264
+		unsigned len = remain;
265
+		if (len > bytes)
266
+			len = bytes;
267
+		memcpy(&buf[offset], &buffer.buf[buffer.cur], len);
268
+		bytes -= len;
269
+		offset += len;
270
+		buffer.cur += len;
271
+	}
272
+}
273
+
274
+void XSFPlayer_SNSF::Terminate()
275
+{
276
+	S9xReset();
277
+	Memory.Deinit();
278
+	S9xDeinitAPU();
279
+
280
+	loaderwork.rom.clear();
281
+	loaderwork.sram.clear();
282
+	loaderwork.first = false;
283
+	loaderwork.base = 0;
284
+}