gosu 1.5.0 → 2.0.0.pre6

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 (241) hide show
  1. checksums.yaml +4 -4
  2. data/dependencies/SDL/include/SDL.h +233 -0
  3. data/dependencies/SDL/include/SDL_assert.h +320 -0
  4. data/dependencies/SDL/include/SDL_atomic.h +414 -0
  5. data/dependencies/SDL/include/SDL_audio.h +1500 -0
  6. data/dependencies/SDL/include/{SDL3/SDL_bits.h → SDL_bits.h} +27 -47
  7. data/dependencies/SDL/include/{SDL3/SDL_blendmode.h → SDL_blendmode.h} +55 -59
  8. data/dependencies/SDL/include/SDL_clipboard.h +141 -0
  9. data/dependencies/SDL/include/SDL_config.h +331 -0
  10. data/dependencies/SDL/include/SDL_cpuinfo.h +594 -0
  11. data/dependencies/SDL/include/{SDL3/SDL_egl.h → SDL_egl.h} +8 -11
  12. data/dependencies/SDL/include/SDL_endian.h +348 -0
  13. data/dependencies/SDL/include/SDL_error.h +163 -0
  14. data/dependencies/SDL/include/SDL_events.h +1166 -0
  15. data/dependencies/SDL/include/SDL_filesystem.h +149 -0
  16. data/dependencies/SDL/include/SDL_gamecontroller.h +1074 -0
  17. data/dependencies/SDL/include/SDL_gesture.h +117 -0
  18. data/dependencies/SDL/include/SDL_guid.h +100 -0
  19. data/dependencies/SDL/include/SDL_haptic.h +1341 -0
  20. data/dependencies/SDL/include/SDL_hidapi.h +451 -0
  21. data/dependencies/SDL/include/SDL_hints.h +2613 -0
  22. data/dependencies/SDL/include/SDL_joystick.h +1069 -0
  23. data/dependencies/SDL/include/SDL_keyboard.h +353 -0
  24. data/dependencies/SDL/include/SDL_keycode.h +358 -0
  25. data/dependencies/SDL/include/SDL_loadso.h +115 -0
  26. data/dependencies/SDL/include/{SDL3/SDL_locale.h → SDL_locale.h} +24 -40
  27. data/dependencies/SDL/include/SDL_log.h +404 -0
  28. data/dependencies/SDL/include/SDL_main.h +282 -0
  29. data/dependencies/SDL/include/{SDL3/SDL_messagebox.h → SDL_messagebox.h} +48 -85
  30. data/dependencies/SDL/include/{SDL3/SDL_metal.h → SDL_metal.h} +29 -29
  31. data/dependencies/SDL/include/{SDL3/SDL_misc.h → SDL_misc.h} +12 -13
  32. data/dependencies/SDL/include/SDL_mouse.h +464 -0
  33. data/dependencies/SDL/include/SDL_mutex.h +545 -0
  34. data/dependencies/SDL/include/SDL_name.h +33 -0
  35. data/dependencies/SDL/include/{SDL3/SDL_opengl.h → SDL_opengl.h} +252 -1221
  36. data/dependencies/SDL/include/{SDL3/SDL_opengles.h → SDL_opengles.h} +7 -6
  37. data/dependencies/SDL/include/{SDL3/SDL_opengles2.h → SDL_opengles2.h} +11 -10
  38. data/dependencies/SDL/include/SDL_pixels.h +644 -0
  39. data/dependencies/SDL/include/SDL_platform.h +261 -0
  40. data/dependencies/SDL/include/{SDL3/SDL_power.h → SDL_power.h} +19 -40
  41. data/dependencies/SDL/include/SDL_quit.h +58 -0
  42. data/dependencies/SDL/include/SDL_rect.h +376 -0
  43. data/dependencies/SDL/include/SDL_render.h +1924 -0
  44. data/dependencies/SDL/include/SDL_revision.h +7 -0
  45. data/dependencies/SDL/include/SDL_rwops.h +841 -0
  46. data/dependencies/SDL/include/{SDL3/SDL_scancode.h → SDL_scancode.h} +68 -60
  47. data/dependencies/SDL/include/SDL_sensor.h +322 -0
  48. data/dependencies/SDL/include/SDL_shape.h +155 -0
  49. data/dependencies/SDL/include/SDL_stdinc.h +838 -0
  50. data/dependencies/SDL/include/SDL_surface.h +997 -0
  51. data/dependencies/SDL/include/SDL_system.h +623 -0
  52. data/dependencies/SDL/include/SDL_syswm.h +386 -0
  53. data/dependencies/SDL/include/{SDL3/SDL_test.h → SDL_test.h} +22 -16
  54. data/dependencies/SDL/include/{SDL3/SDL_test_assert.h → SDL_test_assert.h} +34 -27
  55. data/dependencies/SDL/include/{SDL3/SDL_test_common.h → SDL_test_common.h} +52 -109
  56. data/dependencies/SDL/include/{SDL3/SDL_test_compare.h → SDL_test_compare.h} +14 -22
  57. data/dependencies/SDL/include/{SDL3/SDL_test_crc32.h → SDL_test_crc32.h} +30 -27
  58. data/dependencies/SDL/include/{SDL3/SDL_test_font.h → SDL_test_font.h} +49 -50
  59. data/dependencies/SDL/include/{SDL3/SDL_test_fuzzer.h → SDL_test_fuzzer.h} +79 -64
  60. data/dependencies/SDL/include/{SDL3/SDL_test_harness.h → SDL_test_harness.h} +30 -47
  61. data/dependencies/SDL/include/SDL_test_images.h +78 -0
  62. data/dependencies/SDL/include/{SDL3/SDL_platform.h → SDL_test_log.h} +26 -25
  63. data/dependencies/SDL/include/{SDL3/SDL_test_md5.h → SDL_test_md5.h} +28 -21
  64. data/dependencies/SDL/include/{SDL3/SDL_test_memory.h → SDL_test_memory.h} +16 -19
  65. data/dependencies/SDL/include/SDL_test_random.h +115 -0
  66. data/dependencies/SDL/include/SDL_thread.h +464 -0
  67. data/dependencies/SDL/include/SDL_timer.h +222 -0
  68. data/dependencies/SDL/include/SDL_touch.h +150 -0
  69. data/dependencies/SDL/include/{SDL3/SDL_copying.h → SDL_types.h} +9 -2
  70. data/dependencies/SDL/include/SDL_version.h +204 -0
  71. data/dependencies/SDL/include/SDL_video.h +2178 -0
  72. data/dependencies/SDL/include/SDL_vulkan.h +215 -0
  73. data/dependencies/SDL/include/begin_code.h +187 -0
  74. data/dependencies/SDL/include/{SDL3/SDL_close_code.h → close_code.h} +6 -7
  75. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  76. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  77. data/dependencies/SDL_sound/SDL_sound.c +215 -136
  78. data/dependencies/SDL_sound/SDL_sound.h +725 -0
  79. data/dependencies/SDL_sound/SDL_sound_aiff.c +54 -55
  80. data/dependencies/SDL_sound/SDL_sound_au.c +32 -32
  81. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +41 -24
  82. data/dependencies/SDL_sound/SDL_sound_flac.c +12 -32
  83. data/dependencies/SDL_sound/SDL_sound_internal.h +48 -33
  84. data/dependencies/SDL_sound/SDL_sound_modplug.c +29 -21
  85. data/dependencies/SDL_sound/SDL_sound_mp3.c +13 -35
  86. data/dependencies/SDL_sound/SDL_sound_raw.c +15 -14
  87. data/dependencies/SDL_sound/SDL_sound_shn.c +82 -82
  88. data/dependencies/SDL_sound/SDL_sound_voc.c +30 -30
  89. data/dependencies/SDL_sound/SDL_sound_vorbis.c +25 -34
  90. data/dependencies/SDL_sound/SDL_sound_wav.c +82 -86
  91. data/dependencies/SDL_sound/dr_flac.h +1281 -1845
  92. data/dependencies/SDL_sound/dr_mp3.h +617 -1035
  93. data/dependencies/SDL_sound/libmodplug/fastmix.c +1 -1
  94. data/dependencies/SDL_sound/libmodplug/libmodplug.h +4 -5
  95. data/dependencies/SDL_sound/libmodplug/load_ams.c +3 -6
  96. data/dependencies/SDL_sound/libmodplug/load_dsm.c +1 -2
  97. data/dependencies/SDL_sound/libmodplug/load_mt2.c +2 -2
  98. data/dependencies/SDL_sound/libmodplug/modplug.h +1 -2
  99. data/dependencies/SDL_sound/libmodplug/snd_fx.c +3 -3
  100. data/dependencies/SDL_sound/libmodplug/sndfile.c +0 -3
  101. data/dependencies/SDL_sound/libmodplug/sndmix.c +3 -7
  102. data/dependencies/SDL_sound/stb_vorbis.h +343 -397
  103. data/dependencies/mojoAL/AL/alc.h +2 -2
  104. data/dependencies/mojoAL/mojoal.c +1878 -2113
  105. data/dependencies/stb/stb_image.h +1381 -1192
  106. data/dependencies/stb/stb_image_write.h +129 -329
  107. data/dependencies/stb/stb_truetype.h +60 -304
  108. data/dependencies/utf8proc/utf8proc.c +75 -133
  109. data/dependencies/utf8proc/utf8proc.h +50 -131
  110. data/dependencies/utf8proc/utf8proc_data.h +15658 -16213
  111. data/ext/gosu-ffi/extconf.rb +28 -11
  112. data/ext/gosu-ffi/gosu-ffi.def +0 -3
  113. data/ffi/Gosu.cpp +29 -52
  114. data/ffi/Gosu.h +4 -4
  115. data/ffi/Gosu_Color.cpp +36 -80
  116. data/ffi/Gosu_FFI_internal.h +13 -12
  117. data/ffi/Gosu_Font.cpp +11 -16
  118. data/ffi/Gosu_Font.h +4 -4
  119. data/ffi/Gosu_Image.cpp +36 -69
  120. data/ffi/Gosu_Image.h +5 -16
  121. data/include/Gosu/Bitmap.hpp +1 -1
  122. data/include/Gosu/Color.hpp +4 -5
  123. data/include/Gosu/Graphics.hpp +0 -2
  124. data/include/Gosu/Image.hpp +1 -1
  125. data/include/Gosu/Math.hpp +5 -5
  126. data/include/Gosu/Utility.hpp +1 -27
  127. data/include/Gosu/Version.hpp +2 -2
  128. data/lib/SDL2.dll +0 -0
  129. data/lib/gosu/channel.rb +0 -1
  130. data/lib/gosu/color.rb +13 -36
  131. data/lib/gosu/compat.rb +14 -106
  132. data/lib/gosu/constants.rb +24 -24
  133. data/lib/gosu/ffi.rb +13 -24
  134. data/lib/gosu/font.rb +13 -19
  135. data/lib/gosu/gosu.rb +61 -101
  136. data/lib/gosu/image.rb +34 -72
  137. data/lib/gosu/sample.rb +0 -1
  138. data/lib/gosu/song.rb +0 -1
  139. data/lib/gosu/text_input.rb +1 -15
  140. data/lib/gosu/window.rb +10 -31
  141. data/lib64/SDL2.dll +0 -0
  142. data/rdoc/gosu.rb +0 -2
  143. data/src/Audio.cpp +16 -22
  144. data/src/AudioFileSDLSound.cpp +5 -5
  145. data/src/BinPacker.cpp +4 -5
  146. data/src/Bitmap.cpp +9 -16
  147. data/src/Buffer.cpp +14 -5
  148. data/src/ClipRectStack.hpp +83 -17
  149. data/src/Directories.cpp +1 -1
  150. data/src/DrawOp.hpp +17 -14
  151. data/src/DrawOpQueue.hpp +31 -25
  152. data/src/Font.cpp +1 -1
  153. data/src/GosuGLView.cpp +7 -1
  154. data/src/Graphics.cpp +25 -32
  155. data/src/GraphicsImpl.hpp +24 -0
  156. data/src/Image.cpp +2 -2
  157. data/src/Input.cpp +70 -66
  158. data/src/Macro.cpp +26 -43
  159. data/src/Macro.hpp +16 -22
  160. data/src/Math.cpp +7 -20
  161. data/src/OffScreenTarget.cpp +10 -3
  162. data/src/OpenGLContext.cpp +8 -7
  163. data/src/OpenGLContext.hpp +2 -2
  164. data/src/RenderState.hpp +54 -30
  165. data/src/Resolution.cpp +38 -48
  166. data/src/TexChunk.cpp +2 -2
  167. data/src/TextInput.cpp +9 -9
  168. data/src/Texture.cpp +1 -1
  169. data/src/TiledDrawable.cpp +7 -6
  170. data/src/TrueTypeFontUnix.cpp +9 -12
  171. data/src/Utility.cpp +26 -39
  172. data/src/UtilityWin.cpp +2 -6
  173. data/src/Window.cpp +34 -54
  174. metadata +93 -99
  175. data/dependencies/SDL/include/SDL3/SDL.h +0 -91
  176. data/dependencies/SDL/include/SDL3/SDL_assert.h +0 -710
  177. data/dependencies/SDL/include/SDL3/SDL_asyncio.h +0 -550
  178. data/dependencies/SDL/include/SDL3/SDL_atomic.h +0 -692
  179. data/dependencies/SDL/include/SDL3/SDL_audio.h +0 -2382
  180. data/dependencies/SDL/include/SDL3/SDL_begin_code.h +0 -553
  181. data/dependencies/SDL/include/SDL3/SDL_camera.h +0 -535
  182. data/dependencies/SDL/include/SDL3/SDL_clipboard.h +0 -331
  183. data/dependencies/SDL/include/SDL3/SDL_cpuinfo.h +0 -374
  184. data/dependencies/SDL/include/SDL3/SDL_dialog.h +0 -343
  185. data/dependencies/SDL/include/SDL3/SDL_dlopennote.h +0 -234
  186. data/dependencies/SDL/include/SDL3/SDL_endian.h +0 -645
  187. data/dependencies/SDL/include/SDL3/SDL_error.h +0 -226
  188. data/dependencies/SDL/include/SDL3/SDL_events.h +0 -1651
  189. data/dependencies/SDL/include/SDL3/SDL_filesystem.h +0 -537
  190. data/dependencies/SDL/include/SDL3/SDL_gamepad.h +0 -1657
  191. data/dependencies/SDL/include/SDL3/SDL_gpu.h +0 -4637
  192. data/dependencies/SDL/include/SDL3/SDL_guid.h +0 -106
  193. data/dependencies/SDL/include/SDL3/SDL_haptic.h +0 -1461
  194. data/dependencies/SDL/include/SDL3/SDL_hidapi.h +0 -571
  195. data/dependencies/SDL/include/SDL3/SDL_hints.h +0 -5041
  196. data/dependencies/SDL/include/SDL3/SDL_init.h +0 -508
  197. data/dependencies/SDL/include/SDL3/SDL_intrin.h +0 -410
  198. data/dependencies/SDL/include/SDL3/SDL_iostream.h +0 -1379
  199. data/dependencies/SDL/include/SDL3/SDL_joystick.h +0 -1385
  200. data/dependencies/SDL/include/SDL3/SDL_keyboard.h +0 -615
  201. data/dependencies/SDL/include/SDL3/SDL_keycode.h +0 -348
  202. data/dependencies/SDL/include/SDL3/SDL_loadso.h +0 -145
  203. data/dependencies/SDL/include/SDL3/SDL_log.h +0 -541
  204. data/dependencies/SDL/include/SDL3/SDL_main.h +0 -704
  205. data/dependencies/SDL/include/SDL3/SDL_main_impl.h +0 -149
  206. data/dependencies/SDL/include/SDL3/SDL_mouse.h +0 -813
  207. data/dependencies/SDL/include/SDL3/SDL_mutex.h +0 -1117
  208. data/dependencies/SDL/include/SDL3/SDL_oldnames.h +0 -1339
  209. data/dependencies/SDL/include/SDL3/SDL_pen.h +0 -198
  210. data/dependencies/SDL/include/SDL3/SDL_pixels.h +0 -1441
  211. data/dependencies/SDL/include/SDL3/SDL_platform_defines.h +0 -497
  212. data/dependencies/SDL/include/SDL3/SDL_process.h +0 -441
  213. data/dependencies/SDL/include/SDL3/SDL_properties.h +0 -572
  214. data/dependencies/SDL/include/SDL3/SDL_rect.h +0 -528
  215. data/dependencies/SDL/include/SDL3/SDL_render.h +0 -3034
  216. data/dependencies/SDL/include/SDL3/SDL_revision.h +0 -56
  217. data/dependencies/SDL/include/SDL3/SDL_sensor.h +0 -321
  218. data/dependencies/SDL/include/SDL3/SDL_stdinc.h +0 -6186
  219. data/dependencies/SDL/include/SDL3/SDL_storage.h +0 -686
  220. data/dependencies/SDL/include/SDL3/SDL_surface.h +0 -1769
  221. data/dependencies/SDL/include/SDL3/SDL_system.h +0 -840
  222. data/dependencies/SDL/include/SDL3/SDL_test_log.h +0 -83
  223. data/dependencies/SDL/include/SDL3/SDL_thread.h +0 -602
  224. data/dependencies/SDL/include/SDL3/SDL_time.h +0 -249
  225. data/dependencies/SDL/include/SDL3/SDL_timer.h +0 -454
  226. data/dependencies/SDL/include/SDL3/SDL_touch.h +0 -184
  227. data/dependencies/SDL/include/SDL3/SDL_tray.h +0 -544
  228. data/dependencies/SDL/include/SDL3/SDL_version.h +0 -198
  229. data/dependencies/SDL/include/SDL3/SDL_video.h +0 -3497
  230. data/dependencies/SDL/include/SDL3/SDL_vulkan.h +0 -287
  231. data/dependencies/SDL/lib/x64/libSDL3.dll.a +0 -0
  232. data/dependencies/SDL/lib/x86/libSDL3.dll.a +0 -0
  233. data/dependencies/SDL_sound/SDL3_sound/SDL_sound.h +0 -755
  234. data/lib/SDL3.dll +0 -0
  235. data/lib64/SDL3.dll +0 -0
  236. data/src/ClipRectStack.cpp +0 -38
  237. /data/dependencies/SDL/include/{SDL3/SDL_opengl_glext.h → SDL_opengl_glext.h} +0 -0
  238. /data/dependencies/SDL/include/{SDL3/SDL_opengles2_gl2.h → SDL_opengles2_gl2.h} +0 -0
  239. /data/dependencies/SDL/include/{SDL3/SDL_opengles2_gl2ext.h → SDL_opengles2_gl2ext.h} +0 -0
  240. /data/dependencies/SDL/include/{SDL3/SDL_opengles2_gl2platform.h → SDL_opengles2_gl2platform.h} +0 -0
  241. /data/dependencies/SDL/include/{SDL3/SDL_opengles2_khrplatform.h → 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
- bool available;
37
+ SDL_bool available;
38
38
  const Sound_DecoderFunctions *funcs;
39
39
  } decoder_element;
