gosu 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/dependencies/SDL/include/SDL.h +108 -14
  3. data/dependencies/SDL/include/SDL_assert.h +81 -50
  4. data/dependencies/SDL/include/SDL_atomic.h +135 -35
  5. data/dependencies/SDL/include/SDL_audio.h +960 -355
  6. data/dependencies/SDL/include/SDL_bits.h +11 -6
  7. data/dependencies/SDL/include/SDL_blendmode.h +91 -14
  8. data/dependencies/SDL/include/SDL_clipboard.h +30 -7
  9. data/dependencies/SDL/include/SDL_config.h +277 -27
  10. data/dependencies/SDL/include/SDL_config_android.h +13 -38
  11. data/dependencies/SDL/include/SDL_config_iphoneos.h +21 -62
  12. data/dependencies/SDL/include/SDL_config_macosx.h +23 -92
  13. data/dependencies/SDL/include/SDL_config_minimal.h +1 -4
  14. data/dependencies/SDL/include/SDL_config_pandora.h +15 -22
  15. data/dependencies/SDL/include/SDL_config_psp.h +16 -37
  16. data/dependencies/SDL/include/SDL_config_windows.h +28 -91
  17. data/dependencies/SDL/include/SDL_config_winrt.h +33 -61
  18. data/dependencies/SDL/include/SDL_config_wiz.h +28 -56
  19. data/dependencies/SDL/include/SDL_copying.h +1 -1
  20. data/dependencies/SDL/include/SDL_cpuinfo.h +331 -71
  21. data/dependencies/SDL/include/SDL_egl.h +906 -280
  22. data/dependencies/SDL/include/SDL_endian.h +101 -47
  23. data/dependencies/SDL/include/SDL_error.h +70 -19
  24. data/dependencies/SDL/include/SDL_events.h +387 -79
  25. data/dependencies/SDL/include/SDL_filesystem.h +73 -64
  26. data/dependencies/SDL/include/SDL_gamecontroller.h +585 -125
  27. data/dependencies/SDL/include/SDL_gesture.h +36 -6
  28. data/dependencies/SDL/include/SDL_haptic.h +304 -210
  29. data/dependencies/SDL/include/SDL_hidapi.h +451 -0
  30. data/dependencies/SDL/include/SDL_hints.h +1286 -897
  31. data/dependencies/SDL/include/SDL_joystick.h +577 -130
  32. data/dependencies/SDL/include/SDL_keyboard.h +162 -63
  33. data/dependencies/SDL/include/SDL_keycode.h +7 -5
  34. data/dependencies/SDL/include/SDL_loadso.h +42 -8
  35. data/dependencies/SDL/include/SDL_locale.h +34 -32
  36. data/dependencies/SDL/include/SDL_log.h +212 -19
  37. data/dependencies/SDL/include/SDL_main.h +72 -17
  38. data/dependencies/SDL/include/SDL_messagebox.h +70 -23
  39. data/dependencies/SDL/include/SDL_metal.h +27 -32
  40. data/dependencies/SDL/include/SDL_misc.h +19 -15
  41. data/dependencies/SDL/include/SDL_mouse.h +262 -110
  42. data/dependencies/SDL/include/SDL_mutex.h +286 -66
  43. data/dependencies/SDL/include/SDL_name.h +1 -1
  44. data/dependencies/SDL/include/SDL_opengl.h +1 -1
  45. data/dependencies/SDL/include/SDL_opengles.h +1 -1
  46. data/dependencies/SDL/include/SDL_opengles2.h +2 -2
  47. data/dependencies/SDL/include/SDL_pixels.h +199 -34
  48. data/dependencies/SDL/include/SDL_platform.h +39 -2
  49. data/dependencies/SDL/include/SDL_power.h +23 -10
  50. data/dependencies/SDL/include/SDL_quit.h +1 -1
  51. data/dependencies/SDL/include/SDL_rect.h +78 -28
  52. data/dependencies/SDL/include/SDL_render.h +1204 -472
  53. data/dependencies/SDL/include/SDL_revision.h +2 -2
  54. data/dependencies/SDL/include/SDL_rwops.h +605 -33
  55. data/dependencies/SDL/include/SDL_scancode.h +1 -1
  56. data/dependencies/SDL/include/SDL_sensor.h +76 -42
  57. data/dependencies/SDL/include/SDL_shape.h +38 -27
  58. data/dependencies/SDL/include/SDL_stdinc.h +96 -24
  59. data/dependencies/SDL/include/SDL_surface.h +571 -139
  60. data/dependencies/SDL/include/SDL_system.h +339 -101
  61. data/dependencies/SDL/include/SDL_syswm.h +50 -20
  62. data/dependencies/SDL/include/SDL_test.h +1 -1
  63. data/dependencies/SDL/include/SDL_test_assert.h +2 -2
  64. data/dependencies/SDL/include/SDL_test_common.h +23 -6
  65. data/dependencies/SDL/include/SDL_test_compare.h +1 -1
  66. data/dependencies/SDL/include/SDL_test_crc32.h +1 -1
  67. data/dependencies/SDL/include/SDL_test_font.h +3 -3
  68. data/dependencies/SDL/include/SDL_test_fuzzer.h +28 -26
  69. data/dependencies/SDL/include/SDL_test_harness.h +6 -6
  70. data/dependencies/SDL/include/SDL_test_images.h +1 -1
  71. data/dependencies/SDL/include/SDL_test_log.h +1 -1
  72. data/dependencies/SDL/include/SDL_test_md5.h +1 -1
  73. data/dependencies/SDL/include/SDL_test_memory.h +1 -1
  74. data/dependencies/SDL/include/SDL_test_random.h +2 -2
  75. data/dependencies/SDL/include/SDL_thread.h +226 -128
  76. data/dependencies/SDL/include/SDL_timer.h +129 -22
  77. data/dependencies/SDL/include/SDL_touch.h +48 -8
  78. data/dependencies/SDL/include/SDL_types.h +1 -1
  79. data/dependencies/SDL/include/SDL_version.h +72 -46
  80. data/dependencies/SDL/include/SDL_video.h +1266 -460
  81. data/dependencies/SDL/include/SDL_vulkan.h +100 -161
  82. data/dependencies/SDL/include/begin_code.h +22 -1
  83. data/dependencies/SDL/include/close_code.h +1 -1
  84. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  85. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  86. data/dependencies/SDL_sound/SDL_sound.c +83 -7
  87. data/dependencies/SDL_sound/SDL_sound.h +4 -4
  88. data/dependencies/SDL_sound/SDL_sound_aiff.c +9 -12
  89. data/dependencies/SDL_sound/SDL_sound_au.c +7 -7
  90. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +3 -3
  91. data/dependencies/SDL_sound/SDL_sound_flac.c +1 -1
  92. data/dependencies/SDL_sound/SDL_sound_internal.h +17 -10
  93. data/dependencies/SDL_sound/SDL_sound_modplug.c +25 -27
  94. data/dependencies/SDL_sound/SDL_sound_mp3.c +5 -17
  95. data/dependencies/SDL_sound/SDL_sound_raw.c +11 -11
  96. data/dependencies/SDL_sound/SDL_sound_shn.c +8 -7
  97. data/dependencies/SDL_sound/SDL_sound_voc.c +6 -4
  98. data/dependencies/SDL_sound/SDL_sound_vorbis.c +6 -11
  99. data/dependencies/SDL_sound/SDL_sound_wav.c +35 -29
  100. data/dependencies/SDL_sound/dr_flac.h +618 -220
  101. data/dependencies/SDL_sound/dr_mp3.h +263 -94
  102. data/dependencies/SDL_sound/libmodplug/fastmix.c +58 -64
  103. data/dependencies/SDL_sound/libmodplug/libmodplug.h +25 -103
  104. data/dependencies/SDL_sound/libmodplug/load_669.c +14 -17
  105. data/dependencies/SDL_sound/libmodplug/load_amf.c +11 -7
  106. data/dependencies/SDL_sound/libmodplug/load_ams.c +65 -22
  107. data/dependencies/SDL_sound/libmodplug/load_dbm.c +8 -4
  108. data/dependencies/SDL_sound/libmodplug/load_dmf.c +55 -25
  109. data/dependencies/SDL_sound/libmodplug/load_far.c +9 -13
  110. data/dependencies/SDL_sound/libmodplug/load_gdm.c +448 -0
  111. data/dependencies/SDL_sound/libmodplug/load_it.c +45 -49
  112. data/dependencies/SDL_sound/libmodplug/load_mdl.c +80 -53
  113. data/dependencies/SDL_sound/libmodplug/load_med.c +20 -12
  114. data/dependencies/SDL_sound/libmodplug/load_mod.c +40 -15
  115. data/dependencies/SDL_sound/libmodplug/load_mt2.c +29 -17
  116. data/dependencies/SDL_sound/libmodplug/load_okt.c +12 -8
  117. data/dependencies/SDL_sound/libmodplug/load_psm.c +101 -78
  118. data/dependencies/SDL_sound/libmodplug/load_ptm.c +18 -17
  119. data/dependencies/SDL_sound/libmodplug/load_s3m.c +9 -7
  120. data/dependencies/SDL_sound/libmodplug/load_stm.c +3 -2
  121. data/dependencies/SDL_sound/libmodplug/load_ult.c +2 -2
  122. data/dependencies/SDL_sound/libmodplug/load_umx.c +315 -35
  123. data/dependencies/SDL_sound/libmodplug/load_xm.c +25 -21
  124. data/dependencies/SDL_sound/libmodplug/mmcmp.c +295 -149
  125. data/dependencies/SDL_sound/libmodplug/modplug.c +7 -123
  126. data/dependencies/SDL_sound/libmodplug/modplug.h +32 -29
  127. data/dependencies/SDL_sound/libmodplug/snd_dsp.c +0 -1
  128. data/dependencies/SDL_sound/libmodplug/snd_flt.c +2 -2
  129. data/dependencies/SDL_sound/libmodplug/snd_fx.c +24 -18
  130. data/dependencies/SDL_sound/libmodplug/sndfile.c +55 -156
  131. data/dependencies/SDL_sound/libmodplug/sndmix.c +7 -12
  132. data/dependencies/SDL_sound/libmodplug/tables.h +10 -15
  133. data/dependencies/SDL_sound/stb_vorbis.h +508 -325
  134. data/dependencies/{al_soft → mojoAL}/AL/al.h +38 -30
  135. data/dependencies/{al_soft → mojoAL}/AL/alc.h +27 -56
  136. data/dependencies/mojoAL/mojoal.c +4594 -0
  137. data/ext/gosu/extconf.rb +29 -30
  138. data/include/Gosu/Audio.hpp +70 -85
  139. data/include/Gosu/Color.hpp +19 -11
  140. data/include/Gosu/Font.hpp +40 -44
  141. data/include/Gosu/Graphics.hpp +58 -71
  142. data/include/Gosu/GraphicsBase.hpp +26 -33
  143. data/include/Gosu/Image.hpp +56 -62
  144. data/include/Gosu/ImageData.hpp +23 -27
  145. data/include/Gosu/Inspection.hpp +1 -4
  146. data/include/Gosu/TextInput.hpp +34 -40
  147. data/include/Gosu/Version.hpp +1 -1
  148. data/include/Gosu/Window.hpp +71 -70
  149. data/lib/SDL2.dll +0 -0
  150. data/lib/gosu/compat.rb +24 -37
  151. data/lib/gosu.rb +2 -2
  152. data/lib64/SDL2.dll +0 -0
  153. data/src/Audio.cpp +86 -86
  154. data/src/AudioFile.hpp +6 -6
  155. data/src/AudioFileAudioToolbox.cpp +1 -1
  156. data/src/AudioFileSDLSound.cpp +1 -1
  157. data/src/AudioImpl.hpp +5 -5
  158. data/src/BitmapIO.cpp +0 -20
  159. data/src/BlockAllocator.cpp +2 -1
  160. data/src/Channel.cpp +22 -20
  161. data/src/Color.cpp +12 -9
  162. data/src/EmptyImageData.hpp +15 -17
  163. data/src/FileUnix.cpp +1 -1
  164. data/src/FileWin.cpp +1 -1
  165. data/src/Font.cpp +48 -53
  166. data/src/Graphics.cpp +135 -143
  167. data/src/Image.cpp +41 -42
  168. data/src/Input.cpp +1 -1
  169. data/src/InputUIKit.cpp +1 -1
  170. data/src/LargeImageData.cpp +108 -101
  171. data/src/LargeImageData.hpp +17 -15
  172. data/src/Log.hpp +6 -6
  173. data/src/Macro.cpp +35 -37
  174. data/src/Macro.hpp +11 -11
  175. data/src/Math.cpp +8 -1
  176. data/src/Resolution.cpp +12 -7
  177. data/src/RubyGosu.cxx +5 -5
  178. data/src/TexChunk.cpp +50 -41
  179. data/src/TexChunk.hpp +22 -22
  180. data/src/Text.cpp +37 -37
  181. data/src/TextBuilder.cpp +60 -57
  182. data/src/TextBuilder.hpp +20 -20
  183. data/src/TextInput.cpp +127 -135
  184. data/src/TrueTypeFont.cpp +107 -107
  185. data/src/TrueTypeFont.hpp +39 -38
  186. data/src/TrueTypeFontApple.cpp +19 -22
  187. data/src/TrueTypeFontUnix.cpp +21 -26
  188. data/src/TrueTypeFontWin.cpp +30 -30
  189. data/src/Window.cpp +95 -86
  190. data/src/WindowUIKit.cpp +46 -49
  191. metadata +7 -17
  192. data/dependencies/SDL/include/SDL_config_os2.h +0 -188
  193. data/dependencies/SDL_sound/libmodplug/load_abc.c +0 -4725
  194. data/dependencies/SDL_sound/libmodplug/load_mid.c +0 -1405
  195. data/dependencies/SDL_sound/libmodplug/load_pat.c +0 -1143
  196. data/dependencies/SDL_sound/libmodplug/load_pat.h +0 -25
  197. data/dependencies/al_soft/AL/alext.h +0 -585
  198. data/dependencies/al_soft/AL/efx-creative.h +0 -3
  199. data/dependencies/al_soft/AL/efx-presets.h +0 -402
  200. data/dependencies/al_soft/AL/efx.h +0 -762
  201. data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
  202. data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
  203. data/lib/OpenAL32.dll +0 -0
  204. data/lib64/OpenAL32.dll +0 -0
