gosu 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/dependencies/SDL/include/SDL.h +108 -14
  3. data/dependencies/SDL/include/SDL_assert.h +81 -50
  4. data/dependencies/SDL/include/SDL_atomic.h +135 -35
  5. data/dependencies/SDL/include/SDL_audio.h +960 -355
  6. data/dependencies/SDL/include/SDL_bits.h +11 -6
  7. data/dependencies/SDL/include/SDL_blendmode.h +91 -14
  8. data/dependencies/SDL/include/SDL_clipboard.h +30 -7
  9. data/dependencies/SDL/include/SDL_config.h +277 -27
  10. data/dependencies/SDL/include/SDL_config_android.h +13 -38
  11. data/dependencies/SDL/include/SDL_config_iphoneos.h +21 -62
  12. data/dependencies/SDL/include/SDL_config_macosx.h +23 -92
  13. data/dependencies/SDL/include/SDL_config_minimal.h +1 -4
  14. data/dependencies/SDL/include/SDL_config_pandora.h +15 -22
  15. data/dependencies/SDL/include/SDL_config_psp.h +16 -37
  16. data/dependencies/SDL/include/SDL_config_windows.h +28 -91
  17. data/dependencies/SDL/include/SDL_config_winrt.h +33 -61
  18. data/dependencies/SDL/include/SDL_config_wiz.h +28 -56
  19. data/dependencies/SDL/include/SDL_copying.h +1 -1
  20. data/dependencies/SDL/include/SDL_cpuinfo.h +331 -71
  21. data/dependencies/SDL/include/SDL_egl.h +906 -280
  22. data/dependencies/SDL/include/SDL_endian.h +101 -47
  23. data/dependencies/SDL/include/SDL_error.h +70 -19
  24. data/dependencies/SDL/include/SDL_events.h +387 -79
  25. data/dependencies/SDL/include/SDL_filesystem.h +73 -64
  26. data/dependencies/SDL/include/SDL_gamecontroller.h +585 -125
  27. data/dependencies/SDL/include/SDL_gesture.h +36 -6
  28. data/dependencies/SDL/include/SDL_haptic.h +304 -210
  29. data/dependencies/SDL/include/SDL_hidapi.h +451 -0
  30. data/dependencies/SDL/include/SDL_hints.h +1286 -897
  31. data/dependencies/SDL/include/SDL_joystick.h +577 -130
  32. data/dependencies/SDL/include/SDL_keyboard.h +162 -63
  33. data/dependencies/SDL/include/SDL_keycode.h +7 -5
  34. data/dependencies/SDL/include/SDL_loadso.h +42 -8
  35. data/dependencies/SDL/include/SDL_locale.h +34 -32
  36. data/dependencies/SDL/include/SDL_log.h +212 -19
  37. data/dependencies/SDL/include/SDL_main.h +72 -17
  38. data/dependencies/SDL/include/SDL_messagebox.h +70 -23
  39. data/dependencies/SDL/include/SDL_metal.h +27 -32
  40. data/dependencies/SDL/include/SDL_misc.h +19 -15
  41. data/dependencies/SDL/include/SDL_mouse.h +262 -110
  42. data/dependencies/SDL/include/SDL_mutex.h +286 -66
  43. data/dependencies/SDL/include/SDL_name.h +1 -1
  44. data/dependencies/SDL/include/SDL_opengl.h +1 -1
  45. data/dependencies/SDL/include/SDL_opengles.h +1 -1
  46. data/dependencies/SDL/include/SDL_opengles2.h +2 -2
  47. data/dependencies/SDL/include/SDL_pixels.h +199 -34
  48. data/dependencies/SDL/include/SDL_platform.h +39 -2
  49. data/dependencies/SDL/include/SDL_power.h +23 -10
  50. data/dependencies/SDL/include/SDL_quit.h +1 -1
  51. data/dependencies/SDL/include/SDL_rect.h +78 -28
  52. data/dependencies/SDL/include/SDL_render.h +1204 -472
  53. data/dependencies/SDL/include/SDL_revision.h +2 -2
  54. data/dependencies/SDL/include/SDL_rwops.h +605 -33
  55. data/dependencies/SDL/include/SDL_scancode.h +1 -1
  56. data/dependencies/SDL/include/SDL_sensor.h +76 -42
  57. data/dependencies/SDL/include/SDL_shape.h +38 -27
  58. data/dependencies/SDL/include/SDL_stdinc.h +96 -24
  59. data/dependencies/SDL/include/SDL_surface.h +571 -139
  60. data/dependencies/SDL/include/SDL_system.h +339 -101
  61. data/dependencies/SDL/include/SDL_syswm.h +50 -20
  62. data/dependencies/SDL/include/SDL_test.h +1 -1
  63. data/dependencies/SDL/include/SDL_test_assert.h +2 -2
  64. data/dependencies/SDL/include/SDL_test_common.h +23 -6
  65. data/dependencies/SDL/include/SDL_test_compare.h +1 -1
  66. data/dependencies/SDL/include/SDL_test_crc32.h +1 -1
  67. data/dependencies/SDL/include/SDL_test_font.h +3 -3
  68. data/dependencies/SDL/include/SDL_test_fuzzer.h +28 -26
  69. data/dependencies/SDL/include/SDL_test_harness.h +6 -6
  70. data/dependencies/SDL/include/SDL_test_images.h +1 -1
  71. data/dependencies/SDL/include/SDL_test_log.h +1 -1
  72. data/dependencies/SDL/include/SDL_test_md5.h +1 -1
  73. data/dependencies/SDL/include/SDL_test_memory.h +1 -1
  74. data/dependencies/SDL/include/SDL_test_random.h +2 -2
  75. data/dependencies/SDL/include/SDL_thread.h +226 -128
  76. data/dependencies/SDL/include/SDL_timer.h +129 -22
  77. data/dependencies/SDL/include/SDL_touch.h +48 -8
  78. data/dependencies/SDL/include/SDL_types.h +1 -1
  79. data/dependencies/SDL/include/SDL_version.h +72 -46
  80. data/dependencies/SDL/include/SDL_video.h +1266 -460
  81. data/dependencies/SDL/include/SDL_vulkan.h +100 -161
  82. data/dependencies/SDL/include/begin_code.h +22 -1
  83. data/dependencies/SDL/include/close_code.h +1 -1
  84. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  85. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  86. data/dependencies/SDL_sound/SDL_sound.c +83 -7
  87. data/dependencies/SDL_sound/SDL_sound.h +4 -4
  88. data/dependencies/SDL_sound/SDL_sound_aiff.c +9 -12
  89. data/dependencies/SDL_sound/SDL_sound_au.c +7 -7
  90. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +3 -3
  91. data/dependencies/SDL_sound/SDL_sound_flac.c +1 -1
  92. data/dependencies/SDL_sound/SDL_sound_internal.h +17 -10
  93. data/dependencies/SDL_sound/SDL_sound_modplug.c +25 -27
  94. data/dependencies/SDL_sound/SDL_sound_mp3.c +5 -17
  95. data/dependencies/SDL_sound/SDL_sound_raw.c +11 -11
  96. data/dependencies/SDL_sound/SDL_sound_shn.c +8 -7
  97. data/dependencies/SDL_sound/SDL_sound_voc.c +6 -4
  98. data/dependencies/SDL_sound/SDL_sound_vorbis.c +6 -11
  99. data/dependencies/SDL_sound/SDL_sound_wav.c +35 -29
  100. data/dependencies/SDL_sound/dr_flac.h +618 -220
  101. data/dependencies/SDL_sound/dr_mp3.h +263 -94
  102. data/dependencies/SDL_sound/libmodplug/fastmix.c +58 -64
  103. data/dependencies/SDL_sound/libmodplug/libmodplug.h +25 -103
  104. data/dependencies/SDL_sound/libmodplug/load_669.c +14 -17
  105. data/dependencies/SDL_sound/libmodplug/load_amf.c +11 -7
  106. data/dependencies/SDL_sound/libmodplug/load_ams.c +65 -22
  107. data/dependencies/SDL_sound/libmodplug/load_dbm.c +8 -4
  108. data/dependencies/SDL_sound/libmodplug/load_dmf.c +55 -25
  109. data/dependencies/SDL_sound/libmodplug/load_far.c +9 -13
  110. data/dependencies/SDL_sound/libmodplug/load_gdm.c +448 -0
  111. data/dependencies/SDL_sound/libmodplug/load_it.c +45 -49
  112. data/dependencies/SDL_sound/libmodplug/load_mdl.c +80 -53
  113. data/dependencies/SDL_sound/libmodplug/load_med.c +20 -12
  114. data/dependencies/SDL_sound/libmodplug/load_mod.c +40 -15
  115. data/dependencies/SDL_sound/libmodplug/load_mt2.c +29 -17
  116. data/dependencies/SDL_sound/libmodplug/load_okt.c +12 -8
  117. data/dependencies/SDL_sound/libmodplug/load_psm.c +101 -78
  118. data/dependencies/SDL_sound/libmodplug/load_ptm.c +18 -17
  119. data/dependencies/SDL_sound/libmodplug/load_s3m.c +9 -7
  120. data/dependencies/SDL_sound/libmodplug/load_stm.c +3 -2
  121. data/dependencies/SDL_sound/libmodplug/load_ult.c +2 -2
  122. data/dependencies/SDL_sound/libmodplug/load_umx.c +315 -35
  123. data/dependencies/SDL_sound/libmodplug/load_xm.c +25 -21
  124. data/dependencies/SDL_sound/libmodplug/mmcmp.c +295 -149
  125. data/dependencies/SDL_sound/libmodplug/modplug.c +7 -123
  126. data/dependencies/SDL_sound/libmodplug/modplug.h +32 -29
  127. data/dependencies/SDL_sound/libmodplug/snd_dsp.c +0 -1
  128. data/dependencies/SDL_sound/libmodplug/snd_flt.c +2 -2
  129. data/dependencies/SDL_sound/libmodplug/snd_fx.c +24 -18
  130. data/dependencies/SDL_sound/libmodplug/sndfile.c +55 -156
  131. data/dependencies/SDL_sound/libmodplug/sndmix.c +7 -12
  132. data/dependencies/SDL_sound/libmodplug/tables.h +10 -15
  133. data/dependencies/SDL_sound/stb_vorbis.h +508 -325
  134. data/dependencies/{al_soft → mojoAL}/AL/al.h +38 -30
  135. data/dependencies/{al_soft → mojoAL}/AL/alc.h +27 -56
  136. data/dependencies/mojoAL/mojoal.c +4594 -0
  137. data/ext/gosu/extconf.rb +29 -30
  138. data/include/Gosu/Audio.hpp +70 -85
  139. data/include/Gosu/Color.hpp +19 -11
  140. data/include/Gosu/Font.hpp +40 -44
  141. data/include/Gosu/Graphics.hpp +58 -71
  142. data/include/Gosu/GraphicsBase.hpp +26 -33
  143. data/include/Gosu/Image.hpp +56 -62
  144. data/include/Gosu/ImageData.hpp +23 -27
  145. data/include/Gosu/Inspection.hpp +1 -4
  146. data/include/Gosu/TextInput.hpp +34 -40
  147. data/include/Gosu/Version.hpp +1 -1
  148. data/include/Gosu/Window.hpp +71 -70
  149. data/lib/SDL2.dll +0 -0
  150. data/lib/gosu/compat.rb +24 -37
  151. data/lib/gosu.rb +2 -2
  152. data/lib64/SDL2.dll +0 -0
  153. data/src/Audio.cpp +86 -86
  154. data/src/AudioFile.hpp +6 -6
  155. data/src/AudioFileAudioToolbox.cpp +1 -1
  156. data/src/AudioFileSDLSound.cpp +1 -1
  157. data/src/AudioImpl.hpp +5 -5
  158. data/src/BitmapIO.cpp +0 -20
  159. data/src/BlockAllocator.cpp +2 -1
  160. data/src/Channel.cpp +22 -20
  161. data/src/Color.cpp +12 -9
  162. data/src/EmptyImageData.hpp +15 -17
  163. data/src/FileUnix.cpp +1 -1
  164. data/src/FileWin.cpp +1 -1
  165. data/src/Font.cpp +48 -53
  166. data/src/Graphics.cpp +135 -143
  167. data/src/Image.cpp +41 -42
  168. data/src/Input.cpp +1 -1
  169. data/src/InputUIKit.cpp +1 -1
  170. data/src/LargeImageData.cpp +108 -101
  171. data/src/LargeImageData.hpp +17 -15
  172. data/src/Log.hpp +6 -6
  173. data/src/Macro.cpp +35 -37
  174. data/src/Macro.hpp +11 -11
  175. data/src/Math.cpp +8 -1
  176. data/src/Resolution.cpp +12 -7
  177. data/src/RubyGosu.cxx +5 -5
  178. data/src/TexChunk.cpp +50 -41
  179. data/src/TexChunk.hpp +22 -22
  180. data/src/Text.cpp +37 -37
  181. data/src/TextBuilder.cpp +60 -57
  182. data/src/TextBuilder.hpp +20 -20
  183. data/src/TextInput.cpp +127 -135
  184. data/src/TrueTypeFont.cpp +107 -107
  185. data/src/TrueTypeFont.hpp +39 -38
  186. data/src/TrueTypeFontApple.cpp +19 -22
  187. data/src/TrueTypeFontUnix.cpp +21 -26
  188. data/src/TrueTypeFontWin.cpp +30 -30
  189. data/src/Window.cpp +95 -86
  190. data/src/WindowUIKit.cpp +46 -49
  191. metadata +7 -17
  192. data/dependencies/SDL/include/SDL_config_os2.h +0 -188
  193. data/dependencies/SDL_sound/libmodplug/load_abc.c +0 -4725
  194. data/dependencies/SDL_sound/libmodplug/load_mid.c +0 -1405
  195. data/dependencies/SDL_sound/libmodplug/load_pat.c +0 -1143
  196. data/dependencies/SDL_sound/libmodplug/load_pat.h +0 -25
  197. data/dependencies/al_soft/AL/alext.h +0 -585
  198. data/dependencies/al_soft/AL/efx-creative.h +0 -3
  199. data/dependencies/al_soft/AL/efx-presets.h +0 -402
  200. data/dependencies/al_soft/AL/efx.h +0 -762
  201. data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
  202. data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
  203. data/lib/OpenAL32.dll +0 -0
  204. data/lib64/OpenAL32.dll +0 -0