40
40
 
@@ -46,6 +46,9 @@ 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
49
52
  #if SOUND_SUPPORTS_WAV
50
53
  { 0, &__Sound_DecoderFunctions_WAV },
51
54
  #endif
@@ -70,9 +73,6 @@ static decoder_element decoders[] =
70
73
  #if SOUND_SUPPORTS_FLAC
71
74
  { 0, &__Sound_DecoderFunctions_FLAC },
72
75
  #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;
87
+ static SDL_TLSID tlsid_errmsg = 0;
88
88
 
89
89
  typedef struct
90
90
  {
91
- bool error_available;
91
+ SDL_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,10 +101,16 @@ static int initialized = 0;
101
101
 
102
102
  /* functions ... */
103
103
 
104
- int Sound_Version(void)
104
+ void Sound_GetLinkedVersion(Sound_Version *ver)
105
105
  {
106
- return SDL_SOUND_VERSION;
107
- }
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
+
108
114
 
109
115
  int Sound_Init(void)
110
116
  {
@@ -121,8 +127,7 @@ int Sound_Init(void)
121
127
 
122
128
  SDL_InitSubSystem(SDL_INIT_AUDIO);
123
129
 
124
- tlsid_errmsg.value = 0;
125
- BAIL_IF_MACRO(!SDL_SetTLS(&tlsid_errmsg, NULL, NULL), ERR_OUT_OF_MEMORY, 0);
130
+ tlsid_errmsg = SDL_TLSCreate();
126
131
 
127
132
  samplelist_mutex = SDL_CreateMutex();
128
133
 
@@ -169,7 +174,7 @@ int Sound_Quit(void)
169
174
  SDL_free((void *) available_decoders);
170
175
  available_decoders = NULL;
171
176
 
172
- tlsid_errmsg.value = 0;
177
+ tlsid_errmsg = 0;
173
178
 
174
179
  return 1;
175
180
  } /* Sound_Quit */
@@ -180,9 +185,10 @@ const Sound_DecoderInfo **Sound_AvailableDecoders(void)
180
185
  return available_decoders; /* READ. ONLY. */
181
186
  } /* Sound_AvailableDecoders */
