gosu 0.14.6.pre1 → 1.0.0.pre2

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 +0 -0
  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 +3 -3
  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/compat.rb +9 -4
  197. data/lib/gosu/patches.rb +8 -11
  198. data/lib/gosu/swig_patches.rb +13 -6
  199. data/lib64/OpenAL32.dll +0 -0
  200. data/lib64/SDL2.dll +0 -0
  201. data/rdoc/gosu.rb +114 -21
  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 +11 -5
  217. data/src/GraphicsImpl.hpp +0 -1
  218. data/src/Image.cpp +13 -16
  219. data/src/ImageWrapper.cpp +168 -0
  220. data/src/Input.cpp +412 -164
  221. data/src/LargeImageData.cpp +2 -1
  222. data/src/MarkupParser.cpp +13 -4
  223. data/src/RubyGosu.cxx +502 -219
  224. data/src/RubyGosu.h +4 -2
  225. data/src/SampleWrapper.cpp +30 -0
  226. data/src/SongWrapper.cpp +52 -0
  227. data/src/TexChunk.cpp +29 -19
  228. data/src/Text.cpp +2 -0
  229. data/src/TextBuilder.cpp +6 -4
  230. data/src/TextInputWrapper.cpp +101 -0
  231. data/src/Texture.cpp +1 -1
  232. data/src/TrueTypeFont.cpp +2 -1
  233. data/src/Utility.cpp +11 -7
  234. data/src/Window.cpp +30 -39
  235. data/src/WindowWrapper.cpp +317 -0
  236. metadata +212 -42
  237. data/Gosu/AutoLink.hpp +0 -14
  238. data/Gosu/Bitmap.hpp +0 -113
  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,550 @@
