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,182 @@
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 Ryan C. Gordon.
7
+ */
8
+
9
+ /*
10
+ * FLAC decoder for SDL_sound.
11
+ *
12
+ * FLAC stands for Free Lossless Audio Codec. It's lossless and
13
+ * high-resolution, so it's become popular with tapers and audiophiles, at
14
+ * the cost of a much larger filesize than lossy things like Ogg, MP3, AAC,
15
+ * etc. More details can be found at https://xiph.org/flac/ ...
16
+ *
17
+ * This doesn't use libFLAC from xiph.org, but rather dr_flac, a public
18
+ * domain, single-header library, for decoding. It handles both FLAC and
19
+ * "Ogg FLAC" (FLAC codec wrapped in an Ogg container) files.
20
+ *
21
+ * dr_flac is here: https://github.com/mackron/dr_libs/
22
+ */
23
+
24
+ #define __SDL_SOUND_INTERNAL__
25
+ #include "SDL_sound_internal.h"
26
+
27
+ #if SOUND_SUPPORTS_FLAC
28
+
29
+ #define DR_FLAC_IMPLEMENTATION
30
+ #define DR_FLAC_NO_STDIO 1
31
+ #define DR_FLAC_NO_WIN32_IO 1
32
+ #define DR_FLAC_NO_CRC 1
33
+ #define DRFLAC_ASSERT(x) SDL_assert((x))
34
+ #define DRFLAC_MALLOC(sz) SDL_malloc((sz))
35
+ #define DRFLAC_REALLOC(p, sz) SDL_realloc((p), (sz))
36
+ #define DRFLAC_FREE(p) SDL_free((p))
37
+ #define DRFLAC_COPY_MEMORY(dst, src, sz) SDL_memcpy((dst), (src), (sz))
38
+ #define DRFLAC_ZERO_MEMORY(p, sz) SDL_memset((p), 0, (sz))
39
+ #include "dr_flac.h"
40
+
41
+ static size_t flac_read(void* pUserData, void* pBufferOut, size_t bytesToRead)
42
+ {
43
+ Uint8 *ptr = (Uint8 *) pBufferOut;
44
+ Sound_Sample *sample = (Sound_Sample *) pUserData;
45
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
46
+ SDL_RWops *rwops = internal->rw;
47
+ size_t retval = 0;
48
+
49
+ /* !!! FIXME: dr_flac treats returning less than bytesToRead as EOF. So we can't EAGAIN. */
50
+ while (retval < bytesToRead)
51
+ {
52
+ const size_t rc = SDL_RWread(rwops, ptr, 1, bytesToRead);
53
+ if (rc == 0)
54
+ {
55
+ sample->flags |= SOUND_SAMPLEFLAG_EOF;
56
+ break;
57
+ } /* if */
58
+ else if (retval == -1)
59
+ {
60
+ sample->flags |= SOUND_SAMPLEFLAG_ERROR;
61
+ break;
62
+ } /* else if */
63
+ else
64
+ {
65
+ retval += rc;
66
+ ptr += rc;
67
+ } /* else */
68
+ } /* while */
69
+
70
+ return retval;
71
+ } /* flac_read */
72
+
73
+ static drflac_bool32 flac_seek(void* pUserData, int offset, drflac_seek_origin origin)
74
+ {
75
+ const int whence = (origin == drflac_seek_origin_start) ? RW_SEEK_SET : RW_SEEK_CUR;
76
+ Sound_Sample *sample = (Sound_Sample *) pUserData;
77
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
78
+ return (SDL_RWseek(internal->rw, offset, whence) != -1) ? DRFLAC_TRUE : DRFLAC_FALSE;
79
+ } /* flac_seek */
80
+
81
+
82
+ static int FLAC_init(void)
83
+ {
84
+ return 1; /* always succeeds. */
85
+ } /* FLAC_init */
86
+
87
+
88
+ static void FLAC_quit(void)
89
+ {
90
+ /* it's a no-op. */
91
+ } /* FLAC_quit */
92
+
93
+
94
+ static int FLAC_open(Sound_Sample *sample, const char *ext)
95
+ {
96
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
97
+ drflac *dr = drflac_open(flac_read, flac_seek, sample);
98
+
99
+ if (!dr)
100
+ {
101
+ BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_ERROR, ERR_IO_ERROR, 0);
102
+ BAIL_MACRO("FLAC: Not a FLAC stream.", 0);
103
+ } /* if */
104
+
105
+ SNDDBG(("FLAC: Accepting data stream.\n"));
106
+ sample->flags = SOUND_SAMPLEFLAG_CANSEEK;
107
+
108
+ sample->actual.channels = dr->channels;
109
+ sample->actual.rate = dr->sampleRate;
110
+ sample->actual.format = AUDIO_S32SYS; /* dr_flac only does Sint32. */
111
+
112
+ if (dr->totalSampleCount == 0)
113
+ internal->total_time = -1;
114
+ else
115
+ {
116
+ const Uint32 rate = (Uint32) dr->sampleRate;
117
+ const Uint64 frames = (Uint64) (dr->totalSampleCount / dr->channels);
118
+ internal->total_time = (frames / rate) * 1000;
119
+ internal->total_time += ((dr->totalSampleCount % dr->sampleRate) * 1000) / dr->sampleRate;
120
+ } /* else */
121
+
122
+ internal->decoder_private = dr;
123
+
124
+ return 1;
125
+ } /* FLAC_open */
126
+
127
+ static void FLAC_close(Sound_Sample *sample)
128
+ {
129
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
130
+ drflac *dr = (drflac *) internal->decoder_private;
131
+ drflac_close(dr);
132
+ } /* FLAC_close */
133
+
134
+ static Uint32 FLAC_read(Sound_Sample *sample)
135
+ {
136
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
137
+ drflac *dr = (drflac *) internal->decoder_private;
138
+ const drflac_uint64 rc = drflac_read_s32(dr, internal->buffer_size / sizeof (drflac_int32), (drflac_int32 *) internal->buffer);
139
+ /* !!! FIXME: the flac_read callback sets ERROR and EOF flags, but this only tells you about i/o errors, not corruption. */
140
+ return rc * sizeof (drflac_int32);
141
+ } /* FLAC_read */
142
+
143
+ static int FLAC_rewind(Sound_Sample *sample)
144
+ {
145
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
146
+ drflac *dr = (drflac *) internal->decoder_private;
147
+ return (drflac_seek_to_sample(dr, 0) == DRFLAC_TRUE);
148
+ } /* FLAC_rewind */
149
+
150
+ static int FLAC_seek(Sound_Sample *sample, Uint32 ms)
151
+ {
152
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
153
+ drflac *dr = (drflac *) internal->decoder_private;
154
+ const float frames_per_ms = ((float) sample->actual.rate) / 1000.0f;
155
+ const drflac_uint64 frame_offset = (drflac_uint64) (frames_per_ms * ((float) ms));
156
+ const drflac_uint64 sampnum = frame_offset * sample->actual.channels;
157
+ return (drflac_seek_to_sample(dr, sampnum) == DRFLAC_TRUE);
158
+ } /* FLAC_seek */
159
+
160
+ static const char *extensions_flac[] = { "FLAC", "FLA", NULL };
161
+ const Sound_DecoderFunctions __Sound_DecoderFunctions_FLAC =
162
+ {
163
+ {
164
+ extensions_flac,
165
+ "Free Lossless Audio Codec",
166
+ "Ryan C. Gordon <icculus@icculus.org>",
167
+ "https://icculus.org/SDL_sound/"
168
+ },
169
+
170
+ FLAC_init, /* init() method */
171
+ FLAC_quit, /* quit() method */
172
+ FLAC_open, /* open() method */
173
+ FLAC_close, /* close() method */
174
+ FLAC_read, /* read() method */
175
+ FLAC_rewind, /* rewind() method */
176
+ FLAC_seek /* seek() method */
177
+ };
178
+
179
+ #endif /* SOUND_SUPPORTS_FLAC */
180
+
181
+ /* end of SDL_sound_flac.c ... */
182
+
@@ -0,0 +1,304 @@
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 Ryan C. Gordon.
7
+ */
8
+
9
+ /*
10
+ * Internal function/structure declaration. Do NOT include in your
11
+ * application.
12
+ */
13
+
14
+ #ifndef _INCLUDE_SDL_SOUND_INTERNAL_H_
15
+ #define _INCLUDE_SDL_SOUND_INTERNAL_H_
16
+
17
+ #ifndef __SDL_SOUND_INTERNAL__
18
+ #error Do not include this header from your applications.
19
+ #endif
20
+
21
+ #include <stdio.h>
22
+ #include <stdlib.h>
23
+ #include <string.h>
24
+ #include <math.h>
25
+
26
+ #include "SDL_sound.h"
27
+
28
+ #if (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__)
29
+ #define SOUND_HAVE_PRAGMA_VISIBILITY 1
30
+ #endif
31
+
32
+ #if SOUND_HAVE_PRAGMA_VISIBILITY
33
+ #pragma GCC visibility push(hidden)
34
+ #endif
35
+
36
+ #if (defined DEBUG_CHATTER)
37
+ #define SNDDBG(x) SDL_LogDebug x
38
+ #else
39
+ #define SNDDBG(x)
40
+ #endif
41
+
42
+ #ifndef SOUND_SUPPORTS_MP3
43
+ #define SOUND_SUPPORTS_MP3 1
44
+ #endif
45
+ #ifndef SOUND_SUPPORTS_MODPLUG
46
+ #define SOUND_SUPPORTS_MODPLUG 1
47
+ #endif
48
+ #ifndef SOUND_SUPPORTS_WAV
49
+ #define SOUND_SUPPORTS_WAV 1
50
+ #endif
51
+ #ifndef SOUND_SUPPORTS_AIFF
52
+ #define SOUND_SUPPORTS_AIFF 1
53
+ #endif
54
+ #ifndef SOUND_SUPPORTS_AU
55
+ #define SOUND_SUPPORTS_AU 1
56
+ #endif
57
+ #ifndef SOUND_SUPPORTS_VORBIS
58
+ #define SOUND_SUPPORTS_VORBIS 1
59
+ #endif
60
+ #ifndef SOUND_SUPPORTS_VOC
61
+ #define SOUND_SUPPORTS_VOC 1
62
+ #endif
63
+ #ifndef SOUND_SUPPORTS_RAW
64
+ #define SOUND_SUPPORTS_RAW 1
65
+ #endif
66
+ #ifndef SOUND_SUPPORTS_SHN
67
+ #define SOUND_SUPPORTS_SHN 1
68
+ #endif
69
+ #ifndef SOUND_SUPPORTS_FLAC
70
+ #define SOUND_SUPPORTS_FLAC 1
71
+ #endif
72
+ #ifndef SOUND_SUPPORTS_COREAUDIO
73
+ #define SOUND_SUPPORTS_COREAUDIO 1
74
+ #endif
75
+
76
+ /* only build CoreAudio support if on an Apple platform. */
77
+ #if SOUND_SUPPORTS_COREAUDIO && !defined(__APPLE__)
78
+ #undef SOUND_SUPPORTS_COREAUDIO
79
+ #define SOUND_SUPPORTS_COREAUDIO 0
80
+ #endif
81
+
82
+
83
+ /*
84
+ * SDL itself only supports mono and stereo output, but hopefully we can
85
+ * raise this value someday...there's probably a lot of assumptions in
86
+ * SDL_sound that rely on it, though.
87
+ * !!! FIXME: SDL2 supports more channels.
88
+ */
89
+ #define MAX_CHANNELS 2
90
+
91
+
92
+ typedef struct __SOUND_DECODERFUNCTIONS__
93
+ {
94
+ /* This is a block of info about your decoder. See SDL_sound.h. */
95
+ const Sound_DecoderInfo info;
96
+
97
+ /*
98
+ * This is called during the Sound_Init() function. Use this to
99
+ * set up any global state that your decoder needs, such as
100
+ * initializing an external library, etc.
101
+ *
102
+ * Return non-zero if initialization is successful, zero if there's
103
+ * a fatal error. If this method fails, then this decoder is
104
+ * flagged as unavailable until SDL_sound() is shut down and
105
+ * reinitialized, in which case this method will be tried again.
106
+ *
107
+ * Note that the decoders quit() method won't be called if this
108
+ * method fails, so if you can't intialize, you'll have to clean
109
+ * up the half-initialized state in this method.
110
+ */
111
+ int (*init)(void);
112
+
113
+ /*
114
+ * This is called during the Sound_Quit() function. Use this to
115
+ * clean up any global state that your decoder has used during its
116
+ * lifespan.
117
+ */
118
+ void (*quit)(void);
119
+
120
+ /*
121
+ * Returns non-zero if (sample) has a valid fileformat that this
122
+ * driver can handle. Zero if this driver can NOT handle the data.
123
+ *
124
+ * Extension, which may be NULL, is just a hint as to the form of
125
+ * data that is being passed in. Most decoders should determine if
126
+ * they can handle the data by the data itself, but others, like
127
+ * the raw data handler, need this hint to know if they should
128
+ * accept the data in the first place.
129
+ *
130
+ * (sample)'s (opaque) field should be cast to a Sound_SampleInternal
131
+ * pointer:
132
+ *
133
+ * Sound_SampleInternal *internal;
134
+ * internal = (Sound_SampleInternal *) sample->opaque;
135
+ *
136
+ * Certain fields of sample will be filled in for the decoder before
137
+ * this call, and others should be filled in by the decoder. Some
138
+ * fields are offlimits, and should NOT be modified. The list:
139
+ *
140
+ * in Sound_SampleInternal section:
141
+ * Sound_Sample *next; (offlimits)
142
+ * Sound_Sample *prev; (offlimits)
143
+ * SDL_RWops *rw; (can use, but do NOT close it)
144
+ * const Sound_DecoderFunctions *funcs; (that's this structure)
145
+ * SDL_AudioCVT sdlcvt; (offlimits)
146
+ * void *buffer; (offlimits until read() method)
147
+ * Uint32 buffer_size; (offlimits until read() method)
148
+ * void *decoder_private; (read and write access)
149
+ *
150
+ * in rest of Sound_Sample:
151
+ * void *opaque; (this was internal section, above)
152
+ * const Sound_DecoderInfo *decoder; (read only)
153
+ * Sound_AudioInfo desired; (read only, usually not needed here)
154
+ * Sound_AudioInfo actual; (please fill this in)
155
+ * void *buffer; (offlimits)
156
+ * Uint32 buffer_size; (offlimits)
157
+ * Sound_SampleFlags flags; (set appropriately)
158
+ */
159
+ int (*open)(Sound_Sample *sample, const char *ext);
160
+
161
+ /*
162
+ * Clean up. SDL_sound is done with this sample, so the decoder should
163
+ * clean up any resources it allocated. Anything that wasn't
164
+ * explicitly allocated by the decoder should be LEFT ALONE, since
165
+ * the higher-level SDL_sound layer will clean up its own mess.
166
+ */
167
+ void (*close)(Sound_Sample *sample);
168
+
169
+ /*
170
+ * Get more data from (sample). The decoder should get a pointer to
171
+ * the internal structure...
172
+ *
173
+ * Sound_SampleInternal *internal;
174
+ * internal = (Sound_SampleInternal *) sample->opaque;
175
+ *
176
+ * ...and then start decoding. Fill in up to internal->buffer_size
177
+ * bytes of decoded sound in the space pointed to by
178
+ * internal->buffer. The encoded data is read in from internal->rw.
179
+ * Data should be decoded in the format specified during the
180
+ * decoder's open() method in the sample->actual field. The
181
+ * conversion to the desired format is done at a higher level.
182
+ *
183
+ * The return value is the number of bytes decoded into
184
+ * internal->buffer, which can be no more than internal->buffer_size,
185
+ * but can be less. If it is less, you should set a state flag:
186
+ *
187
+ * If there's just no more data (end of file, etc), then do:
188
+ * sample->flags |= SOUND_SAMPLEFLAG_EOF;
189
+ *
190
+ * If there's an unrecoverable error, then do:
191
+ * __Sound_SetError(ERR_EXPLAIN_WHAT_WENT_WRONG);
192
+ * sample->flags |= SOUND_SAMPLEFLAG_ERROR;
193
+ *
194
+ * If there's more data, but you'd have to block for considerable
195
+ * amounts of time to get at it, or there's a recoverable error,
196
+ * then do:
197
+ * __Sound_SetError(ERR_EXPLAIN_WHAT_WENT_WRONG);
198
+ * sample->flags |= SOUND_SAMPLEFLAG_EAGAIN;
199
+ *
200
+ * SDL_sound will not call your read() method for any samples with
201
+ * SOUND_SAMPLEFLAG_EOF or SOUND_SAMPLEFLAG_ERROR set. The
202
+ * SOUND_SAMPLEFLAG_EAGAIN flag is reset before each call to this
203
+ * method.
204
+ */
205
+ Uint32 (*read)(Sound_Sample *sample);
206
+
207
+ /*
208
+ * Reset the decoding to the beginning of the stream. Nonzero on
209
+ * success, zero on failure.
210
+ *
211
+ * The purpose of this method is to allow for higher efficiency than
212
+ * an application could get by just recreating the sample externally;
213
+ * not only do they not have to reopen the RWops, reallocate buffers,
214
+ * and potentially pass the data through several rejecting decoders,
215
+ * but certain decoders will not have to recreate their existing
216
+ * state (search for metadata, etc) since they already know they
217
+ * have a valid audio stream with a given set of characteristics.
218
+ *
219
+ * The decoder is responsible for calling seek() on the associated
220
+ * SDL_RWops. A failing call to seek() should be the ONLY reason that
221
+ * this method should ever fail!
222
+ */
223
+ int (*rewind)(Sound_Sample *sample);
224
+
225
+ /*
226
+ * Reposition the decoding to an arbitrary point. Nonzero on
227
+ * success, zero on failure.
228
+ *
229
+ * The purpose of this method is to allow for higher efficiency than
230
+ * an application could get by just rewinding the sample and
231
+ * decoding to a given point.
232
+ *
233
+ * The decoder is responsible for calling seek() on the associated
234
+ * SDL_RWops.
235
+ *
236
+ * If there is an error, try to recover so that the next read will
237
+ * continue as if nothing happened.
238
+ */
239
+ int (*seek)(Sound_Sample *sample, Uint32 ms);
240
+ } Sound_DecoderFunctions;
241
+
242
+
243
+ typedef void (*MixFunc)(float *dst, void *src, Uint32 frames, float *gains);
244
+
245
+ typedef struct __SOUND_SAMPLEINTERNAL__
246
+ {
247
+ Sound_Sample *next;
248
+ Sound_Sample *prev;
249
+ SDL_RWops *rw;
250
+ const Sound_DecoderFunctions *funcs;
251
+ SDL_AudioCVT sdlcvt;
252
+ void *buffer;
253
+ Uint32 buffer_size;
254
+ void *decoder_private;
255
+ Sint32 total_time;
256
+ Uint32 mix_position;
257
+ MixFunc mix;
258
+ } Sound_SampleInternal;
259
+
260
+
261
+ /* error messages... */
262
+ #define ERR_IS_INITIALIZED "Already initialized"
263
+ #define ERR_NOT_INITIALIZED "Not initialized"
264
+ #define ERR_INVALID_ARGUMENT "Invalid argument"
265
+ #define ERR_OUT_OF_MEMORY "Out of memory"
266
+ #define ERR_NOT_SUPPORTED "Operation not supported"
267
+ #define ERR_UNSUPPORTED_FORMAT "Sound format unsupported"
268
+ #define ERR_NOT_A_HANDLE "Not a file handle"
269
+ #define ERR_NO_SUCH_FILE "No such file"
270
+ #define ERR_PAST_EOF "Past end of file"
271
+ #define ERR_IO_ERROR "I/O error"
272
+ #define ERR_COMPRESSION "(De)compression error"
273
+ #define ERR_PREV_ERROR "Previous decoding already caused an error"
274
+ #define ERR_PREV_EOF "Previous decoding already triggered EOF"
275
+ #define ERR_CANNOT_SEEK "Sample is not seekable"
276
+
277
+ /*
278
+ * Call this to set the message returned by Sound_GetError().
279
+ * Please only use the ERR_* constants above, or add new constants to the
280
+ * above group, but I want these all in one place.
281
+ *
282
+ * Calling this with a NULL argument is a safe no-op.
283
+ */
284
+ void __Sound_SetError(const char *err);
285
+
286
+ /*
287
+ * Call this to convert milliseconds to an actual byte position, based on
288
+ * audio data characteristics.
289
+ */
290
+ Uint32 __Sound_convertMsToBytePos(Sound_AudioInfo *info, Uint32 ms);
291
+
292
+
293
+ /* These get used all over for lessening code clutter. */
294
+ #define BAIL_MACRO(e, r) { __Sound_SetError(e); return r; }
295
+ #define BAIL_IF_MACRO(c, e, r) if (c) { __Sound_SetError(e); return r; }
296
+
297
+ #ifdef __cplusplus
298
+ extern "C" {
299
+ #endif
300
+
301
+ #endif /* defined _INCLUDE_SDL_SOUND_INTERNAL_H_ */
302
+
303
+ /* end of SDL_sound_internal.h ... */
304
+