Browse code

Port: Add override keyword.

Clarissa Walker authored on 2024/09/16 22:14:51
Showing 1 changed files
... ...
@@ -28,10 +28,10 @@ class XSFPlayer_GSF : public XSFPlayer
28 28
 {
29 29
 public:
30 30
 	XSFPlayer_GSF(const std::filesystem::path &path);
31
-	~XSFPlayer_GSF() { this->Terminate(); }
32
-	bool Load();
33
-	void GenerateSamples(std::vector<std::uint8_t> &buf, unsigned offset, unsigned samples);
34
-	void Terminate();
31
+	~XSFPlayer_GSF() override { this->Terminate(); }
32
+	bool Load() override;
33
+	void GenerateSamples(std::vector<std::uint8_t> &buf, unsigned offset, unsigned samples) override;
34
+	void Terminate() override;
35 35
 };
36 36
 
37 37
 const char *XSFPlayer::WinampDescription = "GSF 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
... ...
@@ -27,10 +27,7 @@
27 27
 class XSFPlayer_GSF : public XSFPlayer
28 28
 {
29 29
 public:
30
-	XSFPlayer_GSF(const std::string &filename);
31
-#ifdef _WIN32
32
-	XSFPlayer_GSF(const std::wstring &filename);
33
-#endif
30
+	XSFPlayer_GSF(const std::filesystem::path &path);
34 31
 	~XSFPlayer_GSF() { this->Terminate(); }
35 32
 	bool Load();
36 33
 	void GenerateSamples(std::vector<std::uint8_t> &buf, unsigned offset, unsigned samples);
... ...
@@ -40,18 +37,11 @@ public:
40 37
 const char *XSFPlayer::WinampDescription = "GSF Decoder";
41 38
 const char *XSFPlayer::WinampExts = "gsf;minigsf\0Game Boy Advance Sound Format files (*.gsf;*.minigsf)\0";
42 39
 
43
-XSFPlayer *XSFPlayer::Create(const std::string &fn)
40
+XSFPlayer *XSFPlayer::Create(const std::filesystem::path &path)
44 41
 {
45
-	return new XSFPlayer_GSF(fn);
42
+	return new XSFPlayer_GSF(path);
46 43
 }
47 44
 
48
-#ifdef _WIN32
49
-XSFPlayer *XSFPlayer::Create(const std::wstring &fn)
50
-{
51
-	return new XSFPlayer_GSF(fn);
52
-}
53
-#endif
54
-
55 45
 static struct
56 46
 {
57 47
 	std::vector<std::uint8_t> rom;
... ...
@@ -156,11 +146,7 @@ static bool RecursiveLoadGSF(XSFFile *xSF, int level)
156 146
 {
157 147
 	if (level <= 10 && xSF->GetTagExists("_lib"))
158 148
 	{
159
-#ifdef _WIN32
160
-		auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSF->GetFilename()).parent_path() / xSF->GetTagValue("_lib")).wstring(), 8, 12);
161
-#else
162
-		auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSF->GetFilename()).parent_path() / xSF->GetTagValue("_lib")).string(), 8, 12);
163
-#endif
149
+		auto libxSF = std::make_unique<XSFFile>(xSF->GetFilepath().parent_path() / xSF->GetTagValue("_lib"), 8, 12);
164 150
 		if (!RecursiveLoadGSF(libxSF.get(), level + 1))
165 151
 			return false;
166 152
 	}
... ...
@@ -177,11 +163,7 @@ static bool RecursiveLoadGSF(XSFFile *xSF, int level)
177 163
 		if (xSF->GetTagExists(libTag))
178 164
 		{
179 165
 			found = true;
180
-#ifdef _WIN32
181
-			auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSF->GetFilename()).parent_path() / xSF->GetTagValue(libTag)).wstring(), 8, 12);
182
-#else
183
-			auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSF->GetFilename()).parent_path() / xSF->GetTagValue(libTag)).string(), 8, 12);
184
-#endif
166
+			auto libxSF = std::make_unique<XSFFile>(xSF->GetFilepath().parent_path() / xSF->GetTagValue(libTag), 8, 12);
185 167
 			if (!RecursiveLoadGSF(libxSF.get(), level + 1))
186 168
 				return false;
187 169
 		}
... ...
@@ -198,17 +180,10 @@ static bool LoadGSF(XSFFile *xSF)
198 180
 	return RecursiveLoadGSF(xSF, 1);
199 181
 }
200 182
 
201
-XSFPlayer_GSF::XSFPlayer_GSF(const std::string &filename) : XSFPlayer()
202
-{
203
-	this->xSF.reset(new XSFFile(filename, 8, 12));
204
-}
205
-
206
-#ifdef _WIN32
207
-XSFPlayer_GSF::XSFPlayer_GSF(const std::wstring &filename) : XSFPlayer()
183
+XSFPlayer_GSF::XSFPlayer_GSF(const std::filesystem::path &path) : XSFPlayer()
208 184
 {
209
-	this->xSF.reset(new XSFFile(filename, 8, 12));
185
+	this->xSF.reset(new XSFFile(path, 8, 12));
210 186
 }
