gosu 1.4.6 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (320) hide show
  1. checksums.yaml +4 -4
  2. data/COPYING +2 -1
  3. data/dependencies/SDL/include/SDL3/SDL.h +91 -0
  4. data/dependencies/SDL/include/SDL3/SDL_assert.h +710 -0
  5. data/dependencies/SDL/include/SDL3/SDL_asyncio.h +550 -0
  6. data/dependencies/SDL/include/SDL3/SDL_atomic.h +692 -0
  7. data/dependencies/SDL/include/SDL3/SDL_audio.h +2382 -0
  8. data/dependencies/SDL/include/SDL3/SDL_begin_code.h +553 -0
  9. data/dependencies/SDL/include/{SDL_bits.h → SDL3/SDL_bits.h} +47 -27
  10. data/dependencies/SDL/include/{SDL_blendmode.h → SDL3/SDL_blendmode.h} +59 -55
  11. data/dependencies/SDL/include/SDL3/SDL_camera.h +535 -0
  12. data/dependencies/SDL/include/SDL3/SDL_clipboard.h +331 -0
  13. data/dependencies/SDL/include/{close_code.h → SDL3/SDL_close_code.h} +9 -8
  14. data/dependencies/SDL/include/{SDL_types.h → SDL3/SDL_copying.h} +2 -9
  15. data/dependencies/SDL/include/SDL3/SDL_cpuinfo.h +374 -0
  16. data/dependencies/SDL/include/SDL3/SDL_dialog.h +343 -0
  17. data/dependencies/SDL/include/SDL3/SDL_dlopennote.h +234 -0
  18. data/dependencies/SDL/include/{SDL_egl.h → SDL3/SDL_egl.h} +11 -8
  19. data/dependencies/SDL/include/SDL3/SDL_endian.h +645 -0
  20. data/dependencies/SDL/include/SDL3/SDL_error.h +226 -0
  21. data/dependencies/SDL/include/SDL3/SDL_events.h +1651 -0
  22. data/dependencies/SDL/include/SDL3/SDL_filesystem.h +537 -0
  23. data/dependencies/SDL/include/SDL3/SDL_gamepad.h +1657 -0
  24. data/dependencies/SDL/include/SDL3/SDL_gpu.h +4637 -0
  25. data/dependencies/SDL/include/SDL3/SDL_guid.h +106 -0
  26. data/dependencies/SDL/include/SDL3/SDL_haptic.h +1461 -0
  27. data/dependencies/SDL/include/SDL3/SDL_hidapi.h +571 -0
  28. data/dependencies/SDL/include/SDL3/SDL_hints.h +5041 -0
  29. data/dependencies/SDL/include/SDL3/SDL_init.h +508 -0
  30. data/dependencies/SDL/include/SDL3/SDL_intrin.h +410 -0
  31. data/dependencies/SDL/include/SDL3/SDL_iostream.h +1379 -0
  32. data/dependencies/SDL/include/SDL3/SDL_joystick.h +1385 -0
  33. data/dependencies/SDL/include/SDL3/SDL_keyboard.h +615 -0
  34. data/dependencies/SDL/include/SDL3/SDL_keycode.h +348 -0
  35. data/dependencies/SDL/include/SDL3/SDL_loadso.h +145 -0
  36. data/dependencies/SDL/include/{SDL_locale.h → SDL3/SDL_locale.h} +40 -24
  37. data/dependencies/SDL/include/SDL3/SDL_log.h +541 -0
  38. data/dependencies/SDL/include/SDL3/SDL_main.h +704 -0
  39. data/dependencies/SDL/include/SDL3/SDL_main_impl.h +149 -0
  40. data/dependencies/SDL/include/{SDL_messagebox.h → SDL3/SDL_messagebox.h} +85 -48
  41. data/dependencies/SDL/include/{SDL_metal.h → SDL3/SDL_metal.h} +29 -29
  42. data/dependencies/SDL/include/{SDL_misc.h → SDL3/SDL_misc.h} +13 -12
  43. data/dependencies/SDL/include/SDL3/SDL_mouse.h +813 -0
  44. data/dependencies/SDL/include/SDL3/SDL_mutex.h +1117 -0
  45. data/dependencies/SDL/include/SDL3/SDL_oldnames.h +1339 -0
  46. data/dependencies/SDL/include/{SDL_opengl.h → SDL3/SDL_opengl.h} +1247 -278
  47. data/dependencies/SDL/include/{SDL_opengl_glext.h → SDL3/SDL_opengl_glext.h} +5 -1
  48. data/dependencies/SDL/include/{SDL_opengles.h → SDL3/SDL_opengles.h} +6 -7
  49. data/dependencies/SDL/include/{SDL_opengles2.h → SDL3/SDL_opengles2.h} +10 -11
  50. data/dependencies/SDL/include/SDL3/SDL_pen.h +198 -0
  51. data/dependencies/SDL/include/SDL3/SDL_pixels.h +1441 -0
  52. data/dependencies/SDL/include/{SDL_test_log.h → SDL3/SDL_platform.h} +25 -26
  53. data/dependencies/SDL/include/SDL3/SDL_platform_defines.h +497 -0
  54. data/dependencies/SDL/include/{SDL_power.h → SDL3/SDL_power.h} +40 -20
  55. data/dependencies/SDL/include/SDL3/SDL_process.h +441 -0
  56. data/dependencies/SDL/include/SDL3/SDL_properties.h +572 -0
  57. data/dependencies/SDL/include/SDL3/SDL_rect.h +528 -0
  58. data/dependencies/SDL/include/SDL3/SDL_render.h +3034 -0
  59. data/dependencies/SDL/include/SDL3/SDL_revision.h +56 -0
  60. data/dependencies/SDL/include/{SDL_scancode.h → SDL3/SDL_scancode.h} +60 -68
  61. data/dependencies/SDL/include/SDL3/SDL_sensor.h +321 -0
  62. data/dependencies/SDL/include/SDL3/SDL_stdinc.h +6186 -0
  63. data/dependencies/SDL/include/SDL3/SDL_storage.h +686 -0
  64. data/dependencies/SDL/include/SDL3/SDL_surface.h +1769 -0
  65. data/dependencies/SDL/include/SDL3/SDL_system.h +840 -0
  66. data/dependencies/SDL/include/{SDL_test.h → SDL3/SDL_test.h} +16 -22
  67. data/dependencies/SDL/include/{SDL_test_assert.h → SDL3/SDL_test_assert.h} +27 -34
  68. data/dependencies/SDL/include/{SDL_test_common.h → SDL3/SDL_test_common.h} +109 -52
  69. data/dependencies/SDL/include/{SDL_test_compare.h → SDL3/SDL_test_compare.h} +22 -14
  70. data/dependencies/SDL/include/{SDL_test_crc32.h → SDL3/SDL_test_crc32.h} +27 -30
  71. data/dependencies/SDL/include/{SDL_test_font.h → SDL3/SDL_test_font.h} +50 -49
  72. data/dependencies/SDL/include/{SDL_test_fuzzer.h → SDL3/SDL_test_fuzzer.h} +64 -79
  73. data/dependencies/SDL/include/{SDL_test_harness.h → SDL3/SDL_test_harness.h} +47 -30
  74. data/dependencies/SDL/include/SDL3/SDL_test_log.h +83 -0
  75. data/dependencies/SDL/include/{SDL_test_md5.h → SDL3/SDL_test_md5.h} +21 -28
  76. data/dependencies/SDL/include/{SDL_test_memory.h → SDL3/SDL_test_memory.h} +19 -16
  77. data/dependencies/SDL/include/SDL3/SDL_thread.h +602 -0
  78. data/dependencies/SDL/include/SDL3/SDL_time.h +249 -0
  79. data/dependencies/SDL/include/SDL3/SDL_timer.h +454 -0
  80. data/dependencies/SDL/include/SDL3/SDL_touch.h +184 -0
  81. data/dependencies/SDL/include/SDL3/SDL_tray.h +544 -0
  82. data/dependencies/SDL/include/SDL3/SDL_version.h +198 -0
  83. data/dependencies/SDL/include/SDL3/SDL_video.h +3497 -0
  84. data/dependencies/SDL/include/SDL3/SDL_vulkan.h +287 -0
  85. data/dependencies/SDL/lib/x64/libSDL3.dll.a +0 -0
  86. data/dependencies/SDL/lib/x86/libSDL3.dll.a +0 -0
  87. data/dependencies/SDL_sound/SDL3_sound/SDL_sound.h +755 -0
  88. data/dependencies/SDL_sound/SDL_sound.c +136 -215
  89. data/dependencies/SDL_sound/SDL_sound_aiff.c +55 -54
  90. data/dependencies/SDL_sound/SDL_sound_au.c +32 -32
  91. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +24 -41
  92. data/dependencies/SDL_sound/SDL_sound_flac.c +32 -12
  93. data/dependencies/SDL_sound/SDL_sound_internal.h +33 -48
  94. data/dependencies/SDL_sound/SDL_sound_modplug.c +21 -29
  95. data/dependencies/SDL_sound/SDL_sound_mp3.c +35 -13
  96. data/dependencies/SDL_sound/SDL_sound_raw.c +14 -15
  97. data/dependencies/SDL_sound/SDL_sound_shn.c +82 -82
  98. data/dependencies/SDL_sound/SDL_sound_voc.c +30 -30
  99. data/dependencies/SDL_sound/SDL_sound_vorbis.c +34 -25
  100. data/dependencies/SDL_sound/SDL_sound_wav.c +86 -82
  101. data/dependencies/SDL_sound/dr_flac.h +1890 -1301
  102. data/dependencies/SDL_sound/dr_mp3.h +1098 -660
  103. data/dependencies/SDL_sound/libmodplug/fastmix.c +1 -1
  104. data/dependencies/SDL_sound/libmodplug/libmodplug.h +5 -4
  105. data/dependencies/SDL_sound/libmodplug/load_ams.c +6 -3
  106. data/dependencies/SDL_sound/libmodplug/load_dsm.c +2 -1
  107. data/dependencies/SDL_sound/libmodplug/load_mt2.c +2 -2
  108. data/dependencies/SDL_sound/libmodplug/modplug.h +2 -1
  109. data/dependencies/SDL_sound/libmodplug/snd_fx.c +3 -3
  110. data/dependencies/SDL_sound/libmodplug/sndfile.c +3 -0
  111. data/dependencies/SDL_sound/libmodplug/sndmix.c +7 -3
  112. data/dependencies/SDL_sound/stb_vorbis.h +397 -342
  113. data/dependencies/mojoAL/AL/alc.h +2 -2
  114. data/dependencies/mojoAL/mojoal.c +2120 -1885
  115. data/dependencies/stb/stb_image.h +1190 -1379
  116. data/dependencies/stb/stb_image_write.h +329 -129
  117. data/dependencies/stb/stb_truetype.h +304 -60
  118. data/dependencies/utf8proc/utf8proc.c +133 -75
  119. data/dependencies/utf8proc/utf8proc.h +131 -50
  120. data/dependencies/utf8proc/utf8proc_data.h +16213 -15658
  121. data/ext/gosu-ffi/extconf.rb +103 -0
  122. data/ext/gosu-ffi/gosu-ffi.def +467 -0
  123. data/ffi/Gosu.cpp +330 -0
  124. data/ffi/Gosu.h +84 -0
  125. data/ffi/Gosu_Channel.cpp +62 -0
  126. data/ffi/Gosu_Channel.h +17 -0
  127. data/ffi/Gosu_Color.cpp +176 -0
  128. data/ffi/Gosu_Color.h +31 -0
  129. data/ffi/Gosu_Constants.cpp +334 -0
  130. data/ffi/Gosu_FFI.h +34 -0
  131. data/ffi/Gosu_FFI_internal.h +160 -0
  132. data/ffi/Gosu_Font.cpp +97 -0
  133. data/ffi/Gosu_Font.h +32 -0
  134. data/ffi/Gosu_Image.cpp +239 -0
  135. data/ffi/Gosu_Image.h +71 -0
  136. data/ffi/Gosu_Sample.cpp +29 -0
  137. data/ffi/Gosu_Sample.h +14 -0
  138. data/ffi/Gosu_Song.cpp +69 -0
  139. data/ffi/Gosu_Song.h +18 -0
  140. data/ffi/Gosu_TextInput.cpp +94 -0
  141. data/ffi/Gosu_TextInput.h +25 -0
  142. data/ffi/Gosu_Window.cpp +314 -0
  143. data/ffi/Gosu_Window.h +78 -0
  144. data/include/Gosu/Audio.hpp +6 -11
  145. data/include/Gosu/Bitmap.hpp +38 -53
  146. data/include/Gosu/Buffer.hpp +54 -0
  147. data/include/Gosu/Color.hpp +29 -36
  148. data/include/Gosu/Directories.hpp +25 -28
  149. data/include/Gosu/Drawable.hpp +58 -0
  150. data/include/Gosu/Font.hpp +6 -5
  151. data/include/Gosu/Fwd.hpp +4 -6
  152. data/include/Gosu/Gosu.hpp +5 -5
  153. data/include/Gosu/Graphics.hpp +53 -61
  154. data/include/Gosu/GraphicsBase.hpp +1 -11
  155. data/include/Gosu/Image.hpp +12 -15
  156. data/include/Gosu/Math.hpp +50 -72
  157. data/include/Gosu/Transform.hpp +32 -0
  158. data/include/Gosu/Utility.hpp +77 -1
  159. data/include/Gosu/Version.hpp +2 -2
  160. data/include/Gosu/Window.hpp +15 -9
  161. data/lib/SDL3.dll +0 -0
  162. data/lib/gosu/channel.rb +50 -0
  163. data/lib/gosu/color.rb +173 -0
  164. data/lib/gosu/compat.rb +130 -17
  165. data/lib/gosu/constants.rb +386 -0
  166. data/lib/gosu/ffi.rb +269 -0
  167. data/lib/gosu/font.rb +62 -0
  168. data/lib/gosu/gl_tex_info.rb +33 -0
  169. data/lib/gosu/gosu.rb +250 -0
  170. data/lib/gosu/image.rb +179 -0
  171. data/lib/gosu/numeric.rb +17 -0
  172. data/lib/gosu/preview.rb +6 -6
  173. data/lib/gosu/sample.rb +25 -0
  174. data/lib/gosu/song.rb +57 -0
  175. data/lib/gosu/text_input.rb +83 -0
  176. data/lib/gosu/window.rb +249 -0
  177. data/lib/gosu.rb +29 -8
  178. data/lib64/SDL3.dll +0 -0
  179. data/rdoc/gosu.rb +2 -2
  180. data/src/Audio.cpp +30 -24
  181. data/src/AudioFile.hpp +5 -4
  182. data/src/AudioFileAudioToolbox.cpp +8 -8
  183. data/src/AudioFileSDLSound.cpp +12 -15
  184. data/src/BinPacker.cpp +188 -0
  185. data/src/BinPacker.hpp +55 -0
  186. data/src/Bitmap.cpp +172 -143
  187. data/src/BitmapIO.cpp +60 -86
  188. data/src/Buffer.cpp +150 -0
  189. data/src/ClipRectStack.cpp +38 -0
  190. data/src/ClipRectStack.hpp +17 -83
  191. data/src/Color.cpp +75 -80
  192. data/src/Directories.cpp +47 -0
  193. data/src/DirectoriesUIKit.cpp +50 -0
  194. data/src/DrawOp.hpp +20 -18
  195. data/src/DrawOpQueue.hpp +27 -33
  196. data/src/Drawable.cpp +95 -0
  197. data/src/EmptyDrawable.hpp +38 -0
  198. data/src/FPS.cpp +31 -0
  199. data/src/Font.cpp +104 -74
  200. data/src/GosuGLView.cpp +13 -11
  201. data/src/GosuViewController.cpp +2 -10
  202. data/src/Graphics.cpp +86 -145
  203. data/src/GraphicsImpl.hpp +14 -68
  204. data/src/Image.cpp +41 -35
  205. data/src/Input.cpp +73 -78
  206. data/src/Macro.cpp +46 -29
  207. data/src/Macro.hpp +23 -17
  208. data/src/MarkupParser.cpp +5 -5
  209. data/src/Math.cpp +48 -22
  210. data/src/OffScreenTarget.cpp +47 -50
  211. data/src/OffScreenTarget.hpp +13 -11
  212. data/src/OpenGLContext.cpp +116 -0
  213. data/src/OpenGLContext.hpp +41 -0
  214. data/src/RenderState.hpp +49 -71
  215. data/src/Resolution.cpp +65 -53
  216. data/src/TexChunk.cpp +35 -80
  217. data/src/TexChunk.hpp +44 -35
  218. data/src/Text.cpp +1 -1
  219. data/src/TextBuilder.cpp +35 -21
  220. data/src/TextBuilder.hpp +6 -9
  221. data/src/TextInput.cpp +9 -9
  222. data/src/Texture.cpp +62 -80
  223. data/src/Texture.hpp +25 -23
  224. data/src/TiledDrawable.cpp +149 -0
  225. data/src/TiledDrawable.hpp +47 -0
  226. data/src/TimingApple.cpp +1 -1
  227. data/src/Transform.cpp +45 -50
  228. data/src/TransformStack.hpp +16 -16
  229. data/src/TrueTypeFont.cpp +59 -51
  230. data/src/TrueTypeFont.hpp +6 -7
  231. data/src/TrueTypeFontApple.cpp +28 -19
  232. data/src/TrueTypeFontUnix.cpp +39 -32
  233. data/src/TrueTypeFontWin.cpp +30 -30
  234. data/src/Utility.cpp +113 -37
  235. data/src/UtilityWin.cpp +49 -0
  236. data/src/Window.cpp +121 -151
  237. data/src/WindowUIKit.cpp +14 -14
  238. metadata +165 -118
  239. data/dependencies/SDL/include/SDL.h +0 -233
  240. data/dependencies/SDL/include/SDL_assert.h +0 -320
  241. data/dependencies/SDL/include/SDL_atomic.h +0 -415
  242. data/dependencies/SDL/include/SDL_audio.h +0 -1500
  243. data/dependencies/SDL/include/SDL_clipboard.h +0 -141
  244. data/dependencies/SDL/include/SDL_config.h +0 -331
  245. data/dependencies/SDL/include/SDL_cpuinfo.h +0 -594
  246. data/dependencies/SDL/include/SDL_endian.h +0 -348
  247. data/dependencies/SDL/include/SDL_error.h +0 -163
  248. data/dependencies/SDL/include/SDL_events.h +0 -1166
  249. data/dependencies/SDL/include/SDL_filesystem.h +0 -149
  250. data/dependencies/SDL/include/SDL_gamecontroller.h +0 -1074
  251. data/dependencies/SDL/include/SDL_gesture.h +0 -117
  252. data/dependencies/SDL/include/SDL_guid.h +0 -100
  253. data/dependencies/SDL/include/SDL_haptic.h +0 -1341
  254. data/dependencies/SDL/include/SDL_hidapi.h +0 -451
  255. data/dependencies/SDL/include/SDL_hints.h +0 -2569
  256. data/dependencies/SDL/include/SDL_joystick.h +0 -1066
  257. data/dependencies/SDL/include/SDL_keyboard.h +0 -353
  258. data/dependencies/SDL/include/SDL_keycode.h +0 -358
  259. data/dependencies/SDL/include/SDL_loadso.h +0 -115
  260. data/dependencies/SDL/include/SDL_log.h +0 -404
  261. data/dependencies/SDL/include/SDL_main.h +0 -275
  262. data/dependencies/SDL/include/SDL_mouse.h +0 -465
  263. data/dependencies/SDL/include/SDL_mutex.h +0 -471
  264. data/dependencies/SDL/include/SDL_name.h +0 -33
  265. data/dependencies/SDL/include/SDL_pixels.h +0 -644
  266. data/dependencies/SDL/include/SDL_platform.h +0 -261
  267. data/dependencies/SDL/include/SDL_quit.h +0 -58
  268. data/dependencies/SDL/include/SDL_rect.h +0 -376
  269. data/dependencies/SDL/include/SDL_render.h +0 -1919
  270. data/dependencies/SDL/include/SDL_revision.h +0 -7
  271. data/dependencies/SDL/include/SDL_rwops.h +0 -841
  272. data/dependencies/SDL/include/SDL_sensor.h +0 -322
  273. data/dependencies/SDL/include/SDL_shape.h +0 -155
  274. data/dependencies/SDL/include/SDL_stdinc.h +0 -830
  275. data/dependencies/SDL/include/SDL_surface.h +0 -997
  276. data/dependencies/SDL/include/SDL_system.h +0 -623
  277. data/dependencies/SDL/include/SDL_syswm.h +0 -386
  278. data/dependencies/SDL/include/SDL_test_images.h +0 -78
  279. data/dependencies/SDL/include/SDL_test_random.h +0 -115
  280. data/dependencies/SDL/include/SDL_thread.h +0 -464
  281. data/dependencies/SDL/include/SDL_timer.h +0 -222
  282. data/dependencies/SDL/include/SDL_touch.h +0 -150
  283. data/dependencies/SDL/include/SDL_version.h +0 -204
  284. data/dependencies/SDL/include/SDL_video.h +0 -2150
  285. data/dependencies/SDL/include/SDL_vulkan.h +0 -215
  286. data/dependencies/SDL/include/begin_code.h +0 -187
  287. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  288. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  289. data/dependencies/SDL_sound/SDL_sound.h +0 -725
  290. data/ext/gosu/extconf.rb +0 -119
  291. data/include/Gosu/IO.hpp +0 -254
  292. data/include/Gosu/ImageData.hpp +0 -53
  293. data/include/Gosu/Inspection.hpp +0 -7
  294. data/lib/SDL2.dll +0 -0
  295. data/lib/gosu/patches.rb +0 -66
  296. data/lib/gosu/run.rb +0 -20
  297. data/lib/gosu/swig_patches.rb +0 -110
  298. data/lib64/SDL2.dll +0 -0
  299. data/src/BlockAllocator.cpp +0 -131
  300. data/src/BlockAllocator.hpp +0 -32
  301. data/src/DirectoriesApple.cpp +0 -69
  302. data/src/DirectoriesUnix.cpp +0 -46
  303. data/src/DirectoriesWin.cpp +0 -65
  304. data/src/EmptyImageData.hpp +0 -52
  305. data/src/FileUnix.cpp +0 -99
  306. data/src/FileWin.cpp +0 -88
  307. data/src/IO.cpp +0 -60
  308. data/src/Iconv.hpp +0 -51
  309. data/src/Inspection.cpp +0 -27
  310. data/src/LargeImageData.cpp +0 -215
  311. data/src/LargeImageData.hpp +0 -39
  312. data/src/Log.hpp +0 -19
  313. data/src/RubyGosu.cxx +0 -13100
  314. data/src/RubyGosu.h +0 -49
  315. data/src/WinUtility.cpp +0 -61
  316. data/src/WinUtility.hpp +0 -27
  317. /data/dependencies/SDL/include/{SDL_opengles2_gl2.h → SDL3/SDL_opengles2_gl2.h} +0 -0
  318. /data/dependencies/SDL/include/{SDL_opengles2_gl2ext.h → SDL3/SDL_opengles2_gl2ext.h} +0 -0
  319. /data/dependencies/SDL/include/{SDL_opengles2_gl2platform.h → SDL3/SDL_opengles2_gl2platform.h} +0 -0
  320. /data/dependencies/SDL/include/{SDL_opengles2_khrplatform.h → SDL3/SDL_opengles2_khrplatform.h} +0 -0
