gosu 0.15.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (242) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/COPYING +1 -1
  4. data/dependencies/SDL/include/SDL.h +138 -0
  5. data/dependencies/SDL/include/SDL_assert.h +293 -0
  6. data/dependencies/SDL/include/SDL_atomic.h +295 -0
  7. data/dependencies/SDL/include/SDL_audio.h +859 -0
  8. data/dependencies/SDL/include/SDL_bits.h +121 -0
  9. data/dependencies/SDL/include/SDL_blendmode.h +123 -0
  10. data/dependencies/SDL/include/SDL_clipboard.h +71 -0
  11. data/dependencies/SDL/include/SDL_config.h +55 -0
  12. data/dependencies/SDL/include/SDL_config_android.h +182 -0
  13. data/dependencies/SDL/include/SDL_config_iphoneos.h +207 -0
  14. data/dependencies/SDL/include/SDL_config_macosx.h +266 -0
  15. data/dependencies/SDL/include/SDL_config_minimal.h +85 -0
  16. data/dependencies/SDL/include/SDL_config_os2.h +188 -0
  17. data/dependencies/SDL/include/SDL_config_pandora.h +135 -0
  18. data/dependencies/SDL/include/SDL_config_psp.h +165 -0
  19. data/dependencies/SDL/include/SDL_config_windows.h +288 -0
  20. data/dependencies/SDL/include/SDL_config_winrt.h +243 -0
  21. data/dependencies/SDL/include/SDL_config_wiz.h +149 -0
  22. data/dependencies/SDL/include/SDL_copying.h +20 -0
  23. data/dependencies/SDL/include/SDL_cpuinfo.h +299 -0
  24. data/dependencies/SDL/include/SDL_egl.h +1676 -0
  25. data/dependencies/SDL/include/SDL_endian.h +263 -0
  26. data/dependencies/SDL/include/SDL_error.h +112 -0
  27. data/dependencies/SDL/include/SDL_events.h +827 -0
  28. data/dependencies/SDL/include/SDL_filesystem.h +136 -0
  29. data/dependencies/SDL/include/SDL_gamecontroller.h +541 -0
  30. data/dependencies/SDL/include/SDL_gesture.h +87 -0
  31. data/dependencies/SDL/include/SDL_haptic.h +1247 -0
  32. data/dependencies/SDL/include/SDL_hints.h +1578 -0
  33. data/dependencies/SDL/include/SDL_joystick.h +499 -0
  34. data/dependencies/SDL/include/SDL_keyboard.h +217 -0
  35. data/dependencies/SDL/include/SDL_keycode.h +351 -0
  36. data/dependencies/SDL/include/SDL_loadso.h +81 -0
  37. data/dependencies/SDL/include/SDL_locale.h +101 -0
  38. data/dependencies/SDL/include/SDL_log.h +211 -0
  39. data/dependencies/SDL/include/SDL_main.h +180 -0
  40. data/dependencies/SDL/include/SDL_messagebox.h +146 -0
  41. data/dependencies/SDL/include/SDL_metal.h +117 -0
  42. data/dependencies/SDL/include/SDL_misc.h +75 -0
  43. data/dependencies/SDL/include/SDL_mouse.h +302 -0
  44. data/dependencies/SDL/include/SDL_mutex.h +251 -0
  45. data/dependencies/SDL/include/SDL_name.h +33 -0
  46. data/dependencies/SDL/include/SDL_opengl.h +2183 -0
  47. data/dependencies/SDL/include/SDL_opengl_glext.h +11180 -0
  48. data/dependencies/SDL/include/SDL_opengles.h +39 -0
  49. data/dependencies/SDL/include/SDL_opengles2.h +52 -0
  50. data/dependencies/SDL/include/SDL_opengles2_gl2.h +621 -0
  51. data/dependencies/SDL/include/SDL_opengles2_gl2ext.h +2050 -0
  52. data/dependencies/SDL/include/SDL_opengles2_gl2platform.h +30 -0
  53. data/dependencies/SDL/include/SDL_opengles2_khrplatform.h +282 -0
  54. data/dependencies/SDL/include/SDL_pixels.h +479 -0
  55. data/dependencies/SDL/include/SDL_platform.h +198 -0
  56. data/dependencies/SDL/include/SDL_power.h +75 -0
  57. data/dependencies/SDL/include/SDL_quit.h +58 -0
  58. data/dependencies/SDL/include/SDL_rect.h +174 -0
  59. data/dependencies/SDL/include/SDL_render.h +1158 -0
  60. data/dependencies/SDL/include/SDL_revision.h +2 -0
  61. data/dependencies/SDL/include/SDL_rwops.h +283 -0
  62. data/dependencies/SDL/include/SDL_scancode.h +413 -0
  63. data/dependencies/SDL/include/SDL_sensor.h +267 -0
  64. data/dependencies/SDL/include/SDL_shape.h +144 -0
  65. data/dependencies/SDL/include/SDL_stdinc.h +647 -0
  66. data/dependencies/SDL/include/SDL_surface.h +563 -0
  67. data/dependencies/SDL/include/SDL_system.h +325 -0
  68. data/dependencies/SDL/include/SDL_syswm.h +354 -0
  69. data/dependencies/SDL/include/SDL_test.h +69 -0
  70. data/dependencies/SDL/include/SDL_test_assert.h +105 -0
  71. data/dependencies/SDL/include/SDL_test_common.h +218 -0
  72. data/dependencies/SDL/include/SDL_test_compare.h +69 -0
  73. data/dependencies/SDL/include/SDL_test_crc32.h +124 -0
  74. data/dependencies/SDL/include/SDL_test_font.h +81 -0
  75. data/dependencies/SDL/include/SDL_test_fuzzer.h +384 -0
  76. data/dependencies/SDL/include/SDL_test_harness.h +134 -0
  77. data/dependencies/SDL/include/SDL_test_images.h +78 -0
  78. data/dependencies/SDL/include/SDL_test_log.h +67 -0
  79. data/dependencies/SDL/include/SDL_test_md5.h +129 -0
  80. data/dependencies/SDL/include/SDL_test_memory.h +63 -0
  81. data/dependencies/SDL/include/SDL_test_random.h +115 -0
  82. data/dependencies/SDL/include/SDL_thread.h +366 -0
  83. data/dependencies/SDL/include/SDL_timer.h +115 -0
  84. data/dependencies/SDL/include/SDL_touch.h +102 -0
  85. data/dependencies/SDL/include/SDL_types.h +29 -0
  86. data/dependencies/SDL/include/SDL_version.h +162 -0
  87. data/dependencies/SDL/include/SDL_video.h +1282 -0
  88. data/dependencies/SDL/include/SDL_vulkan.h +276 -0
  89. data/dependencies/SDL/include/begin_code.h +166 -0
  90. data/dependencies/SDL/include/close_code.h +40 -0
  91. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  92. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  93. data/dependencies/SDL_sound/SDL_sound.c +795 -0
  94. data/dependencies/SDL_sound/SDL_sound.h +725 -0
  95. data/dependencies/SDL_sound/SDL_sound_aiff.c +537 -0
  96. data/dependencies/SDL_sound/SDL_sound_au.c +352 -0
  97. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +747 -0
  98. data/dependencies/SDL_sound/SDL_sound_flac.c +182 -0
  99. data/dependencies/SDL_sound/SDL_sound_internal.h +304 -0
  100. data/dependencies/SDL_sound/SDL_sound_modplug.c +228 -0
  101. data/dependencies/SDL_sound/SDL_sound_mp3.c +184 -0
  102. data/dependencies/SDL_sound/SDL_sound_raw.c +164 -0
  103. data/dependencies/SDL_sound/SDL_sound_shn.c +1309 -0
  104. data/dependencies/SDL_sound/SDL_sound_voc.c +550 -0
  105. data/dependencies/SDL_sound/SDL_sound_vorbis.c +223 -0
  106. data/dependencies/SDL_sound/SDL_sound_wav.c +783 -0
  107. data/dependencies/SDL_sound/dr_flac.h +5906 -0
  108. data/dependencies/SDL_sound/dr_mp3.h +2832 -0
  109. data/dependencies/SDL_sound/libmodplug/fastmix.c +1748 -0
  110. data/dependencies/SDL_sound/libmodplug/libmodplug.h +1001 -0
  111. data/dependencies/SDL_sound/libmodplug/load_669.c +188 -0
  112. data/dependencies/SDL_sound/libmodplug/load_abc.c +4725 -0
  113. data/dependencies/SDL_sound/libmodplug/load_amf.c +403 -0
  114. data/dependencies/SDL_sound/libmodplug/load_ams.c +587 -0
  115. data/dependencies/SDL_sound/libmodplug/load_dbm.c +357 -0
  116. data/dependencies/SDL_sound/libmodplug/load_dmf.c +531 -0
  117. data/dependencies/SDL_sound/libmodplug/load_dsm.c +232 -0
  118. data/dependencies/SDL_sound/libmodplug/load_far.c +253 -0
  119. data/dependencies/SDL_sound/libmodplug/load_it.c +796 -0
  120. data/dependencies/SDL_sound/libmodplug/load_mdl.c +488 -0
  121. data/dependencies/SDL_sound/libmodplug/load_med.c +757 -0
  122. data/dependencies/SDL_sound/libmodplug/load_mid.c +1405 -0
  123. data/dependencies/SDL_sound/libmodplug/load_mod.c +269 -0
  124. data/dependencies/SDL_sound/libmodplug/load_mt2.c +546 -0
  125. data/dependencies/SDL_sound/libmodplug/load_mtm.c +142 -0
  126. data/dependencies/SDL_sound/libmodplug/load_okt.c +192 -0
  127. data/dependencies/SDL_sound/libmodplug/load_pat.c +1143 -0
  128. data/dependencies/SDL_sound/libmodplug/load_pat.h +25 -0
  129. data/dependencies/SDL_sound/libmodplug/load_psm.c +350 -0
  130. data/dependencies/SDL_sound/libmodplug/load_ptm.c +204 -0
  131. data/dependencies/SDL_sound/libmodplug/load_s3m.c +325 -0
  132. data/dependencies/SDL_sound/libmodplug/load_stm.c +180 -0
  133. data/dependencies/SDL_sound/libmodplug/load_ult.c +206 -0
  134. data/dependencies/SDL_sound/libmodplug/load_umx.c +51 -0
  135. data/dependencies/SDL_sound/libmodplug/load_xm.c +554 -0
  136. data/dependencies/SDL_sound/libmodplug/mmcmp.c +382 -0
  137. data/dependencies/SDL_sound/libmodplug/modplug.c +170 -0
  138. data/dependencies/SDL_sound/libmodplug/modplug.h +90 -0
  139. data/dependencies/SDL_sound/libmodplug/snd_dsp.c +301 -0
  140. data/dependencies/SDL_sound/libmodplug/snd_flt.c +63 -0
  141. data/dependencies/SDL_sound/libmodplug/snd_fx.c +2350 -0
  142. data/dependencies/SDL_sound/libmodplug/sndfile.c +1169 -0
  143. data/dependencies/SDL_sound/libmodplug/sndmix.c +1034 -0
  144. data/dependencies/SDL_sound/libmodplug/tables.h +371 -0
  145. data/{src/stb_vorbis.c → dependencies/SDL_sound/stb_vorbis.h} +128 -23
  146. data/dependencies/al_soft/AL/al.h +655 -0
  147. data/dependencies/al_soft/AL/alc.h +270 -0
  148. data/dependencies/al_soft/AL/alext.h +585 -0
  149. data/dependencies/al_soft/AL/efx-creative.h +3 -0
  150. data/dependencies/al_soft/AL/efx-presets.h +402 -0
  151. data/dependencies/al_soft/AL/efx.h +762 -0
  152. data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
  153. data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
  154. data/{src → dependencies/stb}/stb_image.h +476 -176
  155. data/{src → dependencies/stb}/stb_image_write.h +253 -131
  156. data/{src → dependencies/stb}/stb_truetype.h +262 -104
  157. data/{src → dependencies/utf8proc}/utf8proc.c +47 -29
  158. data/{src → dependencies/utf8proc}/utf8proc.h +46 -24
  159. data/{src → dependencies/utf8proc}/utf8proc_data.h +10043 -9609
  160. data/ext/gosu/extconf.rb +53 -39
  161. data/{Gosu → include/Gosu}/Audio.hpp +6 -8
  162. data/include/Gosu/Bitmap.hpp +100 -0
  163. data/{Gosu → include/Gosu}/Buttons.hpp +104 -44
  164. data/include/Gosu/Channel.h +25 -0
  165. data/include/Gosu/Color.h +38 -0
  166. data/{Gosu → include/Gosu}/Color.hpp +0 -0
  167. data/{Gosu → include/Gosu}/Directories.hpp +0 -0
  168. data/include/Gosu/Font.h +36 -0
  169. data/{Gosu → include/Gosu}/Font.hpp +1 -1
  170. data/{Gosu → include/Gosu}/Fwd.hpp +0 -5
  171. data/include/Gosu/Gosu.h +82 -0
  172. data/{Gosu → include/Gosu}/Gosu.hpp +0 -0
  173. data/{Gosu → include/Gosu}/Graphics.hpp +0 -0
  174. data/{Gosu → include/Gosu}/GraphicsBase.hpp +0 -0
  175. data/{Gosu → include/Gosu}/IO.hpp +0 -0
  176. data/include/Gosu/Image.h +54 -0
  177. data/{Gosu → include/Gosu}/Image.hpp +7 -6
  178. data/{Gosu → include/Gosu}/ImageData.hpp +0 -0
  179. data/{Gosu → include/Gosu}/Input.hpp +39 -51
  180. data/{Gosu → include/Gosu}/Inspection.hpp +0 -0
  181. data/{Gosu → include/Gosu}/Math.hpp +0 -0
  182. data/{Gosu → include/Gosu}/Platform.hpp +0 -0
  183. data/include/Gosu/Sample.h +19 -0
  184. data/include/Gosu/Song.h +24 -0
  185. data/{Gosu → include/Gosu}/Text.hpp +0 -0
  186. data/include/Gosu/TextInput.h +30 -0
  187. data/{Gosu → include/Gosu}/TextInput.hpp +0 -0
  188. data/{Gosu → include/Gosu}/Timing.hpp +0 -0
  189. data/{Gosu → include/Gosu}/Utility.hpp +15 -4
  190. data/{Gosu → include/Gosu}/Version.hpp +2 -2
  191. data/include/Gosu/Window.h +63 -0
  192. data/{Gosu → include/Gosu}/Window.hpp +23 -25
  193. data/lib/OpenAL32.dll +0 -0
  194. data/lib/SDL2.dll +0 -0
  195. data/lib/gosu.rb +0 -3
  196. data/lib/gosu/patches.rb +0 -23
  197. data/lib/gosu/preview.rb +1 -3
  198. data/lib/gosu/swig_patches.rb +3 -2
  199. data/lib64/OpenAL32.dll +0 -0
  200. data/lib64/SDL2.dll +0 -0
  201. data/rdoc/gosu.rb +98 -22
  202. data/src/Audio.cpp +50 -224
  203. data/src/AudioFile.hpp +20 -37
  204. data/src/AudioFileAudioToolbox.cpp +237 -0
  205. data/src/AudioFileSDLSound.cpp +147 -0
  206. data/src/AudioImpl.cpp +3 -12
  207. data/src/AudioImpl.hpp +3 -1
  208. data/src/Bitmap.cpp +85 -83
  209. data/src/BitmapIO.cpp +52 -58
  210. data/src/ChannelWrapper.cpp +50 -0
  211. data/src/ColorWrapper.cpp +126 -0
  212. data/src/Constants.cpp +338 -0
  213. data/src/Font.cpp +4 -1
  214. data/src/FontWrapper.cpp +74 -0
  215. data/src/GosuWrapper.cpp +251 -0
  216. data/src/Graphics.cpp +7 -4
  217. data/src/Image.cpp +13 -16
  218. data/src/ImageWrapper.cpp +168 -0
  219. data/src/Input.cpp +412 -164
  220. data/src/LargeImageData.cpp +2 -1
  221. data/src/MarkupParser.cpp +2 -1
  222. data/src/RubyGosu.cxx +912 -172
  223. data/src/RubyGosu.h +4 -2
  224. data/src/SampleWrapper.cpp +30 -0
  225. data/src/SongWrapper.cpp +52 -0
  226. data/src/TexChunk.cpp +1 -1
  227. data/src/Text.cpp +1 -0
  228. data/src/TextBuilder.cpp +3 -1
  229. data/src/TextInputWrapper.cpp +101 -0
  230. data/src/Texture.cpp +1 -1
  231. data/src/TrueTypeFont.cpp +2 -1
  232. data/src/Utility.cpp +11 -7
  233. data/src/Window.cpp +30 -39
  234. data/src/WindowWrapper.cpp +317 -0
  235. metadata +212 -43
  236. data/Gosu/AutoLink.hpp +0 -14
  237. data/Gosu/Bitmap.hpp +0 -113
  238. data/lib/gosu/zen.rb +0 -89
  239. data/src/AudioToolboxFile.hpp +0 -210
  240. data/src/OggFile.hpp +0 -92
  241. data/src/SndFile.hpp +0 -174
  242. data/src/WinMain.cpp +0 -64