211
-#endif
212 187
 
213 188
 bool XSFPlayer_GSF::Load()
214 189
 {
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
... ...
@@ -10,12 +10,16 @@
10 10
  * http://vba-m.com/
11 11
  */
12 12
 
13
+#include <algorithm>
13 14
 #include <filesystem>
14 15
 #include <memory>
16
+#include <string>
17
+#include <vector>
18
+#include <cstddef>
19
+#include <cstdint>
15 20
 #include <zlib.h>
16
-#include "convert.h"
17
-#include "XSFPlayer.h"
18 21
 #include "XSFCommon.h"
22
+#include "XSFPlayer.h"
19 23
 #include "vbam/gba/Globals.h"
20 24
 #include "vbam/gba/Sound.h"
21 25
 #include "vbam/common/SoundDriver.h"
... ...
@@ -29,7 +33,7 @@ public:
29 33
 #endif
30 34
 	~XSFPlayer_GSF() { this->Terminate(); }
31 35
 	bool Load();
32
-	void GenerateSamples(std::vector<uint8_t> &buf, unsigned offset, unsigned samples);
36
+	void GenerateSamples(std::vector<std::uint8_t> &buf, unsigned offset, unsigned samples);
33 37
 	void Terminate();
34 38
 };
35 39
 
... ...
@@ -50,13 +54,13 @@ XSFPlayer *XSFPlayer::Create(const std::wstring &fn)
50 54
 
51 55
 static struct
52 56
 {
53
-	std::vector<uint8_t> rom;
57
+	std::vector<std::uint8_t> rom;
54 58
 	unsigned entry;
55
-} loaderwork = { std::vector<uint8_t>(), 0 };
59
+} loaderwork = { std::vector<std::uint8_t>(), 0 };
56 60
 
57
-int mapgsf(uint8_t *d, int l, int &s)
61
+int mapgsf(std::uint8_t *d, int l, int &s)
58 62
 {
59
-	if (static_cast<size_t>(l) > loaderwork.rom.size())
63
+	if (static_cast<std::size_t>(l) > loaderwork.rom.size())
60 64
 		l = loaderwork.rom.size();
61 65
 	if (l)
62 66
 		std::copy_n(&loaderwork.rom[0], l, d);
... ...
@@ -66,9 +70,9 @@ int mapgsf(uint8_t *d, int l, int &s)
66 70
 
67 71
 static struct
68 72
 {
69
-	std::vector<uint8_t> buf;
70
-	uint32_t len, fil, cur;
71
-} buffer = { std::vector<uint8_t>(), 0, 0, 0 };
73
+	std::vector<std::uint8_t> buf;
74
+	std::uint32_t len, fil, cur;
75
+} buffer = { std::vector<std::uint8_t>(), 0, 0, 0 };
72 76
 
73 77
 class GSFSoundDriver : public SoundDriver
74 78
 {
... ...
@@ -81,7 +85,7 @@ public:
81 85
 	bool init(long sampleRate)
82 86
 	{
83 87
 		freebuffer();
84
-		uint32_t len = (sampleRate / 10) << 2;
88
+		std::int32_t len = (sampleRate / 10) << 2;
85 89
 		buffer.buf.resize(len);
86 90
 		buffer.len = len;
87 91
 		return true;
... ...
@@ -99,13 +103,13 @@ public:
99 103
 	{
100 104
 	}
101 105
 
102
-	void write(uint16_t *finalWave, int length)
106
+	void write(std::uint16_t *finalWave, int length)
103 107
 	{
104
-		if (static_cast<uint32_t>(length) > buffer.len - buffer.fil)
108
+		if (static_cast<std::uint32_t>(length) > buffer.len - buffer.fil)
105 109
 			length = buffer.len - buffer.fil;
106 110
 		if (length > 0)
107 111
 		{
108
-			std::copy_n(reinterpret_cast<uint8_t *>(finalWave), length, &buffer.buf[buffer.fil]);
112
+			std::copy_n(reinterpret_cast<std::uint8_t *>(finalWave), length, &buffer.buf[buffer.fil]);
109 113
 			buffer.fil += length;
110 114
 		}
111 115
 	}
... ...
@@ -120,11 +124,11 @@ SoundDriver *systemSoundInit()
120 124
 	return new GSFSoundDriver();
121 125
 }
122 126
 
123
-static void MapGSFSection(const std::vector<uint8_t> &section, int level)
127
+static void MapGSFSection(const std::vector<std::uint8_t> &section, int level)
124 128
 {
125 129
 	auto &data = loaderwork.rom;
126 130
 
127
-	uint32_t entry = Get32BitsLE(&section[0]), offset = Get32BitsLE(&section[4]) & 0x1FFFFFF, size = Get32BitsLE(&section[8]), finalSize = size + offset;
131
+	std::uint32_t entry = Get32BitsLE(&section[0]), offset = Get32BitsLE(&section[4]) & 0x1FFFFFF, size = Get32BitsLE(&section[8]), finalSize = size + offset;
128 132
 	if (level == 1)
129 133
 		loaderwork.entry = entry;
130 134
 	finalSize = NextHighestPowerOf2(finalSize);
... ...
@@ -226,7 +230,7 @@ bool XSFPlayer_GSF::Load()
226 230
 	return XSFPlayer::Load();
227 231
 }
228 232
 
229
-void XSFPlayer_GSF::GenerateSamples(std::vector<uint8_t> &buf, unsigned offset, unsigned samples)
233
+void XSFPlayer_GSF::GenerateSamples(std::vector<std::uint8_t> &buf, unsigned offset, unsigned samples)
230 234
 {
231 235
 	unsigned bytes = samples << 2;
232 236
 	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
... ...
@@ -52,7 +52,7 @@ static struct
52 52
 {
53 53
 	std::vector<uint8_t> rom;
54 54
 	unsigned entry;
55
-} loaderwork;
55
+} loaderwork = { std::vector<uint8_t>(), 0 };
56 56
 
57 57
 int mapgsf(uint8_t *d, int l, int &s)
58 58
 {
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
... ...
@@ -10,6 +10,7 @@
10 10
  * http://vba-m.com/
11 11
  */
12 12
 
13
+#include <filesystem>
13 14
 #include <memory>
14 15
 #include <zlib.h>
15 16
 #include "convert.h"
... ...
@@ -152,9 +153,9 @@ static bool RecursiveLoadGSF(XSFFile *xSF, int level)
152 153
 	if (level <= 10 && xSF->GetTagExists("_lib"))
153 154
 	{
154 155
 #ifdef _WIN32
155
-		auto libxSF = std::make_unique<XSFFile>(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue("_lib")), 8, 12);
156
+		auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSF->GetFilename()).parent_path() / xSF->GetTagValue("_lib")).wstring(), 8, 12);
156 157
 #else
