dependencies/SDL_sound/SDL_sound.c in gosu-1.3.0 vs dependencies/SDL_sound/SDL_sound.c in gosu-1.4.0
- old
+ new
@@ -17,10 +17,11 @@
#include "SDL_sound_internal.h"
/* The various decoder drivers... */
/* All these externs may be missing; we check SOUND_SUPPORTS_xxx before use. */
+extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MIDI;
extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MODPLUG;
extern const Sound_DecoderFunctions __Sound_DecoderFunctions_MP3;
extern const Sound_DecoderFunctions __Sound_DecoderFunctions_WAV;
extern const Sound_DecoderFunctions __Sound_DecoderFunctions_AIFF;
extern const Sound_DecoderFunctions __Sound_DecoderFunctions_AU;
@@ -38,10 +39,13 @@
const Sound_DecoderFunctions *funcs;
} decoder_element;
static decoder_element decoders[] =
{
+#if SOUND_SUPPORTS_MIDI
+ { 0, &__Sound_DecoderFunctions_MIDI },
+#endif
#if SOUND_SUPPORTS_MODPLUG
{ 0, &__Sound_DecoderFunctions_MODPLUG },
#endif
#if SOUND_SUPPORTS_MP3
{ 0, &__Sound_DecoderFunctions_MP3 },
@@ -346,12 +350,11 @@
#if (defined DEBUG_CHATTER)
static SDL_INLINE const char *fmt_to_str(Uint16 fmt)
{
- switch(fmt)
- {
+ switch(fmt) {
case AUDIO_U8:
return "U8";
case AUDIO_S8:
return "S8";
case AUDIO_U16LSB:
@@ -369,11 +372,10 @@
case AUDIO_S32MSB:
return "S32MSB";
case AUDIO_F32MSB:
return "F32MSB";
} /* switch */
-
return "Unknown";
} /* fmt_to_str */
#endif
@@ -394,11 +396,11 @@
/* fill in the funcs for this decoder... */
sample->decoder = &funcs->info;
internal->funcs = funcs;
if (!funcs->open(sample, ext))
{
- SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */
+ SDL_RWseek(internal->rw, pos, RW_SEEK_SET); /* set for next try... */
return 0;
} /* if */
/* success; we've got a decoder! */
@@ -421,21 +423,21 @@
desired.channels,
desired.rate) == -1)
{
__Sound_SetError(SDL_GetError());
funcs->close(sample);
- SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */
+ SDL_RWseek(internal->rw, pos, RW_SEEK_SET); /* set for next try... */
return 0;
} /* if */
if (internal->sdlcvt.len_mult > 1)
{
void *rc = SDL_realloc(sample->buffer, sample->buffer_size * internal->sdlcvt.len_mult);
if (rc == NULL)
{
funcs->close(sample);
- SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */
+ SDL_RWseek(internal->rw, pos, RW_SEEK_SET); /* set for next try... */
return 0;
} /* if */
sample->buffer = rc;
} /* if */
@@ -515,11 +517,11 @@
const char **decoderExt = decoder->funcs->info.extensions;
/* skip if we would have tried decoder above... */
while (*decoderExt)
{
- if (SDL_strcasecmp(*decoderExt, ext) == 0)
+ if (ext && SDL_strcasecmp(*decoderExt, ext) == 0)
{
should_try = 0;
break;
} /* if */
decoderExt++;
@@ -788,8 +790,82 @@
Sound_SampleInternal *internal;
BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, -1);
internal = (Sound_SampleInternal *) sample->opaque;
return internal->total_time;
} /* Sound_GetDuration */
+
+
+/* Utility functions ... */
+
+/* The following uses the implementation suggested by
+ * the standard document, assumes RAND_MAX == 32767 */
+static unsigned long __Sound_seed = 1;
+int __Sound_rand(void)
+{
+ __Sound_seed = __Sound_seed * 1103515245 + 12345;
+ return (__Sound_seed / 65536) % 32768;
+}
+void __Sound_srand(unsigned int seed)
+{
+ __Sound_seed = seed;
+}
+
+#if !defined(HAVE_SDL_STRTOKR)
+/* Adapted from _PDCLIB_strtok() of PDClib library at
+ * https://github.com/DevSolar/pdclib.git
+ *
+ * The code was under CC0 license:
+ * https://creativecommons.org/publicdomain/zero/1.0/legalcode
+ */
+char *__Sound_strtokr(char *s1, const char *s2, char **ptr)
+{
+ const char *p = s2;
+
+ if (!s2 || !ptr || (!s1 && !*ptr)) return NULL;
+
+ if (s1 != NULL) { /* new string */
+ *ptr = s1;
+ } else { /* old string continued */
+ if (*ptr == NULL) {
+ /* No old string, no new string, nothing to do */
+ return NULL;
+ }
+ s1 = *ptr;
+ }
+
+ /* skip leading s2 characters */
+ while (*p && *s1) {
+ if (*s1 == *p) {
+ /* found separator; skip and start over */
+ ++s1;
+ p = s2;
+ continue;
+ }
+ ++p;
+ }
+
+ if (! *s1) { /* no more to parse */
+ *ptr = s1;
+ return NULL;
+ }
+
+ /* skipping non-s2 characters */
+ *ptr = s1;
+ while (**ptr) {
+ p = s2;
+ while (*p) {
+ if (**ptr == *p++) {
+ /* found separator; overwrite with '\0', position *ptr, return */
+ *((*ptr)++) = '\0';
+ return s1;
+ }
+ }
+ ++(*ptr);
+ }
+
+ /* parsed to end of string */
+ return s1;
+}
+#endif
/* end of SDL_sound.c ... */