@@ -34,7 +34,7 @@ extern const Sound_DecoderFunctions __Sound_DecoderFunctions_CoreAudio;
34
34
 
35
35
  typedef struct
36
36
  {
37
- SDL_bool available;
37
+ bool available;
38
38
  const Sound_DecoderFunctions *funcs;
39
39
  } decoder_element;
40
40
 
@@ -46,9 +46,6 @@ static decoder_element decoders[] =
46
46
  #if SOUND_SUPPORTS_MODPLUG
47
47
  { 0, &__Sound_DecoderFunctions_MODPLUG },
48
48
  #endif
49
- #if SOUND_SUPPORTS_MP3
50
- { 0, &__Sound_DecoderFunctions_MP3 },
51
- #endif
52
49
  #if SOUND_SUPPORTS_WAV
53
50
  { 0, &__Sound_DecoderFunctions_WAV },
54
51
  #endif
@@ -73,6 +70,9 @@ static decoder_element decoders[] =
73
70
  #if SOUND_SUPPORTS_FLAC
74
71
  { 0, &__Sound_DecoderFunctions_FLAC },
75
72
  #endif
73
+ #if SOUND_SUPPORTS_MP3
74
+ { 0, &__Sound_DecoderFunctions_MP3 },
75
+ #endif
76
76
  #if SOUND_SUPPORTS_COREAUDIO
