gosu 1.4.5.pre1 → 1.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -8
- data/dependencies/SDL/include/SDL.h +2 -1
- data/dependencies/SDL/include/SDL_assert.h +8 -12
- data/dependencies/SDL/include/SDL_atomic.h +21 -1
- data/dependencies/SDL/include/SDL_audio.h +41 -5
- data/dependencies/SDL/include/SDL_bits.h +1 -1
- data/dependencies/SDL/include/SDL_blendmode.h +5 -7
- data/dependencies/SDL/include/SDL_clipboard.h +48 -1
- data/dependencies/SDL/include/SDL_config.h +73 -47
- data/dependencies/SDL/include/SDL_cpuinfo.h +40 -5
- data/dependencies/SDL/include/SDL_egl.h +60 -10
- data/dependencies/SDL/include/SDL_endian.h +35 -4
- data/dependencies/SDL/include/SDL_error.h +1 -1
- data/dependencies/SDL/include/SDL_events.h +33 -2
- data/dependencies/SDL/include/SDL_filesystem.h +6 -2
- data/dependencies/SDL/include/SDL_gamecontroller.h +79 -6
- data/dependencies/SDL/include/SDL_gesture.h +1 -1
- data/dependencies/SDL/include/SDL_guid.h +100 -0
- data/dependencies/SDL/include/SDL_haptic.h +1 -1
- data/dependencies/SDL/include/SDL_hidapi.h +1 -1
- data/dependencies/SDL/include/SDL_hints.h +646 -44
- data/dependencies/SDL/include/SDL_joystick.h +128 -8
- data/dependencies/SDL/include/SDL_keyboard.h +39 -2
- data/dependencies/SDL/include/SDL_keycode.h +7 -2
- data/dependencies/SDL/include/SDL_loadso.h +1 -1
- data/dependencies/SDL/include/SDL_locale.h +1 -1
- data/dependencies/SDL/include/SDL_log.h +3 -3
- data/dependencies/SDL/include/SDL_main.h +43 -3
- data/dependencies/SDL/include/SDL_messagebox.h +1 -1
- data/dependencies/SDL/include/SDL_metal.h +3 -2
- data/dependencies/SDL/include/SDL_misc.h +1 -1
- data/dependencies/SDL/include/SDL_mouse.h +13 -2
- data/dependencies/SDL/include/SDL_mutex.h +1 -1
- data/dependencies/SDL/include/SDL_name.h +1 -1
- data/dependencies/SDL/include/SDL_opengl.h +1 -52
- data/dependencies/SDL/include/SDL_opengl_glext.h +2260 -231
- data/dependencies/SDL/include/SDL_opengles.h +1 -1
- data/dependencies/SDL/include/SDL_opengles2.h +1 -1
- data/dependencies/SDL/include/SDL_opengles2_gl2.h +374 -339
- data/dependencies/SDL/include/SDL_opengles2_gl2ext.h +3479 -1496
- data/dependencies/SDL/include/SDL_opengles2_gl2platform.h +6 -9
- data/dependencies/SDL/include/SDL_opengles2_khrplatform.h +43 -14
- data/dependencies/SDL/include/SDL_pixels.h +1 -1
- data/dependencies/SDL/include/SDL_platform.h +33 -7
- data/dependencies/SDL/include/SDL_power.h +1 -1
- data/dependencies/SDL/include/SDL_quit.h +1 -1
- data/dependencies/SDL/include/SDL_rect.h +155 -3
- data/dependencies/SDL/include/SDL_render.h +47 -18
- data/dependencies/SDL/include/SDL_revision.h +6 -1
- data/dependencies/SDL/include/SDL_rwops.h +2 -16
- data/dependencies/SDL/include/SDL_scancode.h +47 -22
- data/dependencies/SDL/include/SDL_sensor.h +25 -4
- data/dependencies/SDL/include/SDL_shape.h +1 -1
- data/dependencies/SDL/include/SDL_stdinc.h +120 -9
- data/dependencies/SDL/include/SDL_surface.h +4 -2
- data/dependencies/SDL/include/SDL_system.h +67 -7
- data/dependencies/SDL/include/SDL_syswm.h +3 -1
- data/dependencies/SDL/include/SDL_test.h +1 -1
- data/dependencies/SDL/include/SDL_test_assert.h +1 -1
- data/dependencies/SDL/include/SDL_test_common.h +2 -1
- data/dependencies/SDL/include/SDL_test_compare.h +1 -1
- data/dependencies/SDL/include/SDL_test_crc32.h +1 -1
- data/dependencies/SDL/include/SDL_test_font.h +91 -4
- data/dependencies/SDL/include/SDL_test_fuzzer.h +1 -1
- data/dependencies/SDL/include/SDL_test_harness.h +1 -1
- data/dependencies/SDL/include/SDL_test_images.h +1 -1
- data/dependencies/SDL/include/SDL_test_log.h +1 -1
- data/dependencies/SDL/include/SDL_test_md5.h +1 -1
- data/dependencies/SDL/include/SDL_test_memory.h +1 -1
- data/dependencies/SDL/include/SDL_test_random.h +1 -1
- data/dependencies/SDL/include/SDL_thread.h +6 -6
- data/dependencies/SDL/include/SDL_timer.h +1 -1
- data/dependencies/SDL/include/SDL_touch.h +9 -1
- data/dependencies/SDL/include/SDL_types.h +1 -1
- data/dependencies/SDL/include/SDL_version.h +20 -4
- data/dependencies/SDL/include/SDL_video.h +72 -10
- data/dependencies/SDL/include/begin_code.h +5 -5
- data/dependencies/SDL/include/close_code.h +1 -1
- data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
- data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
- data/dependencies/SDL_sound/SDL_sound.c +210 -71
- data/dependencies/SDL_sound/SDL_sound.h +1 -1
- data/dependencies/SDL_sound/SDL_sound_coreaudio.c +111 -168
- data/dependencies/SDL_sound/SDL_sound_flac.c +0 -6
- data/dependencies/SDL_sound/SDL_sound_internal.h +24 -2
- data/dependencies/SDL_sound/SDL_sound_modplug.c +20 -8
- data/dependencies/SDL_sound/SDL_sound_mp3.c +11 -7
- data/dependencies/SDL_sound/SDL_sound_raw.c +1 -1
- data/dependencies/SDL_sound/SDL_sound_shn.c +1 -5
- data/dependencies/SDL_sound/SDL_sound_voc.c +1 -1
- data/dependencies/SDL_sound/SDL_sound_vorbis.c +2 -4
- data/dependencies/SDL_sound/SDL_sound_wav.c +49 -20
- data/dependencies/SDL_sound/dr_flac.h +237 -95
- data/dependencies/SDL_sound/dr_mp3.h +46 -33
- data/dependencies/SDL_sound/libmodplug/fastmix.c +53 -39
- data/dependencies/SDL_sound/libmodplug/libmodplug.h +0 -12
- data/dependencies/SDL_sound/libmodplug/load_669.c +37 -32
- data/dependencies/SDL_sound/libmodplug/load_amf.c +57 -44
- data/dependencies/SDL_sound/libmodplug/load_ams.c +127 -100
- data/dependencies/SDL_sound/libmodplug/load_dbm.c +40 -37
- data/dependencies/SDL_sound/libmodplug/load_dmf.c +61 -49
- data/dependencies/SDL_sound/libmodplug/load_dsm.c +18 -13
- data/dependencies/SDL_sound/libmodplug/load_far.c +31 -24
- data/dependencies/SDL_sound/libmodplug/load_gdm.c +27 -21
- data/dependencies/SDL_sound/libmodplug/load_it.c +106 -91
- data/dependencies/SDL_sound/libmodplug/load_mdl.c +43 -35
- data/dependencies/SDL_sound/libmodplug/load_med.c +66 -52
- data/dependencies/SDL_sound/libmodplug/load_mod.c +30 -26
- data/dependencies/SDL_sound/libmodplug/load_mt2.c +61 -50
- data/dependencies/SDL_sound/libmodplug/load_mtm.c +23 -17
- data/dependencies/SDL_sound/libmodplug/load_okt.c +18 -16
- data/dependencies/SDL_sound/libmodplug/load_psm.c +44 -32
- data/dependencies/SDL_sound/libmodplug/load_ptm.c +18 -14
- data/dependencies/SDL_sound/libmodplug/load_s3m.c +59 -53
- data/dependencies/SDL_sound/libmodplug/load_stm.c +23 -18
- data/dependencies/SDL_sound/libmodplug/load_ult.c +33 -29
- data/dependencies/SDL_sound/libmodplug/load_xm.c +64 -57
- data/dependencies/SDL_sound/libmodplug/mmcmp.c +2 -1
- data/dependencies/SDL_sound/libmodplug/snd_dsp.c +30 -20
- data/dependencies/SDL_sound/libmodplug/snd_flt.c +6 -4
- data/dependencies/SDL_sound/libmodplug/snd_fx.c +91 -65
- data/dependencies/SDL_sound/libmodplug/sndfile.c +91 -66
- data/dependencies/SDL_sound/libmodplug/sndmix.c +58 -35
- data/dependencies/SDL_sound/stb_vorbis.h +14 -9
- data/dependencies/mojoAL/mojoal.c +68 -40
- data/dependencies/stb/stb_image.h +117 -27
- data/dependencies/utf8proc/utf8proc.c +1 -1
- data/dependencies/utf8proc/utf8proc.h +1 -1
- data/dependencies/utf8proc/utf8proc_data.h +3366 -3184
- data/ext/gosu/extconf.rb +1 -1
- data/include/Gosu/Version.hpp +1 -1
- data/lib/SDL2.dll +0 -0
- data/lib64/SDL2.dll +0 -0
- data/src/AudioFile.hpp +1 -1
- data/src/AudioFileSDLSound.cpp +2 -0
- data/src/AudioImpl.hpp +2 -2
- data/src/Input.cpp +30 -26
- data/src/RubyGosu.cxx +146 -93
- data/src/RubyGosu.h +5 -7
- data/src/Window.cpp +3 -0
- metadata +6 -15
- data/dependencies/SDL/include/SDL_config_android.h +0 -157
- data/dependencies/SDL/include/SDL_config_iphoneos.h +0 -166
- data/dependencies/SDL/include/SDL_config_macosx.h +0 -197
- data/dependencies/SDL/include/SDL_config_minimal.h +0 -82
- data/dependencies/SDL/include/SDL_config_pandora.h +0 -128
- data/dependencies/SDL/include/SDL_config_psp.h +0 -144
- data/dependencies/SDL/include/SDL_config_windows.h +0 -225
- data/dependencies/SDL/include/SDL_config_winrt.h +0 -215
- data/dependencies/SDL/include/SDL_config_wiz.h +0 -121
- data/dependencies/SDL/include/SDL_copying.h +0 -20
@@ -217,12 +217,6 @@ void Sound_ClearError(void)
|
|
217
217
|
} /* Sound_ClearError */
|
218
218
|
|
219
219
|
|
220
|
-
static void SDLCALL free_errmsg(void *errmsg)
|
221
|
-
{
|
222
|
-
SDL_free(errmsg);
|
223
|
-
} /* free_errmsg */
|
224
|
-
|
225
|
-
|
226
220
|
/*
|
227
221
|
* This is declared in the internal header.
|
228
222
|
*/
|
@@ -245,7 +239,7 @@ void __Sound_SetError(const char *str)
|
|
245
239
|
if (err == NULL)
|
246
240
|
return; /* uhh...? */
|
247
241
|
|
248
|
-
SDL_TLSSet(tlsid_errmsg, err,
|
242
|
+
SDL_TLSSet(tlsid_errmsg, err, SDL_free);
|
249
243
|
} /* if */
|
250
244
|
|
251
245
|
err->error_available = SDL_TRUE;
|
@@ -288,7 +282,8 @@ static Sound_Sample *alloc_sample(SDL_RWops *rw, Sound_AudioInfo *desired,
|
|
288
282
|
} /* if */
|
289
283
|
|
290
284
|
SDL_assert(bufferSize > 0);
|
291
|
-
|
285
|
+
|
286
|
+
retval->buffer = __Sound_SIMDAlloc(bufferSize);
|
292
287
|
if (!retval->buffer)
|
293
288
|
{
|
294
289
|
__Sound_SetError(ERR_OUT_OF_MEMORY);
|
@@ -296,6 +291,7 @@ static Sound_Sample *alloc_sample(SDL_RWops *rw, Sound_AudioInfo *desired,
|
|
296
291
|
SDL_free(retval);
|
297
292
|
return NULL;
|
298
293
|
} /* if */
|
294
|
+
SDL_memset(retval->buffer, '\0', bufferSize);
|
299
295
|
retval->buffer_size = bufferSize;
|
300
296
|
|
301
297
|
if (desired != NULL)
|
@@ -362,7 +358,8 @@ static int init_sample(const Sound_DecoderFunctions *funcs,
|
|
362
358
|
|
363
359
|
/* success; we've got a decoder! */
|
364
360
|
|
365
|
-
/* Now we need to set up
|
361
|
+
/* Now we need to set up an audio stream for data conversion if necessary... */
|
362
|
+
internal->stream = NULL;
|
366
363
|
|
367
364
|
if (_desired == NULL)
|
368
365
|
SDL_memcpy(&desired, &sample->actual, sizeof (Sound_AudioInfo));
|
@@ -371,40 +368,32 @@ static int init_sample(const Sound_DecoderFunctions *funcs,
|
|
371
368
|
desired.format = _desired->format ? _desired->format : sample->actual.format;
|
372
369
|
desired.channels = _desired->channels ? _desired->channels : sample->actual.channels;
|
373
370
|
desired.rate = _desired->rate ? _desired->rate : sample->actual.rate;
|
374
|
-
} /* else */
|
375
|
-
|
376
|
-
if (SDL_BuildAudioCVT(&internal->sdlcvt,
|
377
|
-
sample->actual.format,
|
378
|
-
sample->actual.channels,
|
379
|
-
sample->actual.rate,
|
380
|
-
desired.format,
|
381
|
-
desired.channels,
|
382
|
-
desired.rate) == -1)
|
383
|
-
{
|
384
|
-
__Sound_SetError(SDL_GetError());
|
385
|
-
funcs->close(sample);
|
386
|
-
SDL_RWseek(internal->rw, pos, RW_SEEK_SET); /* set for next try... */
|
387
|
-
return 0;
|
388
|
-
} /* if */
|
389
371
|
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
if (rc == NULL)
|
372
|
+
if ( (sample->actual.format != desired.format) ||
|
373
|
+
(sample->actual.channels != desired.channels) ||
|
374
|
+
(sample->actual.rate != desired.rate) )
|
394
375
|
{
|
395
|
-
|
396
|
-
|
397
|
-
|
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);
|
382
|
+
|
383
|
+
if (internal->stream == NULL)
|
384
|
+
{
|
385
|
+
__Sound_SetError(SDL_GetError());
|
386
|
+
funcs->close(sample);
|
387
|
+
SDL_RWseek(internal->rw, pos, RW_SEEK_SET); /* set for next try... */
|
388
|
+
return 0;
|
389
|
+
} /* if */
|
398
390
|
} /* if */
|
399
|
-
|
400
|
-
sample->buffer = rc;
|
401
|
-
} /* if */
|
391
|
+
} /* else */
|
402
392
|
|
403
393
|
/* these pointers are all one and the same. */
|
404
394
|
SDL_memcpy(&sample->desired, &desired, sizeof (Sound_AudioInfo));
|
405
|
-
internal->
|
406
|
-
internal->buffer_size = sample->buffer_size
|
407
|
-
internal->sdlcvt.len = internal->buffer_size;
|
395
|
+
internal->buffer = sample->buffer;
|
396
|
+
internal->buffer_size = sample->buffer_size;
|
408
397
|
|
409
398
|
/* Prepend our new Sound_Sample to the sample_list... */
|
410
399
|
SDL_LockMutex(samplelist_mutex);
|
@@ -425,7 +414,7 @@ static int init_sample(const Sound_DecoderFunctions *funcs,
|
|
425
414
|
sample->actual.channels));
|
426
415
|
|
427
416
|
SNDDBG(("On-the-fly conversion: %s.\n",
|
428
|
-
internal->
|
417
|
+
(internal->stream != NULL) ? "ENABLED" : "DISABLED"));
|
429
418
|
|
430
419
|
return 1;
|
431
420
|
} /* init_sample */
|
@@ -494,9 +483,14 @@ Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext,
|
|
494
483
|
} /* for */
|
495
484
|
|
496
485
|
/* nothing could handle the sound data... */
|
497
|
-
|
498
|
-
if (retval->
|
499
|
-
|
486
|
+
/* !!! FIXME: can we just push this through Sound_FreeSample() ? */
|
487
|
+
if (retval->opaque != NULL)
|
488
|
+
{
|
489
|
+
SDL_FreeAudioStream(((Sound_SampleInternal *) retval->opaque)->stream);
|
490
|
+
SDL_free(retval->opaque);
|
491
|
+
} /* if */
|
492
|
+
|
493
|
+
__Sound_SIMDFree(retval->buffer);
|
500
494
|
SDL_free(retval);
|
501
495
|
SDL_RWclose(rw);
|
502
496
|
__Sound_SetError(ERR_UNSUPPORTED_FORMAT);
|
@@ -592,14 +586,9 @@ void Sound_FreeSample(Sound_Sample *sample)
|
|
592
586
|
if (internal->rw != NULL) /* this condition is a "just in case" thing. */
|
593
587
|
SDL_RWclose(internal->rw);
|
594
588
|
|
595
|
-
|
596
|
-
SDL_free(internal->buffer);
|
597
|
-
|
589
|
+
SDL_FreeAudioStream(internal->stream);
|
598
590
|
SDL_free(internal);
|
599
|
-
|
600
|
-
if (sample->buffer != NULL)
|
601
|
-
SDL_free(sample->buffer);
|
602
|
-
|
591
|
+
__Sound_SIMDFree(sample->buffer);
|
603
592
|
SDL_free(sample);
|
604
593
|
} /* Sound_FreeSample */
|
605
594
|
|
@@ -612,13 +601,11 @@ int Sound_SetBufferSize(Sound_Sample *sample, Uint32 newSize)
|
|
612
601
|
BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
|
613
602
|
BAIL_IF_MACRO(sample == NULL, ERR_INVALID_ARGUMENT, 0);
|
614
603
|
internal = ((Sound_SampleInternal *) sample->opaque);
|
615
|
-
newBuf =
|
604
|
+
newBuf = __Sound_SIMDRealloc(sample->buffer, newSize);
|
616
605
|
BAIL_IF_MACRO(newBuf == NULL, ERR_OUT_OF_MEMORY, 0);
|
617
606
|
|
618
|
-
internal->
|
619
|
-
sample->buffer_size = newSize;
|
620
|
-
internal->buffer_size = newSize / internal->sdlcvt.len_mult;
|
621
|
-
internal->sdlcvt.len = internal->buffer_size;
|
607
|
+
internal->buffer = sample->buffer = newBuf;
|
608
|
+
internal->buffer_size = sample->buffer_size = newSize;
|
622
609
|
|
623
610
|
return 1;
|
624
611
|
} /* Sound_SetBufferSize */
|
@@ -627,7 +614,7 @@ int Sound_SetBufferSize(Sound_Sample *sample, Uint32 newSize)
|
|
627
614
|
Uint32 Sound_Decode(Sound_Sample *sample)
|
628
615
|
{
|
629
616
|
Sound_SampleInternal *internal = NULL;
|
630
|
-
|
617
|
+
int available;
|
631
618
|
|
632
619
|
/* a boatload of sanity checks... */
|
633
620
|
BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
|
@@ -642,18 +629,80 @@ Uint32 Sound_Decode(Sound_Sample *sample)
|
|
642
629
|
SDL_assert(internal->buffer != NULL);
|
643
630
|
SDL_assert(internal->buffer_size > 0);
|
644
631
|
|
632
|
+
/* No AudioStream? No conversion. Decode right into the buffer and return it. */
|
633
|
+
if (!internal->stream)
|
634
|
+
{
|
645
635
|
/* reset EAGAIN. Decoder can flip it back on if it needs to. */
|
646
|
-
|
647
|
-
|
636
|
+
sample->flags &= ~SOUND_SAMPLEFLAG_EAGAIN;
|
637
|
+
return internal->funcs->read(sample);
|
638
|
+
} /* if */
|
648
639
|
|
649
|
-
|
640
|
+
/* call into the decoder several times until we have enough data. */
|
641
|
+
while ((available = SDL_AudioStreamAvailable(internal->stream)) < internal->buffer_size)
|
650
642
|
{
|
651
|
-
|
652
|
-
|
653
|
-
|
643
|
+
SDL_bool flush_stream = SDL_FALSE;
|
644
|
+
Uint32 br;
|
645
|
+
|
646
|
+
if (internal->pending_eof || internal->pending_error)
|
647
|
+
break;
|
648
|
+
|
649
|
+
/* reset EAGAIN. Decoder can flip it back on if it needs to. */
|
650
|
+
sample->flags &= ~SOUND_SAMPLEFLAG_EAGAIN;
|
651
|
+
br = internal->funcs->read(sample);
|
652
|
+
|
653
|
+
/* if the sample hit an error or EOF, note it, but don't let these flags
|
654
|
+
be set for the calling app until the stream is empty too. */
|
655
|
+
if (sample->flags & SOUND_SAMPLEFLAG_EOF)
|
656
|
+
{
|
657
|
+
sample->flags &= ~SOUND_SAMPLEFLAG_EOF;
|
658
|
+
internal->pending_eof = SDL_TRUE;
|
659
|
+
flush_stream = SDL_TRUE;
|
660
|
+
} /* if */
|
661
|
+
|
662
|
+
if (sample->flags & SOUND_SAMPLEFLAG_ERROR)
|
663
|
+
{
|
664
|
+
sample->flags &= ~SOUND_SAMPLEFLAG_ERROR;
|
665
|
+
internal->pending_error = SDL_TRUE;
|
666
|
+
flush_stream = SDL_TRUE;
|
667
|
+
} /* if */
|
668
|
+
|
669
|
+
if ((br > 0) && (SDL_AudioStreamPut(internal->stream, internal->buffer, (int) br) == -1))
|
670
|
+
{
|
671
|
+
__Sound_SetError(SDL_GetError());
|
672
|
+
sample->flags |= SOUND_SAMPLEFLAG_ERROR;
|
673
|
+
return 0; /* oh well. */
|
674
|
+
} /* if */
|
675
|
+
|
676
|
+
if (flush_stream)
|
677
|
+
SDL_AudioStreamFlush(internal->stream);
|
678
|
+
} /* while */
|
679
|
+
|
680
|
+
/* if we hit eof or error, drain the stream before reporting that. */
|
681
|
+
if (available > 0)
|
682
|
+
{
|
683
|
+
const int readlen = SDL_min(available, sample->buffer_size);
|
684
|
+
const int br = SDL_AudioStreamGet(internal->stream, sample->buffer, readlen);
|
685
|
+
if (br != readlen)
|
686
|
+
{
|
687
|
+
__Sound_SetError(SDL_GetError());
|
688
|
+
sample->flags |= SOUND_SAMPLEFLAG_ERROR;
|
689
|
+
return 0; /* oh well. */
|
690
|
+
} /* if */
|
691
|
+
|
692
|
+
SDL_assert(br > 0);
|
693
|
+
return (Uint32) br;
|
654
694
|
} /* if */
|
655
695
|
|
656
|
-
|
696
|
+
/* stream is empty, set final flags. */
|
697
|
+
if (internal->pending_eof)
|
698
|
+
sample->flags |= SOUND_SAMPLEFLAG_EOF;
|
699
|
+
|
700
|
+
if (internal->pending_error)
|
701
|
+
sample->flags |= SOUND_SAMPLEFLAG_ERROR;
|
702
|
+
|
703
|
+
internal->pending_eof = internal->pending_error = SDL_FALSE;
|
704
|
+
|
705
|
+
return 0;
|
657
706
|
} /* Sound_Decode */
|
658
707
|
|
659
708
|
|
@@ -673,7 +722,7 @@ Uint32 Sound_DecodeAll(Sound_Sample *sample)
|
|
673
722
|
((sample->flags & SOUND_SAMPLEFLAG_ERROR) == 0) )
|
674
723
|
{
|
675
724
|
Uint32 br = Sound_Decode(sample);
|
676
|
-
void *ptr =
|
725
|
+
void *ptr = __Sound_SIMDRealloc(buf, newBufSize + br);
|
677
726
|
if (ptr == NULL)
|
678
727
|
{
|
679
728
|
sample->flags |= SOUND_SAMPLEFLAG_ERROR;
|
@@ -687,18 +736,13 @@ Uint32 Sound_DecodeAll(Sound_Sample *sample)
|
|
687
736
|
} /* else */
|
688
737
|
} /* while */
|
689
738
|
|
690
|
-
if (buf == NULL) /* ...in case first call to
|
739
|
+
if (buf == NULL) /* ...in case first call to __Sound_SIMDRealloc() fails... */
|
691
740
|
return sample->buffer_size;
|
692
741
|
|
693
|
-
|
694
|
-
SDL_free(internal->buffer);
|
695
|
-
|
696
|
-
SDL_free(sample->buffer);
|
742
|
+
__Sound_SIMDFree(sample->buffer);
|
697
743
|
|
698
|
-
internal->
|
699
|
-
sample->buffer_size = newBufSize;
|
700
|
-
internal->buffer_size = newBufSize / internal->sdlcvt.len_mult;
|
701
|
-
internal->sdlcvt.len = internal->buffer_size;
|
744
|
+
internal->buffer = sample->buffer = buf;
|
745
|
+
internal->buffer_size = sample->buffer_size = newBufSize;
|
702
746
|
|
703
747
|
return newBufSize;
|
704
748
|
} /* Sound_DecodeAll */
|
@@ -825,5 +869,100 @@ char *__Sound_strtokr(char *s1, const char *s2, char **ptr)
|
|
825
869
|
}
|
826
870
|
#endif
|
827
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
|
+
void *__Sound_SIMDAlloc(const size_t len)
|
883
|
+
{
|
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
|
900
|
+
}
|
901
|
+
|
902
|
+
void *__Sound_SIMDRealloc(void *mem, const size_t len)
|
903
|
+
{
|
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;
|
911
|
+
void *oldmem = mem;
|
912
|
+
size_t memdiff = 0, ptrdiff;
|
913
|
+
Uint8 *ptr;
|
914
|
+
|
915
|
+
if (mem) {
|
916
|
+
void **realptr = (void **) mem;
|
917
|
+
realptr--;
|
918
|
+
mem = *(((void **) mem) - 1);
|
919
|
+
|
920
|
+
/* Check the delta between the real pointer and user pointer */
|
921
|
+
memdiff = ((size_t) oldmem) - ((size_t) mem);
|
922
|
+
}
|
923
|
+
|
924
|
+
ptr = (Uint8 *) SDL_realloc(mem, padded + alignment + sizeof (void *));
|
925
|
+
|
926
|
+
if (ptr == NULL) {
|
927
|
+
return NULL; /* Out of memory, bail! */
|
928
|
+
}
|
929
|
+
|
930
|
+
/* Store the actual allocated pointer right before our aligned pointer. */
|
931
|
+
retval = ptr + sizeof (void *);
|
932
|
+
retval += alignment - (((size_t) retval) % alignment);
|
933
|
+
|
934
|
+
/* Make sure the delta is the same! */
|
935
|
+
if (mem) {
|
936
|
+
ptrdiff = ((size_t) retval) - ((size_t) ptr);
|
937
|
+
if (memdiff != ptrdiff) { /* Delta has changed, copy to new offset! */
|
938
|
+
oldmem = (void*) (((uintptr_t) ptr) + memdiff);
|
939
|
+
|
940
|
+
/* Even though the data past the old `len` is undefined, this is the
|
941
|
+
* only length value we have, and it guarantees that we copy all the
|
942
|
+
* previous memory anyhow.
|
943
|
+
*/
|
944
|
+
SDL_memmove(retval, oldmem, len);
|
945
|
+
}
|
946
|
+
}
|
947
|
+
|
948
|
+
/* Actually store the allocated pointer, finally. */
|
949
|
+
*(((void **) retval) - 1) = ptr;
|
950
|
+
return retval;
|
951
|
+
#endif
|
952
|
+
}
|
953
|
+
|
954
|
+
void __Sound_SIMDFree(void *ptr)
|
955
|
+
{
|
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
|
965
|
+
}
|
966
|
+
|
828
967
|
/* end of SDL_sound.c ... */
|
829
968
|
|