@@ -0,0 +1,448 @@
1
+ /*
2
+ * This source code is public domain.
3
+ *
4
+ * Authors: Alice Rowan <petrifiedrowan@gmail.com>
5
+ */
6
+
7
+ ////////////////////////////////////////////////////////////
8
+ // General Digital Music module loader
9
+ ////////////////////////////////////////////////////////////
10
+
11
+ #include "libmodplug.h"
12
+
13
+ static const DWORD GDM_SIG = 0xfe4d4447; // GDM\xFE
14
+ static const DWORD GMFS_SIG = 0x53464d47; // GMFS
15
+
16
+ typedef struct tagFILEHEADERGDM
17
+ {
18
+ BYTE sig[4]; // GDM\xFE
19
+ char name[32];
20
+ char author[32];
21
+ BYTE eof[3]; // \x0D\x0A\x1A
22
+ BYTE sig2[4]; // GMFS
23
+ BYTE gdm_ver_major;
24
+ BYTE gdm_ver_minor;
25
+ BYTE tracker_id[2];
26
+ BYTE tracker_ver_major;
27
+ BYTE tracker_ver_minor;
28
+ BYTE panning[32];
29
+ BYTE globalvol;
30
+ BYTE default_speed;
31
+ BYTE default_bpm;
32
+ BYTE origfmt[2];
33
+ BYTE ordersPos[4];
34
+ BYTE nOrders;
35
+ BYTE patternsPos[4];
36
+ BYTE nPatterns;
37
+ BYTE samplesPos[4];
38
+ BYTE sampleDataPos[4];
39
+ BYTE nSamples;
40
+ BYTE messagePos[4];
41
+ BYTE messageLength[4];
42
+ BYTE ignore[12];
43
+ } FILEHEADERGDM;
44
+
45
+ enum SAMPLEGDMFLAGS
46
+ {
47
+ S_LOOP = (1<<0),
48
+ S_16BIT = (1<<1),
49
+ S_VOLUME = (1<<2),
50
+ S_PAN = (1<<3),
51
+ S_LZW = (1<<4),
52
+ S_STEREO = (1<<5)
53
+ };
54
+
55
+ typedef struct tagSAMPLEGDM
56
+ {
57
+ char name[32];
58
+ char dosname[12];
59
+ BYTE ignore;
60
+ BYTE length[4];
61
+ BYTE loopstart[4];
62
+ BYTE loopend[4];
63
+ BYTE flags;
64
+ BYTE c4rate[2];
65
+ BYTE volume;
66
+ BYTE panning;
67
+ } SAMPLEGDM;
68
+
69
+ static WORD fixu16(const BYTE *val)
70
+ {
71
+ return (val[1] << 8) | val[0];
72
+ }
73
+
74
+ static DWORD fixu32(const BYTE val[4])
75
+ {
76
+ return (val[3] << 24) | (val[2] << 16) | (val[1] << 8) | val[0];
77
+ }
78
+
79
+ static void GDM_TranslateEffect(const FILEHEADERGDM *pfh, MODCOMMAND *ev, UINT channel, UINT effect, UINT param)
80
+ //--------------------------------------------------------------------------------------------------------------
81
+ {
82
+ // Note due to the limitations of libmodplug's volume commands,
83
+ // anything that relied on multiple simultaneous non-volume effects
84
+ // is not going to work. Only UltraTracker GDMs should really cause
85
+ // this, and it's likely that none exist in the wild.
86
+ static const BYTE translate_effects[32] =
87
+ {
88
+ CMD_NONE,
89
+ CMD_PORTAMENTOUP,
90
+ CMD_PORTAMENTODOWN,
91
+ CMD_TONEPORTAMENTO,
92
+ CMD_VIBRATO,
93
+ CMD_TONEPORTAVOL,
94
+ CMD_VIBRATOVOL,
95
+ CMD_TREMOLO,
96
+ CMD_TREMOR,
97
+ CMD_OFFSET,
98
+ CMD_VOLUMESLIDE,
99
+ CMD_POSITIONJUMP,
100
+ CMD_VOLUME,
101
+ CMD_PATTERNBREAK,
102
+ CMD_MODCMDEX,
103
+ CMD_SPEED,
104
+
105
+ CMD_ARPEGGIO,
106
+ CMD_NONE, // Set Internal Flag
107
+ CMD_RETRIG,
108
+ CMD_GLOBALVOLUME,
109
+ CMD_FINEVIBRATO,
110
+ CMD_NONE,
111
+ CMD_NONE,
112
+ CMD_NONE,
113
+ CMD_NONE,
114
+ CMD_NONE,
115
+ CMD_NONE,
116
+ CMD_NONE,
117
+ CMD_NONE,
118
+ CMD_NONE,
119
+ CMD_NONE, // Special-- default to nothing.
120
+ CMD_TEMPO
121
+ };
122
+
123
+ if (effect >= 32) return;
124
+
125
+ switch (effect)
126
+ {
127
+ case 0x0c: // Volume
128
+ // Prefer volume command over regular command.
129
+ if (!ev->volcmd)
130
+ {
131
+ ev->volcmd = VOLCMD_VOLUME;
132
+ ev->vol = (param > 64) ? 64 : param;
133
+ } else
134
+ {
135
+ ev->command = CMD_VOLUME;
136
+ ev->param = (param > 64) ? 64 : param;
137
+ }
138
+ break;
139
+
140
+ case 0x0e: // Extended
141
+ // Most of these are effectively MOD extended commands, but
142
+ // the fine volslide and portamento commands need to be
143
+ // converted back to their S3M equivalents.
144
+ switch ((param & 0xf0) >> 4)
145
+ {
146
+ case 0x01: // Fine porta up.
147
+ ev->command = CMD_PORTAMENTOUP;
148
+ ev->param = 0xf0 | (param & 0x0f);
149
+ break;
150
+
151
+ case 0x02: // Fine porta down.
152
+ ev->command = CMD_PORTAMENTODOWN;
153
+ ev->param = 0xf0 | (param & 0x0f);
154
+ break;
155
+
156
+ case 0x08: // Extra fine porta up.
157
+ ev->command = CMD_PORTAMENTOUP;
158
+ ev->param = 0xe0 | (param & 0x0f);
159
+ break;
160
+
161
+ case 0x09: // Extra fine porta down.
162
+ ev->command = CMD_PORTAMENTODOWN;
163
+ ev->param = 0xe0 | (param & 0x0f);
164
+ break;
165
+
166
+ case 0x0a: // Fine volslide up.
167
+ if (param & 0x0f)
168
+ {
169
+ ev->command = CMD_VOLUMESLIDE;
170
+ ev->param = 0x0f | ((param & 0x0f) << 4);
171
+ }
172
+ break;
173
+
174
+ case 0x0b: // Fine volslide down.
175
+ if (param & 0x0f)
176
+ {
177
+ ev->command = CMD_VOLUMESLIDE;
178
+ ev->param = 0xf0 | (param & 0x0f);
179
+ }
180
+ break;
181
+
182
+ default:
183
+ ev->command = CMD_MODCMDEX;
184
+ ev->param = param;
185
+ break;
186
+ }
187
+ break;
188
+
189
+ case 0x1e: // Special
190
+ switch ((param & 0xf0) >> 4)
191
+ {
192
+ case 0x00: // Sample control.
193
+ // Only surround on is emitted by 2GDM.
194
+ // This comes from XA4, so convert it back.
195
+ if ((param & 0x0f) == 1)
196
+ {
197
+ ev->command = CMD_PANNING8;
198
+ ev->param = 0xA4;
199
+ }
200
+ break;
201
+
202
+ case 0x08: // Set Pan Position
203
+ // Prefer volume command over regular command if this
204
+ // this comes from effect channel 0.
205
+ if (!ev->volcmd && channel == 0)
206
+ {
207
+ ev->volcmd = VOLCMD_PANNING;
208
+ ev->vol = ((param & 0x0f) << 2) + 2;
209
+ } else
210
+ {
211
+ ev->command = CMD_PANNING8;
212
+ ev->param = ((param & 0x0f) << 3) + 4;
213
+ }
214
+ break;
215
+ }
216
+ break;
217
+
218
+ default:
219
+ ev->command = translate_effects[effect];
220
+ ev->param = param;
221
+ break;
222
+ }
223
+ }
224
+
225
+ BOOL CSoundFile_ReadGDM(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLength)
226
+ //---------------------------------------------------------------
227
+ {
228
+ const FILEHEADERGDM *pfh = (const FILEHEADERGDM *)lpStream;
229
+ const SAMPLEGDM *psmp;
230
+ BYTE sflags[256];
231
+ DWORD pos;
232
+ UINT npat;
233
+
234
+ if ((!lpStream) || (dwMemLength < sizeof(FILEHEADERGDM))) return FALSE;
235
+ if ((fixu32(pfh->sig) != GDM_SIG) || (fixu32(pfh->sig2) != GMFS_SIG)) return FALSE;
236
+
237
+ DWORD ordersPos = fixu32(pfh->ordersPos);
238
+ DWORD patternsPos = fixu32(pfh->patternsPos);
239
+ DWORD samplesPos = fixu32(pfh->samplesPos);
240
+ DWORD sampleDataPos = fixu32(pfh->sampleDataPos);
241
+ UINT nPatterns = pfh->nPatterns + 1;
242
+ UINT nOrders = pfh->nOrders + 1;
243
+ UINT nSamples = pfh->nSamples + 1;
244
+
245
+ if (nPatterns > MAX_PATTERNS) nPatterns = MAX_PATTERNS;
246
+ if (nOrders > MAX_ORDERS) nOrders = MAX_ORDERS;
247
+ if (nSamples >= MAX_SAMPLES) nSamples = MAX_SAMPLES - 1;
248
+
249
+ if ((ordersPos < sizeof(FILEHEADERGDM)) || (ordersPos >= dwMemLength) || (ordersPos + nOrders > dwMemLength) ||
250
+ (patternsPos < sizeof(FILEHEADERGDM)) || (patternsPos >= dwMemLength) ||
251
+ (samplesPos < sizeof(FILEHEADERGDM)) || (samplesPos >= dwMemLength) ||
252
+ (samplesPos + sizeof(SAMPLEGDM) * nSamples > dwMemLength) ||
253
+ (sampleDataPos < sizeof(FILEHEADERGDM)) || (sampleDataPos >= dwMemLength))
254
+ return TRUE;
255
+
256
+ // Most GDMs were converted from S3M and BWSB generally behaves like an S3M
257
+ // player, so assuming S3M behavior and quirks is a fairly safe bet.
258
+ _this->m_nType = MOD_TYPE_GDM | MOD_TYPE_S3M;
259
+ _this->m_nMinPeriod = 64;
260
+ _this->m_nMaxPeriod = 32767;
261
+ _this->m_nDefaultGlobalVolume = pfh->globalvol << 2;
262
+ _this->m_nDefaultTempo = pfh->default_bpm;
263
+ _this->m_nDefaultSpeed = pfh->default_speed;
264
+ _this->m_nChannels = 0;
265
+ _this->m_nSamples = nSamples;
266
+
267
+ // Get initial panning.
268
+ for (UINT i = 0; i < 32; i++)
269
+ {
270
+ if (pfh->panning[i] < 16)
271
+ {
272
+ _this->ChnSettings[i].nPan = (pfh->panning[i] << 4) + 8;
273
+ }
274
+ // TODO 16=surround
275
+ }
276
+
277
+ // Samples.
278
+ psmp = (const SAMPLEGDM *)(lpStream + samplesPos);
279
+ for (UINT nins = 0; nins < nSamples; nins++)
280
+ {
281
+ const SAMPLEGDM *smp = &psmp[nins];
282
+ MODINSTRUMENT *ins = &_this->Ins[nins + 1];
283
+
284
+ DWORD len = fixu32(smp->length);
285
+ DWORD loopstart = fixu32(smp->loopstart);
286
+ DWORD loopend = fixu32(smp->loopend);
287
+
288
+ UINT flags = smp->flags;
289
+
290
+ // Note: BWSB and 2GDM don't support LZW, stereo samples, sample panning.
291
+ if (flags & S_16BIT)
292
+ {
293
+ sflags[nins] = RS_PCM16U;
294
+ // Due to a 2GDM bug, the sample size is halved.
295
+ // (Note BWSB doesn't even check for these anyway.)
296
+ len /= 2;
297
+ loopstart /= 2;
298
+ loopend /= 2;
299
+ }
300
+ else
301
+ sflags[nins] = RS_PCM8U;
302
+
303
+ if (len > MAX_SAMPLE_LENGTH) len = MAX_SAMPLE_LENGTH;
304
+ if (loopend > len) loopend = len;
305
+ if (loopstart > loopend) loopstart = loopend = 0;
306
+
307
+ ins->nLength = len;
308
+ ins->nLoopStart = loopstart;
309
+ ins->nLoopEnd = loopend;
310
+ if (loopend && (flags & S_LOOP)) ins->uFlags |= CHN_LOOP;
311
+
312
+ ins->nC4Speed = fixu16(smp->c4rate);
313
+ ins->nVolume = (flags & S_VOLUME) && (smp->volume <= 64) ? (smp->volume << 2) : 256;
314
+ ins->nGlobalVol = 64;
315
+ ins->nPan = 128;
316
+ }
317
+
318
+ // Order table.
319
+ SDL_memcpy(_this->Order, lpStream + ordersPos, pfh->nOrders + 1);
320
+
321
+ // Scan patterns to get pattern row counts and the real module channel count.
322
+ // Also do bounds checks to make sure the patterns can be safely loaded.
323
+ pos = patternsPos;
324
+ for (npat = 0; npat < nPatterns && pos + 2 <= dwMemLength; npat++)
325
+ {
326
+ UINT patLen = fixu16(lpStream + pos);
327
+ DWORD patEnd = pos + patLen;
328
+ UINT rows = 0;
329
+ UINT channel;
330
+
331
+ if (patEnd > dwMemLength) break;
332
+
333
+ pos += 2;
334
+ while (pos < patEnd)
335
+ {
336
+ rows++;
337
+
338
+ while (pos < patEnd)
339
+ {
340
+ BYTE dat = lpStream[pos++];
341
+ if (!dat)
342
+ break;
343
+
344
+ channel = dat & 0x1f;
345
+ if (channel >= _this->m_nChannels)
346
+ _this->m_nChannels = channel + 1;
347
+
348
+ // Note and sample.
349
+ if (dat & 0x20)
350
+ {
351
+ if (pos + 2 > patEnd) goto BadPattern;
352
+ pos += 2;
353
+ }
354
+
355
+ // Effects.
356
+ if (dat & 0x40)
357
+ {
358
+ do
359
+ {
360
+ if (pos + 2 > patEnd) goto BadPattern;
361
+ dat = lpStream[pos];
362
+ pos += 2;
363
+ } while (dat & 0x20);
364
+ }
365
+ }
366
+ }
367
+
368
+ _this->PatternSize[npat] = rows;
369
+ }
370
+ BadPattern:
371
+ // Discard truncated/corrupted patterns (if any).
372
+ if (npat < nPatterns)
373
+ nPatterns = npat;
374
+
375
+ // Load patterns.
376
+ pos = patternsPos;
377
+ for (npat = 0; npat < nPatterns && pos + 2 <= dwMemLength; npat++)
378
+ {
379
+ UINT patLen = fixu16(lpStream + pos);
380
+ DWORD patEnd = pos + patLen;
381
+ UINT row = 0;
382
+
383
+ pos += 2;
384
+
385
+ _this->Patterns[npat] = CSoundFile_AllocatePattern(_this->PatternSize[npat], _this->m_nChannels);
386
+ if (!_this->Patterns[npat]) break;
387
+
388
+ MODCOMMAND *m = _this->Patterns[npat];
389
+ while (pos < patEnd)
390
+ {
391
+ while (pos < patEnd)
392
+ {
393
+ BYTE dat = lpStream[pos++];
394
+ if (!dat)
395
+ break;
396
+
397
+ BYTE channel = dat & 0x1f;
398
+ MODCOMMAND *ev = &m[row * _this->m_nChannels + channel];
399
+
400
+ if (dat & 0x20)
401
+ {
402
+ BYTE note = lpStream[pos++];
403
+ BYTE smpl = lpStream[pos++];
404
+
405
+ if (note) // This can be 0, indicating no note (see STARDSTM.GDM).
406
+ {
407
+ BYTE octave = (note & 0x70) >> 4;
408
+ note = octave * 12 + (note & 0x0f) + 12;
409
+ }
410
+
411
+ ev->note = note;
412
+ ev->instr = smpl;
413
+ }
414
+
415
+ if (dat & 0x40)
416
+ {
417
+ BYTE cmd, param;
418
+ do
419
+ {
420
+ cmd = lpStream[pos++];
421
+ param = lpStream[pos++];
422
+ GDM_TranslateEffect(pfh, ev, (cmd & 0xc0) >> 6, (cmd & 0x01f), param);
423
+
424
+ } while (cmd & 0x20);
425
+ }
426
+ }
427
+
428
+ row++;
429
+ }
430
+ }
431
+
432
+ // Reading Samples
433
+ pos = sampleDataPos;
434
+ for (UINT n = 0; n < nSamples; n++)
435
+ {
436
+ MODINSTRUMENT *ins = &_this->Ins[n + 1];
437
+ UINT len = ins->nLength;
438
+
439
+ if (pos >= dwMemLength) break;
440
+ if (len)
441
+ {
442
+ len = CSoundFile_ReadSample(_this, ins, sflags[n], (LPSTR)(lpStream + pos), dwMemLength - pos);
443
+ pos += len;
444
+ }
445
+ }
446
+
447
+ return TRUE;
448
+ }