77
77
  { 0, &__Sound_DecoderFunctions_CoreAudio },
78
78
  #endif
@@ -84,16 +84,16 @@ static decoder_element decoders[] =
84
84
 
85
85
  /* General SDL_sound state ... */
86
86
 
87
- static SDL_TLSID tlsid_errmsg = 0;
87
+ static SDL_TLSID tlsid_errmsg;
88
88
 
89
89
  typedef struct
90
90
  {
91
- SDL_bool error_available;
91
+ bool error_available;
92
92
  char error_string[128];
93
93
  } ErrMsg;
94
94
 
95
95
  static Sound_Sample *sample_list = NULL; /* this is a linked list. */
96
- static SDL_mutex *samplelist_mutex = NULL;
96
+ static SDL_Mutex *samplelist_mutex = NULL;
97
97
 
98
98
  static const Sound_DecoderInfo **available_decoders = NULL;
99
99
  static int initialized = 0;
@@ -101,16 +101,10 @@ static int initialized = 0;
101
101
 
102
102
  /* functions ... */
103
103
 
104
- void Sound_GetLinkedVersion(Sound_Version *ver)
104
+ int Sound_Version(void)
105
105
  {
106
- if (ver != NULL)
107
- {
108
- ver->major = SOUND_VER_MAJOR;
109
- ver->minor = SOUND_VER_MINOR;
110
- ver->patch = SOUND_VER_PATCH;
111
- } /* if */
112
- } /* Sound_GetLinkedVersion */
113
-
106
+ return SDL_SOUND_VERSION;
107
+ }
114
108
 