182
187
 
188
+
183
189
  static ErrMsg *findErrorForCurrentThread(void)
184
190
  {
185
- return (ErrMsg *) SDL_GetTLS(&tlsid_errmsg);
191
+ return (ErrMsg *) SDL_TLSGet(tlsid_errmsg);
186
192
  }
187
193
 
188
194
 
@@ -198,7 +204,7 @@ const char *Sound_GetError(void)
198
204
  if ((err != NULL) && (err->error_available))
199
205
  {
200
206
  retval = err->error_string;
201
- err->error_available = false;
207
+ err->error_available = SDL_FALSE;
202
208
  } /* if */
203
209
 
204
210
  return retval;
@@ -233,18 +239,18 @@ void __Sound_SetError(const char *str)
233
239
  if (err == NULL)
234
240
  return; /* uhh...? */
235
241
 
236
- SDL_SetTLS(&tlsid_errmsg, err, SDL_free);
242
+ SDL_TLSSet(tlsid_errmsg, err, SDL_free);
237
243
  } /* if */
238
244
 
239
- err->error_available = true;
245
+ err->error_available = SDL_TRUE;
240
246
  SDL_strlcpy(err->error_string, str, sizeof (err->error_string));
241
247
  } /* __Sound_SetError */
242
248
 
243
249
 