@@ -0,0 +1,796 @@
1
+ /*
2
+ * This source code is public domain.
3
+ *
4
+ * Authors: Olivier Lapicque <olivierl@jps.net>,
5
+ * Adam Goode <adam@evdebs.org> (Endian and char fixes for PPC)
6
+ * Marco Trillo <toad@arsystel.com> (Endian fixes for SaveIT, XM->IT Sample Converter)
7
+ *
8
+ */
9
+
10
+ #include "libmodplug.h"
11
+
12
+ BYTE autovibit2xm[8] =
13
+ { 0, 3, 1, 4, 2, 0, 0, 0 };
14
+
15
+ BYTE autovibxm2it[8] =
16
+ { 0, 2, 4, 1, 3, 0, 0, 0 };
17
+
18
+ //////////////////////////////////////////////////////////
19
+ // Impulse Tracker IT file support
20
+
21
+ // for conversion of XM samples
22
+ extern WORD XMPeriodTable[96+8];
23
+ extern UINT XMLinearTable[768];
24
+
25
+ static inline UINT ConvertVolParam(UINT value)
26
+ //--------------------------------------------
27
+ {
28
+ return (value > 9) ? 9 : value;
29
+ }
30
+
31
+
32
+ BOOL CSoundFile_ITInstrToMPT(const void *p, INSTRUMENTHEADER *penv, UINT trkvers)
33
+ //--------------------------------------------------------------------------------
34
+ {
35
+ if (trkvers < 0x0200)
36
+ {
37
+ const ITOLDINSTRUMENT *pis = (const ITOLDINSTRUMENT *)p;
38
+ SDL_memcpy(penv->filename, pis->filename, 12);
39
+ penv->nFadeOut = bswapLE16(pis->fadeout) << 6;
40
+ penv->nGlobalVol = 64;
41
+ for (UINT j=0; j<NOTE_MAX; j++)
42
+ {
43
+ UINT note = pis->keyboard[j*2];
44
+ UINT ins = pis->keyboard[j*2+1];
45
+ if (ins < MAX_SAMPLES) penv->Keyboard[j] = ins;
46
+ if (note < 128) penv->NoteMap[j] = note+1;
47
+ else if (note >= 0xFE) penv->NoteMap[j] = note;
48
+ }
49
+ if (pis->flags & 0x01) penv->dwFlags |= ENV_VOLUME;
50
+ if (pis->flags & 0x02) penv->dwFlags |= ENV_VOLLOOP;
51
+ if (pis->flags & 0x04) penv->dwFlags |= ENV_VOLSUSTAIN;
52
+ penv->nVolLoopStart = pis->vls;
53
+ penv->nVolLoopEnd = pis->vle;
54
+ penv->nVolSustainBegin = pis->sls;
55
+ penv->nVolSustainEnd = pis->sle;
56
+ penv->nVolEnv = 25;
57
+ for (UINT ev=0; ev<25; ev++)
58
+ {
59
+ if ((penv->VolPoints[ev] = pis->nodes[ev*2]) == 0xFF)
60
+ {
61
+ penv->nVolEnv = ev;
62
+ break;
63
+ }
64
+ penv->VolEnv[ev] = pis->nodes[ev*2+1];
65
+ }
66
+ penv->nNNA = pis->nna;
67
+ penv->nDCT = pis->dnc;
68
+ penv->nPan = 0x80;
69
+ } else
70
+ {
71
+ const ITINSTRUMENT *pis = (const ITINSTRUMENT *)p;
72
+ SDL_memcpy(penv->filename, pis->filename, 12);
73
+ penv->nMidiProgram = pis->mpr;
74
+ penv->nMidiChannel = pis->mch;
75
+ penv->wMidiBank = bswapLE16(pis->mbank);
76
+ penv->nFadeOut = bswapLE16(pis->fadeout) << 5;
77
+ penv->nGlobalVol = pis->gbv >> 1;
78
+ if (penv->nGlobalVol > 64) penv->nGlobalVol = 64;
79
+ for (UINT j=0; j<NOTE_MAX; j++)
80
+ {
81
+ UINT note = pis->keyboard[j*2];
82
+ UINT ins = pis->keyboard[j*2+1];
83
+ if (ins < MAX_SAMPLES) penv->Keyboard[j] = ins;
84
+ if (note < 128) penv->NoteMap[j] = note+1;
85
+ else if (note >= 0xFE) penv->NoteMap[j] = note;
86
+ }
87
+ // Volume Envelope
88
+ if (pis->volenv.flags & 1) penv->dwFlags |= ENV_VOLUME;
89
+ if (pis->volenv.flags & 2) penv->dwFlags |= ENV_VOLLOOP;
90
+ if (pis->volenv.flags & 4) penv->dwFlags |= ENV_VOLSUSTAIN;
91
+ if (pis->volenv.flags & 8) penv->dwFlags |= ENV_VOLCARRY;
92
+ penv->nVolEnv = pis->volenv.num;
93
+ if (penv->nVolEnv > 25) penv->nVolEnv = 25;
94
+
95
+ penv->nVolLoopStart = pis->volenv.lpb;
96
+ penv->nVolLoopEnd = pis->volenv.lpe;
97
+ penv->nVolSustainBegin = pis->volenv.slb;
98
+ penv->nVolSustainEnd = pis->volenv.sle;
99
+ // Panning Envelope
100
+ if (pis->panenv.flags & 1) penv->dwFlags |= ENV_PANNING;
101
+ if (pis->panenv.flags & 2) penv->dwFlags |= ENV_PANLOOP;
102
+ if (pis->panenv.flags & 4) penv->dwFlags |= ENV_PANSUSTAIN;
103
+ if (pis->panenv.flags & 8) penv->dwFlags |= ENV_PANCARRY;
104
+ penv->nPanEnv = pis->panenv.num;
105
+ if (penv->nPanEnv > 25) penv->nPanEnv = 25;
106
+ penv->nPanLoopStart = pis->panenv.lpb;
107
+ penv->nPanLoopEnd = pis->panenv.lpe;
108
+ penv->nPanSustainBegin = pis->panenv.slb;
109
+ penv->nPanSustainEnd = pis->panenv.sle;
110
+ // Pitch Envelope
111
+ if (pis->pitchenv.flags & 1) penv->dwFlags |= ENV_PITCH;
112
+ if (pis->pitchenv.flags & 2) penv->dwFlags |= ENV_PITCHLOOP;
113
+ if (pis->pitchenv.flags & 4) penv->dwFlags |= ENV_PITCHSUSTAIN;
114
+ if (pis->pitchenv.flags & 8) penv->dwFlags |= ENV_PITCHCARRY;
115
+ if (pis->pitchenv.flags & 0x80) penv->dwFlags |= ENV_FILTER;
116
+ penv->nPitchEnv = pis->pitchenv.num;
117
+ if (penv->nPitchEnv > 25) penv->nPitchEnv = 25;
118
+ penv->nPitchLoopStart = pis->pitchenv.lpb;
119
+ penv->nPitchLoopEnd = pis->pitchenv.lpe;
120
+ penv->nPitchSustainBegin = pis->pitchenv.slb;
121
+ penv->nPitchSustainEnd = pis->pitchenv.sle;
122
+ // Envelopes Data
123
+ for (UINT ev=0; ev<25; ev++)
124
+ {
125
+ penv->VolEnv[ev] = pis->volenv.data[ev*3];
126
+ penv->VolPoints[ev] = (pis->volenv.data[ev*3+2] << 8) | (pis->volenv.data[ev*3+1]);
127
+ penv->PanEnv[ev] = pis->panenv.data[ev*3] + 32;
128
+ penv->PanPoints[ev] = (pis->panenv.data[ev*3+2] << 8) | (pis->panenv.data[ev*3+1]);
129
+ penv->PitchEnv[ev] = pis->pitchenv.data[ev*3] + 32;
130
+ penv->PitchPoints[ev] = (pis->pitchenv.data[ev*3+2] << 8) | (pis->pitchenv.data[ev*3+1]);
131
+ }
132
+ penv->nNNA = pis->nna;
133
+ penv->nDCT = pis->dct;
134
+ penv->nDNA = pis->dca;
135
+ penv->nPPS = pis->pps;
136
+ penv->nPPC = pis->ppc;
137
+ penv->nIFC = pis->ifc;
138
+ penv->nIFR = pis->ifr;
139
+ penv->nVolSwing = pis->rv;
140
+ penv->nPanSwing = pis->rp;
141
+ penv->nPan = (pis->dfp & 0x7F) << 2;
142
+ if (penv->nPan > 256) penv->nPan = 128;
143
+ if (pis->dfp < 0x80) penv->dwFlags |= ENV_SETPANNING;
144
+ }
145
+ if ((penv->nVolLoopStart >= 25) || (penv->nVolLoopEnd >= 25)) penv->dwFlags &= ~ENV_VOLLOOP;
146
+ if ((penv->nVolSustainBegin >= 25) || (penv->nVolSustainEnd >= 25)) penv->dwFlags &= ~ENV_VOLSUSTAIN;
147
+ return TRUE;
148
+ }
149
+
150
+
151
+ BOOL CSoundFile_ReadIT(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLength)
152
+ //--------------------------------------------------------------
153
+ {
154
+ DWORD dwMemPos = sizeof(ITFILEHEADER);
155
+ DWORD inspos[MAX_INSTRUMENTS];
156
+ DWORD smppos[MAX_SAMPLES];
157
+ DWORD patpos[MAX_PATTERNS];
158
+ BYTE chnmask[64], channels_used[64];
159
+ MODCOMMAND lastvalue[64];
160
+
161
+ if ((!lpStream) || (dwMemLength < sizeof(ITFILEHEADER))) return FALSE;
162
+ ITFILEHEADER pifh;
163
+ SDL_memcpy(&pifh, lpStream, sizeof (pifh));
164
+
165
+ pifh.id = bswapLE32(pifh.id);
166
+ pifh.reserved1 = bswapLE16(pifh.reserved1);
167
+ pifh.ordnum = bswapLE16(pifh.ordnum);
168
+ pifh.insnum = bswapLE16(pifh.insnum);
169
+ pifh.smpnum = bswapLE16(pifh.smpnum);
170
+ pifh.patnum = bswapLE16(pifh.patnum);
171
+ pifh.cwtv = bswapLE16(pifh.cwtv);
172
+ pifh.cmwt = bswapLE16(pifh.cmwt);
173
+ pifh.flags = bswapLE16(pifh.flags);
174
+ pifh.special = bswapLE16(pifh.special);
175
+ pifh.msglength = bswapLE16(pifh.msglength);
176
+ pifh.msgoffset = bswapLE32(pifh.msgoffset);
177
+ pifh.reserved2 = bswapLE32(pifh.reserved2);
178
+
179
+ if ((pifh.id != 0x4D504D49) || (pifh.insnum >= MAX_INSTRUMENTS)
180
+ || (!pifh.smpnum) || (pifh.smpnum >= MAX_INSTRUMENTS) || (!pifh.ordnum)) return FALSE;
181
+ if (dwMemPos + pifh.ordnum + pifh.insnum*4
182
+ + pifh.smpnum*4 + pifh.patnum*4 > dwMemLength) return FALSE;
183
+ _this->m_nType = MOD_TYPE_IT;
184
+ if (pifh.flags & 0x08) _this->m_dwSongFlags |= SONG_LINEARSLIDES;
185
+ if (pifh.flags & 0x10) _this->m_dwSongFlags |= SONG_ITOLDEFFECTS;
186
+ if (pifh.flags & 0x20) _this->m_dwSongFlags |= SONG_ITCOMPATMODE;
187
+ if (pifh.flags & 0x80) _this->m_dwSongFlags |= SONG_EMBEDMIDICFG;
188
+ if (pifh.flags & 0x1000) _this->m_dwSongFlags |= SONG_EXFILTERRANGE;
189
+ // Global Volume
190
+ if (pifh.globalvol)
191
+ {
192
+ _this->m_nDefaultGlobalVolume = pifh.globalvol << 1;
193
+ if (!_this->m_nDefaultGlobalVolume) _this->m_nDefaultGlobalVolume = 256;
194
+ if (_this->m_nDefaultGlobalVolume > 256) _this->m_nDefaultGlobalVolume = 256;
195
+ }
196
+ if (pifh.speed) _this->m_nDefaultSpeed = pifh.speed;
197
+ if (pifh.tempo) _this->m_nDefaultTempo = pifh.tempo;
198
+ _this->m_nSongPreAmp = pifh.mv & 0x7F;
199
+ // Reading Channels Pan Positions
200
+ for (int ipan=0; ipan<64; ipan++) if (pifh.chnpan[ipan] != 0xFF)
201
+ {
202
+ _this->ChnSettings[ipan].nVolume = pifh.chnvol[ipan];
203
+ _this->ChnSettings[ipan].nPan = 128;
204
+ if (pifh.chnpan[ipan] & 0x80) _this->ChnSettings[ipan].dwFlags |= CHN_MUTE;
205
+ UINT n = pifh.chnpan[ipan] & 0x7F;
206
+ if (n <= 64) _this->ChnSettings[ipan].nPan = n << 2;
207
+ if (n == 100) _this->ChnSettings[ipan].dwFlags |= CHN_SURROUND;
208
+ }
209
+ if (_this->m_nChannels < 4) _this->m_nChannels = 4;
210
+ // Reading orders
211
+ UINT nordsize = pifh.ordnum;
212
+ if (nordsize > MAX_ORDERS) nordsize = MAX_ORDERS;
213
+ SDL_memcpy(_this->Order, lpStream+dwMemPos, nordsize);
214
+ dwMemPos += pifh.ordnum;
215
+ // Reading Instrument Offsets
216
+ SDL_memset(inspos, 0, sizeof(inspos));
217
+ UINT inspossize = pifh.insnum;
218
+ if (inspossize > MAX_INSTRUMENTS) inspossize = MAX_INSTRUMENTS;
219
+ inspossize <<= 2;
220
+ SDL_memcpy(inspos, lpStream+dwMemPos, inspossize);
221
+ for (UINT j=0; j < (inspossize>>2); j++)
222
+ {
223
+ inspos[j] = bswapLE32(inspos[j]);
224
+ }
225
+ dwMemPos += pifh.insnum * 4;
226
+ // Reading Samples Offsets
227
+ SDL_memset(smppos, 0, sizeof(smppos));
228
+ UINT smppossize = pifh.smpnum;
229
+ if (smppossize > MAX_SAMPLES) smppossize = MAX_SAMPLES;
230
+ smppossize <<= 2;
231
+ SDL_memcpy(smppos, lpStream+dwMemPos, smppossize);
232
+ for (UINT j=0; j < (smppossize>>2); j++)
233
+ {
234
+ smppos[j] = bswapLE32(smppos[j]);
235
+ }
236
+ dwMemPos += pifh.smpnum * 4;
237
+ // Reading Patterns Offsets
238
+ SDL_memset(patpos, 0, sizeof(patpos));
239
+ UINT patpossize = pifh.patnum;
240
+ if (patpossize > MAX_PATTERNS) patpossize = MAX_PATTERNS;
241
+ patpossize <<= 2;
242
+ SDL_memcpy(patpos, lpStream+dwMemPos, patpossize);
243
+ for (UINT j=0; j < (patpossize>>2); j++)
244
+ {
245
+ patpos[j] = bswapLE32(patpos[j]);
246
+ }
247
+ dwMemPos += pifh.patnum * 4;
248
+ // Reading IT Extra Info
249
+ if (dwMemPos + 2 < dwMemLength)
250
+ {
251
+ UINT nflt = bswapLE16(*((WORD *)(lpStream + dwMemPos)));
252
+ dwMemPos += 2;
253
+ if (dwMemPos + nflt * 8 < dwMemLength) dwMemPos += nflt * 8;
254
+ }
255
+ // Reading Midi Output & Macros
256
+ if (_this->m_dwSongFlags & SONG_EMBEDMIDICFG)
257
+ {
258
+ if (dwMemPos + sizeof(MODMIDICFG) < dwMemLength)
259
+ {
260
+ SDL_memcpy(&_this->m_MidiCfg, lpStream+dwMemPos, sizeof(MODMIDICFG));
261
+ dwMemPos += sizeof(MODMIDICFG);
262
+ }
263
+ }
264
+ // Read pattern names: "PNAM"
265
+ if ((dwMemPos + 8 < dwMemLength) && (bswapLE32(*((DWORD *)(lpStream+dwMemPos))) == 0x4d414e50))
266
+ {
267
+ UINT len = bswapLE32(*((DWORD *)(lpStream+dwMemPos+4)));
268
+ dwMemPos += 8;
269
+ if ((dwMemPos + len <= dwMemLength) && (len <= MAX_PATTERNS*MAX_PATTERNNAME) && (len >= MAX_PATTERNNAME))
270
+ {
271
+ _this->m_lpszPatternNames = (char *) SDL_malloc(len);
272
+ if (_this->m_lpszPatternNames)
273
+ {
274
+ _this->m_nPatternNames = len / MAX_PATTERNNAME;
275
+ SDL_memcpy(_this->m_lpszPatternNames, lpStream+dwMemPos, len);
276
+ }
277
+ dwMemPos += len;
278
+ }
279
+ }
280
+ // 4-channels minimum
281
+ _this->m_nChannels = 4;
282
+ // Read channel names: "CNAM"
283
+ if ((dwMemPos + 8 < dwMemLength) && (bswapLE32(*((DWORD *)(lpStream+dwMemPos))) == 0x4d414e43))
284
+ {
285
+ const UINT len = bswapLE32(*((DWORD *)(lpStream+dwMemPos+4)));
286
+ dwMemPos += 8;
287
+ if ((dwMemPos + len <= dwMemLength) && (len <= 64*MAX_CHANNELNAME))
288
+ {
289
+ dwMemPos += len;
290
+ }
291
+ }
292
+ // Read mix plugins information
293
+ if (dwMemPos + 8 < dwMemLength)
294
+ {
295
+ dwMemPos += CSoundFile_LoadMixPlugins(_this, lpStream+dwMemPos, dwMemLength-dwMemPos);
296
+ }
297
+ // Checking for unused channels
298
+ UINT npatterns = pifh.patnum;
299
+ if (npatterns > MAX_PATTERNS) npatterns = MAX_PATTERNS;
300
+ for (UINT patchk=0; patchk<npatterns; patchk++)
301
+ {
302
+ SDL_memset(chnmask, 0, sizeof(chnmask));
303
+ if ((!patpos[patchk]) || ((DWORD)patpos[patchk] >= dwMemLength - 4)) continue;
304
+ UINT len = bswapLE16(*((WORD *)(lpStream+patpos[patchk])));
305
+ UINT rows = bswapLE16(*((WORD *)(lpStream+patpos[patchk]+2)));
306
+ if ((rows < 4) || (rows > 256)) continue;
307
+ if (8+len > dwMemLength || patpos[patchk] > dwMemLength - (8+len)) continue;
308
+ UINT i = 0;
309
+ const BYTE *p = lpStream+patpos[patchk]+8;
310
+ UINT nrow = 0;
311
+ while (nrow<rows)
312
+ {
313
+ if (i >= len) break;
314
+ BYTE b = p[i++];
315
+ if (!b)
316
+ {
317
+ nrow++;
318
+ continue;
319
+ }
320
+ UINT ch = b & 0x7F;
321
+ if (ch) ch = (ch - 1) & 0x3F;
322
+ if (b & 0x80)
323
+ {
324
+ if (i >= len) break;
325
+ chnmask[ch] = p[i++];
326
+ }
327
+ // Channel used
328
+ if (chnmask[ch] & 0x0F)
329
+ {
330
+ if ((ch >= _this->m_nChannels) && (ch < 64)) _this->m_nChannels = ch+1;
331
+ }
332
+ // Note
333
+ if (chnmask[ch] & 1) i++;
334
+ // Instrument
335
+ if (chnmask[ch] & 2) i++;
336
+ // Volume
337
+ if (chnmask[ch] & 4) i++;
338
+ // Effect
339
+ if (chnmask[ch] & 8) i += 2;
340
+ if (i >= len) break;
341
+ }
342
+ }
343
+ // Reading Instruments
344
+ _this->m_nInstruments = 0;
345
+ if (pifh.flags & 0x04) _this->m_nInstruments = pifh.insnum;
346
+ if (_this->m_nInstruments >= MAX_INSTRUMENTS) _this->m_nInstruments = MAX_INSTRUMENTS-1;
347
+ for (UINT nins=0; nins<_this->m_nInstruments; nins++)
348
+ {
349
+ if ((inspos[nins] > 0) && (inspos[nins] < dwMemLength - sizeof(ITOLDINSTRUMENT)))
350
+ {
351
+ INSTRUMENTHEADER *penv = (INSTRUMENTHEADER *) SDL_malloc(sizeof (INSTRUMENTHEADER));
352
+ if (!penv) continue;
353
+ _this->Headers[nins+1] = penv;
354
+ SDL_memset(penv, 0, sizeof(INSTRUMENTHEADER));
355
+ CSoundFile_ITInstrToMPT(lpStream + inspos[nins], penv, pifh.cmwt);
356
+ }
357
+ }
358
+ // Reading Samples
359
+ _this->m_nSamples = pifh.smpnum;
360
+ if (_this->m_nSamples >= MAX_SAMPLES) _this->m_nSamples = MAX_SAMPLES-1;
361
+ for (UINT nsmp=0; nsmp<pifh.smpnum; nsmp++) if ((smppos[nsmp]) && (smppos[nsmp] <= dwMemLength - sizeof(ITSAMPLESTRUCT)))
362
+ {
363
+ ITSAMPLESTRUCT pis;
364
+ SDL_memcpy(&pis, lpStream+smppos[nsmp], sizeof (pis));
365
+ pis.id = bswapLE32(pis.id);
366
+ pis.length = bswapLE32(pis.length);
367
+ pis.loopbegin = bswapLE32(pis.loopbegin);
368
+ pis.loopend = bswapLE32(pis.loopend);
369
+ pis.C5Speed = bswapLE32(pis.C5Speed);
370
+ pis.susloopbegin = bswapLE32(pis.susloopbegin);
371
+ pis.susloopend = bswapLE32(pis.susloopend);
372
+ pis.samplepointer = bswapLE32(pis.samplepointer);
373
+
374
+ if (pis.id == 0x53504D49)
375
+ {
376
+ MODINSTRUMENT *pins = &_this->Ins[nsmp+1];
377
+ pins->uFlags = 0;
378
+ pins->nLength = 0;
379
+ pins->nLoopStart = pis.loopbegin;
380
+ pins->nLoopEnd = pis.loopend;
381
+ pins->nSustainStart = pis.susloopbegin;
382
+ pins->nSustainEnd = pis.susloopend;
383
+ pins->nC4Speed = pis.C5Speed;
384
+ if (!pins->nC4Speed) pins->nC4Speed = 8363;
385
+ if (pis.C5Speed < 256) pins->nC4Speed = 256;
386
+ pins->nVolume = pis.vol << 2;
387
+ if (pins->nVolume > 256) pins->nVolume = 256;
388
+ pins->nGlobalVol = pis.gvl;
389
+ if (pins->nGlobalVol > 64) pins->nGlobalVol = 64;
390
+ if (pis.flags & 0x10) pins->uFlags |= CHN_LOOP;
391
+ if (pis.flags & 0x20) pins->uFlags |= CHN_SUSTAINLOOP;
392
+ if (pis.flags & 0x40) pins->uFlags |= CHN_PINGPONGLOOP;
393
+ if (pis.flags & 0x80) pins->uFlags |= CHN_PINGPONGSUSTAIN;
394
+ pins->nPan = (pis.dfp & 0x7F) << 2;
395
+ if (pins->nPan > 256) pins->nPan = 256;
396
+ if (pis.dfp & 0x80) pins->uFlags |= CHN_PANNING;
397
+ pins->nVibType = autovibit2xm[pis.vit & 7];
398
+ pins->nVibRate = pis.vis;
399
+ pins->nVibDepth = pis.vid & 0x7F;
400
+ pins->nVibSweep = (pis.vir + 3) / 4;
401
+ if ((pis.samplepointer) && (pis.samplepointer < dwMemLength) && (pis.length))
402
+ {
403
+ pins->nLength = pis.length;
404
+ if (pins->nLength > MAX_SAMPLE_LENGTH) pins->nLength = MAX_SAMPLE_LENGTH;
405
+ UINT flags = (pis.cvt & 1) ? RS_PCM8S : RS_PCM8U;
406
+ if (pis.flags & 2)
407
+ {
408
+ flags += 5;
409
+ if (pis.flags & 4) flags |= RSF_STEREO;
410
+ pins->uFlags |= CHN_16BIT;
411
+ // IT 2.14 16-bit packed sample ?
412
+ if (pis.flags & 8) flags = ((pifh.cmwt >= 0x215) && (pis.cvt & 4)) ? RS_IT21516 : RS_IT21416;
413
+ } else
414
+ {
415
+ if (pis.flags & 4) flags |= RSF_STEREO;
416
+ if (pis.cvt == 0xFF) flags = RS_ADPCM4; else
417
+ // IT 2.14 8-bit packed sample ?
418
+ if (pis.flags & 8) flags = ((pifh.cmwt >= 0x215) && (pis.cvt & 4)) ? RS_IT2158 : RS_IT2148;
419
+ }
420
+ CSoundFile_ReadSample(_this, &_this->Ins[nsmp+1], flags, (LPSTR)(lpStream+pis.samplepointer), dwMemLength - pis.samplepointer);
421
+ }
422
+ }
423
+ }
424
+ // Reading Patterns
425
+ for (UINT npat=0; npat<npatterns; npat++)
426
+ {
427
+ if ((!patpos[npat]) || ((DWORD)patpos[npat] >= dwMemLength - 4))
428
+ {
429
+ _this->PatternSize[npat] = 64;
430
+ _this->Patterns[npat] = CSoundFile_AllocatePattern(64, _this->m_nChannels);
431
+ continue;
432
+ }
433
+
434
+ UINT len = bswapLE16(*((WORD *)(lpStream+patpos[npat])));
435
+ UINT rows = bswapLE16(*((WORD *)(lpStream+patpos[npat]+2)));
436
+ if ((rows < 4) || (rows > 256)) continue;
437
+ if (8+len > dwMemLength || patpos[npat] > dwMemLength - (8+len)) continue;
438
+ _this->PatternSize[npat] = rows;
439
+ if ((_this->Patterns[npat] = CSoundFile_AllocatePattern(rows, _this->m_nChannels)) == NULL) continue;
440
+ SDL_memset(lastvalue, 0, sizeof(lastvalue));
441
+ SDL_memset(chnmask, 0, sizeof(chnmask));
442
+ MODCOMMAND *m = _this->Patterns[npat];
443
+ UINT i = 0;
444
+ const BYTE *p = lpStream+patpos[npat]+8;
445
+ UINT nrow = 0;
446
+ while (nrow<rows)
447
+ {
448
+ if (i >= len) break;
449
+ BYTE b = p[i++];
450
+ if (!b)
451
+ {
452
+ nrow++;
453
+ m+=_this->m_nChannels;
454
+ continue;
455
+ }
456
+ UINT ch = b & 0x7F;
457
+ if (ch) ch = (ch - 1) & 0x3F;
458
+ if (b & 0x80)
459
+ {
460
+ if (i >= len) break;
461
+ chnmask[ch] = p[i++];
462
+ }
463
+ if ((chnmask[ch] & 0x10) && (ch < _this->m_nChannels))
464
+ {
465
+ m[ch].note = lastvalue[ch].note;
466
+ }
467
+ if ((chnmask[ch] & 0x20) && (ch < _this->m_nChannels))
468
+ {
469
+ m[ch].instr = lastvalue[ch].instr;
470
+ }
471
+ if ((chnmask[ch] & 0x40) && (ch < _this->m_nChannels))
472
+ {
473
+ m[ch].volcmd = lastvalue[ch].volcmd;
474
+ m[ch].vol = lastvalue[ch].vol;
475
+ }
476
+ if ((chnmask[ch] & 0x80) && (ch < _this->m_nChannels))
477
+ {
478
+ m[ch].command = lastvalue[ch].command;
479
+ m[ch].param = lastvalue[ch].param;
480
+ }
481
+ if (chnmask[ch] & 1) // Note
482
+ {
483
+ if (i >= len) break;
484
+ UINT note = p[i++];
485
+ if (ch < _this->m_nChannels)
486
+ {
487
+ if (note < 0x80) note++;
488
+ m[ch].note = note;
489
+ lastvalue[ch].note = note;
490
+ channels_used[ch] = TRUE;
491
+ }
492
+ }
493
+ if (chnmask[ch] & 2)
494
+ {
495
+ if (i >= len) break;
496
+ UINT instr = p[i++];
497
+ if (ch < _this->m_nChannels)
498
+ {
499
+ m[ch].instr = instr;
500
+ lastvalue[ch].instr = instr;
501
+ }
502
+ }
503
+ if (chnmask[ch] & 4)
504
+ {
505
+ if (i >= len) break;
506
+ UINT vol = p[i++];
507
+ if (ch < _this->m_nChannels)
508
+ {
509
+ // 0-64: Set Volume
510
+ if (vol <= 64) { m[ch].volcmd = VOLCMD_VOLUME; m[ch].vol = vol; } else
511
+ // 128-192: Set Panning
512
+ if ((vol >= 128) && (vol <= 192)) { m[ch].volcmd = VOLCMD_PANNING; m[ch].vol = vol - 128; } else
513
+ // 65-74: Fine Volume Up
514
+ if (vol < 75) { m[ch].volcmd = VOLCMD_FINEVOLUP; m[ch].vol = vol - 65; } else
515
+ // 75-84: Fine Volume Down
516
+ if (vol < 85) { m[ch].volcmd = VOLCMD_FINEVOLDOWN; m[ch].vol = vol - 75; } else
517
+ // 85-94: Volume Slide Up
518
+ if (vol < 95) { m[ch].volcmd = VOLCMD_VOLSLIDEUP; m[ch].vol = vol - 85; } else
519
+ // 95-104: Volume Slide Down
520
+ if (vol < 105) { m[ch].volcmd = VOLCMD_VOLSLIDEDOWN; m[ch].vol = vol - 95; } else
521
+ // 105-114: Pitch Slide Up
522
+ if (vol < 115) { m[ch].volcmd = VOLCMD_PORTADOWN; m[ch].vol = vol - 105; } else
523
+ // 115-124: Pitch Slide Down
524
+ if (vol < 125) { m[ch].volcmd = VOLCMD_PORTAUP; m[ch].vol = vol - 115; } else
525
+ // 193-202: Portamento To
526
+ if ((vol >= 193) && (vol <= 202)) { m[ch].volcmd = VOLCMD_TONEPORTAMENTO; m[ch].vol = vol - 193; } else
527
+ // 203-212: Vibrato
528
+ if ((vol >= 203) && (vol <= 212)) { m[ch].volcmd = VOLCMD_VIBRATOSPEED; m[ch].vol = vol - 203; }
529
+ lastvalue[ch].volcmd = m[ch].volcmd;
530
+ lastvalue[ch].vol = m[ch].vol;
531
+ }
532
+ }
533
+ // Reading command/param
534
+ if (chnmask[ch] & 8)
535
+ {
536
+ if (i > len - 2) break;
537
+ UINT cmd = p[i++];
538
+ UINT param = p[i++];
539
+ if (ch < _this->m_nChannels)
540
+ {
541
+ if (cmd)
542
+ {
543
+ m[ch].command = cmd;
544
+ m[ch].param = param;
545
+ CSoundFile_S3MConvert(&m[ch], TRUE);
546
+ lastvalue[ch].command = m[ch].command;
547
+ lastvalue[ch].param = m[ch].param;
548
+ }
549
+ }
550
+ }
551
+ }
552
+ }
553
+ for (UINT ncu=0; ncu<MAX_BASECHANNELS; ncu++)
554
+ {
555
+ if (ncu>=_this->m_nChannels)
556
+ {
557
+ _this->ChnSettings[ncu].nVolume = 64;
558
+ _this->ChnSettings[ncu].dwFlags &= ~CHN_MUTE;
559
+ }
560
+ }
561
+ _this->m_nMinPeriod = 8;
562
+ _this->m_nMaxPeriod = 0xF000;
563
+ return TRUE;
564
+ }
565
+
566
+
567
+ //////////////////////////////////////////////////////////////////////////////
568
+ // IT 2.14 compression
569
+
570
+ static DWORD ITReadBits(DWORD *bitbuf, UINT *bitnum, LPBYTE *_ibuf, CHAR n)
571
+ //-----------------------------------------------------------------
572
+ {
573
+ LPBYTE ibuf = *_ibuf;
574
+ DWORD retval = 0;
575
+ UINT i = n;
576
+
577
+ if (n > 0)
578
+ {
579
+ do
580
+ {
581
+ if (!*bitnum)
582
+ {
583
+ *bitbuf = *ibuf++;
584
+ *bitnum = 8;
585
+ }
586
+ retval >>= 1;
587
+ retval |= *bitbuf << 31;
588
+ *bitbuf >>= 1;
589
+ (*bitnum)--;
590
+ i--;
591
+ } while (i);
592
+ i = n;
593
+ }
594
+ *_ibuf = ibuf;
595
+ return (retval >> (32-i));
596
+ }
597
+
598
+ #define IT215_SUPPORT
599
+ void ITUnpack8Bit(signed char *pSample, DWORD dwLen, LPBYTE lpMemFile, DWORD dwMemLength, BOOL b215)
600
+ //-------------------------------------------------------------------------------------------
601
+ {
602
+ signed char *pDst = pSample;
603
+ LPBYTE pSrc = lpMemFile;
604
+ DWORD wHdr = 0;
605
+ DWORD wCount = 0;
606
+ DWORD bitbuf = 0;
607
+ UINT bitnum = 0;
608
+ BYTE bLeft = 0, bTemp = 0, bTemp2 = 0;
609
+
610
+ while (dwLen)
611
+ {
612
+ if (!wCount)
613
+ {
614
+ wCount = 0x8000;
615
+ wHdr = bswapLE16(*((LPWORD)pSrc));
616
+ pSrc += 2;
617
+ bLeft = 9;
618
+ bTemp = bTemp2 = 0;
619
+ bitbuf = bitnum = 0;
620
+ }
621
+ DWORD d = wCount;
622
+ if (d > dwLen) d = dwLen;
623
+ // Unpacking
624
+ DWORD dwPos = 0;
625
+ do
626
+ {
627
+ WORD wBits = (WORD)ITReadBits(&bitbuf, &bitnum, &pSrc, bLeft);
628
+ if (bLeft < 7)
629
+ {
630
+ DWORD i = 1 << (bLeft-1);
631
+ DWORD j = wBits & 0xFFFF;
632
+ if (i != j) goto UnpackByte;
633
+ wBits = (WORD)(ITReadBits(&bitbuf, &bitnum, &pSrc, 3) + 1) & 0xFF;
634
+ bLeft = ((BYTE)wBits < bLeft) ? (BYTE)wBits : (BYTE)((wBits+1) & 0xFF);
635
+ goto Next;
636
+ }
637
+ if (bLeft < 9)
638
+ {
639
+ WORD i = (0xFF >> (9 - bLeft)) + 4;
640
+ WORD j = i - 8;
641
+ if ((wBits <= j) || (wBits > i)) goto UnpackByte;
642
+ wBits -= j;
643
+ bLeft = ((BYTE)(wBits & 0xFF) < bLeft) ? (BYTE)(wBits & 0xFF) : (BYTE)((wBits+1) & 0xFF);
644
+ goto Next;
645
+ }
646
+ if (bLeft >= 10) goto SkipByte;
647
+ if (wBits >= 256)
648
+ {
649
+ bLeft = (BYTE)(wBits + 1) & 0xFF;
650
+ goto Next;
651
+ }
652
+ UnpackByte:
653
+ if (bLeft < 8)
654
+ {
655
+ BYTE shift = 8 - bLeft;
656
+ signed char c = (signed char)(wBits << shift);
657
+ c >>= shift;
658
+ wBits = (WORD)c;
659
+ }
660
+ wBits += bTemp;
661
+ bTemp = (BYTE)wBits;
662
+ bTemp2 += bTemp;
663
+ #ifdef IT215_SUPPORT
664
+ pDst[dwPos] = (b215) ? bTemp2 : bTemp;
665
+ #else
666
+ pDst[dwPos] = bTemp;
667
+ #endif
668
+ SkipByte:
669
+ dwPos++;
670
+ Next:
671
+ if (pSrc >= lpMemFile+dwMemLength+1) return;
672
+ } while (dwPos < d);
673
+ // Move On
674
+ wCount -= d;
675
+ dwLen -= d;
676
+ pDst += d;
677
+ }
678
+ }
679
+
680
+
681
+ void ITUnpack16Bit(signed char *pSample, DWORD dwLen, LPBYTE lpMemFile, DWORD dwMemLength, BOOL b215)
682
+ //--------------------------------------------------------------------------------------------
683
+ {
684
+ signed short *pDst = (signed short *)pSample;
685
+ LPBYTE pSrc = lpMemFile;
686
+ DWORD wHdr = 0;
687
+ DWORD wCount = 0;
688
+ DWORD bitbuf = 0;
689
+ UINT bitnum = 0;
690
+ BYTE bLeft = 0;
691
+ signed short wTemp = 0, wTemp2 = 0;
692
+
693
+ while (dwLen)
694
+ {
695
+ if (!wCount)
696
+ {
697
+ wCount = 0x4000;
698
+ wHdr = bswapLE16(*((LPWORD)pSrc));
699
+ pSrc += 2;
700
+ bLeft = 17;
701
+ wTemp = wTemp2 = 0;
702
+ bitbuf = bitnum = 0;
703
+ }
704
+ DWORD d = wCount;
705
+ if (d > dwLen) d = dwLen;
706
+ // Unpacking
707
+ DWORD dwPos = 0;
708
+ do
709
+ {
710
+ DWORD dwBits = ITReadBits(&bitbuf, &bitnum, &pSrc, bLeft);
711
+ if (bLeft < 7)
712
+ {
713
+ DWORD i = 1 << (bLeft-1);
714
+ DWORD j = dwBits;
715
+ if (i != j) goto UnpackByte;
716
+ dwBits = ITReadBits(&bitbuf, &bitnum, &pSrc, 4) + 1;
717
+ bLeft = ((BYTE)(dwBits & 0xFF) < bLeft) ? (BYTE)(dwBits & 0xFF) : (BYTE)((dwBits+1) & 0xFF);
718
+ goto Next;
719
+ }
720
+ if (bLeft < 17)
721
+ {
722
+ DWORD i = (0xFFFF >> (17 - bLeft)) + 8;
723
+ DWORD j = (i - 16) & 0xFFFF;
724
+ if ((dwBits <= j) || (dwBits > (i & 0xFFFF))) goto UnpackByte;
725
+ dwBits -= j;
726
+ bLeft = ((BYTE)(dwBits & 0xFF) < bLeft) ? (BYTE)(dwBits & 0xFF) : (BYTE)((dwBits+1) & 0xFF);
727
+ goto Next;
728
+ }
729
+ if (bLeft >= 18) goto SkipByte;
730
+ if (dwBits >= 0x10000)
731
+ {
732
+ bLeft = (BYTE)(dwBits + 1) & 0xFF;
733
+ goto Next;
734
+ }
735
+ UnpackByte:
736
+ if (bLeft < 16)
737
+ {
738
+ BYTE shift = 16 - bLeft;
739
+ signed short c = (signed short)(dwBits << shift);
740
+ c >>= shift;
741
+ dwBits = (DWORD)c;
742
+ }
743
+ dwBits += wTemp;
744
+ wTemp = (signed short)dwBits;
745
+ wTemp2 += wTemp;
746
+ #ifdef IT215_SUPPORT
747
+ pDst[dwPos] = (b215) ? wTemp2 : wTemp;
748
+ #else
749
+ pDst[dwPos] = wTemp;
750
+ #endif
751
+ SkipByte:
752
+ dwPos++;
753
+ Next:
754
+ if (pSrc >= lpMemFile+dwMemLength+1) return;
755
+ } while (dwPos < d);
756
+ // Move On
757
+ wCount -= d;
758
+ dwLen -= d;
759
+ pDst += d;
760
+ if (pSrc >= lpMemFile+dwMemLength) break;
761
+ }
762
+ }
763
+
764
+ UINT CSoundFile_LoadMixPlugins(CSoundFile *_this, const void *pData, UINT nLen)
765
+ //-----------------------------------------------------------
766
+ {
767
+ const BYTE *p = (const BYTE *)pData;
768
+ UINT nPos = 0;
769
+
770
+ while (nPos+8 < nLen)
771
+ {
772
+ DWORD nPluginSize;
773
+ UINT nPlugin;
774
+
775
+ nPluginSize = bswapLE32(*(DWORD *)(p+nPos+4));
776
+ if (nPluginSize > nLen-nPos-8) break;;
777
+ if ((bswapLE32(*(DWORD *)(p+nPos))) == 0x58464843)
778
+ {
779
+ for (UINT ch=0; ch<64; ch++) if (ch*4 < nPluginSize)
780
+ {
781
+ _this->ChnSettings[ch].nMixPlugin = bswapLE32(*(DWORD *)(p+nPos+8+ch*4));
782
+ }
783
+ } else
784
+ {
785
+ if ((p[nPos] != 'F') || (p[nPos+1] != 'X')
786
+ || (p[nPos+2] < '0') || (p[nPos+3] < '0'))
787
+ {
788
+ break;
789
+ }
790
+ // took out the (otherwise unused) plugin loading code here. --ryan.
791
+ }
792
+ nPos += nPluginSize + 8;
793
+ }
794
+ return nPos;
795
+ }
796
+