1
+ /**
2
+ * SDL_sound; A sound processing toolkit.
3
+ *
4
+ * Please see the file LICENSE.txt in the source's root directory.
5
+ *
6
+ * This file written by Ryan C. Gordon.
7
+ */
8
+
9
+ /*
10
+ * VOC decoder for SDL_sound.
11
+ *
12
+ * This driver handles Creative Labs VOC audio data...this is a legacy format,
13
+ * but there's some game ports that could make use of such a decoder. Plus,
14
+ * VOC is fairly straightforward to decode, so this is a more complex, but
15
+ * still palatable example of an SDL_sound decoder. Y'know, in case the
16
+ * RAW decoder didn't do it for you. :)
17
+ *
18
+ * This code was ripped from a decoder I had written for SDL_mixer, which was
19
+ * largely ripped from sox v12.17.1's voc.c.
20
+ *
21
+ * SDL_mixer: https://www.libsdl.org/projects/SDL_mixer/
22
+ * sox: http://www.freshmeat.net/projects/sox/
23
+ */
24
+
25
+ #define __SDL_SOUND_INTERNAL__
26
+ #include "SDL_sound_internal.h"
27
+
28
+ #if SOUND_SUPPORTS_VOC
29
+
30
+ /* Private data for VOC file */
31
+ typedef struct vocstuff {
32
+ Uint32 rest; /* bytes remaining in current block */
33
+ Uint32 rate; /* rate code (byte) of this chunk */
34
+ int silent; /* sound or silence? */
35
+ Uint32 srate; /* rate code (byte) of silence */
36
+ Uint32 blockseek; /* start of current output block */
37
+ Uint32 samples; /* number of samples output */
38
+ Uint32 size; /* word length of data */
39
+ Uint8 channels; /* number of sound channels */
40
+ int extended; /* Has an extended block been read? */
41
+ Uint32 bufpos; /* byte position in internal->buffer. */
42
+ Uint32 start_pos; /* offset to seek to in stream when rewinding. */
43
+ int error; /* error condition (as opposed to EOF). */
44
+ } vs_t;
45
+
46
+
47
+ /* Size field */
48
+ /* SJB: note that the 1st 3 are sometimes used as sizeof(type) */
49
+ #define ST_SIZE_BYTE 1
50
+ #define ST_SIZE_8BIT 1
51
+ #define ST_SIZE_WORD 2
52
+ #define ST_SIZE_16BIT 2
53
+ #define ST_SIZE_DWORD 4
54
+ #define ST_SIZE_32BIT 4
55
+ #define ST_SIZE_FLOAT 5
56
+ #define ST_SIZE_DOUBLE 6
57
+ #define ST_SIZE_IEEE 7 /* IEEE 80-bit floats. */
58
+
59
+ /* Style field */
60
+ #define ST_ENCODING_UNSIGNED 1 /* unsigned linear: Sound Blaster */
61
+ #define ST_ENCODING_SIGN2 2 /* signed linear 2's comp: Mac */
62
+ #define ST_ENCODING_ULAW 3 /* U-law signed logs: US telephony, SPARC */
63
+ #define ST_ENCODING_ALAW 4 /* A-law signed logs: non-US telephony */
64
+ #define ST_ENCODING_ADPCM 5 /* Compressed PCM */
65
+ #define ST_ENCODING_IMA_ADPCM 6 /* Compressed PCM */
66
+ #define ST_ENCODING_GSM 7 /* GSM 6.10 33-byte frame lossy compression */
67
+
68
+ #define VOC_TERM 0
69
+ #define VOC_DATA 1
70
+ #define VOC_CONT 2
71
+ #define VOC_SILENCE 3
72
+ #define VOC_MARKER 4
73
+ #define VOC_TEXT 5
74
+ #define VOC_LOOP 6
75
+ #define VOC_LOOPEND 7
76
+ #define VOC_EXTENDED 8
77
+ #define VOC_DATA_16 9
78
+
79
+
80
+ static int VOC_init(void)
81
+ {
82
+ return 1; /* always succeeds. */
83
+ } /* VOC_init */
84
+
85
+
86
+ static void VOC_quit(void)
87
+ {
88
+ /* it's a no-op. */
89
+ } /* VOC_quit */
90
+
91
+
92
+ static SDL_INLINE int voc_readbytes(SDL_RWops *src, vs_t *v, void *p, int size)
93
+ {
94
+ if (SDL_RWread(src, p, size, 1) != 1)
95
+ {
96
+ v->error = 1;
97
+ BAIL_MACRO("VOC: i/o error", 0);
98
+ } /* if */
99
+
100
+ return 1;
101
+ } /* voc_readbytes */
102
+
103
+
104
+ static SDL_INLINE int voc_check_header(SDL_RWops *src)
105
+ {
106
+ /* VOC magic header */
107
+ Uint8 signature[20]; /* "Creative Voice File\032" */
108
+ Uint16 datablockofs;
109
+ vs_t v; /* dummy struct for voc_readbytes */
110
+
111
+ if (!voc_readbytes(src, &v, signature, sizeof (signature)))
112
+ return 0;
113
+
114
+ if (SDL_memcmp(signature, "Creative Voice File\032", sizeof (signature)) != 0)
115
+ {
116
+ BAIL_MACRO("VOC: Wrong signature; not a VOC file.", 0);
117
+ } /* if */
118
+
119
+ /* get the offset where the first datablock is located */
120
+ if (!voc_readbytes(src, &v, &datablockofs, sizeof (Uint16)))
121
+ return 0;
122
+
123
+ datablockofs = SDL_SwapLE16(datablockofs);
124
+
125
+ if (SDL_RWseek(src, datablockofs, SEEK_SET) != datablockofs)
126
+ {
127
+ BAIL_MACRO("VOC: Failed to seek to data block.", 0);
128
+ } /* if */
129
+
130
+ return 1; /* success! */
131
+ } /* voc_check_header */
132
+
133
+
134
+ /* Read next block header, save info, leave position at start of data */
135
+ static int voc_get_block(Sound_Sample *sample, vs_t *v)
136
+ {
137
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
138
+ SDL_RWops *src = internal->rw;
139
+ Uint8 bits24[3];
140
+ Uint8 uc, block;
141
+ Uint32 sblen;
142
+ Uint16 new_rate_short;
143
+ Uint32 new_rate_long;
144
+ Uint8 trash[6];
145
+ Uint16 period;
146
+ Uint32 bytes_per_second;
147
+ int i;
148
+
149
+ v->silent = 0;
150
+ while (v->rest == 0)
151
+ {
152
+ if (SDL_RWread(src, &block, sizeof (block), 1) != 1)
153
+ return 1; /* assume that's the end of the file. */
154
+
155
+ if (block == VOC_TERM)
156
+ return 1;
157
+
158
+ if (SDL_RWread(src, bits24, sizeof (bits24), 1) != 1)
159
+ return 1; /* assume that's the end of the file. */
160
+
161
+ /* Size is an 24-bit value. Ugh. */
162
+ sblen = ( (bits24[0]) | (bits24[1] << 8) | (bits24[2] << 16) );
163
+
164
+ switch(block)
165
+ {
166
+ case VOC_DATA:
167
+ if (!voc_readbytes(src, v, &uc, sizeof (uc)))
168
+ return 0;
169
+
170
+ /* When DATA block preceeded by an EXTENDED */
171
+ /* block, the DATA blocks rate value is invalid */
172
+ if (!v->extended)
173
+ {
174
+ BAIL_IF_MACRO(uc == 0, "VOC: Sample rate is zero?", 0);
175
+
176
+ if ((v->rate != -1) && (uc != v->rate))
177
+ BAIL_MACRO("VOC sample rate codes differ", 0);
178
+
179
+ v->rate = uc;
180
+ sample->actual.rate = 1000000.0/(256 - v->rate);
181
+ sample->actual.channels = 1;
182
+ v->channels = 1;
183
+ } /* if */
184
+
185
+ if (!voc_readbytes(src, v, &uc, sizeof (uc)))
186
+ return 0;
187
+
188
+ BAIL_IF_MACRO(uc != 0, "VOC: only supports 8-bit data", 0);
189
+
190
+ v->extended = 0;
191
+ v->rest = sblen - 2;
192
+ v->size = ST_SIZE_BYTE;
193
+
194
+ bytes_per_second = sample->actual.rate
195
+ * sample->actual.channels;
196
+ internal->total_time += ( v->rest ) / bytes_per_second * 1000;
197
+ internal->total_time += (v->rest % bytes_per_second) * 1000
198
+ / bytes_per_second;
199
+ return 1;
200
+
201
+ case VOC_DATA_16:
202
+ if (!voc_readbytes(src, v, &new_rate_long, sizeof (Uint32)))
203
+ return 0;
204
+
205
+ new_rate_long = SDL_SwapLE32(new_rate_long);
206
+ BAIL_IF_MACRO(!new_rate_long, "VOC: Sample rate is zero?", 0);
207
+
208
+ if ((v->rate != -1) && (new_rate_long != v->rate))
209
+ BAIL_MACRO("VOC: sample rate codes differ", 0);
210
+
211
+ v->rate = new_rate_long;
212
+ sample->actual.rate = new_rate_long;
213
+
214
+ if (!voc_readbytes(src, v, &uc, sizeof (uc)))
215
+ return 0;
216
+
217
+ switch (uc)
218
+ {
219
+ case 8: v->size = ST_SIZE_BYTE; break;
220
+ case 16: v->size = ST_SIZE_WORD; break;
221
+ default:
222
+ BAIL_MACRO("VOC: unknown data size", 0);
223
+ } /* switch */
224
+
225
+ if (!voc_readbytes(src, v, &v->channels, sizeof (Uint8)))
226
+ return 0;
227
+
228
+ if (!voc_readbytes(src, v, trash, sizeof (Uint8) * 6))
229
+ return 0;
230
+ v->rest = sblen - 12;
231
+
232
+ bytes_per_second = ((v->size == ST_SIZE_WORD) ? (2) : (1)) *
233
+ sample->actual.rate * v->channels;
234
+ internal->total_time += v->rest / bytes_per_second * 1000;
235
+ internal->total_time += ( v->rest % bytes_per_second ) * 1000
236
+ / bytes_per_second;
237
+ return 1;
238
+
239
+ case VOC_CONT:
240
+ v->rest = sblen;
241
+ return 1;
242
+
243
+ case VOC_SILENCE:
244
+ if (!voc_readbytes(src, v, &period, sizeof (period)))
245
+ return 0;
246
+
247
+ period = SDL_SwapLE16(period);
248
+
249
+ if (!voc_readbytes(src, v, &uc, sizeof (uc)))
250
+ return 0;
251
+
252
+ BAIL_IF_MACRO(uc == 0, "VOC: silence sample rate is zero", 0);
253
+
254
+ /*
255
+ * Some silence-packed files have gratuitously
256
+ * different sample rate codes in silence.
257
+ * Adjust period.
258
+ */
259
+ if ((v->rate != -1) && (uc != v->rate))
260
+ period = (period * (256 - uc))/(256 - v->rate);
261
+ else
262
+ v->rate = uc;
263
+ v->rest = period;
264
+ v->silent = 1;
265
+
266
+ internal->total_time += (period) / (v->rate) * 1000;
267
+ internal->total_time += (period % v->rate) * 1000 / v->rate;
268
+ return 1;
269
+
270
+ case VOC_LOOP:
271
+ case VOC_LOOPEND:
272
+ for(i = 0; i < sblen; i++) /* skip repeat loops. */
273
+ {
274
+ if (!voc_readbytes(src, v, trash, sizeof (Uint8)))
275
+ return 0;
276
+ } /* for */
277
+ break;
278
+
279
+ case VOC_EXTENDED:
280
+ /* An Extended block is followed by a data block */
281
+ /* Set this byte so we know to use the rate */
282
+ /* value from the extended block and not the */
283
+ /* data block. */
284
+ v->extended = 1;
285
+ if (!voc_readbytes(src, v, &new_rate_short, sizeof (Uint16)))
286
+ return 0;
287
+
288
+ new_rate_short = SDL_SwapLE16(new_rate_short);
289
+ BAIL_IF_MACRO(!new_rate_short, "VOC: sample rate is zero", 0);
290
+
291
+ if ((v->rate != -1) && (new_rate_short != v->rate))
292
+ BAIL_MACRO("VOC: sample rate codes differ", 0);
293
+
294
+ v->rate = new_rate_short;
295
+
296
+ if (!voc_readbytes(src, v, &uc, sizeof (uc)))
297
+ return 0;
298
+
299
+ BAIL_IF_MACRO(uc != 0, "VOC: only supports 8-bit data", 0);
300
+
301
+ if (!voc_readbytes(src, v, &uc, sizeof (uc)))
302
+ return 0;
303
+
304
+ if (uc)
305
+ sample->actual.channels = 2; /* Stereo */
306
+
307
+ /* Needed number of channels before finishing
308
+ compute for rate */
309
+ sample->actual.rate =
310
+ (256000000L/(65536L - v->rate)) / sample->actual.channels;
311
+ /* An extended block must be followed by a data */
312
+ /* block to be valid so loop back to top so it */
313
+ /* can be grabed. */
314
+ continue;
315
+
316
+ case VOC_MARKER:
317
+ if (!voc_readbytes(src, v, trash, sizeof (Uint8) * 2))
318
+ return 0;
319
+
320
+ /* Falling! Falling! */
321
+
322
+ default: /* text block or other krapola. */
323
+ for(i = 0; i < sblen; i++) /* skip repeat loops. */
324
+ {
325
+ if (!voc_readbytes(src, v, trash, sizeof (Uint8)))
326
+ return 0;
327
+ } /* for */
328
+
329
+ if (block == VOC_TEXT)
330
+ continue; /* get next block */
331
+ } /* switch */
332
+ } /* while */
333
+
334
+ return 1;
335
+ } /* voc_get_block */
336
+
337
+
338
+ static int voc_read_waveform(Sound_Sample *sample, int fill_buf, Uint32 max)
339
+ {
340
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
341
+ SDL_RWops *src = internal->rw;
342
+ vs_t *v = (vs_t *) internal->decoder_private;
343
+ int done = 0;
344
+ Uint8 silence = 0x80;
345
+ Uint8 *buf = internal->buffer;
346
+
347
+ if (v->rest == 0)
348
+ {
349
+ if (!voc_get_block(sample, v))
350
+ return 0;
351
+ } /* if */
352
+
353
+ if (v->rest == 0)
354
+ return 0;
355
+
356
+ max = (v->rest < max) ? v->rest : max;
357
+
358
+ if (v->silent)
359
+ {
360
+ if (v->size == ST_SIZE_WORD)
361
+ silence = 0x00;
362
+
363
+ /* Fill in silence */
364
+ if (fill_buf)
365
+ SDL_memset(buf + v->bufpos, silence, max);
366
+
367
+ done = max;
368
+ v->rest -= done;
369
+ } /* if */
370
+
371
+ else
372
+ {
373
+ if (fill_buf)
374
+ {
375
+ done = SDL_RWread(src, buf + v->bufpos, 1, max);
376
+ if (done < max)
377
+ {
378
+ __Sound_SetError("VOC: i/o error");
379
+ sample->flags |= SOUND_SAMPLEFLAG_ERROR;
380
+ } /* if */
381
+ } /* if */
382
+
383
+ else
384
+ {
385
+ int cur, rc;
386
+ cur = SDL_RWtell(src);
387
+ if (cur >= 0)
388
+ {
389
+ rc = SDL_RWseek(src, max, SEEK_CUR);
390
+ if (rc >= 0)
391
+ done = rc - cur;
392
+ else
393
+ {
394
+ __Sound_SetError("VOC: seek error");
395
+ sample->flags |= SOUND_SAMPLEFLAG_ERROR;
396
+ } /* else */
397
+ } /* if */
398
+ } /* else */
399
+
400
+ v->rest -= done;
401
+ v->bufpos += done;
402
+ } /* else */
403
+
404
+ return done;
405
+ } /* voc_read_waveform */
406
+
407
+
408
+ static int VOC_open(Sound_Sample *sample, const char *ext)
409
+ {
410
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
411
+ vs_t *v = NULL;
412
+
413
+ if (!voc_check_header(internal->rw))
414
+ return 0;
415
+
416
+ v = (vs_t *) SDL_calloc(1, sizeof (vs_t));
417
+ BAIL_IF_MACRO(v == NULL, ERR_OUT_OF_MEMORY, 0);
418
+
419
+ v->start_pos = SDL_RWtell(internal->rw);
420
+ v->rate = -1;
421
+ if (!voc_get_block(sample, v))
422
+ {
423
+ SDL_free(v);
424
+ return 0;
425
+ } /* if */
426
+
427
+ if (v->rate == -1)
428
+ {
429
+ SDL_free(v);
430
+ BAIL_MACRO("VOC: data had no sound!", 0);
431
+ } /* if */
432
+
433
+ SNDDBG(("VOC: Accepting data stream.\n"));
434
+ sample->actual.format = (v->size == ST_SIZE_WORD) ? AUDIO_S16LSB:AUDIO_U8;
435
+ sample->actual.channels = v->channels;
436
+ sample->flags = SOUND_SAMPLEFLAG_CANSEEK;
437
+ internal->decoder_private = v;
438
+ return 1;
439
+ } /* VOC_open */
440
+
441
+
442
+ static void VOC_close(Sound_Sample *sample)
443
+ {
444
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
445
+ SDL_free(internal->decoder_private);
446
+ } /* VOC_close */
447
+
448
+
449
+ static Uint32 VOC_read(Sound_Sample *sample)
450
+ {
451
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
452
+ vs_t *v = (vs_t *) internal->decoder_private;
453
+
454
+ v->bufpos = 0;
455
+ while (v->bufpos < internal->buffer_size)
456
+ {
457
+ Uint32 rc = voc_read_waveform(sample, 1, internal->buffer_size);
458
+ if (rc == 0)
459
+ {
460
+ sample->flags |= (v->error) ?
461
+ SOUND_SAMPLEFLAG_ERROR :
462
+ SOUND_SAMPLEFLAG_EOF;
463
+ break;
464
+ } /* if */
465
+
466
+ if (!voc_get_block(sample, v))
467
+ {
468
+ sample->flags |= (v->error) ?
469
+ SOUND_SAMPLEFLAG_ERROR :
470
+ SOUND_SAMPLEFLAG_EOF;
471
+ break;
472
+ } /* if */
473
+ } /* while */
474
+
475
+ return v->bufpos;
476
+ } /* VOC_read */
477
+
478
+
479
+ static int VOC_rewind(Sound_Sample *sample)
480
+ {
481
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
482
+ vs_t *v = (vs_t *) internal->decoder_private;
483
+ int rc = SDL_RWseek(internal->rw, v->start_pos, SEEK_SET);
484
+ BAIL_IF_MACRO(rc != v->start_pos, ERR_IO_ERROR, 0);
485
+ v->rest = 0;
486
+ return 1;
487
+ } /* VOC_rewind */
488
+
489
+
490
+ static int VOC_seek(Sound_Sample *sample, Uint32 ms)
491
+ {
492
+ /*
493
+ * VOCs don't lend themselves well to seeking, since you have to
494
+ * parse each section, which is an arbitrary size. The best we can do
495
+ * is rewind, set a flag saying not to write the waveforms to a buffer,
496
+ * and decode to the point that we want. Ugh. Fortunately, there's
497
+ * really no such thing as a large VOC, due to the era and hardware that
498
+ * spawned them, so even though this is inefficient, this is still a
499
+ * relatively fast operation in most cases.
500
+ */
501
+
502
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
503
+ vs_t *v = (vs_t *) internal->decoder_private;
504
+ int offset = __Sound_convertMsToBytePos(&sample->actual, ms);
505
+ int origpos = SDL_RWtell(internal->rw);
506
+ int origrest = v->rest;
507
+
508
+ BAIL_IF_MACRO(!VOC_rewind(sample), NULL, 0);
509
+
510
+ v->bufpos = 0;
511
+
512
+ while (offset > 0)
513
+ {
514
+ Uint32 rc = voc_read_waveform(sample, 0, offset);
515
+ if ( (rc == 0) || (!voc_get_block(sample, v)) )
516
+ {
517
+ SDL_RWseek(internal->rw, origpos, SEEK_SET);
518
+ v->rest = origrest;
519
+ return 0;
520
+ } /* if */
521
+
522
+ offset -= rc;
523
+ } /* while */
524
+
525
+ return 1;
526
+ } /* VOC_seek */
527
+
528
+
529
+ static const char *extensions_voc[] = { "VOC", NULL };
530
+ const Sound_DecoderFunctions __Sound_DecoderFunctions_VOC =
531
+ {
532
+ {
533
+ extensions_voc,
534
+ "Creative Labs Voice format",
535
+ "Ryan C. Gordon <icculus@icculus.org>",
536
+ "https://icculus.org/SDL_sound/"
537
+ },
538
+
539
+ VOC_init, /* init() method */
540
+ VOC_quit, /* quit() method */
541
+ VOC_open, /* open() method */
542
+ VOC_close, /* close() method */
543
+ VOC_read, /* read() method */
544
+ VOC_rewind, /* rewind() method */
545
+ VOC_seek /* seek() method */
546
+ };
547
+
548
+ #endif /* SOUND_SUPPORTS_VOC */
549
+
550
+ /* end of SDL_sound_voc.c ... */