244
- Uint32 __Sound_convertMsToBytePos(SDL_AudioSpec *info, Uint32 ms)
250
+ Uint32 __Sound_convertMsToBytePos(Sound_AudioInfo *info, Uint32 ms)
245
251
  {
246
252
  /* "frames" == "sample frames" */
247
- float frames_per_ms = ((float) info->freq) / 1000.0f;
253
+ float frames_per_ms = ((float) info->rate) / 1000.0f;
248
254
  Uint32 frame_offset = (Uint32) (frames_per_ms * ((float) ms));
249
255
  Uint32 frame_size = (Uint32) ((info->format & 0xFF) / 8) * info->channels;
250
256
  return frame_offset * frame_size;
@@ -255,8 +261,8 @@ Uint32 __Sound_convertMsToBytePos(SDL_AudioSpec *info, Uint32 ms)
255
261
  * Allocate a Sound_Sample, and fill in most of its fields. Those that need
256
262
  * to be filled in later, by a decoder, will be initialized to zero.
257
263
  */
258
- static Sound_Sample *alloc_sample(SDL_IOStream *io, const SDL_AudioSpec *desired,
259
- Uint32 bufferSize)
264
+ static Sound_Sample *alloc_sample(SDL_RWops *rw, Sound_AudioInfo *desired,
265
+ Uint32 bufferSize)
260
266
  {
261
267
  /*
262
268
  * !!! FIXME: We're going to need to pool samples, since the mixer
@@ -289,9 +295,9 @@ static Sound_Sample *alloc_sample(SDL_IOStream *io, const SDL_AudioSpec *desired
289
295
  retval->buffer_size = bufferSize;
290
296
 
291
297
  if (desired != NULL)
292
- SDL_memcpy(&retval->desired, desired, sizeof (SDL_AudioSpec));
298
+ SDL_memcpy(&retval->desired, desired, sizeof (Sound_AudioInfo));
293
299
 
294
- internal->io = io;
300
+ internal->rw = rw;
295
301
  retval->opaque = internal;
296
302
  return retval;
297
303
  } /* alloc_sample */
@@ -301,21 +307,25 @@ static Sound_Sample *alloc_sample(SDL_IOStream *io, const SDL_AudioSpec *desired
301
307
  static SDL_INLINE const char *fmt_to_str(Uint16 fmt)
302
308
  {
303
309
  switch(fmt) {
304
- case SDL_AUDIO_U8:
310
+ case AUDIO_U8:
305
311
  return "U8";
306
- case SDL_AUDIO_S8:
312
+ case AUDIO_S8:
307
313
  return "S8";
308
- case SDL_AUDIO_S16LE:
314
+ case AUDIO_U16LSB:
315
+ return "U16LSB";
316
+ case AUDIO_S16LSB:
309
317
  return "S16LSB";
310
- case SDL_AUDIO_S32LE:
318
+ case AUDIO_S32LSB:
311
319
  return "S32LSB";
312
- case SDL_AUDIO_F32LE:
320
+ case AUDIO_F32LSB:
313
321
  return "F32LSB";
314
- case SDL_AUDIO_S16BE:
322
+ case AUDIO_U16MSB:
323
+ return "U16MSB";
324
+ case AUDIO_S16MSB:
315
325
  return "S16MSB";
316
- case SDL_AUDIO_S32BE:
326
+ case AUDIO_S32MSB:
317
327
  return "S32MSB";
318
- case SDL_AUDIO_F32BE:
328
+ case AUDIO_F32MSB:
319
329
  return "F32MSB";
320
330
  } /* switch */
321
331
  return "Unknown";
@@ -325,24 +335,24 @@ static SDL_INLINE const char *fmt_to_str(Uint16 fmt)
325
335
 
326
336
  /*
327
337
  * The bulk of the Sound_NewSample() work is done here...
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
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
330
340
  * back to where it was, and return false.
331
341
  */
332
342
  static int init_sample(const Sound_DecoderFunctions *funcs,
333
343
  Sound_Sample *sample, const char *ext,
334
- const SDL_AudioSpec *_desired)
344
+ Sound_AudioInfo *_desired)
335
345
  {
336
346
  Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
337
- SDL_AudioSpec desired;
338
- const Sint64 pos = SDL_TellIO(internal->io);
347
+ Sound_AudioInfo desired;
348
+ const Sint64 pos = SDL_RWtell(internal->rw);
339
349
 
340
350
  /* fill in the funcs for this decoder... */
341
351
  sample->decoder = &funcs->info;
342
352
  internal->funcs = funcs;
343
353
  if (!funcs->open(sample, ext))
344
354
  {
345
- SDL_SeekIO(internal->io, pos, SDL_IO_SEEK_SET); /* set for next try... */
355
+ SDL_RWseek(internal->rw, pos, RW_SEEK_SET); /* set for next try... */
346
356
  return 0;
347
357
  } /* if */
348
358
 
@@ -352,31 +362,36 @@ static int init_sample(const Sound_DecoderFunctions *funcs,
352
362
  internal->stream = NULL;
353
363
 
354
364
  if (_desired == NULL)
355
- SDL_memcpy(&desired, &sample->actual, sizeof (SDL_AudioSpec));
365
+ SDL_memcpy(&desired, &sample->actual, sizeof (Sound_AudioInfo));
356
366
  else
357
367
  {
358
368
  desired.format = _desired->format ? _desired->format : sample->actual.format;
359
369
  desired.channels = _desired->channels ? _desired->channels : sample->actual.channels;
360
- desired.freq = _desired->freq ? _desired->freq : sample->actual.freq;
370
+ desired.rate = _desired->rate ? _desired->rate : sample->actual.rate;
361
371
 
362
372
  if ( (sample->actual.format != desired.format) ||
363
373
  (sample->actual.channels != desired.channels) ||
364
- (sample->actual.freq != desired.freq) )
374
+ (sample->actual.rate != desired.rate) )
365
375
  {
366
- internal->stream = SDL_CreateAudioStream(&sample->actual, &desired);
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);
367
382
 
368
383
  if (internal->stream == NULL)
369
384
  {
370
385
  __Sound_SetError(SDL_GetError());
371
386
  funcs->close(sample);
372
- SDL_SeekIO(internal->io, pos, SDL_IO_SEEK_SET); /* set for next try... */
387
+ SDL_RWseek(internal->rw, pos, RW_SEEK_SET); /* set for next try... */
373
388
  return 0;
374
389
  } /* if */
375
390
  } /* if */
376
391
  } /* else */
377
392
 
378
393
  /* these pointers are all one and the same. */
379
- SDL_memcpy(&sample->desired, &desired, sizeof (SDL_AudioSpec));
394
+ SDL_memcpy(&sample->desired, &desired, sizeof (Sound_AudioInfo));
380
395
  internal->buffer = sample->buffer;
381
396
  internal->buffer_size = sample->buffer_size;
382
397
 
@@ -388,14 +403,14 @@ static int init_sample(const Sound_DecoderFunctions *funcs,
388
403
  sample_list = sample;
389
404
  SDL_UnlockMutex(samplelist_mutex);
390
405
 
391
- SNDDBG(("New sample DESIRED format: %s format, %d freq, %d channels.\n",
406
+ SNDDBG(("New sample DESIRED format: %s format, %d rate, %d channels.\n",
392
407
  fmt_to_str(sample->desired.format),
393
- sample->desired.freq,
408
+ sample->desired.rate,
394
409
  sample->desired.channels));
395
410
 
396
- SNDDBG(("New sample ACTUAL format: %s format, %d freq, %d channels.\n",
411
+ SNDDBG(("New sample ACTUAL format: %s format, %d rate, %d channels.\n",
397
412
  fmt_to_str(sample->actual.format),
398
- sample->actual.freq,
413
+ sample->actual.rate,
399
414
  sample->actual.channels));
400
415
 
401
416
  SNDDBG(("On-the-fly conversion: %s.\n",
@@ -405,17 +420,17 @@ static int init_sample(const Sound_DecoderFunctions *funcs,
405
420
  } /* init_sample */
406
421
 
407
422
 
408
- Sound_Sample *Sound_NewSample(SDL_IOStream *io, const char *ext,
409
- const SDL_AudioSpec *desired, Uint32 bSize)
423
+ Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext,
424
+ Sound_AudioInfo *desired, Uint32 bSize)
410
425
  {
411
426
  Sound_Sample *retval;
412
427
  decoder_element *decoder;
413
428
 
414
429
  /* sanity checks. */
415
430
  BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL);
416
- BAIL_IF_MACRO(io == NULL, ERR_INVALID_ARGUMENT, NULL);
431
+ BAIL_IF_MACRO(rw == NULL, ERR_INVALID_ARGUMENT, NULL);
417
432
 
418
- retval = alloc_sample(io, desired, bSize);
433
+ retval = alloc_sample(rw, desired, bSize);
419
434
  if (!retval)
420
435
  return NULL; /* alloc_sample() sets error message... */
421
436
 
@@ -471,55 +486,55 @@ Sound_Sample *Sound_NewSample(SDL_IOStream *io, const char *ext,
471
486
  /* !!! FIXME: can we just push this through Sound_FreeSample() ? */
472
487
  if (retval->opaque != NULL)
473
488
  {
474
- SDL_DestroyAudioStream(((Sound_SampleInternal *) retval->opaque)->stream);
489
+ SDL_FreeAudioStream(((Sound_SampleInternal *) retval->opaque)->stream);
475
490
  SDL_free(retval->opaque);
476
491
  } /* if */
477
492
 
478
493
  __Sound_SIMDFree(retval->buffer);
479
494
  SDL_free(retval);
480
- SDL_CloseIO(io);
495
+ SDL_RWclose(rw);
481
496
  __Sound_SetError(ERR_UNSUPPORTED_FORMAT);
482
497
  return NULL;
483
498
  } /* Sound_NewSample */
484
499
 
485
500
 
486
501
  Sound_Sample *Sound_NewSampleFromFile(const char *filename,
487
- const SDL_AudioSpec *desired,
502
+ Sound_AudioInfo *desired,
488
503
  Uint32 bufferSize)
489
504
  {
490
505
  const char *ext;
491
- SDL_IOStream *io;
506
+ SDL_RWops *rw;
492
507
 
493
508
  BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL);
494
509
  BAIL_IF_MACRO(filename == NULL, ERR_INVALID_ARGUMENT, NULL);
495
510
 
496
511
  ext = SDL_strrchr(filename, '.');
497
- io = SDL_IOFromFile(filename, "rb");
498
- BAIL_IF_MACRO(io == NULL, SDL_GetError(), NULL);
512
+ rw = SDL_RWFromFile(filename, "rb");
513
+ BAIL_IF_MACRO(rw == NULL, SDL_GetError(), NULL);
499
514
 
500
515
  if (ext != NULL)
501
516
  ext++;
502
517
 
503
- return Sound_NewSample(io, ext, desired, bufferSize);
518
+ return Sound_NewSample(rw, ext, desired, bufferSize);
504
519
  } /* Sound_NewSampleFromFile */
505
520
 
506
521
 
507
522
  Sound_Sample *Sound_NewSampleFromMem(const Uint8 *data,
508
523
  Uint32 size,
509
524
  const char *ext,
510
- const SDL_AudioSpec *desired,
525
+ Sound_AudioInfo *desired,
511
526
  Uint32 bufferSize)
512
527
  {
513
- SDL_IOStream *io;
528
+ SDL_RWops *rw;
514
529
 
515
530
  BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL);
516
531
  BAIL_IF_MACRO(data == NULL, ERR_INVALID_ARGUMENT, NULL);
517
532
  BAIL_IF_MACRO(size == 0, ERR_INVALID_ARGUMENT, NULL);
518
533
 
519
- io = SDL_IOFromConstMem(data, size);
520
- BAIL_IF_MACRO(io == NULL, SDL_GetError(), NULL);
534
+ rw = SDL_RWFromConstMem(data, size);
535
+ BAIL_IF_MACRO(rw == NULL, SDL_GetError(), NULL);
521
536
 
522
- return Sound_NewSample(io, ext, desired, bufferSize);
537
+ return Sound_NewSample(rw, ext, desired, bufferSize);
523
538
  } /* Sound_NewSampleFromMem */
524
539
 
525
540
 
@@ -568,10 +583,10 @@ void Sound_FreeSample(Sound_Sample *sample)
568
583
  /* nuke it... */
569
584
  internal->funcs->close(sample);
570
585
 
571
- if (internal->io != NULL) /* this condition is a "just in case" thing. */
572
- SDL_CloseIO(internal->io);
586
+ if (internal->rw != NULL) /* this condition is a "just in case" thing. */
587
+ SDL_RWclose(internal->rw);
573
588
 
574
- SDL_DestroyAudioStream(internal->stream);
589
+ SDL_FreeAudioStream(internal->stream);
575
590
  SDL_free(internal);
576
591
  __Sound_SIMDFree(sample->buffer);
577
592
  SDL_free(sample);
@@ -596,46 +611,6 @@ int Sound_SetBufferSize(Sound_Sample *sample, Uint32 newSize)
596
611
  } /* Sound_SetBufferSize */
597
612
 
598
613
 
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
-
639
614
  Uint32 Sound_Decode(Sound_Sample *sample)
640
615
  {
641
616
  Sound_SampleInternal *internal = NULL;
@@ -663,9 +638,9 @@ Uint32 Sound_Decode(Sound_Sample *sample)
663
638
  } /* if */
664
639
 
665
640
  /* call into the decoder several times until we have enough data. */
666
- while ((available = SDL_GetAudioStreamAvailable(internal->stream)) < internal->buffer_size)
641
+ while ((available = SDL_AudioStreamAvailable(internal->stream)) < internal->buffer_size)
667
642
  {
668
- bool flush_stream = false;
643
+ SDL_bool flush_stream = SDL_FALSE;
669
644
  Uint32 br;
670
645
 
671
646
  if (internal->pending_eof || internal->pending_error)
@@ -680,18 +655,18 @@ Uint32 Sound_Decode(Sound_Sample *sample)
680
655
  if (sample->flags & SOUND_SAMPLEFLAG_EOF)
681
656
  {
682
657
  sample->flags &= ~SOUND_SAMPLEFLAG_EOF;
683
- internal->pending_eof = true;
684
- flush_stream = true;
658
+ internal->pending_eof = SDL_TRUE;
659
+ flush_stream = SDL_TRUE;
685
660
  } /* if */
686
661
 
687
662
  if (sample->flags & SOUND_SAMPLEFLAG_ERROR)
688
663
  {
689
664
  sample->flags &= ~SOUND_SAMPLEFLAG_ERROR;
690
- internal->pending_error = true;
691
- flush_stream = true;
665
+ internal->pending_error = SDL_TRUE;
666
+ flush_stream = SDL_TRUE;
692
667
  } /* if */
693
668
 
694
- if ((br > 0) && (!SDL_PutAudioStreamData(internal->stream, internal->buffer, (int) br)))
669
+ if ((br > 0) && (SDL_AudioStreamPut(internal->stream, internal->buffer, (int) br) == -1))
695
670
  {
696
671
  __Sound_SetError(SDL_GetError());
697
672
  sample->flags |= SOUND_SAMPLEFLAG_ERROR;
@@ -699,14 +674,14 @@ Uint32 Sound_Decode(Sound_Sample *sample)
699
674
  } /* if */
700
675
 
701
676
  if (flush_stream)
702
- SDL_FlushAudioStream(internal->stream);
677
+ SDL_AudioStreamFlush(internal->stream);
703
678
  } /* while */
704
679
 
705
680
  /* if we hit eof or error, drain the stream before reporting that. */
706
681
  if (available > 0)
707
682
  {
708
683
  const int readlen = SDL_min(available, sample->buffer_size);
709
- const int br = SDL_GetAudioStreamData(internal->stream, sample->buffer, readlen);
684
+ const int br = SDL_AudioStreamGet(internal->stream, sample->buffer, readlen);
710
685
  if (br != readlen)
711
686
  {
712
687
  __Sound_SetError(SDL_GetError());
@@ -725,7 +700,7 @@ Uint32 Sound_Decode(Sound_Sample *sample)
725
700
  if (internal->pending_error)
726
701
  sample->flags |= SOUND_SAMPLEFLAG_ERROR;
727
702
 
728
- internal->pending_eof = internal->pending_error = false;
703
+ internal->pending_eof = internal->pending_error = SDL_FALSE;
729
704
 
730
705
  return 0;
731
706
  } /* Sound_Decode */
@@ -823,49 +798,144 @@ Sint32 Sound_GetDuration(Sound_Sample *sample)
823
798
 
824
799
  /* Utility functions ... */
825
800
 
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
+
826
882
  void *__Sound_SIMDAlloc(const size_t len)
827
883
  {
828
- return SDL_aligned_alloc(SDL_GetSIMDAlignment(), len);
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
829
900
  }
830
901
 
831
902
  void *__Sound_SIMDRealloc(void *mem, const size_t len)
832
903
  {
833
- const size_t alignment = SDL_GetSIMDAlignment();
834
- const size_t padding = (alignment - (len % alignment)) % alignment;
835
- Uint8 *retval = (Uint8 *)mem;
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;
836
911
  void *oldmem = mem;
837
912
  size_t memdiff = 0, ptrdiff;
838
913
  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
- }
846
914
 
847
915
  if (mem) {
848
- mem = *(((void **)mem) - 1);
916
+ void **realptr = (void **) mem;
917
+ realptr--;
918
+ mem = *(((void **) mem) - 1);
849
919
 
850
920
  /* Check the delta between the real pointer and user pointer */
851
- memdiff = ((size_t)oldmem) - ((size_t)mem);
921
+ memdiff = ((size_t) oldmem) - ((size_t) mem);
852
922
  }
853
923
 
854
- ptr = (Uint8 *) SDL_realloc(mem, to_allocate);
924
+ ptr = (Uint8 *) SDL_realloc(mem, padded + alignment + sizeof (void *));
855
925
 
856
926
  if (ptr == NULL) {
857
927
  return NULL; /* Out of memory, bail! */
858
928
  }
859
929
 
860
930
  /* Store the actual allocated pointer right before our aligned pointer. */
861
- retval = ptr + sizeof(void *);
862
- retval += alignment - (((size_t)retval) % alignment);
931
+ retval = ptr + sizeof (void *);
932
+ retval += alignment - (((size_t) retval) % alignment);
863
933
 
864
934
  /* Make sure the delta is the same! */
865
935
  if (mem) {
866
- ptrdiff = ((size_t)retval) - ((size_t)ptr);
936
+ ptrdiff = ((size_t) retval) - ((size_t) ptr);
867
937
  if (memdiff != ptrdiff) { /* Delta has changed, copy to new offset! */
868
- oldmem = (void *)(((uintptr_t)ptr) + memdiff);
938
+ oldmem = (void*) (((uintptr_t) ptr) + memdiff);
869
939
 
870
940
  /* Even though the data past the old `len` is undefined, this is the
871
941
  * only length value we have, and it guarantees that we copy all the
@@ -876,13 +946,22 @@ void *__Sound_SIMDRealloc(void *mem, const size_t len)
876
946
  }
877
947
 
878
948
  /* Actually store the allocated pointer, finally. */
879
- *(((void **)retval) - 1) = ptr;
949
+ *(((void **) retval) - 1) = ptr;
880
950
  return retval;
951
+ #endif
881
952
  }
882
953
 
883
954
  void __Sound_SIMDFree(void *ptr)
884
955
  {
885
- SDL_aligned_free(ptr);
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
886
965
  }
887
966
 
888
967
  /* end of SDL_sound.c ... */