gosu 0.15.2 → 1.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (234) hide show
  1. checksums.yaml +4 -4
  2. data/dependencies/SDL/include/SDL.h +138 -0
  3. data/dependencies/SDL/include/SDL_assert.h +293 -0
  4. data/dependencies/SDL/include/SDL_atomic.h +295 -0
  5. data/dependencies/SDL/include/SDL_audio.h +859 -0
  6. data/dependencies/SDL/include/SDL_bits.h +121 -0
  7. data/dependencies/SDL/include/SDL_blendmode.h +123 -0
  8. data/dependencies/SDL/include/SDL_clipboard.h +71 -0
  9. data/dependencies/SDL/include/SDL_config.h +55 -0
  10. data/dependencies/SDL/include/SDL_config_android.h +182 -0
  11. data/dependencies/SDL/include/SDL_config_iphoneos.h +207 -0
  12. data/dependencies/SDL/include/SDL_config_macosx.h +266 -0
  13. data/dependencies/SDL/include/SDL_config_minimal.h +85 -0
  14. data/dependencies/SDL/include/SDL_config_os2.h +188 -0
  15. data/dependencies/SDL/include/SDL_config_pandora.h +135 -0
  16. data/dependencies/SDL/include/SDL_config_psp.h +165 -0
  17. data/dependencies/SDL/include/SDL_config_windows.h +288 -0
  18. data/dependencies/SDL/include/SDL_config_winrt.h +243 -0
  19. data/dependencies/SDL/include/SDL_config_wiz.h +149 -0
  20. data/dependencies/SDL/include/SDL_copying.h +20 -0
  21. data/dependencies/SDL/include/SDL_cpuinfo.h +299 -0
  22. data/dependencies/SDL/include/SDL_egl.h +1676 -0
  23. data/dependencies/SDL/include/SDL_endian.h +263 -0
  24. data/dependencies/SDL/include/SDL_error.h +112 -0
  25. data/dependencies/SDL/include/SDL_events.h +827 -0
  26. data/dependencies/SDL/include/SDL_filesystem.h +136 -0
  27. data/dependencies/SDL/include/SDL_gamecontroller.h +541 -0
  28. data/dependencies/SDL/include/SDL_gesture.h +87 -0
  29. data/dependencies/SDL/include/SDL_haptic.h +1247 -0
  30. data/dependencies/SDL/include/SDL_hints.h +1578 -0
  31. data/dependencies/SDL/include/SDL_joystick.h +499 -0
  32. data/dependencies/SDL/include/SDL_keyboard.h +217 -0
  33. data/dependencies/SDL/include/SDL_keycode.h +351 -0
  34. data/dependencies/SDL/include/SDL_loadso.h +81 -0
  35. data/dependencies/SDL/include/SDL_locale.h +101 -0
  36. data/dependencies/SDL/include/SDL_log.h +211 -0
  37. data/dependencies/SDL/include/SDL_main.h +180 -0
  38. data/dependencies/SDL/include/SDL_messagebox.h +146 -0
  39. data/dependencies/SDL/include/SDL_metal.h +117 -0
  40. data/dependencies/SDL/include/SDL_misc.h +75 -0
  41. data/dependencies/SDL/include/SDL_mouse.h +302 -0
  42. data/dependencies/SDL/include/SDL_mutex.h +251 -0
  43. data/dependencies/SDL/include/SDL_name.h +33 -0
  44. data/dependencies/SDL/include/SDL_opengl.h +2183 -0
  45. data/dependencies/SDL/include/SDL_opengl_glext.h +11180 -0
  46. data/dependencies/SDL/include/SDL_opengles.h +39 -0
  47. data/dependencies/SDL/include/SDL_opengles2.h +52 -0
  48. data/dependencies/SDL/include/SDL_opengles2_gl2.h +621 -0
  49. data/dependencies/SDL/include/SDL_opengles2_gl2ext.h +2050 -0
  50. data/dependencies/SDL/include/SDL_opengles2_gl2platform.h +30 -0
  51. data/dependencies/SDL/include/SDL_opengles2_khrplatform.h +282 -0
  52. data/dependencies/SDL/include/SDL_pixels.h +479 -0
  53. data/dependencies/SDL/include/SDL_platform.h +198 -0
  54. data/dependencies/SDL/include/SDL_power.h +75 -0
  55. data/dependencies/SDL/include/SDL_quit.h +58 -0
  56. data/dependencies/SDL/include/SDL_rect.h +174 -0
  57. data/dependencies/SDL/include/SDL_render.h +1158 -0
  58. data/dependencies/SDL/include/SDL_revision.h +2 -0
  59. data/dependencies/SDL/include/SDL_rwops.h +283 -0
  60. data/dependencies/SDL/include/SDL_scancode.h +413 -0
  61. data/dependencies/SDL/include/SDL_sensor.h +267 -0
  62. data/dependencies/SDL/include/SDL_shape.h +144 -0
  63. data/dependencies/SDL/include/SDL_stdinc.h +647 -0
  64. data/dependencies/SDL/include/SDL_surface.h +563 -0
  65. data/dependencies/SDL/include/SDL_system.h +325 -0
  66. data/dependencies/SDL/include/SDL_syswm.h +354 -0
  67. data/dependencies/SDL/include/SDL_test.h +69 -0
  68. data/dependencies/SDL/include/SDL_test_assert.h +105 -0
  69. data/dependencies/SDL/include/SDL_test_common.h +218 -0
  70. data/dependencies/SDL/include/SDL_test_compare.h +69 -0
  71. data/dependencies/SDL/include/SDL_test_crc32.h +124 -0
  72. data/dependencies/SDL/include/SDL_test_font.h +81 -0
  73. data/dependencies/SDL/include/SDL_test_fuzzer.h +384 -0
  74. data/dependencies/SDL/include/SDL_test_harness.h +134 -0
  75. data/dependencies/SDL/include/SDL_test_images.h +78 -0
  76. data/dependencies/SDL/include/SDL_test_log.h +67 -0
  77. data/dependencies/SDL/include/SDL_test_md5.h +129 -0
  78. data/dependencies/SDL/include/SDL_test_memory.h +63 -0
  79. data/dependencies/SDL/include/SDL_test_random.h +115 -0
  80. data/dependencies/SDL/include/SDL_thread.h +366 -0
  81. data/dependencies/SDL/include/SDL_timer.h +115 -0
  82. data/dependencies/SDL/include/SDL_touch.h +102 -0
  83. data/dependencies/SDL/include/SDL_types.h +29 -0
  84. data/dependencies/SDL/include/SDL_version.h +162 -0
  85. data/dependencies/SDL/include/SDL_video.h +1282 -0
  86. data/dependencies/SDL/include/SDL_vulkan.h +276 -0
  87. data/dependencies/SDL/include/begin_code.h +166 -0
  88. data/dependencies/SDL/include/close_code.h +40 -0
  89. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  90. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  91. data/dependencies/SDL_sound/SDL_sound.c +795 -0
  92. data/dependencies/SDL_sound/SDL_sound.h +725 -0
  93. data/dependencies/SDL_sound/SDL_sound_aiff.c +537 -0
  94. data/dependencies/SDL_sound/SDL_sound_au.c +352 -0
  95. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +747 -0
  96. data/dependencies/SDL_sound/SDL_sound_flac.c +182 -0
  97. data/dependencies/SDL_sound/SDL_sound_internal.h +304 -0
  98. data/dependencies/SDL_sound/SDL_sound_modplug.c +228 -0
  99. data/dependencies/SDL_sound/SDL_sound_mp3.c +184 -0
  100. data/dependencies/SDL_sound/SDL_sound_raw.c +164 -0
  101. data/dependencies/SDL_sound/SDL_sound_shn.c +1309 -0
  102. data/dependencies/SDL_sound/SDL_sound_voc.c +550 -0
  103. data/dependencies/SDL_sound/SDL_sound_vorbis.c +223 -0
  104. data/dependencies/SDL_sound/SDL_sound_wav.c +783 -0
  105. data/dependencies/SDL_sound/dr_flac.h +5906 -0
  106. data/dependencies/SDL_sound/dr_mp3.h +2832 -0
  107. data/dependencies/SDL_sound/libmodplug/fastmix.c +1748 -0
  108. data/dependencies/SDL_sound/libmodplug/libmodplug.h +1001 -0
  109. data/dependencies/SDL_sound/libmodplug/load_669.c +188 -0
  110. data/dependencies/SDL_sound/libmodplug/load_abc.c +4725 -0
  111. data/dependencies/SDL_sound/libmodplug/load_amf.c +403 -0
  112. data/dependencies/SDL_sound/libmodplug/load_ams.c +587 -0
  113. data/dependencies/SDL_sound/libmodplug/load_dbm.c +357 -0
  114. data/dependencies/SDL_sound/libmodplug/load_dmf.c +531 -0
  115. data/dependencies/SDL_sound/libmodplug/load_dsm.c +232 -0
  116. data/dependencies/SDL_sound/libmodplug/load_far.c +253 -0
  117. data/dependencies/SDL_sound/libmodplug/load_it.c +796 -0
  118. data/dependencies/SDL_sound/libmodplug/load_mdl.c +488 -0
  119. data/dependencies/SDL_sound/libmodplug/load_med.c +757 -0
  120. data/dependencies/SDL_sound/libmodplug/load_mid.c +1405 -0
  121. data/dependencies/SDL_sound/libmodplug/load_mod.c +269 -0
  122. data/dependencies/SDL_sound/libmodplug/load_mt2.c +546 -0
  123. data/dependencies/SDL_sound/libmodplug/load_mtm.c +142 -0
  124. data/dependencies/SDL_sound/libmodplug/load_okt.c +192 -0
  125. data/dependencies/SDL_sound/libmodplug/load_pat.c +1143 -0
  126. data/dependencies/SDL_sound/libmodplug/load_pat.h +25 -0
  127. data/dependencies/SDL_sound/libmodplug/load_psm.c +350 -0
  128. data/dependencies/SDL_sound/libmodplug/load_ptm.c +204 -0
  129. data/dependencies/SDL_sound/libmodplug/load_s3m.c +325 -0
  130. data/dependencies/SDL_sound/libmodplug/load_stm.c +180 -0
  131. data/dependencies/SDL_sound/libmodplug/load_ult.c +206 -0
  132. data/dependencies/SDL_sound/libmodplug/load_umx.c +51 -0
  133. data/dependencies/SDL_sound/libmodplug/load_xm.c +554 -0
  134. data/dependencies/SDL_sound/libmodplug/mmcmp.c +382 -0
  135. data/dependencies/SDL_sound/libmodplug/modplug.c +170 -0
  136. data/dependencies/SDL_sound/libmodplug/modplug.h +90 -0
  137. data/dependencies/SDL_sound/libmodplug/snd_dsp.c +301 -0
  138. data/dependencies/SDL_sound/libmodplug/snd_flt.c +63 -0
  139. data/dependencies/SDL_sound/libmodplug/snd_fx.c +2350 -0
  140. data/dependencies/SDL_sound/libmodplug/sndfile.c +1169 -0
  141. data/dependencies/SDL_sound/libmodplug/sndmix.c +1034 -0
  142. data/dependencies/SDL_sound/libmodplug/tables.h +371 -0
  143. data/{src/stb_vorbis.c → dependencies/SDL_sound/stb_vorbis.h} +143 -78
  144. data/dependencies/al_soft/AL/al.h +655 -0
  145. data/dependencies/al_soft/AL/alc.h +270 -0
  146. data/dependencies/al_soft/AL/alext.h +585 -0
  147. data/dependencies/al_soft/AL/efx-creative.h +3 -0
  148. data/dependencies/al_soft/AL/efx-presets.h +402 -0
  149. data/dependencies/al_soft/AL/efx.h +762 -0
  150. data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
  151. data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
  152. data/{src → dependencies/stb}/stb_image.h +330 -127
  153. data/{src → dependencies/stb}/stb_image_write.h +156 -85
  154. data/{src → dependencies/stb}/stb_truetype.h +192 -69
  155. data/{src → dependencies/utf8proc}/utf8proc.c +0 -0
  156. data/{src → dependencies/utf8proc}/utf8proc.h +0 -0
  157. data/{src → dependencies/utf8proc}/utf8proc_data.h +0 -0
  158. data/ext/gosu/extconf.rb +56 -22
  159. data/{Gosu → include/Gosu}/Audio.hpp +6 -8
  160. data/{Gosu → include/Gosu}/AutoLink.hpp +0 -0
  161. data/include/Gosu/Bitmap.hpp +100 -0
  162. data/{Gosu → include/Gosu}/Buttons.hpp +94 -35
  163. data/{Gosu → include/Gosu}/Channel.h +0 -0
  164. data/{Gosu → include/Gosu}/Color.h +0 -0
  165. data/{Gosu → include/Gosu}/Color.hpp +0 -0
  166. data/{Gosu → include/Gosu}/Directories.hpp +0 -0
  167. data/{Gosu → include/Gosu}/Font.h +0 -0
  168. data/{Gosu → include/Gosu}/Font.hpp +0 -0
  169. data/{Gosu → include/Gosu}/Fwd.hpp +0 -0
  170. data/{Gosu → include/Gosu}/Gosu.h +3 -0
  171. data/{Gosu → include/Gosu}/Gosu.hpp +0 -0
  172. data/{Gosu → include/Gosu}/Graphics.hpp +0 -0
  173. data/{Gosu → include/Gosu}/GraphicsBase.hpp +0 -0
  174. data/{Gosu → include/Gosu}/IO.hpp +0 -0
  175. data/{Gosu → include/Gosu}/Image.h +0 -0
  176. data/{Gosu → include/Gosu}/Image.hpp +7 -6
  177. data/{Gosu → include/Gosu}/ImageData.hpp +0 -0
  178. data/{Gosu → include/Gosu}/Input.hpp +30 -15
  179. data/{Gosu → include/Gosu}/Inspection.hpp +0 -0
  180. data/{Gosu → include/Gosu}/Math.hpp +0 -0
  181. data/{Gosu → include/Gosu}/Platform.hpp +0 -0
  182. data/{Gosu → include/Gosu}/Sample.h +0 -0
  183. data/{Gosu → include/Gosu}/Song.h +0 -0
  184. data/{Gosu → include/Gosu}/Text.hpp +0 -0
  185. data/{Gosu → include/Gosu}/TextInput.h +0 -0
  186. data/{Gosu → include/Gosu}/TextInput.hpp +0 -0
  187. data/{Gosu → include/Gosu}/Timing.hpp +0 -0
  188. data/{Gosu → include/Gosu}/Utility.hpp +1 -1
  189. data/{Gosu → include/Gosu}/Version.hpp +0 -0
  190. data/{Gosu → include/Gosu}/Window.h +2 -0
  191. data/{Gosu → include/Gosu}/Window.hpp +21 -13
  192. data/lib/OpenAL32.dll +0 -0
  193. data/lib/SDL2.dll +0 -0
  194. data/lib/gosu.rb +0 -3
  195. data/lib/gosu/patches.rb +0 -9
  196. data/lib/gosu/swig_patches.rb +3 -2
  197. data/lib/libmpg123.dll +0 -0
  198. data/lib/libsndfile.dll +0 -0
  199. data/lib64/OpenAL32.dll +0 -0
  200. data/lib64/SDL2.dll +0 -0
  201. data/lib64/libmpg123.dll +0 -0
  202. data/lib64/libsndfile.dll +0 -0
  203. data/rdoc/gosu.rb +95 -20
  204. data/src/Audio.cpp +50 -224
  205. data/src/AudioFile.hpp +17 -37
  206. data/src/AudioFileAudioToolbox.cpp +237 -0
  207. data/src/AudioFileSDLSound.cpp +147 -0
  208. data/src/AudioImpl.cpp +3 -12
  209. data/src/AudioImpl.hpp +3 -1
  210. data/src/Bitmap.cpp +85 -83
  211. data/src/BitmapIO.cpp +52 -58
  212. data/src/Constants.cpp +80 -33
  213. data/src/Font.cpp +3 -1
  214. data/src/GosuWrapper.cpp +19 -0
  215. data/src/Graphics.cpp +7 -4
  216. data/src/Image.cpp +13 -16
  217. data/src/Input.cpp +408 -159
  218. data/src/LargeImageData.cpp +1 -1
  219. data/src/MarkupParser.cpp +2 -1
  220. data/src/RubyGosu.cxx +349 -83
  221. data/src/RubyGosu.h +4 -2
  222. data/src/TexChunk.cpp +1 -1
  223. data/src/TextBuilder.cpp +3 -1
  224. data/src/Texture.cpp +1 -1
  225. data/src/TrueTypeFont.cpp +1 -1
  226. data/src/Utility.cpp +11 -7
  227. data/src/Window.cpp +30 -39
  228. data/src/WindowWrapper.cpp +28 -0
  229. metadata +207 -52
  230. data/Gosu/Bitmap.hpp +0 -113
  231. data/src/AudioToolboxFile.hpp +0 -210
  232. data/src/OggFile.hpp +0 -92
  233. data/src/SndFile.hpp +0 -174
  234. data/src/WinMain.cpp +0 -64