157
-		auto libxSF = std::make_unique<XSFFile>(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue("_lib"), 8, 12);
158
+		auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSF->GetFilename()).parent_path() / xSF->GetTagValue("_lib")).string(), 8, 12);
158 159
 #endif
159 160
 		if (!RecursiveLoadGSF(libxSF.get(), level + 1))
160 161
 			return false;
... ...
@@ -173,9 +174,9 @@ static bool RecursiveLoadGSF(XSFFile *xSF, int level)
173 174
 		{
174 175
 			found = true;
175 176
 #ifdef _WIN32
176
-			auto libxSF = std::make_unique<XSFFile>(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue(libTag)), 8, 12);
177
+			auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSF->GetFilename()).parent_path() / xSF->GetTagValue(libTag)).wstring(), 8, 12);
177 178
 #else
178
-			auto libxSF = std::make_unique<XSFFile>(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue(libTag), 8, 12);
179
+			auto libxSF = std::make_unique<XSFFile>((std::filesystem::path(xSF->GetFilename()).parent_path() / xSF->GetTagValue(libTag)).string(), 8, 12);
179 180
 #endif
180 181
 			if (!RecursiveLoadGSF(libxSF.get(), level + 1))
181 182
 				return false;
Browse code

Use std::make_unique where possible.

Naram Qashat authored on 2021/03/20 04:37:08
Showing 1 changed files
... ...
@@ -152,9 +152,9 @@ static bool RecursiveLoadGSF(XSFFile *xSF, int level)
152 152
 	if (level <= 10 && xSF->GetTagExists("_lib"))
153 153
 	{
154 154
 #ifdef _WIN32
155
-		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue("_lib")), 8, 12));
155
+		auto libxSF = std::make_unique<XSFFile>(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue("_lib")), 8, 12);
156 156
 #else
157
-		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue("_lib"), 8, 12));
157
+		auto libxSF = std::make_unique<XSFFile>(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue("_lib"), 8, 12);
158 158
 #endif
159 159
 		if (!RecursiveLoadGSF(libxSF.get(), level + 1))
160 160
 			return false;
... ...
@@ -173,9 +173,9 @@ static bool RecursiveLoadGSF(XSFFile *xSF, int level)
173 173
 		{
174 174
 			found = true;
175 175
 #ifdef _WIN32
176
-			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue(libTag)), 8, 12));
176
+			auto libxSF = std::make_unique<XSFFile>(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue(libTag)), 8, 12);
177 177
 #else
178
-			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue(libTag), 8, 12));
178
+			auto libxSF = std::make_unique<XSFFile>(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue(libTag), 8, 12);
179 179
 #endif
180 180
 			if (!RecursiveLoadGSF(libxSF.get(), level + 1))
181 181
 				return false;
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
... ...
@@ -58,7 +58,7 @@ int mapgsf(uint8_t *d, int l, int &s)
58 58
 	if (static_cast<size_t>(l) > loaderwork.rom.size())
59 59
 		l = loaderwork.rom.size();
60 60
 	if (l)