115
109
  int Sound_Init(void)
116
110
  {
@@ -127,7 +121,8 @@ int Sound_Init(void)
127
121
 
128
122
  SDL_InitSubSystem(SDL_INIT_AUDIO);
129
123
 
130
- tlsid_errmsg = SDL_TLSCreate();
124
+ tlsid_errmsg.value = 0;
125
+ BAIL_IF_MACRO(!SDL_SetTLS(&tlsid_errmsg, NULL, NULL), ERR_OUT_OF_MEMORY, 0);
131
126
 
132
127
  samplelist_mutex = SDL_CreateMutex();
133
128
 
@@ -174,7 +169,7 @@ int Sound_Quit(void)
174
169
  SDL_free((void *) available_decoders);
175
170
  available_decoders = NULL;
176
171
 
177
- tlsid_errmsg = 0;
172
+ tlsid_errmsg.value = 0;
178
173
 
179
174
  return 1;
180
175
  } /* Sound_Quit */
@@ -185,10 +180,9 @@ const Sound_DecoderInfo **Sound_AvailableDecoders(void)
185
180
  return available_decoders; /* READ. ONLY. */
186
181
  } /* Sound_AvailableDecoders */
187
182
 
188
-
189
183
  static ErrMsg *findErrorForCurrentThread(void)