@@ -0,0 +1,537 @@
1
+ /**
2
+ * SDL_sound; An abstract sound format decoding API.
3
+ *
4
+ * Please see the file LICENSE.txt in the source's root directory.
5
+ *
6
+ * This file written by Torbjörn Andersson.
7
+ */
8
+
9
+ /*
10
+ * AIFF decoder for SDL_sound
11
+ *
12
+ * [Insert something profound about the AIFF file format here.]
13
+ *
14
+ * This code was ripped from a decoder I had written for SDL_mixer, which was
15
+ * based on SDL_mixer's old AIFF music loader. (This loader was unfortunately
16
+ * completely broken, but it was still useful because all the pieces were
17
+ * still there, so to speak.)
18
+ *
19
+ * When rewriting it for SDL_sound, I changed its structure to be more like
20
+ * the WAV loader Ryan wrote. Had they not both been part of the same project
21
+ * it would have been embarrassing how similar they are.
22
+ *
23
+ * It is not the most feature-complete AIFF loader the world has ever seen.
24
+ * For instance, it only makes a token attempt at implementing the AIFF-C
25
+ * standard; basically the parts of it that I can easily understand and test.
26
+ * It's a start, though.
27
+ */
28
+
29
+ #define __SDL_SOUND_INTERNAL__
30
+ #include "SDL_sound_internal.h"
31
+
32
+ #if SOUND_SUPPORTS_AIFF
33
+
34
+ /*****************************************************************************
35
+ * aiff_t is what we store in our internal->decoder_private field... *
36
+ *****************************************************************************/
37
+ typedef struct S_AIFF_FMT_T
38
+ {
39
+ Uint32 type;
40
+
41
+ Uint32 total_bytes;
42
+ Uint32 data_starting_offset;
43
+
44
+ void (*free)(struct S_AIFF_FMT_T *fmt);
45
+ Uint32 (*read_sample)(Sound_Sample *sample);
46
+ int (*rewind_sample)(Sound_Sample *sample);
47
+ int (*seek_sample)(Sound_Sample *sample, Uint32 ms);
48
+
49
+
50
+ #if 0
51
+ /*
52
+ this is ripped from wav.c as ann example of format-specific data.
53
+ please replace with something more appropriate when the need arises.
54
+ */
55
+ union
56
+ {
57
+ struct
58
+ {
59
+ Uint16 cbSize;
60
+ Uint16 wSamplesPerBlock;
61
+ Uint16 wNumCoef;
62
+ ADPCMCOEFSET *aCoeff;
63
+ } adpcm;
64
+
65
+ /* put other format-specific data here... */
66
+ } fmt;
67
+ #endif
68
+ } fmt_t;
69
+
70
+
71
+ typedef struct
72
+ {
73
+ fmt_t fmt;
74
+ Sint32 bytesLeft;
75
+ } aiff_t;
76
+
77
+
78
+
79
+ /* Chunk management code... */
80
+
81
+ #define formID 0x4D524F46 /* "FORM", in ascii. */
82
+ #define aiffID 0x46464941 /* "AIFF", in ascii. */
83
+ #define aifcID 0x43464941 /* "AIFC", in ascii. */
84
+ #define ssndID 0x444E5353 /* "SSND", in ascii. */
85
+
86
+
87
+ /*****************************************************************************
88
+ * The COMM chunk... *
89
+ *****************************************************************************/
90
+
91
+ #define commID 0x4D4D4F43 /* "COMM", in ascii. */
92
+
93
+ /* format/compression types... */
94
+ #define noneID 0x454E4F4E /* "NONE", in ascii. */
95
+
96
+ typedef struct
97
+ {
98
+ Uint32 ckID;
99
+ Uint32 ckDataSize;
100
+ Uint16 numChannels;
101
+ Uint32 numSampleFrames;
102
+ Uint16 sampleSize;
103
+ Uint32 sampleRate;
104
+ /*
105
+ * We don't handle AIFF-C compressed audio yet, but for those
106
+ * interested the allowed compression types are supposed to be
107
+ *
108
+ * compressionType compressionName meaning
109
+ * ---------------------------------------------------------------
110
+ * 'NONE' "not compressed" uncompressed, that is,
111
+ * straight digitized samples
112
+ * 'ACE2' "ACE 2-to-1" 2-to-1 IIGS ACE (Audio
113
+ * Compression / Expansion)
114
+ * 'ACE8' "ACE 8-to-3" 8-to-3 IIGS ACE (Audio
115
+ * Compression / Expansion)
116
+ * 'MAC3' "MACE 3-to-1" 3-to-1 Macintosh Audio
117
+ * Compression / Expansion
118
+ * 'MAC6' "MACE 6-to-1" 6-to-1 Macintosh Audio
119
+ * Compression / Expansion
120
+ *
121
+ * A pstring is a "Pascal-style string", that is, "one byte followed
122
+ * by test bytes followed when needed by one pad byte. The total
123
+ * number of bytes in a pstring must be even. The pad byte is
124
+ * included when the number of text bytes is even, so the total of
125
+ * text bytes + one count byte + one pad byte will be even. This pad
126
+ * byte is not reflected in the count."
127
+ *
128
+ * As for how these compression algorithms work, your guess is as
129
+ * good as mine.
130
+ */
131
+ Uint32 compressionType;
132
+ #if 0
133
+ pstring compressionName;
134
+ #endif
135
+ } comm_t;
136
+
137
+
138
+ /*
139
+ * Sample rate is encoded as an "80 bit IEEE Standard 754 floating point
140
+ * number (Standard Apple Numeric Environment [SANE] data type Extended)".
141
+ * Whose bright idea was that?
142
+ *
143
+ * This function was adapted from libsndfile, and while I do know a little
144
+ * bit about the IEEE floating point standard I don't pretend to fully
145
+ * understand this.
146
+ */
147
+ static Uint32 SANE_to_Uint32 (Uint8 *sanebuf)
148
+ {
149
+ /* Is the frequency outside of what we can represent with Uint32? */
150
+ if ( (sanebuf[0] & 0x80)
151
+ || (sanebuf[0] <= 0x3F)
152
+ || (sanebuf[0] > 0x40)
153
+ || (sanebuf[0] == 0x40 && sanebuf[1] > 0x1C) )
154
+ return 0;
155
+
156
+ return ((sanebuf[2] << 23) | (sanebuf[3] << 15) | (sanebuf[4] << 7)
157
+ | (sanebuf[5] >> 1)) >> (29 - sanebuf[1]);
158
+ } /* SANE_to_Uint32 */
159
+
160
+
161
+ /*
162
+ * Read in a comm_t from disk. This makes this process safe regardless of
163
+ * the processor's byte order or how the comm_t structure is packed.
164
+ */
165
+ static int read_comm_chunk(SDL_RWops *rw, comm_t *comm)
166
+ {
167
+ Uint8 sampleRate[10];
168
+
169
+ /* skip reading the chunk ID, since it was already read at this point... */
170
+ comm->ckID = commID;
171
+
172
+ if (SDL_RWread(rw, &comm->ckDataSize, sizeof (comm->ckDataSize), 1) != 1)
173
+ return 0;
174
+ comm->ckDataSize = SDL_SwapBE32(comm->ckDataSize);
175
+
176
+ if (SDL_RWread(rw, &comm->numChannels, sizeof (comm->numChannels), 1) != 1)
177
+ return 0;
178
+ comm->numChannels = SDL_SwapBE16(comm->numChannels);
179
+
180
+ if (SDL_RWread(rw, &comm->numSampleFrames,
181
+ sizeof (comm->numSampleFrames), 1) != 1)
182
+ return 0;
183
+ comm->numSampleFrames = SDL_SwapBE32(comm->numSampleFrames);
184
+
185
+ if (SDL_RWread(rw, &comm->sampleSize, sizeof (comm->sampleSize), 1) != 1)
186
+ return 0;
187
+ comm->sampleSize = SDL_SwapBE16(comm->sampleSize);
188
+
189
+ if (SDL_RWread(rw, sampleRate, sizeof (sampleRate), 1) != 1)
190
+ return 0;
191
+ comm->sampleRate = SANE_to_Uint32(sampleRate);
192
+
193
+ if (comm->ckDataSize > sizeof(comm->numChannels)
194
+ + sizeof(comm->numSampleFrames)
195
+ + sizeof(comm->sampleSize)
196
+ + sizeof(sampleRate))
197
+ {
198
+ if (SDL_RWread(rw, &comm->compressionType,
199
+ sizeof (comm->compressionType), 1) != 1)
200
+ return 0;
201
+ comm->compressionType = SDL_SwapBE32(comm->compressionType);
202
+ } /* if */
203
+ else
204
+ {
205
+ comm->compressionType = noneID;
206
+ } /* else */
207
+
208
+ return 1;
209
+ } /* read_comm_chunk */
210
+
211
+
212
+
213
+ /*****************************************************************************
214
+ * The SSND chunk... *
215
+ *****************************************************************************/
216
+
217
+ typedef struct
218
+ {
219
+ Uint32 ckID;
220
+ Uint32 ckDataSize;
221
+ Uint32 offset;
222
+ Uint32 blockSize;
223
+ /*
224
+ * Then, comm->numSampleFrames sample frames. (It's better to get the
225
+ * length from numSampleFrames than from ckDataSize.)
226
+ */
227
+ } ssnd_t;
228
+
229
+
230
+ static int read_ssnd_chunk(SDL_RWops *rw, ssnd_t *ssnd)
231
+ {
232
+ /* skip reading the chunk ID, since it was already read at this point... */
233
+ ssnd->ckID = ssndID;
234
+
235
+ if (SDL_RWread(rw, &ssnd->ckDataSize, sizeof (ssnd->ckDataSize), 1) != 1)
236
+ return 0;
237
+ ssnd->ckDataSize = SDL_SwapBE32(ssnd->ckDataSize);
238
+
239
+ if (SDL_RWread(rw, &ssnd->offset, sizeof (ssnd->offset), 1) != 1)
240
+ return 0;
241
+ ssnd->offset = SDL_SwapBE32(ssnd->offset);
242
+
243
+ if (SDL_RWread(rw, &ssnd->blockSize, sizeof (ssnd->blockSize), 1) != 1)
244
+ return 0;
245
+ ssnd->blockSize = SDL_SwapBE32(ssnd->blockSize);
246
+
247
+ /* Leave the SDL_RWops position indicator at the start of the samples */
248
+ if (SDL_RWseek(rw, (int) ssnd->offset, SEEK_CUR) == -1)
249
+ return 0;
250
+
251
+ return 1;
252
+ } /* read_ssnd_chunk */
253
+
254
+
255
+
256
+ /*****************************************************************************
257
+ * Normal, uncompressed aiff handler... *
258
+ *****************************************************************************/
259
+
260
+ static Uint32 read_sample_fmt_normal(Sound_Sample *sample)
261
+ {
262
+ Uint32 retval;
263
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
264
+ aiff_t *a = (aiff_t *) internal->decoder_private;
265
+ Uint32 max = (internal->buffer_size < (Uint32) a->bytesLeft) ?
266
+ internal->buffer_size : (Uint32) a->bytesLeft;
267
+
268
+ SDL_assert(max > 0);
269
+
270
+ /*
271
+ * We don't actually do any decoding, so we read the AIFF data
272
+ * directly into the internal buffer...
273
+ */
274
+ retval = SDL_RWread(internal->rw, internal->buffer, 1, max);
275
+
276
+ a->bytesLeft -= retval;
277
+
278
+ /* Make sure the read went smoothly... */
279
+ if ((retval == 0) || (a->bytesLeft == 0))
280
+ sample->flags |= SOUND_SAMPLEFLAG_EOF;
281
+
282
+ else if (retval == -1)
283
+ sample->flags |= SOUND_SAMPLEFLAG_ERROR;
284
+
285
+ /* (next call this EAGAIN may turn into an EOF or error.) */
286
+ else if (retval < internal->buffer_size)
287
+ sample->flags |= SOUND_SAMPLEFLAG_EAGAIN;
288
+
289
+ return retval;
290
+ } /* read_sample_fmt_normal */
291
+
292
+
293
+ static int rewind_sample_fmt_normal(Sound_Sample *sample)
294
+ {
295
+ /* no-op. */
296
+ return 1;
297
+ } /* rewind_sample_fmt_normal */
298
+
299
+
300
+ static int seek_sample_fmt_normal(Sound_Sample *sample, Uint32 ms)
301
+ {
302
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
303
+ aiff_t *a = (aiff_t *) internal->decoder_private;
304
+ fmt_t *fmt = &a->fmt;
305
+ int offset = __Sound_convertMsToBytePos(&sample->actual, ms);
306
+ int pos = (int) (fmt->data_starting_offset + offset);
307
+ int rc = SDL_RWseek(internal->rw, pos, SEEK_SET);
308
+ BAIL_IF_MACRO(rc != pos, ERR_IO_ERROR, 0);
309
+ a->bytesLeft = fmt->total_bytes - offset;
310
+ return 1; /* success. */
311
+ } /* seek_sample_fmt_normal */
312
+
313
+
314
+ static void free_fmt_normal(fmt_t *fmt)
315
+ {
316
+ /* it's a no-op. */
317
+ } /* free_fmt_normal */
318
+
319
+
320
+ static int read_fmt_normal(SDL_RWops *rw, fmt_t *fmt)
321
+ {
322
+ /* (don't need to read more from the RWops...) */
323
+ fmt->free = free_fmt_normal;
324
+ fmt->read_sample = read_sample_fmt_normal;
325
+ fmt->rewind_sample = rewind_sample_fmt_normal;
326
+ fmt->seek_sample = seek_sample_fmt_normal;
327
+ return 1;
328
+ } /* read_fmt_normal */
329
+
330
+
331
+
332
+
333
+ /*****************************************************************************
334
+ * Everything else... *
335
+ *****************************************************************************/
336
+
337
+ static int AIFF_init(void)
338
+ {
339
+ return 1; /* always succeeds. */
340
+ } /* AIFF_init */
341
+
342
+
343
+ static void AIFF_quit(void)
344
+ {
345
+ /* it's a no-op. */
346
+ } /* AIFF_quit */
347
+
348
+
349
+ static int find_chunk(SDL_RWops *rw, Uint32 id)
350
+ {
351
+ Sint32 siz = 0;
352
+ Uint32 _id = 0;
353
+
354
+ while (1)
355
+ {
356
+ BAIL_IF_MACRO(SDL_RWread(rw, &_id, sizeof (_id), 1) != 1, NULL, 0);
357
+ if (SDL_SwapLE32(_id) == id)
358
+ return 1;
359
+
360
+ BAIL_IF_MACRO(SDL_RWread(rw, &siz, sizeof (siz), 1) != 1, NULL, 0);
361
+ siz = SDL_SwapBE32(siz);
362
+ SDL_assert(siz > 0);
363
+ BAIL_IF_MACRO(SDL_RWseek(rw, siz, SEEK_CUR) == -1, NULL, 0);
364
+ } /* while */
365
+
366
+ return 0; /* shouldn't hit this, but just in case... */
367
+ } /* find_chunk */
368
+
369
+
370
+ static int read_fmt(SDL_RWops *rw, comm_t *c, fmt_t *fmt)
371
+ {
372
+ fmt->type = c->compressionType;
373
+
374
+ /* if it's in this switch statement, we support the format. */
375
+ switch (fmt->type)
376
+ {
377
+ case noneID:
378
+ SNDDBG(("AIFF: Appears to be uncompressed audio.\n"));
379
+ return read_fmt_normal(rw, fmt);
380
+
381
+ /* add other types here. */
382
+
383
+ default:
384
+ SNDDBG(("AIFF: Format %lu is unknown.\n",
385
+ (unsigned int) fmt->type));
386
+ BAIL_MACRO("AIFF: Unsupported format", 0);
387
+ } /* switch */
388
+
389
+ SDL_assert(0); /* shouldn't hit this point. */
390
+ return 0;
391
+ } /* read_fmt */
392
+
393
+
394
+ static int AIFF_open(Sound_Sample *sample, const char *ext)
395
+ {
396
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
397
+ SDL_RWops *rw = internal->rw;
398
+ Uint32 chunk_id;
399
+ int bytes_per_sample;
400
+ long pos;
401
+ comm_t c;
402
+ ssnd_t s;
403
+ aiff_t *a;
404
+
405
+ BAIL_IF_MACRO(SDL_ReadLE32(rw) != formID, "AIFF: Not a FORM file.", 0);
406
+ SDL_ReadBE32(rw); /* throw the length away; we don't need it. */
407
+
408
+ chunk_id = SDL_ReadLE32(rw);
409
+ BAIL_IF_MACRO(chunk_id != aiffID && chunk_id != aifcID,
410
+ "AIFF: Not an AIFF or AIFC file.", 0);
411
+
412
+ /* Chunks may appear in any order, so we establish base camp here. */
413
+ pos = SDL_RWtell(rw);
414
+
415
+ BAIL_IF_MACRO(!find_chunk(rw, commID), "AIFF: No common chunk.", 0);
416
+ BAIL_IF_MACRO(!read_comm_chunk(rw, &c),
417
+ "AIFF: Can't read common chunk.", 0);
418
+
419
+ sample->actual.channels = (Uint8) c.numChannels;
420
+ sample->actual.rate = c.sampleRate;
421
+
422
+ /* Really, sample->total_time = (c.numSampleFrames*1000) c.sampleRate */
423
+ internal->total_time = (c.numSampleFrames / c.sampleRate) * 1000;
424
+ internal->total_time += (c.numSampleFrames % c.sampleRate)
425
+ * 1000 / c.sampleRate;
426
+
427
+ if (c.sampleSize <= 8)
428
+ {
429
+ sample->actual.format = AUDIO_S8;
430
+ bytes_per_sample = c.numChannels;
431
+ } /* if */
432
+ else if (c.sampleSize <= 16)
433
+ {
434
+ sample->actual.format = AUDIO_S16MSB;
435
+ bytes_per_sample = 2 * c.numChannels;
436
+ } /* if */
437
+ else
438
+ {
439
+ BAIL_MACRO("AIFF: Unsupported sample size.", 0);
440
+ } /* else */
441
+
442
+ BAIL_IF_MACRO(c.sampleRate == 0, "AIFF: Unsupported sample rate.", 0);
443
+
444
+ a = (aiff_t *) SDL_malloc(sizeof(aiff_t));
445
+ BAIL_IF_MACRO(a == NULL, ERR_OUT_OF_MEMORY, 0);
446
+
447
+ if (!read_fmt(rw, &c, &(a->fmt)))
448
+ {
449
+ SDL_free(a);
450
+ return 0;
451
+ } /* if */
452
+
453
+ SDL_RWseek(rw, pos, SEEK_SET); /* if the seek fails, let it go... */
454
+
455
+ if (!find_chunk(rw, ssndID))
456
+ {
457
+ SDL_free(a);
458
+ BAIL_MACRO("AIFF: No sound data chunk.", 0);
459
+ } /* if */
460
+
461
+ if (!read_ssnd_chunk(rw, &s))
462
+ {
463
+ SDL_free(a);
464
+ BAIL_MACRO("AIFF: Can't read sound data chunk.", 0);
465
+ } /* if */
466
+
467
+ a->fmt.total_bytes = a->bytesLeft = bytes_per_sample * c.numSampleFrames;
468
+ a->fmt.data_starting_offset = SDL_RWtell(rw);
469
+ internal->decoder_private = (void *) a;
470
+
471
+ sample->flags = SOUND_SAMPLEFLAG_CANSEEK;
472
+
473
+ SNDDBG(("AIFF: Accepting data stream.\n"));
474
+ return 1; /* we'll handle this data. */
475
+ } /* AIFF_open */
476
+
477
+
478
+ static void AIFF_close(Sound_Sample *sample)
479
+ {
480
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
481
+ aiff_t *a = (aiff_t *) internal->decoder_private;
482
+ a->fmt.free(&(a->fmt));
483
+ SDL_free(a);
484
+ } /* AIFF_close */
485
+
486
+
487
+ static Uint32 AIFF_read(Sound_Sample *sample)
488
+ {
489
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
490
+ aiff_t *a = (aiff_t *) internal->decoder_private;
491
+ return a->fmt.read_sample(sample);
492
+ } /* AIFF_read */
493
+
494
+
495
+ static int AIFF_rewind(Sound_Sample *sample)
496
+ {
497
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
498
+ aiff_t *a = (aiff_t *) internal->decoder_private;
499
+ fmt_t *fmt = &a->fmt;
500
+ int rc = SDL_RWseek(internal->rw, fmt->data_starting_offset, SEEK_SET);
501
+ BAIL_IF_MACRO(rc != fmt->data_starting_offset, ERR_IO_ERROR, 0);
502
+ a->bytesLeft = fmt->total_bytes;
503
+ return fmt->rewind_sample(sample);
504
+ } /* AIFF_rewind */
505
+
506
+
507
+ static int AIFF_seek(Sound_Sample *sample, Uint32 ms)
508
+ {
509
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
510
+ aiff_t *a = (aiff_t *) internal->decoder_private;
511
+ return a->fmt.seek_sample(sample, ms);
512
+ } /* AIFF_seek */
513
+
514
+ static const char *extensions_aiff[] = { "AIFF", "AIF", NULL };
515
+ const Sound_DecoderFunctions __Sound_DecoderFunctions_AIFF =
516
+ {
517
+ {
518
+ extensions_aiff,
519
+ "Audio Interchange File Format",
520
+ "Torbjörn Andersson <d91tan@Update.UU.SE>",
521
+ "https://icculus.org/SDL_sound/"
522
+ },
523
+
524
+ AIFF_init, /* init() method */
525
+ AIFF_quit, /* quit() method */
526
+ AIFF_open, /* open() method */
527
+ AIFF_close, /* close() method */
528
+ AIFF_read, /* read() method */
529
+ AIFF_rewind, /* rewind() method */
530
+ AIFF_seek /* seek() method */
531
+ };
532
+
533
+
534
+ #endif /* SOUND_SUPPORTS_AIFF */
535
+
536
+ /* end of SDL_sound_aiff.c ... */
537
+