@@ -1,5 +1,5 @@
1
1
  // MP3 audio decoder. Public domain. See "unlicense" statement at the end of this file.
2
- // dr_mp3 - v0.2.7 - 2018-07-13
2
+ // dr_mp3 - v0.3.2 - 2018-09-11
3
3
  //
4
4
  // David Reid - mackron@gmail.com
5
5
  //
@@ -122,7 +122,11 @@ typedef struct
122
122
  void drmp3dec_init(drmp3dec *dec);
123
123
 
124
124
  // Reads a frame from a low level decoder.
125
- int drmp3dec_decode_frame(drmp3dec *dec, const unsigned char *mp3, int mp3_bytes, short *pcm, drmp3dec_frame_info *info);
125
+ int drmp3dec_decode_frame(drmp3dec *dec, const unsigned char *mp3, int mp3_bytes, void *pcm, drmp3dec_frame_info *info);
126
+
127
+ // Helper for converting between f32 and s16.
128
+ void drmp3dec_f32_to_s16(const float *in, drmp3_int16 *out, int num_samples);
129
+
126
130
 
127
131
 
128
132
  // Main API (Pull API)
@@ -222,7 +226,7 @@ typedef struct
222
226
  drmp3_uint32 frameSampleRate; // The sample rate of the currently loaded MP3 frame. Internal use only.
