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,228 @@
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
+ * Module player for SDL_sound. This driver handles anything that ModPlug does.
11
+ *
12
+ * ModPlug can be found at https://sourceforge.net/projects/modplug-xmms
13
+ *
14
+ * An unofficial version of modplug with all C++ dependencies removed is also
15
+ * available: http://freecraft.net/snapshots/
16
+ * (Look for something like "libmodplug-johns-*.tar.gz")
17
+ * (update: this domain is gone. --ryan.)
18
+ */
19
+
20
+ #define __SDL_SOUND_INTERNAL__
21
+ #include "SDL_sound_internal.h"
22
+
23
+ #if SOUND_SUPPORTS_MODPLUG
24
+
25
+ #include "libmodplug/modplug.h"
26
+
27
+ static const char *extensions_modplug[] =
28
+ {
29
+ /* The XMMS plugin is apparently able to load compressed modules as
30
+ * well, but libmodplug does not handle this.
31
+ */
32
+ "669", /* Composer 669 / UNIS 669 module */
33
+ "AMF", /* ASYLUM Music Format / Advanced Music Format(DSM) */
34
+ "AMS", /* AMS module */
35
+ "DBM", /* DigiBooster Pro Module */
36
+ "DMF", /* DMF DELUSION DIGITAL MUSIC FILEFORMAT (X-Tracker) */
37
+ "DSM", /* DSIK Internal Format module */
38
+ "FAR", /* Farandole module */
39
+ "IT", /* Impulse Tracker IT file */
40
+ "MDL", /* DigiTracker module */
41
+ "MED", /* OctaMed MED file */
42
+ "MOD", /* ProTracker / NoiseTracker MOD/NST file */
43
+ "MT2", /* MadTracker 2.0 */
44
+ "MTM", /* MTM file */
45
+ "OKT", /* Oktalyzer module */
46
+ "PTM", /* PTM PolyTracker module */
47
+ "PSM", /* PSM module */
48
+ "S3M", /* ScreamTracker file */
49
+ "STM", /* ST 2.xx */
50
+ "ULT",
51
+ "UMX",
52
+ "XM", /* FastTracker II */
53
+ "ABC",
54
+ "MID",
55
+ "MIDI",
56
+ NULL
57
+ };
58
+
59
+
60
+
61
+ static int MODPLUG_init(void)
62
+ {
63
+ return ModPlug_Init(); /* success. */
64
+ } /* MODPLUG_init */
65
+
66
+
67
+ static void MODPLUG_quit(void)
68
+ {
69
+ /* it's a no-op. */
70
+ } /* MODPLUG_quit */
71
+
72
+
73
+ /*
74
+ * Most MOD files I've seen have tended to be a few hundred KB, even if some
75
+ * of them were much smaller than that.
76
+ */
77
+ #define CHUNK_SIZE 65536
78
+
79
+ static int MODPLUG_open(Sound_Sample *sample, const char *ext)
80
+ {
81
+ ModPlug_Settings settings;
82
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
83
+ ModPlugFile *module;
84
+ Uint8 *data;
85
+ size_t size;
86
+ Uint32 retval;
87
+ int has_extension = 0;
88
+ int i;
89
+
90
+ /*
91
+ * Apparently ModPlug's loaders are too forgiving. They gladly accept
92
+ * streams that they shouldn't. For now, rely on file extension instead.
93
+ */
94
+ for (i = 0; extensions_modplug[i] != NULL; i++)
95
+ {
96
+ if (SDL_strcasecmp(ext, extensions_modplug[i]) == 0)
97
+ {
98
+ has_extension = 1;
99
+ break;
100
+ } /* if */
101
+ } /* for */
102
+
103
+ if (!has_extension)
104
+ {
105
+ SNDDBG(("MODPLUG: Unrecognized file type: %s\n", ext));
106
+ BAIL_MACRO("MODPLUG: Not a module file.", 0);
107
+ } /* if */
108
+
109
+ /* ModPlug needs the entire stream in one big chunk. I don't like it,
110
+ but I don't think there's any way around it. !!! FIXME: rework modplug? */
111
+ data = (Uint8 *) SDL_malloc(CHUNK_SIZE);
112
+ BAIL_IF_MACRO(data == NULL, ERR_OUT_OF_MEMORY, 0);
113
+ size = 0;
114
+
115
+ do
116
+ {
117
+ retval = SDL_RWread(internal->rw, &data[size], 1, CHUNK_SIZE);
118
+ size += retval;
119
+ if (retval == CHUNK_SIZE)
120
+ {
121
+ data = (Uint8 *) SDL_realloc(data, size + CHUNK_SIZE);
122
+ BAIL_IF_MACRO(data == NULL, ERR_OUT_OF_MEMORY, 0);
123
+ } /* if */
124
+ } while (retval > 0);
125
+
126
+ SDL_memcpy(&sample->actual, &sample->desired, sizeof (Sound_AudioInfo));
127
+ if (sample->actual.rate == 0) sample->actual.rate = 44100;
128
+ if (sample->actual.channels == 0) sample->actual.channels = 2;
129
+ if (sample->actual.format == 0) sample->actual.format = AUDIO_S16SYS;
130
+
131
+ settings.mChannels=sample->actual.channels;
132
+ settings.mFrequency=sample->actual.rate;
133
+ settings.mBits = sample->actual.format & 0xFF;
134
+
135
+ /* The settings will require some experimenting. I've borrowed some
136
+ of them from the XMMS ModPlug plugin. */
137
+ settings.mFlags = MODPLUG_ENABLE_OVERSAMPLING;
138
+ settings.mFlags |= MODPLUG_ENABLE_NOISE_REDUCTION |
139
+ MODPLUG_ENABLE_MEGABASS |
140
+ MODPLUG_ENABLE_SURROUND;
141
+
142
+ settings.mReverbDepth = 30;
143
+ settings.mReverbDelay = 100;
144
+ settings.mBassAmount = 40;
145
+ settings.mBassRange = 30;
146
+ settings.mSurroundDepth = 20;
147
+ settings.mSurroundDelay = 20;
148
+ settings.mChannels = 2;
149
+ settings.mBits = 16;
150
+ settings.mFrequency = 44100;
151
+ settings.mResamplingMode = MODPLUG_RESAMPLE_FIR;
152
+ settings.mLoopCount = 0;
153
+
154
+ /* The buffer may be a bit too large, but that doesn't matter. I think
155
+ it's safe to free it as soon as ModPlug_Load() is finished anyway. */
156
+ module = ModPlug_Load((void *) data, size, &settings);
157
+ SDL_free(data);
158
+ BAIL_IF_MACRO(module == NULL, "MODPLUG: Not a module file.", 0);
159
+
160
+ internal->total_time = ModPlug_GetLength(module);
161
+ internal->decoder_private = (void *) module;
162
+ sample->flags = SOUND_SAMPLEFLAG_CANSEEK;
163
+
164
+ SNDDBG(("MODPLUG: Accepting data stream\n"));
165
+ return 1; /* we'll handle this data. */
166
+ } /* MODPLUG_open */
167
+
168
+
169
+ static void MODPLUG_close(Sound_Sample *sample)
170
+ {
171
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
172
+ ModPlugFile *module = (ModPlugFile *) internal->decoder_private;
173
+ ModPlug_Unload(module);
174
+ } /* MODPLUG_close */
175
+
176
+
177
+ static Uint32 MODPLUG_read(Sound_Sample *sample)
178
+ {
179
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
180
+ ModPlugFile *module = (ModPlugFile *) internal->decoder_private;
181
+ int retval;
182
+ retval = ModPlug_Read(module, internal->buffer, internal->buffer_size);
183
+ if (retval == 0)
184
+ sample->flags |= SOUND_SAMPLEFLAG_EOF;
185
+ return retval;
186
+ } /* MODPLUG_read */
187
+
188
+
189
+ static int MODPLUG_rewind(Sound_Sample *sample)
190
+ {
191
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
192
+ ModPlugFile *module = (ModPlugFile *) internal->decoder_private;
193
+ ModPlug_Seek(module, 0);
194
+ return 1;
195
+ } /* MODPLUG_rewind */
196
+
197
+
198
+ static int MODPLUG_seek(Sound_Sample *sample, Uint32 ms)
199
+ {
200
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
201
+ ModPlugFile *module = (ModPlugFile *) internal->decoder_private;
202
+ ModPlug_Seek(module, ms);
203
+ return 1;
204
+ } /* MODPLUG_seek */
205
+
206
+
207
+ const Sound_DecoderFunctions __Sound_DecoderFunctions_MODPLUG =
208
+ {
209
+ {
210
+ extensions_modplug,
211
+ "Play modules through ModPlug",
212
+ "Torbjörn Andersson <d91tan@Update.UU.SE>",
213
+ "http://modplug-xmms.sourceforge.net/"
214
+ },
215
+
216
+ MODPLUG_init, /* init() method */
217
+ MODPLUG_quit, /* quit() method */
218
+ MODPLUG_open, /* open() method */
219
+ MODPLUG_close, /* close() method */
220
+ MODPLUG_read, /* read() method */
221
+ MODPLUG_rewind, /* rewind() method */
222
+ MODPLUG_seek /* seek() method */
223
+ };
224
+
225
+ #endif /* SOUND_SUPPORTS_MODPLUG */
226
+
227
+ /* end of SDL_sound_modplug.c ... */
228
+
@@ -0,0 +1,184 @@
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
+ * MP3 decoder for SDL_sound.
11
+ *
12
+ * !!! FIXME: write something here.
13
+ *
14
+ * dr_mp3 is here: https://github.com/mackron/dr_libs/
15
+ */
16
+
17
+ #define __SDL_SOUND_INTERNAL__
18
+ #include "SDL_sound_internal.h"
19
+
20
+ #if SOUND_SUPPORTS_MP3
21
+
22
+ #define DR_MP3_IMPLEMENTATION
23
+ #define DR_MP3_NO_STDIO 1
24
+ #define DRMP3_ASSERT(x) SDL_assert((x))
25
+ #define DRMP3_MALLOC(sz) SDL_malloc((sz))
26
+ #define DRMP3_REALLOC(p, sz) SDL_realloc((p), (sz))
27
+ #define DRMP3_FREE(p) SDL_free((p))
28
+ #define DRMP3_COPY_MEMORY(dst, src, sz) SDL_memcpy((dst), (src), (sz))
29
+ #define DRMP3_ZERO_MEMORY(p, sz) SDL_memset((p), 0, (sz))
30
+
31
+ #if !defined(__clang_analyzer__)
32
+ #ifdef memset
33
+ #undef memset
34
+ #endif
35
+ #ifdef memcpy
36
+ #undef memcpy
37
+ #endif
38
+ #ifdef memmove
39
+ #undef memmove
40
+ #endif
41
+ #define memset SDL_memset
42
+ #define memcpy SDL_memcpy
43
+ #define memmove SDL_memmove
44
+ #endif
45
+
46
+ #include "dr_mp3.h"
47
+
48
+ static size_t mp3_read(void* pUserData, void* pBufferOut, size_t bytesToRead)
49
+ {
50
+ Uint8 *ptr = (Uint8 *) pBufferOut;
51
+ Sound_Sample *sample = (Sound_Sample *) pUserData;
52
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
53
+ SDL_RWops *rwops = internal->rw;
54
+ size_t retval = 0;
55
+
56
+ /* !!! FIXME: dr_mp3 treats returning less than bytesToRead as EOF. So we can't EAGAIN. */
57
+ while (retval < bytesToRead)
58
+ {
59
+ const size_t rc = SDL_RWread(rwops, ptr, 1, bytesToRead);
60
+ if (rc == 0)
61
+ {
62
+ sample->flags |= SOUND_SAMPLEFLAG_EOF;
63
+ break;
64
+ } /* if */
65
+ else if (retval == -1)
66
+ {
67
+ sample->flags |= SOUND_SAMPLEFLAG_ERROR;
68
+ break;
69
+ } /* else if */
70
+ else
71
+ {
72
+ retval += rc;
73
+ ptr += rc;
74
+ } /* else */
75
+ } /* while */
76
+
77
+ return retval;
78
+ } /* mp3_read */
79
+
80
+ static drmp3_bool32 mp3_seek(void* pUserData, int offset, drmp3_seek_origin origin)
81
+ {
82
+ const int whence = (origin == drmp3_seek_origin_start) ? RW_SEEK_SET : RW_SEEK_CUR;
83
+ Sound_Sample *sample = (Sound_Sample *) pUserData;
84
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
85
+ return (SDL_RWseek(internal->rw, offset, whence) != -1) ? DRMP3_TRUE : DRMP3_FALSE;
86
+ } /* mp3_seek */
87
+
88
+
89
+ static int MP3_init(void)
90
+ {
91
+ return 1; /* always succeeds. */
92
+ } /* MP3_init */
93
+
94
+
95
+ static void MP3_quit(void)
96
+ {
97
+ /* it's a no-op. */
98
+ } /* MP3_quit */
99
+
100
+ static int MP3_open(Sound_Sample *sample, const char *ext)
101
+ {
102
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
103
+ drmp3 *dr = (drmp3 *) SDL_calloc(1, sizeof (drmp3));
104
+
105
+ BAIL_IF_MACRO(!dr, ERR_OUT_OF_MEMORY, 0);
106
+ if (drmp3_init(dr, mp3_read, mp3_seek, sample, NULL) != DRMP3_TRUE)
107
+ {
108
+ SDL_free(dr);
109
+ BAIL_IF_MACRO(sample->flags & SOUND_SAMPLEFLAG_ERROR, ERR_IO_ERROR, 0);
110
+ BAIL_MACRO("MP3: Not an MPEG-1 layer 1-3 stream.", 0);
111
+ } /* if */
112
+
113
+ SNDDBG(("MP3: Accepting data stream.\n"));
114
+ sample->flags = SOUND_SAMPLEFLAG_CANSEEK;
115
+
116
+ sample->actual.channels = dr->channels;
117
+ sample->actual.rate = dr->sampleRate;
118
+ sample->actual.format = AUDIO_F32SYS; /* dr_mp3 only does float. */
119
+
120
+ internal->total_time = -1; /* !!! FIXME? */
121
+ internal->decoder_private = dr;
122
+
123
+ return 1;
124
+ } /* MP3_open */
125
+
126
+ static void MP3_close(Sound_Sample *sample)
127
+ {
128
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
129
+ drmp3 *dr = (drmp3 *) internal->decoder_private;
130
+ drmp3_uninit(dr);
131
+ SDL_free(dr);
132
+ } /* MP3_close */
133
+
134
+ static Uint32 MP3_read(Sound_Sample *sample)
135
+ {
136
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
137
+ const int channels = (int) sample->actual.channels;
138
+ drmp3 *dr = (drmp3 *) internal->decoder_private;
139
+ const drmp3_uint64 frames_to_read = (internal->buffer_size / channels) / sizeof (float);
140
+ const drmp3_uint64 rc = drmp3_read_f32(dr, frames_to_read, (float *) internal->buffer);
141
+ /* !!! FIXME: the mp3_read callback sets ERROR and EOF flags, but this only tells you about i/o errors, not corruption. */
142
+ return rc * channels * sizeof (float);
143
+ } /* MP3_read */
144
+
145
+ static int MP3_rewind(Sound_Sample *sample)
146
+ {
147
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
148
+ drmp3 *dr = (drmp3 *) internal->decoder_private;
149
+ return (drmp3_seek_to_frame(dr, 0) == DRMP3_TRUE);
150
+ } /* MP3_rewind */
151
+
152
+ static int MP3_seek(Sound_Sample *sample, Uint32 ms)
153
+ {
154
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
155
+ drmp3 *dr = (drmp3 *) internal->decoder_private;
156
+ const float frames_per_ms = ((float) sample->actual.rate) / 1000.0f;
157
+ const drmp3_uint64 frame_offset = (drmp3_uint64) (frames_per_ms * ((float) ms));
158
+ return (drmp3_seek_to_frame(dr, frame_offset) == DRMP3_TRUE);
159
+ } /* MP3_seek */
160
+
161
+ /* dr_mp3 will play layer 1 and 2 files, too */
162
+ static const char *extensions_mp3[] = { "MP3", "MP2", "MP1", NULL };
163
+ const Sound_DecoderFunctions __Sound_DecoderFunctions_MP3 =
164
+ {
165
+ {
166
+ extensions_mp3,
167
+ "MPEG-1 Audio Layer I-III",
168
+ "Ryan C. Gordon <icculus@icculus.org>",
169
+ "https://icculus.org/SDL_sound/"
170
+ },
171
+
172
+ MP3_init, /* init() method */
173
+ MP3_quit, /* quit() method */
174
+ MP3_open, /* open() method */
175
+ MP3_close, /* close() method */
176
+ MP3_read, /* read() method */
177
+ MP3_rewind, /* rewind() method */
178
+ MP3_seek /* seek() method */
179
+ };
180
+
181
+ #endif /* SOUND_SUPPORTS_MP3 */
182
+
183
+ /* end of SDL_sound_mp3.c ... */
184
+
@@ -0,0 +1,164 @@
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
+ * RAW decoder for SDL_sound. This is as simple as it gets.
11
+ *
12
+ * This driver handles raw audio data. You must, regardless of where the
13
+ * data is actually coming from, specify the string "RAW" in the extension
14
+ * parameter of Sound_NewSample() (or, alternately, open a file with the
15
+ * extension ".raw" in Sound_NewSampleFromFile()). The string is checked
16
+ * case-insensitive. We need this check, because raw data, being raw, has
17
+ * no headers or magic number we can use to determine if we should handle a
18
+ * given file, so we needed some way to have this "decoder" discriminate.
19
+ *
20
+ * When calling Sound_NewSample*(), you must also specify a "desired"
21
+ * audio format. The "actual" format will always match what you specify, so
22
+ * there will be no conversion overhead, but these routines need to know how
23
+ * to treat the bits, since it's all random garbage otherwise.
24
+ */
25
+
26
+ #define __SDL_SOUND_INTERNAL__
27
+ #include "SDL_sound_internal.h"
28
+
29
+ #if SOUND_SUPPORTS_RAW
30
+
31
+ static int RAW_init(void)
32
+ {
33
+ return 1; /* always succeeds. */
34
+ } /* RAW_init */
35
+
36
+
37
+ static void RAW_quit(void)
38
+ {
39
+ /* it's a no-op. */
40
+ } /* RAW_quit */
41
+
42
+
43
+ static int RAW_open(Sound_Sample *sample, const char *ext)
44
+ {
45
+ Sound_SampleInternal *internal = sample->opaque;
46
+ SDL_RWops *rw = internal->rw;
47
+ Uint32 pos, sample_rate;
48
+
49
+ /*
50
+ * We check this explicitly, since we have no other way to
51
+ * determine whether we should handle this data or not.
52
+ */
53
+ if (SDL_strcasecmp(ext, "RAW") != 0)
54
+ BAIL_MACRO("RAW: extension isn't explicitly \"RAW\".", 0);
55
+
56
+ /*
57
+ * You must also specify a desired format, so we know how to
58
+ * treat the bits that are otherwise binary garbage.
59
+ */
60
+ if ( (sample->desired.channels < 1) ||
61
+ (sample->desired.channels > 2) ||
62
+ (sample->desired.rate == 0) ||
63
+ (sample->desired.format == 0) )
64
+ {
65
+ BAIL_MACRO("RAW: invalid desired format.", 0);
66
+ } /* if */
67
+
68
+ SNDDBG(("RAW: Accepting data stream.\n"));
69
+
70
+ /*
71
+ * We never convert raw samples; what you ask for is what you get.
72
+ */
73
+ SDL_memcpy(&sample->actual, &sample->desired, sizeof (Sound_AudioInfo));
74
+ sample->flags = SOUND_SAMPLEFLAG_CANSEEK;
75
+
76
+ if ( (pos = SDL_RWseek(internal->rw, 0, SEEK_END) ) <= 0) {
77
+ BAIL_MACRO("RAW: cannot seek the end of the file \"RAW\".", 0);
78
+ }
79
+ if ( SDL_RWseek(internal->rw, 0, SEEK_SET) ) {
80
+ BAIL_MACRO("RAW: cannot reset file \"RAW\".", 0);
81
+ }
82
+
83
+ sample_rate = (sample->actual.rate * sample->actual.channels
84
+ * ( (sample->actual.format & 0x0018) >> 3) );
85
+ internal->total_time = ( pos ) / sample_rate * 1000;
86
+ internal->total_time += (pos % sample_rate) * 1000 / sample_rate;
87
+
88
+ return 1; /* we'll handle this data. */
89
+ } /* RAW_open */
90
+
91
+
92
+ static void RAW_close(Sound_Sample *sample)
93
+ {
94
+ /* we don't allocate anything that we need to free. That's easy, eh? */
95
+ } /* RAW_close */
96
+
97
+
98
+ static Uint32 RAW_read(Sound_Sample *sample)
99
+ {
100
+ Uint32 retval;
101
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
102
+
103
+ /*
104
+ * We don't actually do any decoding, so we read the raw data
105
+ * directly into the internal buffer...
106
+ */
107
+ retval = SDL_RWread(internal->rw, internal->buffer,
108
+ 1, internal->buffer_size);
109
+
110
+ /* Make sure the read went smoothly... */
111
+ if (retval == 0)
112
+ sample->flags |= SOUND_SAMPLEFLAG_EOF;
113
+
114
+ else if (retval == -1)
115
+ sample->flags |= SOUND_SAMPLEFLAG_ERROR;
116
+
117
+ /* (next call this EAGAIN may turn into an EOF or error.) */
118
+ else if (retval < internal->buffer_size)
119
+ sample->flags |= SOUND_SAMPLEFLAG_EAGAIN;
120
+
121
+ return retval;
122
+ } /* RAW_read */
123
+
124
+
125
+ static int RAW_rewind(Sound_Sample *sample)
126
+ {
127
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
128
+ BAIL_IF_MACRO(SDL_RWseek(internal->rw, 0, SEEK_SET) != 0, ERR_IO_ERROR, 0);
129
+ return 1;
130
+ } /* RAW_rewind */
131
+
132
+
133
+ static int RAW_seek(Sound_Sample *sample, Uint32 ms)
134
+ {
135
+ Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
136
+ int pos = (int) __Sound_convertMsToBytePos(&sample->actual, ms);
137
+ int err = (SDL_RWseek(internal->rw, pos, SEEK_SET) != pos);
138
+ BAIL_IF_MACRO(err, ERR_IO_ERROR, 0);
139
+ return 1;
140
+ } /* RAW_seek */
141
+
142
+ static const char *extensions_raw[] = { "RAW", NULL };
143
+ const Sound_DecoderFunctions __Sound_DecoderFunctions_RAW =
144
+ {
145
+ {
146
+ extensions_raw,
147
+ "Raw audio",
148
+ "Ryan C. Gordon <icculus@icculus.org>",
149
+ "https://icculus.org/SDL_sound/"
150
+ },
151
+
152
+ RAW_init, /* init() method */
153
+ RAW_quit, /* quit() method */
154
+ RAW_open, /* open() method */
155
+ RAW_close, /* close() method */
156
+ RAW_read, /* read() method */
157
+ RAW_rewind, /* rewind() method */
158
+ RAW_seek /* seek() method */
159
+ };
160
+
161
+ #endif /* SOUND_SUPPORTS_RAW */
162
+
163
+ /* end of SDL_sound_raw.c ... */
164
+