61
-		memcpy(d, &loaderwork.rom[0], l);
61
+		std::copy_n(&loaderwork.rom[0], l, d);
62 62
 	s = l;
63 63
 	return l;
64 64
 }
... ...
@@ -104,7 +104,7 @@ public:
104 104
 			length = buffer.len - buffer.fil;
105 105
 		if (length > 0)
106 106
 		{
107
-			memcpy(&buffer.buf[buffer.fil], finalWave, length);
107
+			std::copy_n(reinterpret_cast<uint8_t *>(finalWave), length, &buffer.buf[buffer.fil]);
108 108
 			buffer.fil += length;
109 109
 		}
110 110
 	}
... ...
@@ -131,7 +131,7 @@ static void MapGSFSection(const std::vector<uint8_t> &section, int level)
131 131
 		data.resize(finalSize + 10, 0);
132 132
 	else if (data.size() < size + offset)
133 133
 		data.resize(offset + finalSize + 10);
134
-	memcpy(&data[offset], &section[12], size);
134
+	std::copy_n(&section[12], size, &data[offset]);
135 135
 }
136 136
 
137 137
 static bool MapGSF(XSFFile *xSF, int level)
... ...
@@ -241,7 +241,7 @@ void XSFPlayer_GSF::GenerateSamples(std::vector<uint8_t> &buf, unsigned offset,
241 241
 		unsigned len = remainbytes;
242 242
 		if (len > bytes)
243 243
 			len = bytes;
244
-		memcpy(&buf[offset], &buffer.buf[buffer.cur], len);
244
+		std::copy_n(&buffer.buf[buffer.cur], len, &buf[offset]);
245 245
 		bytes -= len;
246 246
 		offset += len;
247 247
 		buffer.cur += len;
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
... ...
@@ -119,7 +119,7 @@ SoundDriver *systemSoundInit()
119 119
 	return new GSFSoundDriver();
120 120
 }
121 121
 
122
-static void Map2SFSection(const std::vector<uint8_t> &section, int level)
122
+static void MapGSFSection(const std::vector<uint8_t> &section, int level)
123 123
 {
124 124
 	auto &data = loaderwork.rom;
125 125
 
... ...
@@ -134,7 +134,7 @@ static void Map2SFSection(const std::vector<uint8_t> &section, int level)
134 134
 	memcpy(&data[offset], &section[12], size);
135 135
 }
136 136
 
137
-static bool Map2SF(XSFFile *xSF, int level)
137
+static bool MapGSF(XSFFile *xSF, int level)
138 138
 {
139 139
 	if (!xSF->IsValidType(0x22))
140 140
 		return false;
... ...
@@ -142,12 +142,12 @@ static bool Map2SF(XSFFile *xSF, int level)
142 142
 	auto &programSection = xSF->GetProgramSection();
143 143
 
144 144
 	if (!programSection.empty())
145
-		Map2SFSection(programSection, level);
145
+		MapGSFSection(programSection, level);
146 146
 
147 147
 	return true;
148 148
 }
149 149
 
150
-static bool RecursiveLoad2SF(XSFFile *xSF, int level)
150
+static bool RecursiveLoadGSF(XSFFile *xSF, int level)
151 151
 {
152 152
 	if (level <= 10 && xSF->GetTagExists("_lib"))
153 153
 	{
... ...
@@ -156,11 +156,11 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
156 156
 #else
157 157
 		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue("_lib"), 8, 12));
158 158
 #endif
159
-		if (!RecursiveLoad2SF(libxSF.get(), level + 1))
159
+		if (!RecursiveLoadGSF(libxSF.get(), level + 1))
160 160
 			return false;
161 161
 	}
162 162
 
163
-	if (!Map2SF(xSF, level))
163
+	if (!MapGSF(xSF, level))
164 164
 		return false;
165 165
 
166 166
 	unsigned n = 2;
... ...
@@ -177,7 +177,7 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
177 177
 #else
178 178
 			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue(libTag), 8, 12));
179 179
 #endif
180
-			if (!RecursiveLoad2SF(libxSF.get(), level + 1))
180
+			if (!RecursiveLoadGSF(libxSF.get(), level + 1))
181 181
 				return false;
182 182
 		}
183 183
 	} while (found);
... ...
@@ -185,12 +185,12 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
185 185
 	return true;
186 186
 }
187 187
 
188
-static bool Load2SF(XSFFile *xSF)
188
+static bool LoadGSF(XSFFile *xSF)
189 189
 {
190 190
 	loaderwork.rom.clear();
191 191
 	loaderwork.entry = 0;
192 192
 
193
-	return RecursiveLoad2SF(xSF, 1);
193
+	return RecursiveLoadGSF(xSF, 1);
194 194
 }
195 195
 
196 196
 XSFPlayer_GSF::XSFPlayer_GSF(const std::string &filename) : XSFPlayer()
... ...
@@ -207,7 +207,7 @@ XSFPlayer_GSF::XSFPlayer_GSF(const std::wstring &filename) : XSFPlayer()
207 207
 