223
227
  drmp3_uint32 framesConsumed;
224
228
  drmp3_uint32 framesRemaining;
225
- drmp3_int16 frames[DRMP3_MAX_SAMPLES_PER_FRAME];
229
+ drmp3_uint8 frames[sizeof(float)*DRMP3_MAX_SAMPLES_PER_FRAME]; // <-- Multipled by sizeof(float) to ensure there's enough room for DR_MP3_FLOAT_OUTPUT.
226
230
  drmp3_src src;
227
231
  size_t dataSize;
228
232
  size_t dataCapacity;
@@ -316,8 +320,12 @@ void drmp3_free(void* p);
316
320
  #define DR_MP3_NO_SIMD
317
321
  #endif
318
322
 
323
+ #define DRMP3_OFFSET_PTR(p, offset) ((void*)((drmp3_uint8*)(p) + (offset)))
324
+
319
325
  #define DRMP3_MAX_FREE_FORMAT_FRAME_SIZE 2304 /* more than ISO spec's */
326
+ #ifndef DRMP3_MAX_FRAME_SYNC_MATCHES
320
327
  #define DRMP3_MAX_FRAME_SYNC_MATCHES 10
328
+ #endif
321
329
 
322
330
  #define DRMP3_MAX_L3_FRAME_PAYLOAD_BYTES DRMP3_MAX_FREE_FORMAT_FRAME_SIZE /* MUST be >= 320000/8/32000*1152 = 1440 */
323
331
 
@@ -363,7 +371,7 @@ void drmp3_free(void* p);
363
371
  #if defined(_MSC_VER)
364
372
  #include <intrin.h>
365
373
  #endif
366
- #include <immintrin.h>
374
+ #include <emmintrin.h>
367
375
  #define DRMP3_HAVE_SSE 1
368
376
  #define DRMP3_HAVE_SIMD 1
369
377
  #define DRMP3_VSTORE _mm_storeu_ps
@@ -461,6 +469,39 @@ static int drmp3_have_simd()
461
469
 
462
470
  #endif
463
471
 
472
+ // Standard library stuff.
473
+ #ifndef DRMP3_ASSERT
474
+ #include <assert.h>
475
+ #define DRMP3_ASSERT(expression) assert(expression)
476
+ #endif
477
+ #ifndef DRMP3_COPY_MEMORY
478
+ #define DRMP3_COPY_MEMORY(dst, src, sz) memcpy((dst), (src), (sz))
479
+ #endif
480
+ #ifndef DRMP3_MOVE_MEMORY
481
+ #define DRMP3_MOVE_MEMORY(dst, src, sz) memmove((dst), (src), (sz))
482
+ #endif
483
+ #ifndef DRMP3_ZERO_MEMORY
484
+ #define DRMP3_ZERO_MEMORY(p, sz) memset((p), 0, (sz))
485
+ #endif
486
+ #define DRMP3_ZERO_OBJECT(p) DRMP3_ZERO_MEMORY((p), sizeof(*(p)))
487
+ #ifndef DRMP3_MALLOC
488
+ #define DRMP3_MALLOC(sz) malloc((sz))
489
+ #endif
490
+ #ifndef DRMP3_REALLOC
491
+ #define DRMP3_REALLOC(p, sz) realloc((p), (sz))
492
+ #endif
493
+ #ifndef DRMP3_FREE
494
+ #define DRMP3_FREE(p) free((p))
495
+ #endif
496
+
497
+ #define drmp3_assert DRMP3_ASSERT
498
+ #define drmp3_copy_memory DRMP3_COPY_MEMORY
499
+ #define drmp3_move_memory DRMP3_MOVE_MEMORY
500
+ #define drmp3_zero_memory DRMP3_ZERO_MEMORY
501
+ #define drmp3_zero_object DRMP3_ZERO_OBJECT
502
+ #define drmp3_malloc DRMP3_MALLOC
503
+ #define drmp3_realloc DRMP3_REALLOC
504
+
464
505
  typedef struct