190
184
  {
191
- return (ErrMsg *) SDL_TLSGet(tlsid_errmsg);
185
+ return (ErrMsg *) SDL_GetTLS(&tlsid_errmsg);
192
186
  }
193
187
 
194
188
 
@@ -204,7 +198,7 @@ const char *Sound_GetError(void)
204
198
  if ((err != NULL) && (err->error_available))
205
199
  {
206
200
  retval = err->error_string;
207
- err->error_available = SDL_FALSE;
201
+ err->error_available = false;
208
202
  } /* if */
209
203
 
210
204
  return retval;
@@ -239,18 +233,18 @@ void __Sound_SetError(const char *str)
239
233
  if (err == NULL)
240
234
  return; /* uhh...? */
241
235
 
242
- SDL_TLSSet(tlsid_errmsg, err, SDL_free);
236
+ SDL_SetTLS(&tlsid_errmsg, err, SDL_free);
243
237
  } /* if */
244
238
 
245
- err->error_available = SDL_TRUE;
239
+ err->error_available = true;
246
240
  SDL_strlcpy(err->error_string, str, sizeof (err->error_string));
247
241
  } /* __Sound_SetError */
248
242
 
249
243
 
250
- Uint32 __Sound_convertMsToBytePos(Sound_AudioInfo *info, Uint32 ms)
244
+ Uint32 __Sound_convertMsToBytePos(SDL_AudioSpec *info, Uint32 ms)
251
245
  {
252
246
  /* "frames" == "sample frames" */
253
- float frames_per_ms = ((float) info->rate) / 1000.0f;
247
+ float frames_per_ms = ((float) info->freq) / 1000.0f;
254
248
  Uint32 frame_offset = (Uint32) (frames_per_ms * ((float) ms));
255
249
  Uint32 frame_size = (Uint32) ((info->format & 0xFF) / 8) * info->channels;
256
250
  return frame_offset * frame_size;
@@ -261,8 +255,8 @@ Uint32 __Sound_convertMsToBytePos(Sound_AudioInfo *info, Uint32 ms)
261
255
  * Allocate a Sound_Sample, and fill in most of its fields. Those that need
262
256
  * to be filled in later, by a decoder, will be initialized to zero.
263
257
  */
264
- static Sound_Sample *alloc_sample(SDL_RWops *rw, Sound_AudioInfo *desired,
265
- Uint32 bufferSize)
258
+ static Sound_Sample *alloc_sample(SDL_IOStream *io, const SDL_AudioSpec *desired,
259
+ Uint32 bufferSize)
266
260
  {
267
261
  /*
268
262
  * !!! FIXME: We're going to need to pool samples, since the mixer
@@ -295,9 +289,9 @@ static Sound_Sample *alloc_sample(SDL_RWops *rw, Sound_AudioInfo *desired,
295
289
  retval->buffer_size = bufferSize;
296
290
 
297
291
  if (desired != NULL)
298
- SDL_memcpy(&retval->desired, desired, sizeof (Sound_AudioInfo));
292
+ SDL_memcpy(&retval->desired, desired, sizeof (SDL_AudioSpec));
299
293
 
300
- internal->rw = rw;
294
+ internal->io = io;
301
295
  retval->opaque = internal;
302
296
  return retval;
303
297
  } /* alloc_sample */
@@ -307,25 +301,21 @@ static Sound_Sample *alloc_sample(SDL_RWops *rw, Sound_AudioInfo *desired,
307
301
  static SDL_INLINE const char *fmt_to_str(Uint16 fmt)
308
302
  {
309
303
  switch(fmt) {
310
- case AUDIO_U8:
304
+ case SDL_AUDIO_U8:
311
305
  return "U8";
312
- case AUDIO_S8:
306
+ case SDL_AUDIO_S8:
313
307
  return "S8";
314
- case AUDIO_U16LSB:
315
- return "U16LSB";
316
- case AUDIO_S16LSB:
308
+ case SDL_AUDIO_S16LE:
317
309
  return "S16LSB";
318
- case AUDIO_S32LSB:
310
+ case SDL_AUDIO_S32LE:
319
311
  return "S32LSB";
320
- case AUDIO_F32LSB:
312
+ case SDL_AUDIO_F32LE:
321
313
  return "F32LSB";
322
- case AUDIO_U16MSB:
323
- return "U16MSB";
324
- case AUDIO_S16MSB:
314
+ case SDL_AUDIO_S16BE:
325
315
  return "S16MSB";
326
- case AUDIO_S32MSB:
316
+ case SDL_AUDIO_S32BE:
327
317
  return "S32MSB";
328
- case AUDIO_F32MSB:
318
+ case SDL_AUDIO_F32BE:
329
319
  return "F32MSB";
330
320
  } /* switch */
331
321
  return "Unknown";
@@ -335,24 +325,24 @@ static SDL_INLINE const char *fmt_to_str(Uint16 fmt)
335
325
 
336
326
  /*
337
327
  * The bulk of the Sound_NewSample() work is done here...
338
- * Ask the specified decoder to handle the data in (rw), and if
339
- * so, construct the Sound_Sample. Otherwise, try to wind (rw)'s stream
328
+ * Ask the specified decoder to handle the data in (io), and if
329
+ * so, construct the Sound_Sample. Otherwise, try to wind (io)'s stream
340
330
  * back to where it was, and return false.
341
331
  */
342
332
  static int init_sample(const Sound_DecoderFunctions *funcs,
343
333
  Sound_Sample *sample, const char *ext,
344
- Sound_AudioInfo *_desired)
334
+ const SDL_AudioSpec *_desired)
345
335
  {
346
336
  Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
347
- Sound_AudioInfo desired;
348
- const Sint64 pos = SDL_RWtell(internal->rw);
337
+ SDL_AudioSpec desired;
338
+ const Sint64 pos = SDL_TellIO(internal->io);
349
339
 
350
340
  /* fill in the funcs for this decoder... */
351
341
  sample->decoder = &funcs->info;
352
342
  internal->funcs = funcs;
353
343
  if (!funcs->open(sample, ext))
354
344
  {
355
- SDL_RWseek(internal->rw, pos, RW_SEEK_SET); /* set for next try... */
345
+ SDL_SeekIO(internal->io, pos, SDL_IO_SEEK_SET); /* set for next try... */
356
346
  return 0;
357
347
  } /* if */
358
348
 
@@ -362,36 +352,31 @@ static int init_sample(const Sound_DecoderFunctions *funcs,
362
352
  internal->stream = NULL;
363
353
 
364
354
  if (_desired == NULL)
365
- SDL_memcpy(&desired, &sample->actual, sizeof (Sound_AudioInfo));
355
+ SDL_memcpy(&desired, &sample->actual, sizeof (SDL_AudioSpec));
366
356
  else
367
357
  {
368
358
  desired.format = _desired->format ? _desired->format : sample->actual.format;
369
359
  desired.channels = _desired->channels ? _desired->channels : sample->actual.channels;
370
- desired.rate = _desired->rate ? _desired->rate : sample->actual.rate;
360
+ desired.freq = _desired->freq ? _desired->freq : sample->actual.freq;
371
361
 
372
362
  if ( (sample->actual.format != desired.format) ||
373
363
  (sample->actual.channels != desired.channels) ||
374
- (sample->actual.rate != desired.rate) )
364
+ (sample->actual.freq != desired.freq) )
375
365
  {
376
- internal->stream = SDL_NewAudioStream(sample->actual.format,
377
- sample->actual.channels,
378
- sample->actual.rate,
379
- desired.format,
380
- desired.channels,
381
- desired.rate);
366
+ internal->stream = SDL_CreateAudioStream(&sample->actual, &desired);
382
367
 
383
368
  if (internal->stream == NULL)
384
369
  {
385
370
  __Sound_SetError(SDL_GetError());
386
371
  funcs->close(sample);
387
- SDL_RWseek(internal->rw, pos, RW_SEEK_SET); /* set for next try... */
372
+ SDL_SeekIO(internal->io, pos, SDL_IO_SEEK_SET); /* set for next try... */
388
373
  return 0;
389
374
  } /* if */
390
375
  } /* if */
391
376
  } /* else */
392
377
 
393
378
  /* these pointers are all one and the same. */
394
- SDL_memcpy(&sample->desired, &desired, sizeof (Sound_AudioInfo));
379
+ SDL_memcpy(&sample->desired, &desired, sizeof (SDL_AudioSpec));
395
380
  internal->buffer = sample->buffer;
396
381
  internal->buffer_size = sample->buffer_size;
397
382
 
@@ -403,14 +388,14 @@ static int init_sample(const Sound_DecoderFunctions *funcs,
403
388
  sample_list = sample;
404
389
  SDL_UnlockMutex(samplelist_mutex);
405
390
 
406
- SNDDBG(("New sample DESIRED format: %s format, %d rate, %d channels.\n",
391
+ SNDDBG(("New sample DESIRED format: %s format, %d freq, %d channels.\n",
407
392
  fmt_to_str(sample->desired.format),
408
- sample->desired.rate,
393
+ sample->desired.freq,
409
394
  sample->desired.channels));
410
395
 
411
- SNDDBG(("New sample ACTUAL format: %s format, %d rate, %d channels.\n",
396
+ SNDDBG(("New sample ACTUAL format: %s format, %d freq, %d channels.\n",
412
397
  fmt_to_str(sample->actual.format),
413
- sample->actual.rate,
398
+ sample->actual.freq,
414
399
  sample->actual.channels));
415
400
 
416
401
  SNDDBG(("On-the-fly conversion: %s.\n",
@@ -420,17 +405,17 @@ static int init_sample(const Sound_DecoderFunctions *funcs,
420
405
  } /* init_sample */
421
406
 
422
407
 
423
- Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext,
424
- Sound_AudioInfo *desired, Uint32 bSize)
408
+ Sound_Sample *Sound_NewSample(SDL_IOStream *io, const char *ext,
409
+ const SDL_AudioSpec *desired, Uint32 bSize)
425
410
  {
426
411
  Sound_Sample *retval;
427
412
  decoder_element *decoder;
428
413
 
429
414
  /* sanity checks. */
430
415
  BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL);
431
- BAIL_IF_MACRO(rw == NULL, ERR_INVALID_ARGUMENT, NULL);
416
+ BAIL_IF_MACRO(io == NULL, ERR_INVALID_ARGUMENT, NULL);
432
417
 
433
- retval = alloc_sample(rw, desired, bSize);
418
+ retval = alloc_sample(io, desired, bSize);
434
419
  if (!retval)
435
420
  return NULL; /* alloc_sample() sets error message... */
436
421
 
@@ -486,55 +471,55 @@ Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext,
486
471
  /* !!! FIXME: can we just push this through Sound_FreeSample() ? */
487
472
  if (retval->opaque != NULL)
488
473
  {
489
- SDL_FreeAudioStream(((Sound_SampleInternal *) retval->opaque)->stream);
474
+ SDL_DestroyAudioStream(((Sound_SampleInternal *) retval->opaque)->stream);
490
475
  SDL_free(retval->opaque);
491
476
  } /* if */
492
477
 
493
478
  __Sound_SIMDFree(retval->buffer);
494
479
  SDL_free(retval);
495
- SDL_RWclose(rw);
480
+ SDL_CloseIO(io);
496
481
  __Sound_SetError(ERR_UNSUPPORTED_FORMAT);
497
482
  return NULL;
498
483
  } /* Sound_NewSample */
499
484
 
500
485
 
501
486
  Sound_Sample *Sound_NewSampleFromFile(const char *filename,
502
- Sound_AudioInfo *desired,
487
+ const SDL_AudioSpec *desired,
503
488
  Uint32 bufferSize)
504
489
  {
505
490
  const char *ext;
506
- SDL_RWops *rw;
491
+ SDL_IOStream *io;
507
492
 
508
493
  BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL);
509
494
  BAIL_IF_MACRO(filename == NULL, ERR_INVALID_ARGUMENT, NULL);
510
495
 
511
496
  ext = SDL_strrchr(filename, '.');
512
- rw = SDL_RWFromFile(filename, "rb");
513
- BAIL_IF_MACRO(rw == NULL, SDL_GetError(), NULL);
497
+ io = SDL_IOFromFile(filename, "rb");
498
+ BAIL_IF_MACRO(io == NULL, SDL_GetError(), NULL);
514
499
 
515
500
  if (ext != NULL)
516
501
  ext++;
517
502
 
518
- return Sound_NewSample(rw, ext, desired, bufferSize);
503
+ return Sound_NewSample(io, ext, desired, bufferSize);
519
504
  } /* Sound_NewSampleFromFile */
520
505
 
521
506
 
522
507
  Sound_Sample *Sound_NewSampleFromMem(const Uint8 *data,
523
508
  Uint32 size,
524
509
  const char *ext,
525
- Sound_AudioInfo *desired,
510
+ const SDL_AudioSpec *desired,
526
511
  Uint32 bufferSize)
527
512
  {
528
- SDL_RWops *rw;
513
+ SDL_IOStream *io;
529
514
 
530
515
  BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL);
531
516
  BAIL_IF_MACRO(data == NULL, ERR_INVALID_ARGUMENT, NULL);
532
517
  BAIL_IF_MACRO(size == 0, ERR_INVALID_ARGUMENT, NULL);
533
518
 
534
- rw = SDL_RWFromConstMem(data, size);
535
- BAIL_IF_MACRO(rw == NULL, SDL_GetError(), NULL);
519
+ io = SDL_IOFromConstMem(data, size);
520
+ BAIL_IF_MACRO(io == NULL, SDL_GetError(), NULL);
536
521
 
537
- return Sound_NewSample(rw, ext, desired, bufferSize);
522
+ return Sound_NewSample(io, ext, desired, bufferSize);
538
523
  } /* Sound_NewSampleFromMem */
539
524
 
540
525
 
@@ -583,10 +568,10 @@ void Sound_FreeSample(Sound_Sample *sample)
583
568
  /* nuke it... */
584
569
  internal->funcs->close(sample);
585
570
 
586
- if (internal->rw != NULL) /* this condition is a "just in case" thing. */
587
- SDL_RWclose(internal->rw);
571
+ if (internal->io != NULL) /* this condition is a "just in case" thing. */
572
+ SDL_CloseIO(internal->io);
588
573
 
589
- SDL_FreeAudioStream(internal->stream);
574
+ SDL_DestroyAudioStream(internal->stream);
590
575
  SDL_free(internal);
591
576
  __Sound_SIMDFree(sample->buffer);
592
577
  SDL_free(sample);
@@ -611,6 +596,46 @@ int Sound_SetBufferSize(Sound_Sample *sample, Uint32 newSize)
611
596
  } /* Sound_SetBufferSize */
612
597
 
613
598
 
599
+ int Sound_SetDesiredFormat(Sound_Sample *sample, const SDL_AudioSpec *desired)
600
+ {
601
+ Sound_SampleInternal *internal = NULL;
602
+ Uint32 framesize;
603
+
604
+ BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
605
+ BAIL_IF_MACRO(sample == NULL, ERR_INVALID_ARGUMENT, 0);
606
+ internal = ((Sound_SampleInternal *) sample->opaque);
607
+
608
+ /* no conversion necessary. */
609
+ if (!desired || (SDL_memcmp(desired, &sample->actual, sizeof (*desired)) == 0)) {
610
+ if (internal->stream) {
611
+ SDL_DestroyAudioStream(internal->stream);
612
+ internal->stream = NULL;
613
+ }
614
+ SDL_copyp(&sample->desired, &sample->actual);
615
+ } else if (!internal->stream) { /* have to convert formats and we need an audiostream. */
616
+ internal->stream = SDL_CreateAudioStream(&sample->actual, desired);
617
+ if (!internal->stream) {
618
+ return 0;
619
+ }
620
+ SDL_copyp(&sample->desired, desired);
621
+ } else { /* have to convert formats and we have a stream, so just adjust it. */
622
+ if (!SDL_SetAudioStreamFormat(internal->stream, NULL, desired)) {
623
+ return 0;
624
+ }
625
+ SDL_copyp(&sample->desired, desired);
626
+ }
627
+
628
+ framesize = (Uint32) SDL_AUDIO_FRAMESIZE(sample->desired);
629
+ if (sample->buffer_size < framesize) { /* uhoh. */
630
+ sample->buffer_size = 0;
631
+ } else {
632
+ sample->buffer_size -= sample->buffer_size % framesize;
633
+ }
634
+
635
+ return 1;
636
+ } /* Sound_SetDesiredFormat */
637
+
638
+
614
639
  Uint32 Sound_Decode(Sound_Sample *sample)
615
640
  {
616
641
  Sound_SampleInternal *internal = NULL;
@@ -638,9 +663,9 @@ Uint32 Sound_Decode(Sound_Sample *sample)
638
663
  } /* if */
639
664
 
640
665
  /* call into the decoder several times until we have enough data. */
641
- while ((available = SDL_AudioStreamAvailable(internal->stream)) < internal->buffer_size)
666
+ while ((available = SDL_GetAudioStreamAvailable(internal->stream)) < internal->buffer_size)
642
667
  {
643
- SDL_bool flush_stream = SDL_FALSE;
668
+ bool flush_stream = false;
644
669
  Uint32 br;
645
670
 
646
671
  if (internal->pending_eof || internal->pending_error)
@@ -655,18 +680,18 @@ Uint32 Sound_Decode(Sound_Sample *sample)
655
680
  if (sample->flags & SOUND_SAMPLEFLAG_EOF)
656
681
  {
657
682
  sample->flags &= ~SOUND_SAMPLEFLAG_EOF;
658
- internal->pending_eof = SDL_TRUE;
659
- flush_stream = SDL_TRUE;
683
+ internal->pending_eof = true;
684
+ flush_stream = true;
660
685
  } /* if */
661
686
 
662
687
  if (sample->flags & SOUND_SAMPLEFLAG_ERROR)
663
688
  {
664
689
  sample->flags &= ~SOUND_SAMPLEFLAG_ERROR;
665
- internal->pending_error = SDL_TRUE;
666
- flush_stream = SDL_TRUE;
690
+ internal->pending_error = true;
691
+ flush_stream = true;
667
692
  } /* if */
668
693
 
669
- if ((br > 0) && (SDL_AudioStreamPut(internal->stream, internal->buffer, (int) br) == -1))
694
+ if ((br > 0) && (!SDL_PutAudioStreamData(internal->stream, internal->buffer, (int) br)))
670
695
  {
671
696
  __Sound_SetError(SDL_GetError());
672
697
  sample->flags |= SOUND_SAMPLEFLAG_ERROR;
@@ -674,14 +699,14 @@ Uint32 Sound_Decode(Sound_Sample *sample)
674
699
  } /* if */
675
700
 
676
701
  if (flush_stream)
677
- SDL_AudioStreamFlush(internal->stream);
702
+ SDL_FlushAudioStream(internal->stream);
678
703
  } /* while */
679
704
 
680
705
  /* if we hit eof or error, drain the stream before reporting that. */
681
706
  if (available > 0)
682
707
  {
683
708
  const int readlen = SDL_min(available, sample->buffer_size);
684
- const int br = SDL_AudioStreamGet(internal->stream, sample->buffer, readlen);
709
+ const int br = SDL_GetAudioStreamData(internal->stream, sample->buffer, readlen);
685
710
  if (br != readlen)
686
711
  {
687
712
  __Sound_SetError(SDL_GetError());
@@ -700,7 +725,7 @@ Uint32 Sound_Decode(Sound_Sample *sample)
700
725
  if (internal->pending_error)
701
726
  sample->flags |= SOUND_SAMPLEFLAG_ERROR;
702
727
 
703
- internal->pending_eof = internal->pending_error = SDL_FALSE;
728
+ internal->pending_eof = internal->pending_error = false;
704
729
 
705
730
  return 0;
706
731
  } /* Sound_Decode */
@@ -798,144 +823,49 @@ Sint32 Sound_GetDuration(Sound_Sample *sample)
798
823
 
799
824
  /* Utility functions ... */
800
825
 
801
- /* The following uses the implementation suggested by
802
- * the standard document, assumes RAND_MAX == 32767 */
803
- static unsigned long __Sound_seed = 1;
804
- int __Sound_rand(void)
805
- {
806
- __Sound_seed = __Sound_seed * 1103515245 + 12345;
807
- return (__Sound_seed / 65536) % 32768;
808
- }
809
- void __Sound_srand(unsigned int seed)
810
- {
811
- __Sound_seed = seed;
812
- }
813
-
814
- #if !defined(HAVE_SDL_STRTOKR)
815
- /* Adapted from _PDCLIB_strtok() of PDClib library at
816
- * https://github.com/DevSolar/pdclib.git
817
- *
818
- * The code was under CC0 license:
819
- * https://creativecommons.org/publicdomain/zero/1.0/legalcode
820
- */
821
- char *__Sound_strtokr(char *s1, const char *s2, char **ptr)
822
- {
823
- const char *p = s2;
824
-
825
- if (!s2 || !ptr || (!s1 && !*ptr)) return NULL;
826
-
827
- if (s1 != NULL) { /* new string */
828
- *ptr = s1;
829
- } else { /* old string continued */
830
- if (*ptr == NULL) {
831
- /* No old string, no new string, nothing to do */
832
- return NULL;
833
- }
834
- s1 = *ptr;
835
- }
836
-
837
- /* skip leading s2 characters */
838
- while (*p && *s1) {
839
- if (*s1 == *p) {
840
- /* found separator; skip and start over */
841
- ++s1;
842
- p = s2;
843
- continue;
844
- }
845
- ++p;
846
- }
847
-
848
- if (! *s1) { /* no more to parse */
849
- *ptr = s1;
850
- return NULL;
851
- }
852
-
853
- /* skipping non-s2 characters */
854
- *ptr = s1;
855
- while (**ptr) {
856
- p = s2;
857
- while (*p) {
858
- if (**ptr == *p++) {
859
- /* found separator; overwrite with '\0', position *ptr, return */
860
- *((*ptr)++) = '\0';
861
- return s1;
862
- }
863
- }
864
- ++(*ptr);
865
- }
866
-
867
- /* parsed to end of string */
868
- return s1;
869
- }
870
- #endif
871
-
872
-
873
- /* This falls back to an included copy/paste of SDL's SIMDAlloc code if you aren't using a new enough SDL.
874
- To keep this simple, the included copy assumes you need to align to 64 bytes, which is a little
875
- wasteful but should work on everything from MMX to AVX-512. The real SDL checks the CPU at runtime
876
- to decide what's available and aligns to smaller numbers if all you have is SSE, Altivec or NEON.
877
- Not to mention this is just a second copy of the code that doesn't get attention...you should really
878
- upgrade your SDL. Ideally this copy goes away at some point. */
879
-
880
- #define USE_REAL_SDL_SIMDALLOC SDL_VERSION_ATLEAST(2, 0, 14)
881
-
882
826
  void *__Sound_SIMDAlloc(const size_t len)
883
827
  {
884
- #if USE_REAL_SDL_SIMDALLOC
885
- return SDL_SIMDAlloc(len);
886
- #else
887
- const size_t alignment = 64;
888
- const size_t padding = alignment - (len % alignment);
889
- const size_t padded = (padding != alignment) ? (len + padding) : len;
890
- Uint8 *retval = NULL;
891
- Uint8 *ptr = (Uint8 *) SDL_malloc(padded + alignment + sizeof (void *));
892
- if (ptr) {
893
- /* store the actual allocated pointer right before our aligned pointer. */
894
- retval = ptr + sizeof (void *);
895
- retval += alignment - (((size_t) retval) % alignment);
896
- *(((void **) retval) - 1) = ptr;
897
- }
898
- return retval;
899
- #endif
828
+ return SDL_aligned_alloc(SDL_GetSIMDAlignment(), len);
900
829
  }
901
830
 
902
831
  void *__Sound_SIMDRealloc(void *mem, const size_t len)
903
832
  {
904
- #if USE_REAL_SDL_SIMDALLOC
905
- return SDL_SIMDRealloc(mem, len);
906
- #else
907
- const size_t alignment = 64;
908
- const size_t padding = alignment - (len % alignment);
909
- const size_t padded = (padding != alignment) ? (len + padding) : len;
910
- Uint8 *retval = (Uint8*) mem;
833
+ const size_t alignment = SDL_GetSIMDAlignment();
834
+ const size_t padding = (alignment - (len % alignment)) % alignment;
835
+ Uint8 *retval = (Uint8 *)mem;
911
836
  void *oldmem = mem;
912
837
  size_t memdiff = 0, ptrdiff;
913
838
  Uint8 *ptr;
839
+ size_t to_allocate;
840
+
841
+ /* alignment + padding + sizeof (void *) is bounded (a few hundred
842
+ * bytes max), so no need to check for overflow within that argument */
843
+ if (!SDL_size_add_check_overflow(len, alignment + padding + sizeof(void *), &to_allocate)) {
844
+ return NULL;
845
+ }
914
846
 
915
847
  if (mem) {
916
- void **realptr = (void **) mem;
917
- realptr--;
918
- mem = *(((void **) mem) - 1);
848
+ mem = *(((void **)mem) - 1);
919
849
 
920
850
  /* Check the delta between the real pointer and user pointer */
921
- memdiff = ((size_t) oldmem) - ((size_t) mem);
851
+ memdiff = ((size_t)oldmem) - ((size_t)mem);
922
852
  }
923
853
 
924
- ptr = (Uint8 *) SDL_realloc(mem, padded + alignment + sizeof (void *));
854
+ ptr = (Uint8 *) SDL_realloc(mem, to_allocate);
925
855
 
926
856
  if (ptr == NULL) {
927
857
  return NULL; /* Out of memory, bail! */
928
858
  }
929
859
 
930
860
  /* Store the actual allocated pointer right before our aligned pointer. */
931
- retval = ptr + sizeof (void *);
932
- retval += alignment - (((size_t) retval) % alignment);
861
+ retval = ptr + sizeof(void *);
862
+ retval += alignment - (((size_t)retval) % alignment);
933
863
 
934
864
  /* Make sure the delta is the same! */
935
865
  if (mem) {
936
- ptrdiff = ((size_t) retval) - ((size_t) ptr);
866
+ ptrdiff = ((size_t)retval) - ((size_t)ptr);
937
867
  if (memdiff != ptrdiff) { /* Delta has changed, copy to new offset! */
938
- oldmem = (void*) (((uintptr_t) ptr) + memdiff);
868
+ oldmem = (void *)(((uintptr_t)ptr) + memdiff);
939
869
 
940
870
  /* Even though the data past the old `len` is undefined, this is the
941
871
  * only length value we have, and it guarantees that we copy all the
@@ -946,22 +876,13 @@ void *__Sound_SIMDRealloc(void *mem, const size_t len)
946
876
  }
947
877
 
948
878
  /* Actually store the allocated pointer, finally. */
949
- *(((void **) retval) - 1) = ptr;
879
+ *(((void **)retval) - 1) = ptr;
950
880
  return retval;
951
- #endif
952
881
  }
953
882
 
954
883
  void __Sound_SIMDFree(void *ptr)
955
884
  {
956
- #if USE_REAL_SDL_SIMDALLOC
957
- SDL_SIMDFree(ptr);
958
- #else
959
- if (ptr) {
960
- void **realptr = (void **) ptr;
961
- realptr--;
962
- SDL_free(*(((void **) ptr) - 1));
963
- }
964
- #endif
885
+ SDL_aligned_free(ptr);
965
886
  }
966
887
 
967
888
  /* end of SDL_sound.c ... */