208 208
 bool XSFPlayer_GSF::Load()
209 209
 {
210
-	if (!Load2SF(this->xSF.get()))
210
+	if (!LoadGSF(this->xSF.get()))
211 211
 		return false;
212 212
 
213 213
 	cpuIsMultiBoot = (loaderwork.entry >> 24) == 2;
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
... ...
@@ -168,7 +168,7 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
168 168
 	do
169 169
 	{
170 170
 		found = false;
171
-		std::string libTag = "_lib" + stringify(n++);
171
+		std::string libTag = "_lib" + std::to_string(n++);
172 172
 		if (xSF->GetTagExists(libTag))
173 173
 		{
174 174
 			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 - GSF Player
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2014-09-24
5 4
  *
6 5
  * Based on a modified viogsf v0.08
7 6
  *
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 - GSF 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 viogsf v0.08
7 7
  *
... ...
@@ -24,7 +24,7 @@ class XSFPlayer_GSF : public XSFPlayer
24 24
 {
25 25
 public:
26 26
 	XSFPlayer_GSF(const std::string &filename);
27
-#ifdef _MSC_VER
27
+#ifdef _WIN32
28 28
 	XSFPlayer_GSF(const std::wstring &filename);
29 29
 #endif
30 30
 	~XSFPlayer_GSF() { this->Terminate(); }
... ...
@@ -41,7 +41,7 @@ XSFPlayer *XSFPlayer::Create(const std::string &fn)
41 41
 	return new XSFPlayer_GSF(fn);
42 42
 }
43 43
 
44
-#ifdef _MSC_VER
44
+#ifdef _WIN32
45 45
 XSFPlayer *XSFPlayer::Create(const std::wstring &fn)
46 46
 {
47 47
 	return new XSFPlayer_GSF(fn);
... ...
@@ -152,10 +152,10 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
152 152
 {
153 153
 	if (level <= 10 && xSF->GetTagExists("_lib"))
154 154
 	{
155
-#ifdef _MSC_VER
156
-		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue("_lib").GetWStr(), 8, 12));
155
+#ifdef _WIN32
156
+		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue("_lib")), 8, 12));
157 157
 #else
158
-		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue("_lib").GetAnsi(), 8, 12));
158
+		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue("_lib"), 8, 12));
159 159
 #endif
160 160
 		if (!RecursiveLoad2SF(libxSF.get(), level + 1))
161 161
 			return false;
... ...
@@ -173,10 +173,10 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
173 173
 		if (xSF->GetTagExists(libTag))
174 174
 		{
175 175
 			found = true;
176
-#ifdef _MSC_VER
177
-			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue(libTag).GetWStr(), 8, 12));
176
+#ifdef _WIN32
177
+			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ConvertFuncs::StringToWString(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue(libTag)), 8, 12));
178 178
 #else
179
-			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue(libTag).GetAnsi(), 8, 12));
179
+			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename()) + xSF->GetTagValue(libTag), 8, 12));
180 180
 #endif
181 181
 			if (!RecursiveLoad2SF(libxSF.get(), level + 1))
182 182
 				return false;
... ...
@@ -199,7 +199,7 @@ XSFPlayer_GSF::XSFPlayer_GSF(const std::string &filename) : XSFPlayer()
199 199
 	this->xSF.reset(new XSFFile(filename, 8, 12));
200 200
 }
201 201
 
202
-#ifdef _MSC_VER
202
+#ifdef _WIN32
203 203
 XSFPlayer_GSF::XSFPlayer_GSF(const std::wstring &filename) : XSFPlayer()
204 204
 {
205 205
 	this->xSF.reset(new XSFFile(filename, 8, 12));
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 - GSF Player
3 3
  * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
- * Last modification on 2013-04-23
4
+ * Last modification on 2014-09-17
5 5
  *
6 6
  * Based on a modified viogsf v0.08
7 7
  *
... ...
@@ -24,7 +24,9 @@ class XSFPlayer_GSF : public XSFPlayer
24 24
 {
25 25
 public:
26 26
 	XSFPlayer_GSF(const std::string &filename);
27
+#ifdef _MSC_VER
27 28
 	XSFPlayer_GSF(const std::wstring &filename);
29
+#endif
28 30
 	~XSFPlayer_GSF() { this->Terminate(); }
29 31
 	bool Load();
30 32
 	void GenerateSamples(std::vector<uint8_t> &buf, unsigned offset, unsigned samples);
... ...
@@ -39,10 +41,12 @@ XSFPlayer *XSFPlayer::Create(const std::string &fn)
39 41
 	return new XSFPlayer_GSF(fn);
40 42
 }
41 43
 
44
+#ifdef _MSC_VER
42 45
 XSFPlayer *XSFPlayer::Create(const std::wstring &fn)
43 46
 {
44 47
 	return new XSFPlayer_GSF(fn);
45 48
 }
49
+#endif
46 50
 
47 51
 static struct
48 52
 {
... ...
@@ -148,7 +152,7 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
148 152
 {
149 153
 	if (level <= 10 && xSF->GetTagExists("_lib"))
150 154
 	{
151
-#ifdef _WIN32
155
+#ifdef _MSC_VER
152 156
 		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue("_lib").GetWStr(), 8, 12));
153 157
 #else
154 158
 		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue("_lib").GetAnsi(), 8, 12));