465
506
  {
466
507
  const drmp3_uint8 *buf;
@@ -727,7 +768,7 @@ static int drmp3_L12_dequantize_granule(float *grbuf, drmp3_bs *bs, drmp3_L12_sc
727
768
  static void drmp3_L12_apply_scf_384(drmp3_L12_scale_info *sci, const float *scf, float *dst)
728
769
  {
729
770
  int i, k;
730
- memcpy(dst + 576 + sci->stereo_bands*18, dst + sci->stereo_bands*18, (sci->total_bands - sci->stereo_bands)*18*sizeof(float));
771
+ drmp3_copy_memory(dst + 576 + sci->stereo_bands*18, dst + sci->stereo_bands*18, (sci->total_bands - sci->stereo_bands)*18*sizeof(float));
731
772
  for (i = 0; i < sci->total_bands; i++, dst += 18, scf += 6)
732
773
  {
733
774
  for (k = 0; k < 12; k++)
@@ -872,14 +913,14 @@ static void drmp3_L3_read_scalefactors(drmp3_uint8 *scf, drmp3_uint8 *ist_pos, c
872
913
  int cnt = scf_count[i];
873
914
  if (scfsi & 8)
874
915
  {
875
- memcpy(scf, ist_pos, cnt);
916
+ drmp3_copy_memory(scf, ist_pos, cnt);
876
917
  } else
877
918
  {
878
919
  int bits = scf_size[i];
879
920
  if (!bits)
880
921
  {
881
- memset(scf, 0, cnt);
882
- memset(ist_pos, 0, cnt);
922
+ drmp3_zero_memory(scf, cnt);
923
+ drmp3_zero_memory(ist_pos, cnt);
883
924
  } else
884
925
  {
885
926
  int max_scf = (scfsi < 0) ? (1 << bits) - 1 : -1;
@@ -1037,7 +1078,7 @@ static void drmp3_L3_huffman(float *dst, drmp3_bs *bs, const drmp3_L3_gr_info *g
1037
1078
  {
1038
1079
  int tab_num = gr_info->table_select[ireg];
1039
1080
  int sfb_cnt = gr_info->region_count[ireg++];
1040
- const short *codebook = tabs + tabindex[tab_num];
1081
+ const drmp3_int16 *codebook = tabs + tabindex[tab_num];
1041
1082
  int linbits = g_linbits[tab_num];
1042
1083
  do
1043
1084
  {
@@ -1223,7 +1264,7 @@ static void drmp3_L3_reorder(float *grbuf, float *scratch, const drmp3_uint8 *sf
1223
1264
  *dst++ = src[2*len];
1224
1265
  }
1225
1266
  }
1226
- memcpy(grbuf, scratch, (dst - scratch)*sizeof(float));
1267
+ drmp3_copy_memory(grbuf, scratch, (dst - scratch)*sizeof(float));
1227
1268
  }
1228
1269
 
1229
1270
  static void drmp3_L3_antialias(float *grbuf, int nbands)
@@ -1392,8 +1433,8 @@ static void drmp3_L3_imdct_short(float *grbuf, float *overlap, int nbands)
1392
1433
  for (;nbands > 0; nbands--, overlap += 9, grbuf += 18)
1393
1434
  {
1394
1435
  float tmp[18];
1395
- memcpy(tmp, grbuf, sizeof(tmp));
1396
- memcpy(grbuf, overlap, 6*sizeof(float));
1436
+ drmp3_copy_memory(tmp, grbuf, sizeof(tmp));
1437
+ drmp3_copy_memory(grbuf, overlap, 6*sizeof(float));
1397
1438
  drmp3_L3_imdct12(tmp, grbuf + 6, overlap + 6);
1398
1439
  drmp3_L3_imdct12(tmp + 1, grbuf + 12, overlap + 6);
1399
1440
  drmp3_L3_imdct12(tmp + 2, overlap, overlap + 6);
@@ -1437,7 +1478,7 @@ static void drmp3_L3_save_reservoir(drmp3dec *h, drmp3dec_scratch *s)
1437
1478
  }
1438
1479
  if (remains > 0)
1439
1480
  {
1440
- memmove(h->reserv_buf, s->maindata + pos, remains);
1481
+ drmp3_move_memory(h->reserv_buf, s->maindata + pos, remains);
1441
1482
  }
1442
1483
  h->reserv = remains;
1443
1484
  }
@@ -1446,8 +1487,8 @@ static int drmp3_L3_restore_reservoir(drmp3dec *h, drmp3_bs *bs, drmp3dec_scratc
1446
1487
  {
1447
1488
  int frame_bytes = (bs->limit - bs->pos)/8;
1448
1489
  int bytes_have = DRMP3_MIN(h->reserv, main_data_begin);
1449
- memcpy(s->maindata, h->reserv_buf + DRMP3_MAX(0, h->reserv - main_data_begin), DRMP3_MIN(h->reserv, main_data_begin));
1450
- memcpy(s->maindata + bytes_have, bs->buf + bs->pos/8, frame_bytes);
1490
+ drmp3_copy_memory(s->maindata, h->reserv_buf + DRMP3_MAX(0, h->reserv - main_data_begin), DRMP3_MIN(h->reserv, main_data_begin));
1491
+ drmp3_copy_memory(s->maindata + bytes_have, bs->buf + bs->pos/8, frame_bytes);
1451
1492
  drmp3_bs_init(&s->bs, s->maindata, bytes_have + frame_bytes);
1452
1493
  return h->reserv >= main_data_begin;
1453
1494
  }
@@ -1643,18 +1684,27 @@ static void drmp3d_DCT_II(float *grbuf, int n)
1643
1684
  #endif
1644
1685
  }
1645
1686
 
1646
- static short drmp3d_scale_pcm(float sample)
1687
+ #ifndef DR_MP3_FLOAT_OUTPUT
1688
+ typedef drmp3_int16 drmp3d_sample_t;
1689
+
1690
+ static drmp3_int16 drmp3d_scale_pcm(float sample)
1647
1691
  {
1648
- if (sample > 32767.0) return (short) 32767;
1649
- if (sample < -32768.0) return (short)-32768;
1650
- int s = (int)(sample + .5f);
1692
+ if (sample >= 32766.5) return (drmp3_int16) 32767;
1693
+ if (sample <= -32767.5) return (drmp3_int16)-32768;
1694
+ drmp3_int16 s = (drmp3_int16)(sample + .5f);
1651
1695
  s -= (s < 0); /* away from zero, to be compliant */
1652
- if (s > 32767) return (short) 32767;
1653
- if (s < -32768) return (short)-32768;
1654
- return (short)s;
1696
+ return (drmp3_int16)s;
1655
1697
  }
1698
+ #else
1699
+ typedef float drmp3d_sample_t;
1656
1700
 
1657
- static void drmp3d_synth_pair(short *pcm, int nch, const float *z)
1701
+ static float drmp3d_scale_pcm(float sample)
1702
+ {
1703
+ return sample*(1.f/32768.f);
1704
+ }
1705
+ #endif
1706
+
1707
+ static void drmp3d_synth_pair(drmp3d_sample_t *pcm, int nch, const float *z)
1658
1708
  {
1659
1709
  float a;
1660
1710
  a = (z[14*64] - z[ 0]) * 29;
@@ -1679,11 +1729,11 @@ static void drmp3d_synth_pair(short *pcm, int nch, const float *z)
1679
1729
  pcm[16*nch] = drmp3d_scale_pcm(a);
1680
1730
  }
1681
1731
 
1682
- static void drmp3d_synth(float *xl, short *dstl, int nch, float *lins)
1732
+ static void drmp3d_synth(float *xl, drmp3d_sample_t *dstl, int nch, float *lins)
1683
1733
  {
1684
1734
  int i;
1685
1735
  float *xr = xl + 576*(nch - 1);
1686
- short *dstr = dstl + (nch - 1);
1736
+ drmp3d_sample_t *dstr = dstl + (nch - 1);
1687
1737
 
1688
1738
  static const float g_win[] = {
1689
1739
  -1,26,-31,208,218,401,-519,2063,2000,4788,-5517,7134,5959,35640,-39336,74992,
@@ -1740,19 +1790,20 @@ static void drmp3d_synth(float *xl, short *dstl, int nch, float *lins)
1740
1790
  DRMP3_V0(0) DRMP3_V2(1) DRMP3_V1(2) DRMP3_V2(3) DRMP3_V1(4) DRMP3_V2(5) DRMP3_V1(6) DRMP3_V2(7)
1741
1791
 
1742
1792
  {
1793
+ #ifndef DR_MP3_FLOAT_OUTPUT
1743
1794
  #if DRMP3_HAVE_SSE
1744
1795
  static const drmp3_f4 g_max = { 32767.0f, 32767.0f, 32767.0f, 32767.0f };
1745
1796
  static const drmp3_f4 g_min = { -32768.0f, -32768.0f, -32768.0f, -32768.0f };
1746
1797
  __m128i pcm8 = _mm_packs_epi32(_mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(a, g_max), g_min)),
1747
1798
  _mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(b, g_max), g_min)));
1748
- dstr[(15 - i)*nch] = (short)_mm_extract_epi16(pcm8, 1);
1749
- dstr[(17 + i)*nch] = (short)_mm_extract_epi16(pcm8, 5);
1750
- dstl[(15 - i)*nch] = (short)_mm_extract_epi16(pcm8, 0);
1751
- dstl[(17 + i)*nch] = (short)_mm_extract_epi16(pcm8, 4);
1752
- dstr[(47 - i)*nch] = (short)_mm_extract_epi16(pcm8, 3);
1753
- dstr[(49 + i)*nch] = (short)_mm_extract_epi16(pcm8, 7);
1754
- dstl[(47 - i)*nch] = (short)_mm_extract_epi16(pcm8, 2);
1755
- dstl[(49 + i)*nch] = (short)_mm_extract_epi16(pcm8, 6);
1799
+ dstr[(15 - i)*nch] = (drmp3_int16)_mm_extract_epi16(pcm8, 1);
1800
+ dstr[(17 + i)*nch] = (drmp3_int16)_mm_extract_epi16(pcm8, 5);
1801
+ dstl[(15 - i)*nch] = (drmp3_int16)_mm_extract_epi16(pcm8, 0);
1802
+ dstl[(17 + i)*nch] = (drmp3_int16)_mm_extract_epi16(pcm8, 4);
1803
+ dstr[(47 - i)*nch] = (drmp3_int16)_mm_extract_epi16(pcm8, 3);
1804
+ dstr[(49 + i)*nch] = (drmp3_int16)_mm_extract_epi16(pcm8, 7);
1805
+ dstl[(47 - i)*nch] = (drmp3_int16)_mm_extract_epi16(pcm8, 2);
1806
+ dstl[(49 + i)*nch] = (drmp3_int16)_mm_extract_epi16(pcm8, 6);
1756
1807
  #else
1757
1808
  int16x4_t pcma, pcmb;
1758
1809
  a = DRMP3_VADD(a, DRMP3_VSET(0.5f));
@@ -1768,6 +1819,30 @@ static void drmp3d_synth(float *xl, short *dstl, int nch, float *lins)
1768
1819
  vst1_lane_s16(dstl + (47 - i)*nch, pcma, 2);
1769
1820
  vst1_lane_s16(dstl + (49 + i)*nch, pcmb, 2);
1770
1821
  #endif
1822
+ #else
1823
+ static const drmp3_f4 g_scale = { 1.0f/32768.0f, 1.0f/32768.0f, 1.0f/32768.0f, 1.0f/32768.0f };
1824
+ a = DRMP3_VMUL(a, g_scale);
1825
+ b = DRMP3_VMUL(b, g_scale);
1826
+ #if DRMP3_HAVE_SSE
1827
+ _mm_store_ss(dstr + (15 - i)*nch, _mm_shuffle_ps(a, a, _MM_SHUFFLE(1, 1, 1, 1)));
1828
+ _mm_store_ss(dstr + (17 + i)*nch, _mm_shuffle_ps(b, b, _MM_SHUFFLE(1, 1, 1, 1)));
1829
+ _mm_store_ss(dstl + (15 - i)*nch, _mm_shuffle_ps(a, a, _MM_SHUFFLE(0, 0, 0, 0)));
1830
+ _mm_store_ss(dstl + (17 + i)*nch, _mm_shuffle_ps(b, b, _MM_SHUFFLE(0, 0, 0, 0)));
1831
+ _mm_store_ss(dstr + (47 - i)*nch, _mm_shuffle_ps(a, a, _MM_SHUFFLE(3, 3, 3, 3)));
1832
+ _mm_store_ss(dstr + (49 + i)*nch, _mm_shuffle_ps(b, b, _MM_SHUFFLE(3, 3, 3, 3)));
1833
+ _mm_store_ss(dstl + (47 - i)*nch, _mm_shuffle_ps(a, a, _MM_SHUFFLE(2, 2, 2, 2)));
1834
+ _mm_store_ss(dstl + (49 + i)*nch, _mm_shuffle_ps(b, b, _MM_SHUFFLE(2, 2, 2, 2)));
1835
+ #else
1836
+ vst1q_lane_f32(dstr + (15 - i)*nch, a, 1);
1837
+ vst1q_lane_f32(dstr + (17 + i)*nch, b, 1);
1838
+ vst1q_lane_f32(dstl + (15 - i)*nch, a, 0);
1839
+ vst1q_lane_f32(dstl + (17 + i)*nch, b, 0);
1840
+ vst1q_lane_f32(dstr + (47 - i)*nch, a, 3);
1841
+ vst1q_lane_f32(dstr + (49 + i)*nch, b, 3);
1842
+ vst1q_lane_f32(dstl + (47 - i)*nch, a, 2);
1843
+ vst1q_lane_f32(dstl + (49 + i)*nch, b, 2);
1844
+ #endif
1845
+ #endif /* DR_MP3_FLOAT_OUTPUT */
1771
1846
  }
1772
1847
  } else
1773
1848
  #endif
@@ -1805,7 +1880,7 @@ static void drmp3d_synth(float *xl, short *dstl, int nch, float *lins)
1805
1880
  #endif
1806
1881
  }
1807
1882
 
1808
- static void drmp3d_synth_granule(float *qmf_state, float *grbuf, int nbands, int nch, short *pcm, float *lins)
1883
+ static void drmp3d_synth_granule(float *qmf_state, float *grbuf, int nbands, int nch, drmp3d_sample_t *pcm, float *lins)
1809
1884
  {
1810
1885
  int i;
1811
1886
  for (i = 0; i < nch; i++)
@@ -1813,7 +1888,7 @@ static void drmp3d_synth_granule(float *qmf_state, float *grbuf, int nbands, int
1813
1888
  drmp3d_DCT_II(grbuf + 576*i, nbands);
1814
1889
  }
1815
1890
 
1816
- memcpy(lins, qmf_state, sizeof(float)*15*64);
1891
+ drmp3_copy_memory(lins, qmf_state, sizeof(float)*15*64);
1817
1892
 
1818
1893
  for (i = 0; i < nbands; i += 2)
1819
1894
  {
@@ -1829,7 +1904,7 @@ static void drmp3d_synth_granule(float *qmf_state, float *grbuf, int nbands, int
1829
1904
  } else
1830
1905
  #endif
1831
1906
  {
1832
- memcpy(qmf_state, lins + nbands*64, sizeof(float)*15*64);
1907
+ drmp3_copy_memory(qmf_state, lins + nbands*64, sizeof(float)*15*64);
1833
1908
  }
1834
1909
  }
1835
1910
 
@@ -1890,7 +1965,7 @@ void drmp3dec_init(drmp3dec *dec)
1890
1965
  dec->header[0] = 0;
1891
1966
  }
1892
1967
 
1893
- int drmp3dec_decode_frame(drmp3dec *dec, const unsigned char *mp3, int mp3_bytes, short *pcm, drmp3dec_frame_info *info)
1968
+ int drmp3dec_decode_frame(drmp3dec *dec, const unsigned char *mp3, int mp3_bytes, void *pcm, drmp3dec_frame_info *info)
1894
1969
  {
1895
1970
  int i = 0, igr, frame_size = 0, success = 1;
1896
1971
  const drmp3_uint8 *hdr;
@@ -1907,7 +1982,7 @@ int drmp3dec_decode_frame(drmp3dec *dec, const unsigned char *mp3, int mp3_bytes
1907
1982
  }
1908
1983
  if (!frame_size)
1909
1984
  {
1910
- memset(dec, 0, sizeof(drmp3dec));
1985
+ drmp3_zero_memory(dec, sizeof(drmp3dec));
1911
1986
  i = drmp3d_find_frame(mp3, mp3_bytes, &dec->free_format_bytes, &frame_size);
1912
1987
  if (!frame_size || i + frame_size > mp3_bytes)
1913
1988
  {
@@ -1917,13 +1992,18 @@ int drmp3dec_decode_frame(drmp3dec *dec, const unsigned char *mp3, int mp3_bytes
1917
1992
  }
1918
1993
 
1919
1994
  hdr = mp3 + i;
1920
- memcpy(dec->header, hdr, DRMP3_HDR_SIZE);
1995
+ drmp3_copy_memory(dec->header, hdr, DRMP3_HDR_SIZE);
1921
1996
  info->frame_bytes = i + frame_size;
1922
1997
  info->channels = DRMP3_HDR_IS_MONO(hdr) ? 1 : 2;
1923
1998
  info->hz = drmp3_hdr_sample_rate_hz(hdr);
1924
1999
  info->layer = 4 - DRMP3_HDR_GET_LAYER(hdr);
1925
2000
  info->bitrate_kbps = drmp3_hdr_bitrate_kbps(hdr);
1926
2001
 
2002
+ if (!pcm)
2003
+ {
2004
+ return drmp3_hdr_frame_samples(hdr);
2005
+ }
2006
+
1927
2007
  drmp3_bs_init(bs_frame, hdr + DRMP3_HDR_SIZE, frame_size - DRMP3_HDR_SIZE);
1928
2008
  if (DRMP3_HDR_IS_CRC(hdr))
1929
2009
  {
@@ -1941,11 +2021,11 @@ int drmp3dec_decode_frame(drmp3dec *dec, const unsigned char *mp3, int mp3_bytes
1941
2021
  success = drmp3_L3_restore_reservoir(dec, bs_frame, &scratch, main_data_begin);
1942
2022
  if (success)
1943
2023
  {
1944
- for (igr = 0; igr < (DRMP3_HDR_TEST_MPEG1(hdr) ? 2 : 1); igr++, pcm += 576*info->channels)
2024
+ for (igr = 0; igr < (DRMP3_HDR_TEST_MPEG1(hdr) ? 2 : 1); igr++, pcm = DRMP3_OFFSET_PTR(pcm, sizeof(drmp3d_sample_t)*576*info->channels))
1945
2025
  {
1946
- memset(scratch.grbuf[0], 0, 576*2*sizeof(float));
2026
+ drmp3_zero_memory(scratch.grbuf[0], 576*2*sizeof(float));
1947
2027
  drmp3_L3_decode(dec, &scratch, scratch.gr_info + igr*info->channels, info->channels);
1948
- drmp3d_synth_granule(dec->qmf_state, scratch.grbuf[0], 18, info->channels, pcm, scratch.syn[0]);
2028
+ drmp3d_synth_granule(dec->qmf_state, scratch.grbuf[0], 18, info->channels, (drmp3d_sample_t*)pcm, scratch.syn[0]);
1949
2029
  }
1950
2030
  }
1951
2031
  drmp3_L3_save_reservoir(dec, &scratch);
@@ -1957,16 +2037,16 @@ int drmp3dec_decode_frame(drmp3dec *dec, const unsigned char *mp3, int mp3_bytes
1957
2037
  drmp3_L12_scale_info sci[1];
1958
2038
  drmp3_L12_read_scale_info(hdr, bs_frame, sci);
1959
2039
 
1960
- memset(scratch.grbuf[0], 0, 576*2*sizeof(float));
2040
+ drmp3_zero_memory(scratch.grbuf[0], 576*2*sizeof(float));
1961
2041
  for (i = 0, igr = 0; igr < 3; igr++)
1962
2042
  {
1963
2043
  if (12 == (i += drmp3_L12_dequantize_granule(scratch.grbuf[0] + i, bs_frame, sci, info->layer | 1)))
1964
2044
  {
1965
2045
  i = 0;
1966
2046
  drmp3_L12_apply_scf_384(sci, sci->scf + igr, scratch.grbuf[0]);
1967
- drmp3d_synth_granule(dec->qmf_state, scratch.grbuf[0], 12, info->channels, pcm, scratch.syn[0]);
1968
- memset(scratch.grbuf[0], 0, 576*2*sizeof(float));
1969
- pcm += 384*info->channels;
2047
+ drmp3d_synth_granule(dec->qmf_state, scratch.grbuf[0], 12, info->channels, (drmp3d_sample_t*)pcm, scratch.syn[0]);
2048
+ drmp3_zero_memory(scratch.grbuf[0], 576*2*sizeof(float));
2049
+ pcm = DRMP3_OFFSET_PTR(pcm, sizeof(drmp3d_sample_t)*384*info->channels);
1970
2050
  }
1971
2051
  if (bs_frame->pos > bs_frame->limit)
1972
2052
  {
@@ -1979,7 +2059,64 @@ int drmp3dec_decode_frame(drmp3dec *dec, const unsigned char *mp3, int mp3_bytes
1979
2059
  return success*drmp3_hdr_frame_samples(dec->header);
1980
2060
  }
1981
2061
 
1982
-
2062
+ void drmp3dec_f32_to_s16(const float *in, drmp3_int16 *out, int num_samples)
2063
+ {
2064
+ if(num_samples > 0)
2065
+ {
2066
+ int i = 0;
2067
+ #if DRMP3_HAVE_SIMD
2068
+ int aligned_count = num_samples & ~7;
2069
+ for(; i < aligned_count; i+=8)
2070
+ {
2071
+ static const drmp3_f4 g_scale = { 32768.0f, 32768.0f, 32768.0f, 32768.0f };
2072
+ drmp3_f4 a = DRMP3_VMUL(DRMP3_VLD(&in[i ]), g_scale);
2073
+ drmp3_f4 b = DRMP3_VMUL(DRMP3_VLD(&in[i+4]), g_scale);
2074
+ #if DRMP3_HAVE_SSE
2075
+ static const drmp3_f4 g_max = { 32767.0f, 32767.0f, 32767.0f, 32767.0f };
2076
+ static const drmp3_f4 g_min = { -32768.0f, -32768.0f, -32768.0f, -32768.0f };
2077
+ __m128i pcm8 = _mm_packs_epi32(_mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(a, g_max), g_min)),
2078
+ _mm_cvtps_epi32(_mm_max_ps(_mm_min_ps(b, g_max), g_min)));
2079
+ out[i ] = (drmp3_int16)_mm_extract_epi16(pcm8, 0);
2080
+ out[i+1] = (drmp3_int16)_mm_extract_epi16(pcm8, 1);
2081
+ out[i+2] = (drmp3_int16)_mm_extract_epi16(pcm8, 2);
2082
+ out[i+3] = (drmp3_int16)_mm_extract_epi16(pcm8, 3);
2083
+ out[i+4] = (drmp3_int16)_mm_extract_epi16(pcm8, 4);
2084
+ out[i+5] = (drmp3_int16)_mm_extract_epi16(pcm8, 5);
2085
+ out[i+6] = (drmp3_int16)_mm_extract_epi16(pcm8, 6);
2086
+ out[i+7] = (drmp3_int16)_mm_extract_epi16(pcm8, 7);
2087
+ #else
2088
+ int16x4_t pcma, pcmb;
2089
+ a = DRMP3_VADD(a, DRMP3_VSET(0.5f));
2090
+ b = DRMP3_VADD(b, DRMP3_VSET(0.5f));
2091
+ pcma = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(a), vreinterpretq_s32_u32(vcltq_f32(a, DRMP3_VSET(0)))));
2092
+ pcmb = vqmovn_s32(vqaddq_s32(vcvtq_s32_f32(b), vreinterpretq_s32_u32(vcltq_f32(b, DRMP3_VSET(0)))));
2093
+ vst1_lane_s16(out+i , pcma, 0);
2094
+ vst1_lane_s16(out+i+1, pcma, 1);
2095
+ vst1_lane_s16(out+i+2, pcma, 2);
2096
+ vst1_lane_s16(out+i+3, pcma, 3);
2097
+ vst1_lane_s16(out+i+4, pcmb, 0);
2098
+ vst1_lane_s16(out+i+5, pcmb, 1);
2099
+ vst1_lane_s16(out+i+6, pcmb, 2);
2100
+ vst1_lane_s16(out+i+7, pcmb, 3);
2101
+ #endif
2102
+ }
2103
+ #endif
2104
+ for(; i < num_samples; i++)
2105
+ {
2106
+ float sample = in[i] * 32768.0f;
2107
+ if (sample >= 32766.5)
2108
+ out[i] = (drmp3_int16) 32767;
2109
+ else if (sample <= -32767.5)
2110
+ out[i] = (drmp3_int16)-32768;
2111
+ else
2112
+ {
2113
+ short s = (drmp3_int16)(sample + .5f);
2114
+ s -= (s < 0); /* away from zero, to be compliant */
2115
+ out[i] = s;
2116
+ }
2117
+ }
2118
+ }
2119
+ }
1983
2120
 
1984
2121
 
1985
2122
  ///////////////////////////////////////////////////////////////////////////////
@@ -1988,6 +2125,16 @@ int drmp3dec_decode_frame(drmp3dec *dec, const unsigned char *mp3, int mp3_bytes
1988
2125
  //
1989
2126
  ///////////////////////////////////////////////////////////////////////////////
1990
2127
 
2128
+ #if defined(SIZE_MAX)
2129
+ #define DRMP3_SIZE_MAX SIZE_MAX
2130
+ #else
2131
+ #if defined(_WIN64) || defined(_LP64) || defined(__LP64__)
2132
+ #define DRMP3_SIZE_MAX ((drmp3_uint64)0xFFFFFFFFFFFFFFFF)
2133
+ #else
2134
+ #define DRMP3_SIZE_MAX 0xFFFFFFFF
2135
+ #endif
2136
+ #endif
2137
+
1991
2138
  // Options.
1992
2139
  #ifndef DR_MP3_DEFAULT_CHANNELS
1993
2140
  #define DR_MP3_DEFAULT_CHANNELS 2
@@ -1996,36 +2143,6 @@ int drmp3dec_decode_frame(drmp3dec *dec, const unsigned char *mp3, int mp3_bytes
1996
2143
  #define DR_MP3_DEFAULT_SAMPLE_RATE 44100
1997
2144
  #endif
1998
2145
 
1999
-
2000
- // Standard library stuff.
2001
- #ifndef DRMP3_ASSERT
2002
- #include <assert.h>
2003
- #define DRMP3_ASSERT(expression) assert(expression)
2004
- #endif
2005
- #ifndef DRMP3_COPY_MEMORY
2006
- #define DRMP3_COPY_MEMORY(dst, src, sz) memcpy((dst), (src), (sz))
2007
- #endif
2008
- #ifndef DRMP3_ZERO_MEMORY
2009
- #define DRMP3_ZERO_MEMORY(p, sz) memset((p), 0, (sz))
2010
- #endif
2011
- #define DRMP3_ZERO_OBJECT(p) DRMP3_ZERO_MEMORY((p), sizeof(*(p)))
2012
- #ifndef DRMP3_MALLOC
2013
- #define DRMP3_MALLOC(sz) malloc((sz))
2014
- #endif
2015
- #ifndef DRMP3_REALLOC
2016
- #define DRMP3_REALLOC(p, sz) realloc((p), (sz))
2017
- #endif
2018
- #ifndef DRMP3_FREE
2019
- #define DRMP3_FREE(p) free((p))
2020
- #endif
2021
-
2022
- #define drmp3_assert DRMP3_ASSERT
2023
- #define drmp3_copy_memory DRMP3_COPY_MEMORY
2024
- #define drmp3_zero_memory DRMP3_ZERO_MEMORY
2025
- #define drmp3_zero_object DRMP3_ZERO_OBJECT
2026
- #define drmp3_malloc DRMP3_MALLOC
2027
- #define drmp3_realloc DRMP3_REALLOC
2028
-
2029
2146
  #define drmp3_countof(x) (sizeof(x) / sizeof(x[0]))
2030
2147
  #define drmp3_max(x, y) (((x) > (y)) ? (x) : (y))
2031
2148
  #define drmp3_min(x, y) (((x) < (y)) ? (x) : (y))
@@ -2082,7 +2199,6 @@ drmp3_uint64 drmp3_src_cache_read_frames(drmp3_src_cache* pCache, drmp3_uint64 f
2082
2199
  break;
2083
2200
  }
2084
2201
 
2085
-
2086
2202
  // At this point there are still more frames to read from the client, so we'll need to reload the cache with fresh data.
2087
2203
  drmp3_assert(frameCount > 0);
2088
2204
  pFramesOut += framesToReadFromMemory * channels;
@@ -2097,7 +2213,6 @@ drmp3_uint64 drmp3_src_cache_read_frames(drmp3_src_cache* pCache, drmp3_uint64 f
2097
2213
 
2098
2214
  pCache->cachedFrameCount = (drmp3_uint32)pCache->pSRC->onRead(pCache->pSRC, framesToReadFromClient, pCache->pCachedFrames, pCache->pSRC->pUserData);
2099
2215
 
2100
-
2101
2216
  // Get out of this loop if nothing was able to be retrieved.
2102
2217
  if (pCache->cachedFrameCount == 0) {
2103
2218
  break;
@@ -2269,7 +2384,6 @@ drmp3_uint64 drmp3_src_read_frames_linear(drmp3_src* pSRC, drmp3_uint64 frameCou
2269
2384
  }
2270
2385
 
2271
2386
 
2272
-
2273
2387
  static drmp3_bool32 drmp3_decode_next_frame(drmp3* pMP3)
2274
2388
  {
2275
2389
  drmp3_assert(pMP3 != NULL);
@@ -2295,8 +2409,10 @@ static drmp3_bool32 drmp3_decode_next_frame(drmp3* pMP3)
2295
2409
 
2296
2410
  size_t bytesRead = pMP3->onRead(pMP3->pUserData, pMP3->pData + pMP3->dataSize, (pMP3->dataCapacity - pMP3->dataSize));
2297
2411
  if (bytesRead == 0) {
2298
- pMP3->atEnd = DRMP3_TRUE;
2299
- return DRMP3_FALSE; // No data.
2412
+ if (pMP3->dataSize == 0) {
2413
+ pMP3->atEnd = DRMP3_TRUE;
2414
+ return DRMP3_FALSE; // No data.
2415
+ }
2300
2416
  }
2301
2417
 
2302
2418
  pMP3->dataSize += bytesRead;
@@ -2308,13 +2424,13 @@ static drmp3_bool32 drmp3_decode_next_frame(drmp3* pMP3)
2308
2424
  }
2309
2425
 
2310
2426
  drmp3dec_frame_info info;
2311
- drmp3_uint32 samplesRead = drmp3dec_decode_frame(&pMP3->decoder, pMP3->pData, (int)pMP3->dataSize, pMP3->frames, &info); // <-- Safe size_t -> int conversion thanks to the check above.
2427
+ drmp3_uint32 samplesRead = drmp3dec_decode_frame(&pMP3->decoder, pMP3->pData, (int)pMP3->dataSize, (drmp3d_sample_t*)pMP3->frames, &info); // <-- Safe size_t -> int conversion thanks to the check above.
2312
2428
  if (samplesRead != 0) {
2313
2429
  size_t leftoverDataSize = (pMP3->dataSize - (size_t)info.frame_bytes);
2314
2430
  for (size_t i = 0; i < leftoverDataSize; ++i) {
2315
2431
  pMP3->pData[i] = pMP3->pData[i + (size_t)info.frame_bytes];
2316
2432
  }
2317
-
2433
+
2318
2434
  pMP3->dataSize = leftoverDataSize;
2319
2435
  pMP3->framesConsumed = 0;
2320
2436
  pMP3->framesRemaining = samplesRead;
@@ -2361,28 +2477,54 @@ static drmp3_uint64 drmp3_read_src(drmp3_src* pSRC, drmp3_uint64 frameCount, voi
2361
2477
  while (frameCount > 0) {
2362
2478
  // Read from the in-memory buffer first.
2363
2479
  while (pMP3->framesRemaining > 0 && frameCount > 0) {
2480
+ drmp3d_sample_t* frames = (drmp3d_sample_t*)pMP3->frames;
2481
+ #ifndef DR_MP3_FLOAT_OUTPUT
2482
+ if (pMP3->frameChannels == 1) {
2483
+ if (pMP3->channels == 1) {
2484
+ // Mono -> Mono.
2485
+ pFramesOutF[0] = frames[pMP3->framesConsumed] / 32768.0f;
2486
+ } else {
2487
+ // Mono -> Stereo.
2488
+ pFramesOutF[0] = frames[pMP3->framesConsumed] / 32768.0f;
2489
+ pFramesOutF[1] = frames[pMP3->framesConsumed] / 32768.0f;
2490
+ }
2491
+ } else {
2492
+ if (pMP3->channels == 1) {
2493
+ // Stereo -> Mono
2494
+ float sample = 0;
2495
+ sample += frames[(pMP3->framesConsumed*pMP3->frameChannels)+0] / 32768.0f;
2496
+ sample += frames[(pMP3->framesConsumed*pMP3->frameChannels)+1] / 32768.0f;
2497
+ pFramesOutF[0] = sample * 0.5f;
2498
+ } else {
2499
+ // Stereo -> Stereo
2500
+ pFramesOutF[0] = frames[(pMP3->framesConsumed*pMP3->frameChannels)+0] / 32768.0f;
2501
+ pFramesOutF[1] = frames[(pMP3->framesConsumed*pMP3->frameChannels)+1] / 32768.0f;
2502
+ }
2503
+ }
2504
+ #else
2364
2505
  if (pMP3->frameChannels == 1) {
2365
2506
  if (pMP3->channels == 1) {
2366
2507
  // Mono -> Mono.
2367
- pFramesOutF[0] = pMP3->frames[pMP3->framesConsumed] / 32768.0f;
2508
+ pFramesOutF[0] = frames[pMP3->framesConsumed];
2368
2509
  } else {
2369
2510
  // Mono -> Stereo.
2370
- pFramesOutF[0] = pMP3->frames[pMP3->framesConsumed] / 32768.0f;
2371
- pFramesOutF[1] = pMP3->frames[pMP3->framesConsumed] / 32768.0f;
2511
+ pFramesOutF[0] = frames[pMP3->framesConsumed];
2512
+ pFramesOutF[1] = frames[pMP3->framesConsumed];
2372
2513
  }
2373
2514
  } else {
2374
2515
  if (pMP3->channels == 1) {
2375
2516
  // Stereo -> Mono
2376
2517
  float sample = 0;
2377
- sample += pMP3->frames[(pMP3->framesConsumed*pMP3->frameChannels)+0] / 32768.0f;
2378
- sample += pMP3->frames[(pMP3->framesConsumed*pMP3->frameChannels)+1] / 32768.0f;
2518
+ sample += frames[(pMP3->framesConsumed*pMP3->frameChannels)+0];
2519
+ sample += frames[(pMP3->framesConsumed*pMP3->frameChannels)+1];
2379
2520
  pFramesOutF[0] = sample * 0.5f;
2380
2521
  } else {
2381
2522
  // Stereo -> Stereo
2382
- pFramesOutF[0] = pMP3->frames[(pMP3->framesConsumed*pMP3->frameChannels)+0] / 32768.0f;
2383
- pFramesOutF[1] = pMP3->frames[(pMP3->framesConsumed*pMP3->frameChannels)+1] / 32768.0f;
2523
+ pFramesOutF[0] = frames[(pMP3->framesConsumed*pMP3->frameChannels)+0];
2524
+ pFramesOutF[1] = frames[(pMP3->framesConsumed*pMP3->frameChannels)+1];
2384
2525
  }
2385
2526
  }
2527
+ #endif
2386
2528
 
2387
2529
  pMP3->framesConsumed += 1;
2388
2530
  pMP3->framesRemaining -= 1;
@@ -2450,11 +2592,13 @@ drmp3_bool32 drmp3_init_internal(drmp3* pMP3, drmp3_read_proc onRead, drmp3_seek
2450
2592
  srcConfig.channels = pMP3->channels;
2451
2593
  srcConfig.algorithm = drmp3_src_algorithm_linear;
2452
2594
  if (!drmp3_src_init(&srcConfig, drmp3_read_src, pMP3, &pMP3->src)) {
2595
+ drmp3_uninit(pMP3);
2453
2596
  return DRMP3_FALSE;
2454
2597
  }
2455
-
2598
+
2456
2599
  // Decode the first frame to confirm that it is indeed a valid MP3 stream.
2457
2600
  if (!drmp3_decode_next_frame(pMP3)) {
2601
+ drmp3_uninit(pMP3);
2458
2602
  return DRMP3_FALSE; // Not a valid MP3 stream.
2459
2603
  }
2460
2604
 
@@ -2574,7 +2718,7 @@ drmp3_bool32 drmp3_init_file(drmp3* pMP3, const char* filePath, const drmp3_conf
2574
2718
  void drmp3_uninit(drmp3* pMP3)
2575
2719
  {
2576
2720
  if (pMP3 == NULL) return;
2577
-
2721
+
2578
2722
  #ifndef DR_MP3_NO_STDIO
2579
2723
  if (pMP3->onRead == drmp3__on_read_stdio) {
2580
2724
  fclose((FILE*)pMP3->pUserData);
@@ -2665,7 +2809,7 @@ float* drmp3__full_decode_and_close_f32(drmp3* pMP3, drmp3_config* pConfig, drmp
2665
2809
  }
2666
2810
 
2667
2811
  drmp3_uint64 newFramesBufferSize = framesCapacity*pMP3->channels*sizeof(float);
2668
- if (newFramesBufferSize > SIZE_MAX) {
2812
+ if (newFramesBufferSize > (drmp3_uint64)DRMP3_SIZE_MAX) {
2669
2813
  break;
2670
2814
  }
2671
2815
 
@@ -2755,6 +2899,31 @@ void drmp3_free(void* p)
2755
2899
  // REVISION HISTORY
2756
2900
  // ===============
2757
2901
  //
2902
+ // v0.3.2 - 2018-09-11
2903
+ // - Fix a couple of memory leaks.
2904
+ // - Bring up to date with minimp3.
2905
+ //
2906
+ // v0.3.1 - 2018-08-25
2907
+ // - Fix C++ build.
2908
+ //
2909
+ // v0.3.0 - 2018-08-25
2910
+ // - Bring up to date with minimp3. This has a minor API change: the "pcm" parameter of drmp3dec_decode_frame() has
2911
+ // been changed from short* to void* because it can now output both s16 and f32 samples, depending on whether or
2912
+ // not the DR_MP3_FLOAT_OUTPUT option is set.
2913
+ //
2914
+ // v0.2.11 - 2018-08-08
2915
+ // - Fix a bug where the last part of a file is not read.
2916
+ //
2917
+ // v0.2.10 - 2018-08-07
2918
+ // - Improve 64-bit detection.
2919
+ //
2920
+ // v0.2.9 - 2018-08-05
2921
+ // - Fix C++ build on older versions of GCC.
2922
+ // - Bring up to date with minimp3.
2923
+ //
2924
+ // v0.2.8 - 2018-08-02
2925
+ // - Fix compilation errors with older versions of GCC.
2926
+ //
2758
2927
  // v0.2.7 - 2018-07-13
2759
2928
  // - Bring up to date with minimp3.
2760
2929
  //