... ...
@@ -169,7 +173,7 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
169 173
 		if (xSF->GetTagExists(libTag))
170 174
 		{
171 175
 			found = true;
172
-#ifdef _WIN32
176
+#ifdef _MSC_VER
173 177
 			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue(libTag).GetWStr(), 8, 12));
174 178
 #else
175 179
 			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue(libTag).GetAnsi(), 8, 12));
... ...
@@ -195,10 +199,12 @@ XSFPlayer_GSF::XSFPlayer_GSF(const std::string &filename) : XSFPlayer()
195 199
 	this->xSF.reset(new XSFFile(filename, 8, 12));
196 200
 }
197 201
 
202
+#ifdef _MSC_VER
198 203
 XSFPlayer_GSF::XSFPlayer_GSF(const std::wstring &filename) : XSFPlayer()
199 204
 {
200 205
 	this->xSF.reset(new XSFFile(filename, 8, 12));
201 206
 }
207
+#endif
202 208
 
203 209
 bool XSFPlayer_GSF::Load()
204 210
 {
Browse code

[GSF] Massive code cleanup.

(As an aside, blargg's code style makes me go blarg myself.)

Naram Qashat authored on 2013/05/14 01:07:18
Showing 1 changed files
... ...
@@ -207,14 +207,14 @@ bool XSFPlayer_GSF::Load()
207 207
 
208 208
 	cpuIsMultiBoot = (loaderwork.entry >> 24) == 2;
209 209
 
210
-	CPULoadRom(nullptr);
210
+	CPULoadRom();
211 211
 
212 212
 	soundSetSampleRate(this->sampleRate);
213 213
 	soundInit();
214 214
 	soundReset();
215
-	soundSetEnable(0x3FF);
215
+	soundSetEnable(0x30F);
216 216
 
217
-	CPUInit(nullptr, false);
217
+	CPUInit();
218 218
 	CPUReset();
219 219
 
220 220
 	return XSFPlayer::Load();
... ...
@@ -245,7 +245,6 @@ void XSFPlayer_GSF::GenerateSamples(std::vector<uint8_t> &buf, unsigned offset,
245 245
 
246 246
 void XSFPlayer_GSF::Terminate()
247 247
 {
248
-	CPUCleanUp();
249 248
 	soundShutdown();
250 249
 
251 250
 	loaderwork.rom.clear();
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 - GSF 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 viogsf v0.08
7 7
  *
... ...
@@ -192,17 +192,17 @@ static bool Load2SF(XSFFile *xSF)
192 192
 
193 193
 XSFPlayer_GSF::XSFPlayer_GSF(const std::string &filename) : XSFPlayer()
194 194
 {
195
-	this->xSF = new XSFFile(filename, 8, 12);
195
+	this->xSF.reset(new XSFFile(filename, 8, 12));
196 196
 }
197 197
 
198 198
 XSFPlayer_GSF::XSFPlayer_GSF(const std::wstring &filename) : XSFPlayer()
199 199
 {
200
-	this->xSF = new XSFFile(filename, 8, 12);
200
+	this->xSF.reset(new XSFFile(filename, 8, 12));
201 201
 }
202 202
 
203 203
 bool XSFPlayer_GSF::Load()
204 204
 {
205
-	if (!Load2SF(this->xSF))
205
+	if (!Load2SF(this->xSF.get()))
206 206
 		return false;
207 207
 
208 208
 	cpuIsMultiBoot = (loaderwork.entry >> 24) == 2;
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 - GSF 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 viogsf v0.08
7 7
  *
... ...
@@ -106,7 +106,7 @@ public:
106 106
 		}
107 107
 	}
108 108
 
109
-	void setThrottle(unsigned short throttle)
109
+	void setThrottle(unsigned short)
110 110
 	{
111 111
 	}
112 112
 };
... ...
@@ -207,14 +207,14 @@ bool XSFPlayer_GSF::Load()
207 207
 
208 208
 	cpuIsMultiBoot = (loaderwork.entry >> 24) == 2;
209 209
 
210
-	CPULoadRom(NULL);
210
+	CPULoadRom(nullptr);
211 211
 
212 212
 	soundSetSampleRate(this->sampleRate);
213 213
 	soundInit();
214 214
 	soundReset();
215 215
 	soundSetEnable(0x3FF);
216 216
 
217
-	CPUInit(NULL, false);
217
+	CPUInit(nullptr, false);
218 218
 	CPUReset();
219 219
 
220 220
 	return XSFPlayer::Load();
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
... ...
@@ -149,9 +149,9 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
149 149
 	if (level <= 10 && xSF->GetTagExists("_lib"))
150 150
 	{
151 151
 #ifdef _WIN32
152
-		auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue("_lib").GetWStr(), 8, 12));
152
+		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue("_lib").GetWStr(), 8, 12));
153 153
 #else
154
-		auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue("_lib").GetAnsi(), 8, 12));
154
+		auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue("_lib").GetAnsi(), 8, 12));
155 155
 #endif
156 156
 		if (!RecursiveLoad2SF(libxSF.get(), level + 1))
157 157
 			return false;
... ...
@@ -170,9 +170,9 @@ static bool RecursiveLoad2SF(XSFFile *xSF, int level)
170 170
 		{
171 171
 			found = true;
172 172
 #ifdef _WIN32
173
-			auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue(libTag).GetWStr(), 8, 12));
173
+			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue(libTag).GetWStr(), 8, 12));
174 174
 #else
175
-			auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue(libTag).GetAnsi(), 8, 12));
175
+			auto libxSF = std::unique_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue(libTag).GetAnsi(), 8, 12));
176 176
 #endif
177 177
 			if (!RecursiveLoad2SF(libxSF.get(), level + 1))
178 178
 				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,253 @@
1
+/*
2
+ * xSF - GSF Player
3
+ * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
4
+ * Last modification on 2013-03-25
5
+ *
6
+ * Based on a modified viogsf v0.08
7
+ *
8
+ * Partially based on the vio*sf framework
9
+ *
10
+ * Utilizes a modified VBA-M, SVN revision 1102, for playback
11
+ * http://vba-m.com/
12
+ */
13
+
14
+#include <memory>
15
+#include <zlib.h>
16
+#include "convert.h"
17
+#include "XSFPlayer.h"
18
+#include "XSFCommon.h"
19
+#include "vbam/gba/Globals.h"
20
+#include "vbam/gba/Sound.h"
21
+#include "vbam/common/SoundDriver.h"
22
+
23
+class XSFPlayer_GSF : public XSFPlayer
24
+{
25
+public:
26
+	XSFPlayer_GSF(const std::string &filename);
27
+	XSFPlayer_GSF(const std::wstring &filename);
28
+	~XSFPlayer_GSF() { this->Terminate(); }
29
+	bool Load();
30
+	void GenerateSamples(std::vector<uint8_t> &buf, unsigned offset, unsigned samples);
31
+	void Terminate();
32
+};
33
+
34
+const char *XSFPlayer::WinampDescription = "GSF Decoder";
35
+const char *XSFPlayer::WinampExts = "gsf;minigsf\0Game Boy Advance Sound Format files (*.gsf;*.minigsf)\0";
36
+
37
+XSFPlayer *XSFPlayer::Create(const std::string &fn)
38
+{
39
+	return new XSFPlayer_GSF(fn);
40
+}
41
+
42
+XSFPlayer *XSFPlayer::Create(const std::wstring &fn)
43
+{
44
+	return new XSFPlayer_GSF(fn);
45
+}
46
+
47
+static struct
48
+{
49
+	std::vector<uint8_t> rom;
50
+	unsigned entry;
51
+} loaderwork;
52
+
53
+int mapgsf(uint8_t *d, int l, int &s)
54
+{
55
+	if (static_cast<size_t>(l) > loaderwork.rom.size())
56
+		l = loaderwork.rom.size();
57
+	if (l)
58
+		memcpy(d, &loaderwork.rom[0], l);
59
+	s = l;
60
+	return l;
61
+}
62
+
63
+static struct
64
+{
65
+	std::vector<uint8_t> buf;
66
+	uint32_t len, fil, cur;
67
+} buffer = { std::vector<uint8_t>(), 0, 0, 0 };
68
+
69
+class GSFSoundDriver : public SoundDriver
70
+{
71
+	void freebuffer()
72
+	{
73
+		buffer.buf.clear();
74
+		buffer.len = buffer.fil = buffer.cur = 0;
75
+	}
76
+public:
77
+	bool init(long sampleRate)
78
+	{
79
+		freebuffer();
80
+		uint32_t len = (sampleRate / 10) << 2;
81
+		buffer.buf.resize(len);
82
+		buffer.len = len;
83
+		return true;
84
+	}
85
+
86
+	void pause()
87
+	{
88
+	}
89
+
90
+	void reset()
91
+	{
92
+	}
93
+
94
+	void resume()
95
+	{
96
+	}
97
+
98
+	void write(uint16_t *finalWave, int length)
99
+	{
100
+		if (static_cast<uint32_t>(length) > buffer.len - buffer.fil)
101
+			length = buffer.len - buffer.fil;
102
+		if (length > 0)
103
+		{
104
+			memcpy(&buffer.buf[buffer.fil], finalWave, length);
105
+			buffer.fil += length;
106
+		}
107
+	}
108
+
109
+	void setThrottle(unsigned short throttle)
110
+	{
111
+	}
112
+};
113
+
114
+SoundDriver *systemSoundInit()
115
+{
116
+	return new GSFSoundDriver();
117
+}
118
+
119
+static void Map2SFSection(const std::vector<uint8_t> &section, int level)
120
+{
121
+	auto &data = loaderwork.rom;
122
+
123
+	uint32_t entry = Get32BitsLE(&section[0]), offset = Get32BitsLE(&section[4]) & 0x1FFFFFF, size = Get32BitsLE(&section[8]), finalSize = size + offset;
124
+	if (level == 1)
125
+		loaderwork.entry = entry;
126
+	finalSize = NextHighestPowerOf2(finalSize);
127
+	if (data.empty())
128
+		data.resize(finalSize + 10, 0);
129
+	else if (data.size() < size + offset)
130
+		data.resize(offset + finalSize + 10);
131
+	memcpy(&data[offset], &section[12], size);
132
+}
133
+
134
+static bool Map2SF(XSFFile *xSF, int level)
135
+{
136
+	if (!xSF->IsValidType(0x22))
137
+		return false;
138
+
139
+	auto &programSection = xSF->GetProgramSection();
140
+
141
+	if (!programSection.empty())
142
+		Map2SFSection(programSection, level);
143
+
144
+	return true;
145
+}
146
+
147
+static bool RecursiveLoad2SF(XSFFile *xSF, int level)
148
+{
149
+	if (level <= 10 && xSF->GetTagExists("_lib"))
150
+	{
151
+#ifdef _WIN32
152
+		auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue("_lib").GetWStr(), 8, 12));
153
+#else
154
+		auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue("_lib").GetAnsi(), 8, 12));
155
+#endif
156
+		if (!RecursiveLoad2SF(libxSF.get(), level + 1))
157
+			return false;
158
+	}
159
+
160
+	if (!Map2SF(xSF, level))
161
+		return false;
162
+
163
+	unsigned n = 2;
164
+	bool found;
165
+	do
166
+	{
167
+		found = false;
168
+		std::string libTag = "_lib" + stringify(n++);
169
+		if (xSF->GetTagExists(libTag))
170
+		{
171
+			found = true;
172
+#ifdef _WIN32
173
+			auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetWStr()) + xSF->GetTagValue(libTag).GetWStr(), 8, 12));
174
+#else
175
+			auto libxSF = std::auto_ptr<XSFFile>(new XSFFile(ExtractDirectoryFromPath(xSF->GetFilename().GetAnsi()) + xSF->GetTagValue(libTag).GetAnsi(), 8, 12));
176
+#endif
177
+			if (!RecursiveLoad2SF(libxSF.get(), level + 1))
178
+				return false;
179
+		}
180
+	} while (found);
181
+
182
+	return true;
183
+}
184
+
185
+static bool Load2SF(XSFFile *xSF)
186
+{
187
+	loaderwork.rom.clear();
188
+	loaderwork.entry = 0;
189
+
190
+	return RecursiveLoad2SF(xSF, 1);
191
+}
192
+
193
+XSFPlayer_GSF::XSFPlayer_GSF(const std::string &filename) : XSFPlayer()
194
+{
195
+	this->xSF = new XSFFile(filename, 8, 12);
196
+}
197
+
198
+XSFPlayer_GSF::XSFPlayer_GSF(const std::wstring &filename) : XSFPlayer()
199
+{
200
+	this->xSF = new XSFFile(filename, 8, 12);
201
+}
202
+
203
+bool XSFPlayer_GSF::Load()
204
+{
205
+	if (!Load2SF(this->xSF))
206
+		return false;
207
+
208
+	cpuIsMultiBoot = (loaderwork.entry >> 24) == 2;
209
+
210
+	CPULoadRom(NULL);
211
+
212
+	soundSetSampleRate(this->sampleRate);
213
+	soundInit();
214
+	soundReset();
215
+	soundSetEnable(0x3FF);
216
+
217
+	CPUInit(NULL, false);
218
+	CPUReset();
219
+
220
+	return XSFPlayer::Load();
221
+}
222
+
223
+void XSFPlayer_GSF::GenerateSamples(std::vector<uint8_t> &buf, unsigned offset, unsigned samples)
224
+{
225
+	unsigned bytes = samples << 2;
226
+	while (bytes)
227
+	{
228
+		unsigned remainbytes = buffer.fil - buffer.cur;
229
+		while (!remainbytes)
230
+		{
231
+			buffer.cur = buffer.fil = 0;
232
+			CPULoop(250000);
233
+
234
+			remainbytes = buffer.fil - buffer.cur;
235
+		}
236
+		unsigned len = remainbytes;
237
+		if (len > bytes)
238
+			len = bytes;
239
+		memcpy(&buf[offset], &buffer.buf[buffer.cur], len);
240
+		bytes -= len;
241
+		offset += len;
242
+		buffer.cur += len;
243
+	}
244
+}
245
+
246
+void XSFPlayer_GSF::Terminate()
247
+{
248
+	CPUCleanUp();
249
+	soundShutdown();
250
+
251
+	loaderwork.rom.clear();
252
+	loaderwork.entry = 0;
253
+}